예제 #1
0
파일: GZipTests.cs 프로젝트: rakkeh/hammock
		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");

		}
예제 #2
0
파일: ZipTests.cs 프로젝트: Gremlin2/Fb2Fix
        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");
        }
예제 #3
0
파일: ZipTests.cs 프로젝트: Gremlin2/Fb2Fix
        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");
        }
예제 #4
0
        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");
        }