Skip to content

Commit

Permalink
tests: make test coverage consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Oct 20, 2022
1 parent 75d1cf8 commit 2956e8b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 53 deletions.
23 changes: 7 additions & 16 deletions test/ICSharpCode.SharpZipLib.Tests/Tar/TarBufferTests.cs
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System.Threading.Tasks;
using ICSharpCode.SharpZipLib.Tar;
using ICSharpCode.SharpZipLib.Tests.TestSupport;
using NUnit.Framework;

namespace ICSharpCode.SharpZipLib.Tests.Tar
Expand All @@ -18,9 +19,7 @@ public void TestSimpleReadWrite()
var writer = TarBuffer.CreateOutputTarBuffer(ms, 1);
writer.IsStreamOwner = false;

var block = new byte[TarBuffer.BlockSize];
var r = new Random();
r.NextBytes(block);
var block = Utils.GetDummyBytes(TarBuffer.BlockSize);

writer.WriteBlock(block);
writer.WriteBlock(block);
Expand All @@ -46,11 +45,8 @@ public void TestSkipBlock()
var writer = TarBuffer.CreateOutputTarBuffer(ms, 1);
writer.IsStreamOwner = false;

var block0 = new byte[TarBuffer.BlockSize];
var block1 = new byte[TarBuffer.BlockSize];
var r = new Random();
r.NextBytes(block0);
r.NextBytes(block1);
var block0 = Utils.GetDummyBytes(TarBuffer.BlockSize);
var block1 = Utils.GetDummyBytes(TarBuffer.BlockSize);

writer.WriteBlock(block0);
writer.WriteBlock(block1);
Expand All @@ -72,9 +68,7 @@ public async Task TestSimpleReadWriteAsync()
var writer = TarBuffer.CreateOutputTarBuffer(ms, 1);
writer.IsStreamOwner = false;

var block = new byte[TarBuffer.BlockSize];
var r = new Random();
r.NextBytes(block);
var block = Utils.GetDummyBytes(TarBuffer.BlockSize);

await writer.WriteBlockAsync(block, CancellationToken.None);
await writer.WriteBlockAsync(block, CancellationToken.None);
Expand Down Expand Up @@ -103,11 +97,8 @@ public async Task TestSkipBlockAsync()
var writer = TarBuffer.CreateOutputTarBuffer(ms, 1);
writer.IsStreamOwner = false;

var block0 = new byte[TarBuffer.BlockSize];
var block1 = new byte[TarBuffer.BlockSize];
var r = new Random();
r.NextBytes(block0);
r.NextBytes(block1);
var block0 = Utils.GetDummyBytes(TarBuffer.BlockSize);
var block1 = Utils.GetDummyBytes(TarBuffer.BlockSize);

await writer.WriteBlockAsync(block0, CancellationToken.None);
await writer.WriteBlockAsync(block1, CancellationToken.None);
Expand Down
8 changes: 2 additions & 6 deletions test/ICSharpCode.SharpZipLib.Tests/Tar/TarInputStreamTests.cs
Expand Up @@ -15,9 +15,7 @@ public class TarInputStreamTests
[Test]
public void TestRead()
{
var entryBytes = new byte[2000];
var r = new Random();
r.NextBytes(entryBytes);
var entryBytes = Utils.GetDummyBytes(2000);
using var ms = new MemoryStream();
using (var tos = new TarOutputStream(ms, Encoding.UTF8) { IsStreamOwner = false })
{
Expand Down Expand Up @@ -54,9 +52,7 @@ public void TestRead()
[Test]
public async Task TestReadAsync()
{
var entryBytes = new byte[2000];
var r = new Random();
r.NextBytes(entryBytes);
var entryBytes = Utils.GetDummyBytes(2000);
using var ms = new MemoryStream();
using (var tos = new TarOutputStream(ms, Encoding.UTF8) { IsStreamOwner = false })
{
Expand Down
5 changes: 1 addition & 4 deletions test/ICSharpCode.SharpZipLib.Tests/Tar/TarTests.cs
Expand Up @@ -140,10 +140,7 @@ public void TrailerContainsNulls()
}
tarOut.PutNextEntry(entry);

byte[] buffer = new byte[TarBuffer.BlockSize];

var r = new Random();
r.NextBytes(buffer);
byte[] buffer = Utils.GetDummyBytes(TarBuffer.BlockSize);

if (iteration > 0)
{
Expand Down
4 changes: 2 additions & 2 deletions test/ICSharpCode.SharpZipLib.Tests/TestSupport/RingBuffer.cs
Expand Up @@ -510,7 +510,7 @@ public void Threaded()

private void Reader()
{
var r = new Random();
var r = new Random(Utils.DefaultSeed);
byte nextValue = 0;

while (readTarget_ > 0)
Expand Down Expand Up @@ -541,7 +541,7 @@ private void Reader()

private void Writer()
{
var r = new Random();
var r = new Random(Utils.DefaultSeed);

byte nextValue = 0;
while (writeTarget_ > 0)
Expand Down
24 changes: 4 additions & 20 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/GeneralHandling.cs
Expand Up @@ -19,18 +19,6 @@ namespace ICSharpCode.SharpZipLib.Tests.Zip
[TestFixture]
public class GeneralHandling : ZipBase
{
private void AddRandomDataToEntry(ZipOutputStream zipStream, int size)
{
if (size > 0)
{
byte[] data = new byte[size];
var rnd = new Random();
rnd.NextBytes(data);

zipStream.Write(data, 0, data.Length);
}
}

private void ExerciseZip(CompressionMethod method, int compressionLevel,
int size, string password, bool canSeek)
{
Expand Down Expand Up @@ -366,16 +354,12 @@ public void StoredNonSeekableKnownSizeNoCrc()
Assert.AreEqual(CompressionMethod.Deflated, entry.CompressionMethod, "Entry should be deflated");
Assert.AreEqual(-1, entry.CompressedSize, "Compressed size should be known");

var rnd = new Random();

int size = TargetSize;
byte[] original = new byte[size];
rnd.NextBytes(original);
byte[] original = Utils.GetDummyBytes(TargetSize);

// Although this could be written in one chunk doing it in lumps
// throws up buffering problems including with encryption the original
// source for this change.
int index = 0;
int index = 0, size = TargetSize;
while (size > 0)
{
int count = (size > 0x200) ? 0x200 : size;
Expand Down Expand Up @@ -565,12 +549,12 @@ public void StoredNonSeekableConvertToDeflate()
outStream.PutNextEntry(entry);
Assert.AreEqual(0, outStream.GetLevel(), "Compression level invalid");

AddRandomDataToEntry(outStream, 100);
Utils.WriteDummyData(outStream, 100);
entry = new ZipEntry("2.tst");
entry.CompressionMethod = CompressionMethod.Deflated;
outStream.PutNextEntry(entry);
Assert.AreEqual(8, outStream.GetLevel(), "Compression level invalid");
AddRandomDataToEntry(outStream, 100);
Utils.WriteDummyData(outStream, 100);

outStream.Close();
}
Expand Down
7 changes: 2 additions & 5 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/ZipTests.cs
Expand Up @@ -25,8 +25,7 @@ internal class RuntimeInfo
original = new byte[Size];
if (random)
{
var rnd = new Random();
rnd.NextBytes(original);
original = Utils.GetDummyBytes(Size);
}
else
{
Expand Down Expand Up @@ -251,9 +250,7 @@ protected byte[] MakeInMemoryZip(bool withSeek, params object[] createSpecs)

if (size > 0)
{
var rnd = new Random();
original = new byte[size];
rnd.NextBytes(original);
original = Utils.GetDummyBytes(size);

// Although this could be written in one chunk doing it in lumps
// throws up buffering problems including with encryption the original
Expand Down

0 comments on commit 2956e8b

Please sign in to comment.