@@ -19,18 +19,6 @@ namespace ICSharpCode.SharpZipLib.Tests.Zip
1919 [ TestFixture ]
2020 public class GeneralHandling : ZipBase
2121 {
22- private void AddRandomDataToEntry ( ZipOutputStream zipStream , int size )
23- {
24- if ( size > 0 )
25- {
26- byte [ ] data = new byte [ size ] ;
27- var rnd = new Random ( ) ;
28- rnd . NextBytes ( data ) ;
29-
30- zipStream . Write ( data , 0 , data . Length ) ;
31- }
32- }
33-
3422 private void ExerciseZip ( CompressionMethod method , int compressionLevel ,
3523 int size , string password , bool canSeek )
3624 {
@@ -343,57 +331,11 @@ public void BasicStoredNonSeekable()
343331
344332 [ Test ]
345333 [ Category ( "Zip" ) ]
346- public void StoredNonSeekableKnownSizeNoCrc ( )
347- {
348- // This cannot be stored directly as the crc is not be known.
349- const int TargetSize = 21348 ;
350- const string Password = null ;
351-
352- MemoryStream ms = new MemoryStreamWithoutSeek ( ) ;
353-
354- using ( ZipOutputStream outStream = new ZipOutputStream ( ms ) )
355- {
356- outStream . Password = Password ;
357- outStream . IsStreamOwner = false ;
358- var entry = new ZipEntry ( "dummyfile.tst" ) ;
359- entry . CompressionMethod = CompressionMethod . Stored ;
360-
361- // The bit thats in question is setting the size before its added to the archive.
362- entry . Size = TargetSize ;
363-
364- outStream . PutNextEntry ( entry ) ;
365-
366- Assert . AreEqual ( CompressionMethod . Deflated , entry . CompressionMethod , "Entry should be deflated" ) ;
367- Assert . AreEqual ( - 1 , entry . CompressedSize , "Compressed size should be known" ) ;
368-
369- var rnd = new Random ( ) ;
370-
371- int size = TargetSize ;
372- byte [ ] original = new byte [ size ] ;
373- rnd . NextBytes ( original ) ;
374-
375- // Although this could be written in one chunk doing it in lumps
376- // throws up buffering problems including with encryption the original
377- // source for this change.
378- int index = 0 ;
379- while ( size > 0 )
380- {
381- int count = ( size > 0x200 ) ? 0x200 : size ;
382- outStream . Write ( original , index , count ) ;
383- size -= 0x200 ;
384- index += count ;
385- }
386- }
387- Assert . That ( ms . ToArray ( ) , Does . PassTestArchive ( ) ) ;
388- }
389-
390- [ Test ]
391- [ Category ( "Zip" ) ]
392- public void StoredNonSeekableKnownSizeNoCrcEncrypted ( )
334+ [ TestCase ( 21348 , null ) ]
335+ [ TestCase ( 24692 , "Mabutu" ) ]
336+ public void StoredNonSeekableKnownSizeNoCrc ( int targetSize , string password )
393337 {
394- // This cant be stored directly as the crc is not known
395- const int targetSize = 24692 ;
396- const string password = "Mabutu" ;
338+ // This cannot be stored directly as the crc is not known.
397339
398340 MemoryStream ms = new MemoryStreamWithoutSeek ( ) ;
399341
@@ -409,19 +351,15 @@ public void StoredNonSeekableKnownSizeNoCrcEncrypted()
409351
410352 outStream . PutNextEntry ( entry ) ;
411353
412- Assert . AreEqual ( CompressionMethod . Deflated , entry . CompressionMethod , "Entry should be stored " ) ;
354+ Assert . AreEqual ( CompressionMethod . Deflated , entry . CompressionMethod , "Entry should be deflated " ) ;
413355 Assert . AreEqual ( - 1 , entry . CompressedSize , "Compressed size should be known" ) ;
414356
415- var rnd = new Random ( ) ;
416-
417- int size = targetSize ;
418- byte [ ] original = new byte [ size ] ;
419- rnd . NextBytes ( original ) ;
357+ byte [ ] original = Utils . GetDummyBytes ( targetSize ) ;
420358
421359 // Although this could be written in one chunk doing it in lumps
422360 // throws up buffering problems including with encryption the original
423361 // source for this change.
424- int index = 0 ;
362+ int index = 0 , size = targetSize ;
425363 while ( size > 0 )
426364 {
427365 int count = ( size > 0x200 ) ? 0x200 : size ;
@@ -565,12 +503,12 @@ public void StoredNonSeekableConvertToDeflate()
565503 outStream . PutNextEntry ( entry ) ;
566504 Assert . AreEqual ( 0 , outStream . GetLevel ( ) , "Compression level invalid" ) ;
567505
568- AddRandomDataToEntry ( outStream , 100 ) ;
506+ Utils . WriteDummyData ( outStream , 100 ) ;
569507 entry = new ZipEntry ( "2.tst" ) ;
570508 entry . CompressionMethod = CompressionMethod . Deflated ;
571509 outStream . PutNextEntry ( entry ) ;
572510 Assert . AreEqual ( 8 , outStream . GetLevel ( ) , "Compression level invalid" ) ;
573- AddRandomDataToEntry ( outStream , 100 ) ;
511+ Utils . WriteDummyData ( outStream , 100 ) ;
574512
575513 outStream . Close ( ) ;
576514 }
0 commit comments