コード例 #1
0
        public static void VerifyBlocksCreated(BlockAllocationTableWriter table, int count)
        {
            MemoryStream stream = new MemoryStream();

            table.WriteBlocks(stream);
            byte[] output = stream.ToArray();

            Assert.AreEqual(count * 512, output.Length);
        }
コード例 #2
0
        public void TestProduct()
        {
            BlockAllocationTableWriter table = new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);

            for (int i = 1; i <= 22; i++)
            {
                table.AllocateSpace(i);
            }

            table.CreateBlocks();
            MemoryStream stream = new MemoryStream();

            table.WriteBlocks(stream);
            byte[] output = stream.ToArray();

            Assert.AreEqual(1024, output.Length);
            byte[] expected = new byte[1024];

            for (int i = 0; i < expected.Length; i++)
            {
                expected[i] = (byte)0xFF;
            }
            int offset     = 0;
            int blockIndex = 1;

            for (int i = 1; i <= 22; i++)
            {
                int limit = i - 1;

                for (int j = 0; j < limit; j++)
                {
                    LittleEndian.PutInt(expected, offset, blockIndex++);
                    offset += LittleEndianConsts.INT_SIZE;
                }

                LittleEndian.PutInt(expected, offset, POIFSConstants.END_OF_CHAIN);

                offset += 4;
                blockIndex++;
            }

            LittleEndian.PutInt(expected, offset, blockIndex++);
            offset += LittleEndianConsts.INT_SIZE;
            LittleEndian.PutInt(expected, offset, POIFSConstants.END_OF_CHAIN);

            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], output[i], "At offset " + i);
            }
        }
コード例 #3
0
        public void TestProduct()
        {
            BlockAllocationTableWriter table = new BlockAllocationTableWriter();

            for (int k = 1; k <= 22; k++)
            {
                table.AllocateSpace(k);
            }
            table.CreateBlocks();
            MemoryStream stream = new MemoryStream();

            table.WriteBlocks(stream);
            byte[] output = stream.ToArray();

            Assert.AreEqual(1024, output.Length);
            byte[] expected = new byte[1024];

            for (int i = 0; i < expected.Length; i++)
            {
                expected[i] = (byte)0xFF;
            }
            int offset      = 0;
            int block_index = 1;

            for (int k = 1; k <= 22; k++)
            {
                int limit = k - 1;

                for (int j = 0; j < limit; j++)
                {
                    LittleEndian.PutInt(expected, offset, block_index++);
                    offset += LittleEndianConstants.INT_SIZE;
                }
                LittleEndian.PutInt(expected, offset,
                                    POIFSConstants.END_OF_CHAIN);
                offset += 4;
                block_index++;
            }

            // Add BAT block indices
            LittleEndian.PutInt(expected, offset, block_index++);
            offset += LittleEndianConstants.INT_SIZE;
            LittleEndian.PutInt(expected, offset, POIFSConstants.END_OF_CHAIN);
            for (int k = 0; k < expected.Length; k++)
            {
                Assert.AreEqual(expected[k], output[k], "At offset " + k);
            }
        }