コード例 #1
0
ファイル: TestEntryUtils.cs プロジェクト: newlysoft/NStorage
        public void TestAreDocumentsIdentical()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryEntry dirA = fs.CreateDirectory("DirA");
            DirectoryEntry dirB = fs.CreateDirectory("DirB");

            DocumentEntry entryA1 = dirA.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA));
            DocumentEntry entryA1b = dirA.CreateDocument("Entry1b", new ByteArrayInputStream(dataSmallA));
            DocumentEntry entryA2 = dirA.CreateDocument("Entry2", new ByteArrayInputStream(dataSmallB));
            DocumentEntry entryB1 = dirB.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA));


            // Names must match
            Assert.AreEqual(false, entryA1.Name.Equals(entryA1b.Name));
            Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(entryA1, entryA1b));

            // Contents must match
            Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(entryA1, entryA2));

            // Parents don't matter if contents + names are the same
            Assert.AreEqual(false, entryA1.Parent.Equals(entryB1.Parent));
            Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(entryA1, entryB1));


            // Can work with NPOIFS + POIFS
            //ByteArrayOutputStream tmpO = new ByteArrayOutputStream();
            MemoryStream tmpO = new MemoryStream();
            fs.WriteFileSystem(tmpO);
            ByteArrayInputStream tmpI = new ByteArrayInputStream(tmpO.ToArray());
            NPOIFSFileSystem nfs = new NPOIFSFileSystem(tmpI);

            DirectoryEntry dN1 = (DirectoryEntry)nfs.Root.GetEntry("DirA");
            DirectoryEntry dN2 = (DirectoryEntry)nfs.Root.GetEntry("DirB");
            DocumentEntry eNA1 = (DocumentEntry)dN1.GetEntry(entryA1.Name);
            DocumentEntry eNA2 = (DocumentEntry)dN1.GetEntry(entryA2.Name);
            DocumentEntry eNB1 = (DocumentEntry)dN2.GetEntry(entryB1.Name);

            Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, eNA2));
            Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, eNB1));

            Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, entryA1b));
            Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, entryA2));

            Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, entryA1));
            Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, entryB1));
        }
コード例 #2
0
        public void TestBadSectorAllocationTableSize_bug48085()
        {
            int BLOCK_SIZE = 512;
            POIFSBigBlockSize bigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;
            Assert.AreEqual(BLOCK_SIZE, bigBlockSize.GetBigBlockSize());

            // 512 bytes take from the start of bugzilla attachment 24444
            byte[] initData = HexRead.ReadFromString(

            "D0 CF 11 E0 A1 B1 1A E1 20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20 3E 20 03 20 FE FF 09 20" +
            "06 20 20 20 20 20 20 20 20 20 20 20 01 20 20 20  01 20 20 20 20 20 20 20 20 10 20 20 02 20 20 20" +
            "02 20 20 20 FE FF FF FF 20 20 20 20 20 20 20 20  "
            );
            // the rest of the block is 'FF'
            byte[] data = new byte[BLOCK_SIZE];
            Arrays.Fill(data, (byte)0xFF);
            Array.Copy(initData, 0, data, 0, initData.Length);

            // similar code to POIFSFileSystem.<init>:
            Stream stream = new ByteArrayInputStream(data);
            HeaderBlock hb;
            RawDataBlockList dataBlocks;
            try
            {
                hb = new HeaderBlock(stream);
                dataBlocks = new RawDataBlockList(stream, bigBlockSize);
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
            try
            {
                new BlockAllocationTableReader(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,
                      hb.BATCount, hb.BATArray, hb.XBATCount,
                        hb.XBATIndex, dataBlocks);
            }
            catch (IOException e)
            {
                // expected during successful test
                Assert.AreEqual("Block count 538976257 is too high. POI maximum is 65535.", e.Message);
            }
            catch (OutOfMemoryException e)
            {
                if (e.StackTrace.Contains("testBadSectorAllocationTableSize"))
                {
                    throw new AssertionException("Identified bug 48085");
                }
            }
        }