예제 #1
0
        public void Test4KBlocks()
        {

            Stream inp = _samples.OpenResourceAsStream("BlockSize4096.zvi");
            try
            {
                // First up, check that we can process the header properly
                HeaderBlock header_block = new HeaderBlock(inp);
                POIFSBigBlockSize bigBlockSize = header_block.BigBlockSize;
                Assert.AreEqual(4096, bigBlockSize.GetBigBlockSize());

                // Check the fat info looks sane
                Assert.AreEqual(1, header_block.BATArray.Length);
                Assert.AreEqual(1, header_block.BATCount);
                Assert.AreEqual(0, header_block.XBATCount);

                // Now check we can get the basic fat
                RawDataBlockList data_blocks = new RawDataBlockList(inp, bigBlockSize);
                Assert.AreEqual(15, data_blocks.BlockCount());

                // Now try and open properly
                POIFSFileSystem fs = new POIFSFileSystem(
                      _samples.OpenResourceAsStream("BlockSize4096.zvi")
                );
                Assert.IsTrue(fs.Root.EntryCount > 3);

                // Check we can get at all the contents
                CheckAllDirectoryContents(fs.Root);


                // Finally, check we can do a similar 512byte one too
                fs = new POIFSFileSystem(
                     _samples.OpenResourceAsStream("BlockSize512.zvi")
               );
                Assert.IsTrue(fs.Root.EntryCount > 3);
                CheckAllDirectoryContents(fs.Root);
            }
            finally
            {
                inp.Close();
            }
        }
예제 #2
0
        public void TestBATandXBAT()
        {
            byte[] hugeStream = new byte[8 * 1024 * 1024];
            POIFSFileSystem fs = new POIFSFileSystem();
            fs.Root.CreateDocument("BIG", new MemoryStream(hugeStream));

            MemoryStream baos = new MemoryStream();
            fs.WriteFileSystem(baos);
            byte[] fsData = baos.ToArray();


            // Check the header was written properly
            Stream inp = new MemoryStream(fsData);
            HeaderBlock header = new HeaderBlock(inp);
            Assert.AreEqual(109 + 21, header.BATCount);
            Assert.AreEqual(1, header.XBATCount);

            ByteBuffer xbatData = ByteBuffer.CreateBuffer(512);
            xbatData.Write(fsData, (1 + header.XBATIndex) * 512, 512);

            xbatData.Position = 0;

            BATBlock xbat = BATBlock.CreateBATBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, xbatData);

            for (int i = 0; i < 21; i++)
            {
                Assert.IsTrue(xbat.GetValueAt(i) != POIFSConstants.UNUSED_BLOCK);
            }

            for (int i = 21; i < 127; i++)
                Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, xbat.GetValueAt(i));

            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, xbat.GetValueAt(127));

            RawDataBlockList blockList = new RawDataBlockList(inp, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
            Assert.AreEqual(fsData.Length / 512, blockList.BlockCount() + 1);
            new BlockAllocationTableReader(header.BigBlockSize,
                                            header.BATCount,
                                            header.BATArray,
                                            header.XBATCount,
                                            header.XBATIndex,
                                            blockList);
            Assert.AreEqual(fsData.Length / 512, blockList.BlockCount() + 1);

            //fs = null;
            //fs = new POIFSFileSystem(new MemoryStream(fsData));


            //DirectoryNode root = fs.Root;
            //Assert.AreEqual(1, root.EntryCount);
            //DocumentNode big = (DocumentNode)root.GetEntry("BIG");
            //Assert.AreEqual(hugeStream.Length, big.Size);

        }