public void RoundTrip_StreamingStreaming()
        {
            var testStream = DataGenerator.GetLargeStream(DataFill.Sequential);
            var tempStream = new MemoryStream();

            using (var compressionStream = new CompressorStream(tempStream))
                testStream.CopyTo(compressionStream);

            var resultStream = new MemoryStream();

            tempStream.Position = 0;
            using (var decompressionsStream = new DecompressorStream(tempStream))
                decompressionsStream.CopyTo(resultStream);

            Validate(testStream.ToArray(), resultStream.ToArray());
        }
        public void RoundTrip_BatchToStreaming()
        {
            var testBuffer = DataGenerator.GetLargeBuffer(DataFill.Sequential);

            byte[] compressedBuffer;

            using (var compressor = new Compressor())
                compressedBuffer = compressor.Wrap(testBuffer);

            var resultStream = new MemoryStream();

            using (var decompressionStream = new DecompressorStream(new MemoryStream(compressedBuffer)))
                decompressionStream.CopyTo(resultStream);

            Validate(testBuffer, resultStream.ToArray());
        }
        public virtual void TestBuiltInGzipDecompressorExceptions()
        {
            BuiltInGzipDecompressor decompresser = new BuiltInGzipDecompressor();

            try
            {
                decompresser.SetInput(null, 0, 1);
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception ex)
            {
                // expected
                NUnit.Framework.Assert.Fail("testBuiltInGzipDecompressorExceptions npe error " +
                                            ex);
            }
            try
            {
                decompresser.SetInput(new byte[] { 0 }, 0, -1);
            }
            catch (IndexOutOfRangeException)
            {
            }
            catch (Exception ex)
            {
                // expected
                NUnit.Framework.Assert.Fail("testBuiltInGzipDecompressorExceptions aioob error" +
                                            ex);
            }
            Assert.True("decompresser.getBytesRead error", decompresser.GetBytesRead
                            () == 0);
            Assert.True("decompresser.getRemaining error", decompresser.GetRemaining
                            () == 0);
            decompresser.Reset();
            decompresser.End();
            InputStream decompStream = null;

            try
            {
                // invalid 0 and 1 bytes , must be 31, -117
                int             buffSize     = 1 * 1024;
                byte[]          buffer       = new byte[buffSize];
                Decompressor    decompressor = new BuiltInGzipDecompressor();
                DataInputBuffer gzbuf        = new DataInputBuffer();
                decompStream = new DecompressorStream(gzbuf, decompressor);
                gzbuf.Reset(new byte[] { 0, 0, 1, 1, 1, 1, 11, 1, 1, 1, 1 }, 11);
                decompStream.Read(buffer);
            }
            catch (IOException)
            {
            }
            catch (Exception ex)
            {
                // expected
                NUnit.Framework.Assert.Fail("invalid 0 and 1 byte in gzip stream" + ex);
            }
            // invalid 2 byte, must be 8
            try
            {
                int             buffSize     = 1 * 1024;
                byte[]          buffer       = new byte[buffSize];
                Decompressor    decompressor = new BuiltInGzipDecompressor();
                DataInputBuffer gzbuf        = new DataInputBuffer();
                decompStream = new DecompressorStream(gzbuf, decompressor);
                gzbuf.Reset(new byte[] { 31, unchecked ((byte)(-117)), 7, 1, 1, 1, 1, 11, 1, 1, 1,
                                         1 }, 11);
                decompStream.Read(buffer);
            }
            catch (IOException)
            {
            }
            catch (Exception ex)
            {
                // expected
                NUnit.Framework.Assert.Fail("invalid 2 byte in gzip stream" + ex);
            }
            try
            {
                int             buffSize     = 1 * 1024;
                byte[]          buffer       = new byte[buffSize];
                Decompressor    decompressor = new BuiltInGzipDecompressor();
                DataInputBuffer gzbuf        = new DataInputBuffer();
                decompStream = new DecompressorStream(gzbuf, decompressor);
                gzbuf.Reset(new byte[] { 31, unchecked ((byte)(-117)), 8, unchecked ((byte)(-32)),
                                         1, 1, 1, 11, 1, 1, 1, 1 }, 11);
                decompStream.Read(buffer);
            }
            catch (IOException)
            {
            }
            catch (Exception ex)
            {
                // expected
                NUnit.Framework.Assert.Fail("invalid 3 byte in gzip stream" + ex);
            }
            try
            {
                int             buffSize     = 1 * 1024;
                byte[]          buffer       = new byte[buffSize];
                Decompressor    decompressor = new BuiltInGzipDecompressor();
                DataInputBuffer gzbuf        = new DataInputBuffer();
                decompStream = new DecompressorStream(gzbuf, decompressor);
                gzbuf.Reset(new byte[] { 31, unchecked ((byte)(-117)), 8, 4, 1, 1, 1, 11, 1, 1, 1,
                                         1 }, 11);
                decompStream.Read(buffer);
            }
            catch (IOException)
            {
            }
            catch (Exception ex)
            {
                // expected
                NUnit.Framework.Assert.Fail("invalid 3 byte make hasExtraField" + ex);
            }
        }