public void SendTest()
        {
            var encoder = new ZlibEncoder();

            byte[] raw1 = null;
            byte[] raw2 = null;

            using (MemoryStream output = new MemoryStream())
            {
                var contents = Encoding.ASCII.GetBytes("hello, world    ");

                // Individual rectangles are compressed using the _same_ zlib stream. Let's send two
                // rectangles to make sure this is the case.
                encoder.Send(output, new VncPixelFormat(), new VncRectangle(), contents);
                raw1 = output.ToArray();

                output.SetLength(0);
                encoder.Send(output, new VncPixelFormat(), new VncRectangle(), contents);
                raw2 = output.ToArray();
            }

            byte[] expected1 = new byte[] { 0x00, 0x00, 0x00, 0x17, 0x78, 0x9c, 0xca, 0x48, 0xcd, 0xc9, 0xc9, 0xd7, 0x51, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff };
            byte[] expected2 = new byte[] { 0x00, 0x00, 0x00, 0x15, 0xca, 0x48, 0xcd, 0xc9, 0xc9, 0xd7, 0x51, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff };

            Assert.Equal(expected1, raw1);
            Assert.Equal(expected2, raw2);
        }
Example #2
0
        static byte[] GzCompress(byte[] input)
        {
            ZlibEncoder encoder = ZlibCodecFactory.NewZlibEncoder(ZlibWrapper.Gzip);
            var         channel = new EmbeddedChannel(encoder);

            Assert.True(channel.WriteOutbound(Unpooled.WrappedBuffer(input)));
            Assert.True(channel.Finish());  // close the channel to indicate end-of-data

            int         outputSize = 0;
            IByteBuffer o;
            var         outbound = new List <IByteBuffer>();

            while ((o = channel.ReadOutbound <IByteBuffer>()) != null)
            {
                outbound.Add(o);
                outputSize += o.ReadableBytes;
            }

            var output    = new byte[outputSize];
            int readCount = 0;

            foreach (IByteBuffer b in outbound)
            {
                int readableBytes = b.ReadableBytes;
                b.ReadBytes(output, readCount, readableBytes);
                b.Release();
                readCount += readableBytes;
            }
            Assert.True(channel.InboundMessages.Count == 0 && channel.OutboundMessages.Count == 0);

            return(output);
        }
        public void EncodingTest()
        {
            var zlib = new ZlibEncoder();

            Assert.Equal(VncEncoding.Zlib, zlib.Encoding);
        }