コード例 #1
0
        public void TestRtfCompressedToRtfByteByByte()
        {
            var          input = new byte[] { (byte)'-', 0x00, 0x00, 0x00, (byte)'+', 0x00, 0x00, 0x00, (byte)'L', (byte)'Z', (byte)'F', (byte)'u', 0xf1, 0xc5, 0xc7, 0xa7, 0x03, 0x00, (byte)'\n', 0x00, (byte)'r', (byte)'c', (byte)'p', (byte)'g', (byte)'1', (byte)'2', (byte)'5', (byte)'B', (byte)'2', (byte)'\n', 0xf3, (byte)' ', (byte)'h', (byte)'e', (byte)'l', (byte)'\t', 0x00, (byte)' ', (byte)'b', (byte)'w', 0x05, 0xb0, (byte)'l', (byte)'d', (byte)'}', (byte)'\n', 0x80, 0x0f, 0xa0 };
            const string expected = "{\\rtf1\\ansi\\ansicpg1252\\pard hello world}\r\n";
            var          filter = new RtfCompressedToRtf();
            int          outputIndex, outputLength;

            byte[] output;

            using (var memory = new MemoryStream()) {
                for (int i = 0; i < input.Length; i++)
                {
                    output = filter.Filter(input, i, 1, out outputIndex, out outputLength);
                    memory.Write(output, outputIndex, outputLength);
                }

                output = filter.Flush(input, 0, 0, out outputIndex, out outputLength);
                memory.Write(output, outputIndex, outputLength);

                output = memory.ToArray();
            }

            Assert.AreEqual(43, output.Length, "outputLength");
            Assert.IsTrue(filter.IsValidCrc32, "IsValidCrc32");
            Assert.AreEqual(RtfCompressionMode.Compressed, filter.CompressionMode, "ComnpressionMode");

            var text = Encoding.ASCII.GetString(output);

            Assert.AreEqual(expected, text);
        }
コード例 #2
0
        public void TestRtfCompressedToRtfRawByteByByte()
        {
            var          input = new byte[] { (byte)'.', 0x00, 0x00, 0x00, (byte)'\"', 0x00, 0x00, 0x00, (byte)'M', (byte)'E', (byte)'L', (byte)'A', (byte)' ', 0xdf, 0x12, 0xce, (byte)'{', (byte)'\\', (byte)'r', (byte)'t', (byte)'f', (byte)'1', (byte)'\\', (byte)'a', (byte)'n', (byte)'s', (byte)'i', (byte)'\\', (byte)'a', (byte)'n', (byte)'s', (byte)'i', (byte)'c', (byte)'p', (byte)'g', (byte)'1', (byte)'2', (byte)'5', (byte)'2', (byte)'\\', (byte)'p', (byte)'a', (byte)'r', (byte)'d', (byte)' ', (byte)'t', (byte)'e', (byte)'s', (byte)'t', (byte)'}' };
            const string expected = "{\\rtf1\\ansi\\ansicpg1252\\pard test}";
            var          filter = new RtfCompressedToRtf();
            int          outputIndex, outputLength;

            byte[] output;

            using (var memory = new MemoryStream()) {
                for (int i = 0; i < input.Length; i++)
                {
                    output = filter.Filter(input, i, 1, out outputIndex, out outputLength);
                    memory.Write(output, outputIndex, outputLength);
                }

                output = filter.Flush(input, 0, 0, out outputIndex, out outputLength);
                memory.Write(output, outputIndex, outputLength);

                output = memory.ToArray();
            }

            Assert.AreEqual(34, output.Length, "outputLength");
            Assert.IsTrue(filter.IsValidCrc32, "IsValidCrc32");
            Assert.AreEqual(RtfCompressionMode.Uncompressed, filter.CompressionMode, "ComnpressionMode");

            var text = Encoding.ASCII.GetString(output);

            Assert.AreEqual(expected, text);
        }
コード例 #3
0
        public void TestRtfCompressedToRtfInvalidCrc()
        {
            var input = new byte[] { 0x10, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, (byte)'L', (byte)'Z', (byte)'F', (byte)'u', 0xff, 0xff, 0xff, 0xff };
            var filter = new RtfCompressedToRtf();
            int outputIndex, outputLength;

            byte[] output;

            output = filter.Flush(input, 0, input.Length, out outputIndex, out outputLength);

            Assert.AreEqual(0, outputIndex, "outputIndex");
            Assert.AreEqual(0, outputLength, "outputLength");
            Assert.IsFalse(filter.IsValidCrc32, "IsValidCrc32");
            Assert.AreEqual(RtfCompressionMode.Compressed, filter.CompressionMode, "ComnpressionMode");
        }
コード例 #4
0
        public void TestRtfCompressedToRtfUnknownCompressionType()
        {
            var input = new byte[] { 0x10, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, (byte)'A', (byte)'B', (byte)'C', (byte)'D', 0xff, 0xff, 0xff, 0xff };
            var filter = new RtfCompressedToRtf();
            int outputIndex, outputLength;

            byte[] output;

            output = filter.Flush(input, 0, input.Length, out outputIndex, out outputLength);

            Assert.AreEqual(16, outputIndex, "outputIndex");
            Assert.AreEqual(0, outputLength, "outputLength");
            Assert.IsFalse(filter.IsValidCrc32, "IsValidCrc32");
            Assert.AreEqual((RtfCompressionMode)1145258561, filter.CompressionMode, "ComnpressionMode");
        }
コード例 #5
0
        public void TestRtfCompressedToRtfRaw()
        {
            var          input = new byte[] { (byte)'.', 0x00, 0x00, 0x00, (byte)'\"', 0x00, 0x00, 0x00, (byte)'M', (byte)'E', (byte)'L', (byte)'A', (byte)' ', 0xdf, 0x12, 0xce, (byte)'{', (byte)'\\', (byte)'r', (byte)'t', (byte)'f', (byte)'1', (byte)'\\', (byte)'a', (byte)'n', (byte)'s', (byte)'i', (byte)'\\', (byte)'a', (byte)'n', (byte)'s', (byte)'i', (byte)'c', (byte)'p', (byte)'g', (byte)'1', (byte)'2', (byte)'5', (byte)'2', (byte)'\\', (byte)'p', (byte)'a', (byte)'r', (byte)'d', (byte)' ', (byte)'t', (byte)'e', (byte)'s', (byte)'t', (byte)'}' };
            const string expected = "{\\rtf1\\ansi\\ansicpg1252\\pard test}";
            var          filter = new RtfCompressedToRtf();
            int          outputIndex, outputLength;

            byte[] output;

            output = filter.Flush(input, 0, input.Length, out outputIndex, out outputLength);

            Assert.AreEqual(16, outputIndex, "outputIndex");
            Assert.AreEqual(34, outputLength, "outputLength");
            Assert.IsTrue(filter.IsValidCrc32, "IsValidCrc32");
            Assert.AreEqual(RtfCompressionMode.Uncompressed, filter.CompressionMode, "ComnpressionMode");

            var text = Encoding.ASCII.GetString(output, outputIndex, outputLength);

            Assert.AreEqual(expected, text);
        }
コード例 #6
0
        public void TestCrossingWritePositionExample()
        {
            // http://msdn.microsoft.com/en-us/library/ee158471(v=exchg.80).aspx
            var compressedRtfData = new byte[] {
                // header
                0x1a, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x4c, 0x5a, 0x46, 0x75, 0xe2, 0xd4, 0x4b, 0x51,

                // data
                0x41, 0x00, 0x04, 0x20, 0x57, 0x58, 0x59, 0x5a, 0x0d, 0x6e, 0x7d, 0x01, 0x0e, 0xb0
            };
            var expected = "{\\rtf1 WXYZWXYZWXYZWXYZWXYZ}";

            var converter = new RtfCompressedToRtf();
            int outputLength, outputIndex;

            var decompressed = converter.Flush(compressedRtfData, 0, compressedRtfData.Length, out outputIndex, out outputLength);
            var text         = Encoding.UTF8.GetString(decompressed, outputIndex, outputLength);

            Assert.AreEqual(expected, text, "Decompressed RTF data does not match.");
            Assert.IsTrue(converter.IsValidCrc32, "Invalid CRC32 checksum.");
        }
コード例 #7
0
        public void TestSimpleCompressedRtfExample()
        {
            // http://msdn.microsoft.com/en-us/library/ee217938(v=exchg.80).aspx
            var compressedRtfData = new byte[] {
                // header
                0x2d, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x4c, 0x5a, 0x46, 0x75, 0xf1, 0xc5, 0xc7, 0xa7,

                // data
                0x03, 0x00, 0x0a, 0x00, 0x72, 0x63, 0x70, 0x67, 0x31, 0x32, 0x35, 0x42, 0x32, 0x0a, 0xf3, 0x20,
                0x68, 0x65, 0x6c, 0x09, 0x00, 0x20, 0x62, 0x77, 0x05, 0xb0, 0x6c, 0x64, 0x7d, 0x0a, 0x80, 0x0f,
                0xa0
            };
            var expected = "{\\rtf1\\ansi\\ansicpg1252\\pard hello world}\r\n";

            var converter = new RtfCompressedToRtf();
            int outputLength, outputIndex;

            var decompressed = converter.Flush(compressedRtfData, 0, compressedRtfData.Length, out outputIndex, out outputLength);
            var text         = Encoding.UTF8.GetString(decompressed, outputIndex, outputLength);

            Assert.AreEqual(expected, text, "Decompressed RTF data does not match.");
            Assert.IsTrue(converter.IsValidCrc32, "Invalid CRC32 checksum.");
        }