Beispiel #1
0
        private void VerifyReadingProperty(int index, byte[] input, int offset, string name)
        {
            DocumentProperty property = new DocumentProperty(index, input, offset);
            MemoryStream     stream   = new MemoryStream(128);

            byte[] expected = new byte[128];

            Array.Copy(input, offset, expected, 0, 128);
            property.WriteData(stream);
            byte[] output = stream.ToArray();

            Assert.AreEqual(128, output.Length);
            for (int j = 0; j < 128; j++)
            {
                Assert.AreEqual(expected[j],
                                output[j], "mismatch at offset " + j);
            }
            Assert.AreEqual(index, property.Index);
            Assert.AreEqual(name, property.Name);
        }
Beispiel #2
0
        private void VerifyProperty(string name, int size)
        {
            DocumentProperty property = new DocumentProperty(name, size);

            if (size >= 4096)
            {
                Assert.IsTrue(!property.ShouldUseSmallBlocks);
            }
            else
            {
                Assert.IsTrue(property.ShouldUseSmallBlocks);
            }
            byte[] Testblock = new byte[128];
            int    index     = 0;

            for (; index < 0x40; index++)
            {
                Testblock[index] = (byte)0;
            }
            int limit = Math.Min(31, name.Length);

            Testblock[index++] = (byte)(2 * (limit + 1));
            Testblock[index++] = (byte)0;
            Testblock[index++] = (byte)2;
            Testblock[index++] = (byte)1;
            for (; index < 0x50; index++)
            {
                Testblock[index] = (byte)0xFF;
            }
            for (; index < 0x78; index++)
            {
                Testblock[index] = (byte)0;
            }
            int sz = size;

            Testblock[index++] = (byte)sz;
            sz /= 256;
            Testblock[index++] = (byte)sz;
            sz /= 256;
            Testblock[index++] = (byte)sz;
            sz /= 256;
            Testblock[index++] = (byte)sz;
            for (; index < 0x80; index++)
            {
                Testblock[index] = (byte)0x0;
            }
            byte[] name_bytes = Encoding.UTF8.GetBytes(name);

            for (index = 0; index < limit; index++)
            {
                Testblock[index * 2] = name_bytes[index];
            }
            MemoryStream stream = new MemoryStream(512);

            property.WriteData(stream);
            byte[] output = stream.ToArray();

            Assert.AreEqual(Testblock.Length, output.Length);
            for (int j = 0; j < Testblock.Length; j++)
            {
                Assert.AreEqual(Testblock[j],
                                output[j], "mismatch at offset " + j);
            }
        }
Beispiel #3
0
        public void TestPOIFSDocument()
        {
            // Verify correct number of blocks Get Created for document
            // that is exact multituple of block size
            POIFSDocument document;

            byte[] array = new byte[4096];

            for (int j = 0; j < array.Length; j++)
            {
                array[j] = (byte)j;
            }
            document = new POIFSDocument("foo", new SlowInputStream(new MemoryStream(array)));
            checkDocument(document, array);

            // Verify correct number of blocks Get Created for document
            // that is not an exact multiple of block size
            array = new byte[4097];
            for (int j = 0; j < array.Length; j++)
            {
                array[j] = (byte)j;
            }
            document = new POIFSDocument("bar", new MemoryStream(array));
            checkDocument(document, array);

            // Verify correct number of blocks Get Created for document
            // that is small
            array = new byte[4095];
            for (int j = 0; j < array.Length; j++)
            {
                array[j] = (byte)j;
            }
            document = new POIFSDocument("_bar", new MemoryStream(array));
            checkDocument(document, array);

            // Verify correct number of blocks Get Created for document
            // that is rather small
            array = new byte[199];
            for (int j = 0; j < array.Length; j++)
            {
                array[j] = (byte)j;
            }
            document = new POIFSDocument("_bar2",
                                         new MemoryStream(array));
            checkDocument(document, array);

            // Verify that output is correct
            array = new byte[4097];
            for (int j = 0; j < array.Length; j++)
            {
                array[j] = (byte)j;
            }
            document = new POIFSDocument("foobar",
                                         new MemoryStream(array));
            checkDocument(document, array);
            document.StartBlock = 0x12345678;   // what a big file!!
            DocumentProperty property = document.DocumentProperty;
            MemoryStream     stream   = new MemoryStream();

            property.WriteData(stream);
            byte[] output = stream.ToArray();
            byte[] array2 =
            {
                ( byte )'f',            ( byte )0,              ( byte )'o',            ( byte )0,              ( byte )'o',
                ( byte )0,              ( byte )'b',            ( byte )0,              ( byte )'a',            ( byte )0,
                ( byte )'r',            ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )14,
                ( byte )0,              ( byte )2,              ( byte )1,              unchecked (( byte )-1), unchecked (( byte )-1),
                unchecked (( byte )-1), unchecked (( byte )-1), unchecked (( byte )-1), unchecked (( byte )-1), unchecked (( byte )-1),
                unchecked (( byte )-1), unchecked (( byte )-1), unchecked (( byte )-1), unchecked (( byte )-1), unchecked (( byte )-1),
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0x78,           ( byte )0x56,           ( byte )0x34,
                ( byte )0x12,           ( byte )1,              ( byte )16,             ( byte )0,              ( byte )0,
                ( byte )0,              ( byte )0,              ( byte )0,              ( byte )0
            };

            Assert.AreEqual(array2.Length, output.Length);
            for (int j = 0; j < output.Length; j++)
            {
                Assert.AreEqual(array2[j],
                                output[j], "Checking property offset " + j);
            }
        }