From 34d7472c4379770ec27140e902ed25b87d61c72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nils=20m=C3=A5s=C3=A9n?= Date: Tue, 6 Aug 2019 22:47:35 +0200 Subject: [PATCH] Merge PR #371: Add test for GZip with small buffer Add test reproducing issue #360 --- .../GZip/GZipTests.cs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/ICSharpCode.SharpZipLib.Tests/GZip/GZipTests.cs b/test/ICSharpCode.SharpZipLib.Tests/GZip/GZipTests.cs index ea3399ac4..a8138aa6a 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/GZip/GZipTests.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/GZip/GZipTests.cs @@ -344,6 +344,56 @@ public void FlushToUnderlyingStream() } } + [Test] + [Category("GZip")] + public void SmallBufferDecompression() + { + var outputBufferSize = 100000; + var inputBufferSize = outputBufferSize * 4; + + var outputBuffer = new byte[outputBufferSize]; + var inputBuffer = new byte[inputBufferSize]; + + using (var msGzip = new MemoryStream()) + { + using (var gzos = new GZipOutputStream(msGzip)) + { + gzos.IsStreamOwner = false; + + var rnd = new Random(0); + rnd.NextBytes(inputBuffer); + gzos.Write(inputBuffer, 0, inputBuffer.Length); + + gzos.Flush(); + gzos.Finish(); + } + + msGzip.Seek(0, SeekOrigin.Begin); + + + using (var gzis = new GZipInputStream(msGzip)) + using (var msRaw = new MemoryStream()) + { + + int readOut; + while ((readOut = gzis.Read(outputBuffer, 0, outputBuffer.Length)) > 0) + { + msRaw.Write(outputBuffer, 0, readOut); + } + + var resultBuffer = msRaw.ToArray(); + + for (var i = 0; i < resultBuffer.Length; i++) + { + Assert.AreEqual(inputBuffer[i], resultBuffer[i]); + } + + + } + } + + } + [Test] [Category("GZip")] [Category("Performance")]