Beispiel #1
0
        public void TestShortConstructor()
        {
            // Get the logger to be used
            DummyPOILogger logger = (DummyPOILogger)POILogFactory.GetLogger(
                typeof(RawDataBlock)
                );

            logger.Reset(); // the logger may have been used before
            Assert.AreEqual(0, logger.logged.Count);

            // Test for various short sizes
            for (int k = 2049; k < 2560; k++)
            {
                byte[] data = new byte[k];

                for (int j = 0; j < k; j++)
                {
                    data[j] = (byte)j;
                }

                // Check we logged the error
                logger.Reset();
                new RawDataBlockList(new MemoryStream(data), POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
                Assert.AreEqual(1, logger.logged.Count);
            }
        }
Beispiel #2
0
        public void TestShortConstructor()
        {
            //// Get the logger to be used
            DummyPOILogger logger = (DummyPOILogger)POILogFactory.GetLogger(typeof(RawDataBlock));

            logger.Reset(); // the logger may have been used before
            Assert.AreEqual(0, logger.logged.Count);

            // Test for various data sizes
            for (int k = 1; k <= 512; k++)
            {
                byte[] data = new byte[k];

                for (int j = 0; j < k; j++)
                {
                    data[j] = (byte)j;
                }
                RawDataBlock block = null;

                logger.Reset();
                Assert.AreEqual(0, logger.logged.Count);

                // Have it created
                block = new RawDataBlock(new MemoryStream(data));
                Assert.IsNotNull(block);

                // Check for the warning Is there for <512
                if (k < 512)
                {
                    Assert.AreEqual(
                        1, logger.logged.Count, "Warning on " + k + " byte short block"
                        );

                    // Build the expected warning message, and check
                    String bts = k + " byte";
                    if (k > 1)
                    {
                        bts += "s";
                    }

                    Assert.AreEqual(
                        (String)logger.logged[0],
                        "7 - Unable to read entire block; " + bts + " read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!"
                        );
                }
                else
                {
                    Assert.AreEqual(0, logger.logged.Count);
                }
            }
        }
Beispiel #3
0
        public void TestSlowInputStream()
        {
            // Get the logger to be used
            DummyPOILogger logger = (DummyPOILogger)POILogFactory.GetLogger(typeof(RawDataBlock));

            logger.Reset(); // the logger may have been used before
            Assert.AreEqual(0, logger.logged.Count);

            // Test for various ok data sizes
            for (int k = 1; k < 512; k++)
            {
                byte[] data = new byte[512];
                for (int j = 0; j < data.Length; j++)
                {
                    data[j] = (byte)j;
                }

                // Shouldn't complain, as there Is enough data,
                //  even if it dribbles through
                RawDataBlock block =
                    new RawDataBlock(new SlowInputStream(data, 512));   //k is changed to 512
                Assert.IsFalse(block.EOF);
            }

            // But if there wasn't enough data available, will
            //  complain
            for (int k = 1; k < 512; k++)
            {
                byte[] data = new byte[511];
                for (int j = 0; j < data.Length; j++)
                {
                    data[j] = (byte)j;
                }

                logger.Reset();
                Assert.AreEqual(0, logger.logged.Count);

                // Should complain, as there Isn't enough data
                RawDataBlock block =
                    new RawDataBlock(new SlowInputStream(data, k));
                Assert.IsNotNull(block);
                Assert.AreEqual(
                    1, logger.logged.Count, "Warning on " + k + " byte short block"
                    );
            }
        }