4
4
5
5
using NUnit . Framework ;
6
6
7
+ using ICSharpCode . SharpZipLib . Tests . TestSupport ;
7
8
using ICSharpCode . SharpZipLib . Tar ;
8
9
9
10
namespace ICSharpCode . SharpZipLib . Tests . Tar {
@@ -50,11 +51,13 @@ public void EmptyTar()
50
51
Assert . AreEqual ( 0 , entryCount , "Expected 0 tar entries" ) ;
51
52
}
52
53
}
54
+
53
55
/// <summary>
54
56
/// Check that the tar block factor can be varied successfully.
55
57
/// </summary>
56
58
[ Test ]
57
- public void BlockFactorHandling ( )
59
+ [ Category ( "Tar" ) ]
60
+ public void BlockFactorHandling ( )
58
61
{
59
62
const int MinimumBlockFactor = 1 ;
60
63
const int MaximumBlockFactor = 64 ;
@@ -111,13 +114,13 @@ public void BlockFactorHandling()
111
114
}
112
115
}
113
116
}
114
-
115
117
116
118
/// <summary>
117
119
/// Check that the tar trailer only contains nulls.
118
120
/// </summary>
119
121
[ Test ]
120
- public void TrailerContainsNulls ( )
122
+ [ Category ( "Tar" ) ]
123
+ public void TrailerContainsNulls ( )
121
124
{
122
125
const int TestBlockFactor = 3 ;
123
126
@@ -438,19 +441,20 @@ public void ValuesPreserved()
438
441
/// Check invalid mod times are detected
439
442
/// </summary>
440
443
[ Test ]
441
- [ ExpectedException ( typeof ( ArgumentOutOfRangeException ) ) ]
444
+ [ Category ( "Tar" ) ]
445
+ [ ExpectedException ( typeof ( ArgumentOutOfRangeException ) ) ]
442
446
public void InvalidModTime ( )
443
447
{
444
448
TarEntry e = TarEntry . CreateTarEntry ( "test" ) ;
445
449
e . ModTime = DateTime . MinValue ;
446
450
}
447
451
448
-
449
452
/// <summary>
450
453
/// Check invalid sizes are detected
451
454
/// </summary>
452
455
[ Test ]
453
- [ ExpectedException ( typeof ( ArgumentOutOfRangeException ) ) ]
456
+ [ Category ( "Tar" ) ]
457
+ [ ExpectedException ( typeof ( ArgumentOutOfRangeException ) ) ]
454
458
public void InvalidSize ( )
455
459
{
456
460
TarEntry e = TarEntry . CreateTarEntry ( "test" ) ;
@@ -461,7 +465,8 @@ public void InvalidSize()
461
465
/// Check invalid names are detected
462
466
/// </summary>
463
467
[ Test ]
464
- [ ExpectedException ( typeof ( ArgumentNullException ) ) ]
468
+ [ Category ( "Tar" ) ]
469
+ [ ExpectedException ( typeof ( ArgumentNullException ) ) ]
465
470
public void InvalidName ( )
466
471
{
467
472
TarEntry e = TarEntry . CreateTarEntry ( "test" ) ;
@@ -472,7 +477,8 @@ public void InvalidName()
472
477
/// Check setting user and group names.
473
478
/// </summary>
474
479
[ Test ]
475
- public void UserAndGroupNames ( )
480
+ [ Category ( "Tar" ) ]
481
+ public void UserAndGroupNames ( )
476
482
{
477
483
TarEntry e = TarEntry . CreateTarEntry ( "test" ) ;
478
484
e . UserName = null ;
@@ -487,7 +493,8 @@ public void UserAndGroupNames()
487
493
/// Check invalid magic values are detected
488
494
/// </summary>
489
495
[ Test ]
490
- [ ExpectedException ( typeof ( ArgumentNullException ) ) ]
496
+ [ Category ( "Tar" ) ]
497
+ [ ExpectedException ( typeof ( ArgumentNullException ) ) ]
491
498
public void InvalidMagic ( )
492
499
{
493
500
TarEntry e = TarEntry . CreateTarEntry ( "test" ) ;
@@ -498,7 +505,8 @@ public void InvalidMagic()
498
505
/// Check invalid link names are detected
499
506
/// </summary>
500
507
[ Test ]
501
- [ ExpectedException ( typeof ( ArgumentNullException ) ) ]
508
+ [ Category ( "Tar" ) ]
509
+ [ ExpectedException ( typeof ( ArgumentNullException ) ) ]
502
510
public void InvalidLinkName ( )
503
511
{
504
512
TarEntry e = TarEntry . CreateTarEntry ( "test" ) ;
@@ -509,15 +517,17 @@ public void InvalidLinkName()
509
517
/// Check invalid version names are detected
510
518
/// </summary>
511
519
[ Test ]
512
- [ ExpectedException ( typeof ( ArgumentNullException ) ) ]
520
+ [ Category ( "Tar" ) ]
521
+ [ ExpectedException ( typeof ( ArgumentNullException ) ) ]
513
522
public void InvalidVersionName ( )
514
523
{
515
524
TarEntry e = TarEntry . CreateTarEntry ( "test" ) ;
516
525
e . TarHeader . Version = null ;
517
526
}
518
527
519
528
[ Test ]
520
- public void CloningAndUniqueness ( )
529
+ [ Category ( "Tar" ) ]
530
+ public void CloningAndUniqueness ( )
521
531
{
522
532
// Partial test of cloning for TarHeader and TarEntry
523
533
TarEntry e = TarEntry . CreateTarEntry ( "ohsogood" ) ;
@@ -557,5 +567,61 @@ public void CloningAndUniqueness()
557
567
558
568
Assert . AreNotEqual ( headerD . LinkName , entryf . TarHeader . LinkName , "Entry headers should be unique" ) ;
559
569
}
560
- }
570
+
571
+ [ Test ]
572
+ [ Category ( "Tar" ) ]
573
+ public void OutputStreamOwnership ( )
574
+ {
575
+ TrackedMemoryStream memStream = new TrackedMemoryStream ( ) ;
576
+ TarOutputStream s = new TarOutputStream ( memStream ) ;
577
+
578
+ Assert . IsFalse ( memStream . IsClosed , "Shouldnt be closed initially" ) ;
579
+ Assert . IsFalse ( memStream . IsDisposed , "Shouldnt be disposed initially" ) ;
580
+
581
+ s . Close ( ) ;
582
+
583
+ Assert . IsTrue ( memStream . IsClosed , "Should be closed after parent owner close" ) ;
584
+ Assert . IsTrue ( memStream . IsDisposed , "Should be disposed after parent owner close" ) ;
585
+
586
+ memStream = new TrackedMemoryStream ( ) ;
587
+ s = new TarOutputStream ( memStream ) ;
588
+
589
+ Assert . IsFalse ( memStream . IsClosed , "Shouldnt be closed initially" ) ;
590
+ Assert . IsFalse ( memStream . IsDisposed , "Shouldnt be disposed initially" ) ;
591
+
592
+ s . IsStreamOwner = false ;
593
+ s . Close ( ) ;
594
+
595
+ Assert . IsFalse ( memStream . IsClosed , "Should not be closed after parent owner close" ) ;
596
+ Assert . IsFalse ( memStream . IsDisposed , "Should not be disposed after parent owner close" ) ;
597
+ }
598
+
599
+ [ Test ]
600
+ [ Category ( "Tar" ) ]
601
+ public void InputStreamOwnership ( )
602
+ {
603
+ TrackedMemoryStream memStream = new TrackedMemoryStream ( ) ;
604
+ TarInputStream s = new TarInputStream ( memStream ) ;
605
+
606
+ Assert . IsFalse ( memStream . IsClosed , "Shouldnt be closed initially" ) ;
607
+ Assert . IsFalse ( memStream . IsDisposed , "Shouldnt be disposed initially" ) ;
608
+
609
+ s . Close ( ) ;
610
+
611
+ Assert . IsTrue ( memStream . IsClosed , "Should be closed after parent owner close" ) ;
612
+ Assert . IsTrue ( memStream . IsDisposed , "Should be disposed after parent owner close" ) ;
613
+
614
+ memStream = new TrackedMemoryStream ( ) ;
615
+ s = new TarInputStream ( memStream ) ;
616
+
617
+ Assert . IsFalse ( memStream . IsClosed , "Shouldnt be closed initially" ) ;
618
+ Assert . IsFalse ( memStream . IsDisposed , "Shouldnt be disposed initially" ) ;
619
+
620
+ s . IsStreamOwner = false ;
621
+ s . Close ( ) ;
622
+
623
+ Assert . IsFalse ( memStream . IsClosed , "Should not be closed after parent owner close" ) ;
624
+ Assert . IsFalse ( memStream . IsDisposed , "Should not be disposed after parent owner close" ) ;
625
+ }
626
+ }
561
627
}
0 commit comments