Пример #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);
        }