diff --git a/test/ICSharpCode.SharpZipLib.Tests/Tar/TarBufferTests.cs b/test/ICSharpCode.SharpZipLib.Tests/Tar/TarBufferTests.cs index 3974ffb5..6f7ffedc 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Tar/TarBufferTests.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Tar/TarBufferTests.cs @@ -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 @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/test/ICSharpCode.SharpZipLib.Tests/Tar/TarInputStreamTests.cs b/test/ICSharpCode.SharpZipLib.Tests/Tar/TarInputStreamTests.cs index fb5a2671..a69cfdf6 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Tar/TarInputStreamTests.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Tar/TarInputStreamTests.cs @@ -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 }) { @@ -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 }) { diff --git a/test/ICSharpCode.SharpZipLib.Tests/Tar/TarTests.cs b/test/ICSharpCode.SharpZipLib.Tests/Tar/TarTests.cs index c6a35ff0..e49035af 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Tar/TarTests.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Tar/TarTests.cs @@ -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) { diff --git a/test/ICSharpCode.SharpZipLib.Tests/TestSupport/RingBuffer.cs b/test/ICSharpCode.SharpZipLib.Tests/TestSupport/RingBuffer.cs index d4b75e3c..c8ee1188 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/TestSupport/RingBuffer.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/TestSupport/RingBuffer.cs @@ -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) @@ -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) diff --git a/test/ICSharpCode.SharpZipLib.Tests/Zip/GeneralHandling.cs b/test/ICSharpCode.SharpZipLib.Tests/Zip/GeneralHandling.cs index d45eedf3..bd8e7425 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Zip/GeneralHandling.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Zip/GeneralHandling.cs @@ -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) { @@ -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; @@ -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(); } diff --git a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipTests.cs b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipTests.cs index 4a0c9954..dc398000 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipTests.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipTests.cs @@ -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 { @@ -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