Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test for issue #123 #469

Merged
merged 1 commit into from
May 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ICSharpCode.SharpZipLib.Tests.TestSupport;
using ICSharpCode.SharpZipLib.Zip;
using NUnit.Framework;
using System;
using System.IO;

namespace ICSharpCode.SharpZipLib.Tests.Zip
Expand Down Expand Up @@ -191,6 +192,49 @@ public void EmptyZipEntries()
Assert.AreEqual(extractCount, 0, "No data should be read from empty entries");
}

/// <summary>
/// Test that calling Write with 0 bytes behaves.
/// See issue @ https://github.com/icsharpcode/SharpZipLib/issues/123.
/// </summary>
[Test]
[Category("Zip")]
public void TestZeroByteWrite()
{
using (var ms = new MemoryStreamWithoutSeek())
{
using (var outStream = new ZipOutputStream(ms) { IsStreamOwner = false })
{
var ze = new ZipEntry("Striped Marlin");
outStream.PutNextEntry(ze);

var buffer = Array.Empty<byte>();
outStream.Write(buffer, 0, 0);
}

ms.Seek(0, SeekOrigin.Begin);

using (var inStream = new ZipInputStream(ms) { IsStreamOwner = false })
{
int extractCount = 0;
byte[] decompressedData = new byte[100];

while (inStream.GetNextEntry() != null)
{
while (true)
{
int numRead = inStream.Read(decompressedData, extractCount, decompressedData.Length);
if (numRead <= 0)
{
break;
}
extractCount += numRead;
}
}
Assert.Zero(extractCount, "No data should be read from empty entries");
}
}
}

[Test]
[Category("Zip")]
public void WriteZipStreamWithNoCompression([Values(0, 1, 256)] int contentLength)
Expand Down