public void EncodeDecode(CompressionLevel level)
        {
            foreach (CompressionStrategy strategy in (CompressionStrategy[])Enum.GetValues(typeof(CompressionStrategy)))
            {
                const int count     = 2 * 4096 * 4;
                byte[]    expected  = GetBuffer(count);
                byte[]    reference = new byte[count];
                byte[]    actual    = new byte[count];

                using (var compressed = new MemoryStream())
                {
                    var options = new ZlibOptions {
                        CompressionStrategy = strategy, CompressionLevel = level
                    };
                    using (var deflate = new ZlibOutputStream(compressed, options))
                    {
                        deflate.Write(expected, 0, expected.Length);
                    }

                    compressed.Position = 0;

                    using (var refInflate = new InflaterInputStream(compressed))
                    {
                        refInflate.IsStreamOwner = false;
                        refInflate.Read(reference, 0, reference.Length);
                    }

                    compressed.Position = 0;

                    using (var inflate = new ZlibInputStream(compressed))
                    {
                        inflate.Read(actual, 0, actual.Length);
                    }
                }

                for (int i = 0; i < expected.Length; i++)
                {
                    byte e = expected[i];
                    byte r = reference[i];
                    byte a = actual[i];

                    Assert.Equal(e, r);
                    Assert.Equal(e, a);
                }
            }
        }
Example #2
0
        public void EncodeDecode(CompressionLevel compression)
        {
            const int count     = 2 * 4096 * 4;
            var       expected  = GetBuffer(count);
            var       reference = new byte[count];
            var       actual    = new byte[count];

            using (var compressed = new MemoryStream())
            {
                using (var deflate = new ZlibOutputStream(compressed, compression))
                {
                    deflate.Write(expected);
                }

                compressed.Position = 0;

                using (var refInflate = new InflaterInputStream(compressed))
                {
                    refInflate.IsStreamOwner = false;
                    refInflate.Read(reference);
                }

                compressed.Position = 0;

                using (var inflate = new ZlibInputStream(compressed))
                {
                    inflate.Read(actual);
                }
            }

            for (int i = 0; i < expected.Length; i++)
            {
                byte e = expected[i];
                byte r = reference[i];
                byte a = actual[i];

                Assert.Equal(e, r);
                Assert.Equal(e, a);
            }
        }