public void InputStreamOwnership() { MemoryStreamEx memStream = new MemoryStreamEx(); GZipInputStream s = new GZipInputStream(memStream); Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially"); Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially"); s.Close(); Assert.IsTrue(memStream.IsClosed, "Should be closed after parent owner close"); Assert.IsTrue(memStream.IsDisposed, "Should be disposed after parent owner close"); memStream = new MemoryStreamEx(); s = new GZipInputStream(memStream); Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially"); Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially"); s.IsStreamOwner = false; s.Close(); Assert.IsFalse(memStream.IsClosed, "Should not be closed after parent owner close"); Assert.IsFalse(memStream.IsDisposed, "Should not be disposed after parent owner close"); }
public void BaseClosedAfterFailure() { MemoryStreamEx ms=new MemoryStreamEx(new byte[32]); Assert.IsFalse(ms.IsClosed, "Underlying stream should NOT be closed initially"); bool blewUp = false; try { using( ZipOutputStream stream=new ZipOutputStream(ms) ) { Assert.IsTrue(stream.IsStreamOwner, "Should be stream owner by default"); try { stream.PutNextEntry(new ZipEntry("Tiny")); stream.Write(new byte[32], 0, 32); } finally { Assert.IsFalse(ms.IsClosed, "Stream should still not be closed."); stream.Close(); Assert.Fail("Exception not thrown"); } } } catch { blewUp = true; } Assert.IsTrue(blewUp, "Should have failed to write to stream"); Assert.IsTrue(ms.IsClosed, "Underlying stream should be closed"); }
public void BaseNotClosedWhenNotOwner() { MemoryStreamEx ms=new MemoryStreamEx(); Assert.IsFalse(ms.IsClosed, "Underlying stream should NOT be closed"); using( ZipOutputStream stream=new ZipOutputStream(ms) ) { Assert.IsTrue(stream.IsStreamOwner, "Should be stream owner by default"); stream.IsStreamOwner=false; } Assert.IsFalse(ms.IsClosed, "Underlying stream should still NOT be closed"); }
public void BaseClosedWhenOwner() { var ms = new MemoryStreamEx(); Assert.IsFalse(ms.IsClosed, "Underlying stream should NOT be closed"); using (var stream = new ZipOutputStream(ms)) { Assert.IsTrue(stream.IsStreamOwner, "Should be stream owner by default"); } Assert.IsTrue(ms.IsClosed, "Underlying stream should be closed"); }