コード例 #1
0
ファイル: SafeHandleTest.cs プロジェクト: LevNNN/mono
		public void MultipleDisposes ()
		{
			FakeSafeHandle sf = new FakeSafeHandle ();

			sf.Dispose ();
			sf.Dispose ();
			sf.Dispose ();
		}
コード例 #2
0
        public void MultipleDisposes()
        {
            FakeSafeHandle sf = new FakeSafeHandle();

            sf.Dispose();
            sf.Dispose();
            sf.Dispose();
        }
コード例 #3
0
        public void BadDispose3()
        {
            FakeSafeHandle sf = new FakeSafeHandle();

            sf.Dispose();
            sf.DangerousRelease();
        }
コード例 #4
0
        public void ReleaseAfterDispose1()
        {
            int            dummyHandle = 0xDEAD;
            FakeSafeHandle sf          = new FakeSafeHandle(true);

            sf.ChangeHandle(new IntPtr(dummyHandle));
            Assert.AreEqual((int)sf.DangerousGetHandle(), dummyHandle, "handle");

            bool success = false;

            sf.DangerousAddRef(ref success);
            Assert.IsTrue(success, "dar");

            sf.Dispose();
            //Still one ref left.
            Assert.IsFalse(sf.released, "released");
            Assert.IsFalse(sf.IsClosed, "closed");

            sf.DangerousRelease();
            //In Ms.Net SafeHandle does not change the value of the handle after being SetInvalid or Disposed.
            Assert.AreEqual((int)sf.DangerousGetHandle(), dummyHandle, "handle");
            //Handle was closed properly.
            Assert.IsTrue(sf.released, "released");
            Assert.IsTrue(sf.IsClosed, "closed");
            //Handle value is not changed, so the value itself is still valid (not 0 or -1)
            Assert.IsFalse(sf.IsInvalid, "invalid");
        }
コード例 #5
0
        public void GoodDispose()
        {
            int            dummyHandle = 0xDEAD;
            FakeSafeHandle sf          = new FakeSafeHandle();

            sf.ChangeHandle(new IntPtr(dummyHandle));
            Assert.AreEqual((int)sf.DangerousGetHandle(), dummyHandle, "handle");

            sf.DangerousRelease();

            try {
                sf.Close();
                Assert.Fail("#1");
            } catch (ObjectDisposedException) {
            }

            try {
                sf.Dispose();
                Assert.Fail("#2");
            } catch (ObjectDisposedException) {
            }

            //In Ms.Net SafeHandle does not change the value of the handle after being SetInvalid or Disposed.
            Assert.AreEqual((int)sf.DangerousGetHandle(), dummyHandle, "handle");
            //Handle was closed properly.
            Assert.IsTrue(sf.released, "released");
            Assert.IsTrue(sf.IsClosed, "closed");
            //Handle value is not changed, so the value itself is still valid (not 0 or -1)
            Assert.IsFalse(sf.IsInvalid, "invalid");

            GC.SuppressFinalize(sf);
        }
コード例 #6
0
ファイル: SafeHandleTest.cs プロジェクト: LevNNN/mono
		public void BadDispose3 ()
		{
			FakeSafeHandle sf = new FakeSafeHandle ();

			sf.Dispose ();
			sf.DangerousRelease ();
		}
コード例 #7
0
        public void ReleaseAfterDispose2()
        {
            FakeSafeHandle sf = new FakeSafeHandle(true);

            bool success = false;

            sf.DangerousAddRef(ref success);
            Assert.IsTrue(success, "dar");

            sf.Dispose();

            sf.DangerousRelease();

            //Second release need to throw ObjectDisposedException.
            //No more ref to release.
            sf.DangerousRelease();
        }
コード例 #8
0
        public void SetInvalidDispose()
        {
            int            dummyHandle = 0xDEAD;
            FakeSafeHandle sf          = new FakeSafeHandle(true);

            sf.ChangeHandle(new IntPtr(dummyHandle));
            Assert.AreEqual((int)sf.DangerousGetHandle(), dummyHandle, "handle");

            sf.SetHandleAsInvalid();
            sf.Dispose();

            //In Ms.Net SafeHandle does not change the value of the handle after being SetInvalid or Disposed.
            Assert.AreEqual((int)sf.DangerousGetHandle(), dummyHandle, "handle");
            //Released == false since handle was not released, Set Invalid was called before it could be released.
            Assert.IsFalse(sf.released, "released");
            //IsClosed == true since handle is pointing to a disposed or invalid object.
            Assert.IsTrue(sf.IsClosed, "closed");
            //Handle value is not changed, so the value itself is still valid (not 0 or -1)
            Assert.IsFalse(sf.IsInvalid, "invalid");
        }
コード例 #9
0
ファイル: SafeHandleTest.cs プロジェクト: psni/mono
		public void SimpleDispose ()
		{
			FakeSafeHandle sf = new FakeSafeHandle ();
			sf.Dispose ();
		}
コード例 #10
0
ファイル: SafeHandleTest.cs プロジェクト: psni/mono
		public void ReleaseAfterDispose2 ()
		{
			FakeSafeHandle sf = new FakeSafeHandle (true);

			bool success = false;
			sf.DangerousAddRef(ref success);
			Assert.IsTrue (success, "dar");

			sf.Dispose ();

			sf.DangerousRelease ();

			//Second release need to throw ObjectDisposedException.
			//No more ref to release.
			sf.DangerousRelease ();
		}
コード例 #11
0
ファイル: SafeHandleTest.cs プロジェクト: psni/mono
		public void ReleaseAfterDispose1 ()
		{
			int dummyHandle = 0xDEAD;
			FakeSafeHandle sf = new FakeSafeHandle (true);
			sf.ChangeHandle (new IntPtr (dummyHandle));
			Assert.AreEqual ((int)sf.DangerousGetHandle(), dummyHandle, "handle");

			bool success = false;
			sf.DangerousAddRef(ref success);
			Assert.IsTrue (success, "dar");

			sf.Dispose ();
			//Still one ref left.
			Assert.IsFalse (sf.released, "released");
			Assert.IsFalse (sf.IsClosed, "closed");

			sf.DangerousRelease ();
			//In Ms.Net SafeHandle does not change the value of the handle after being SetInvalid or Disposed.
			Assert.AreEqual ((int)sf.DangerousGetHandle(), dummyHandle, "handle");
			//Handle was closed properly.
			Assert.IsTrue (sf.released, "released");
			Assert.IsTrue (sf.IsClosed, "closed");
			//Handle value is not changed, so the value itself is still valid (not 0 or -1)
			Assert.IsFalse (sf.IsInvalid, "invalid");
		}
コード例 #12
0
ファイル: SafeHandleTest.cs プロジェクト: psni/mono
		public void SetInvalidDispose ()
		{
			int dummyHandle = 0xDEAD;
			FakeSafeHandle sf = new FakeSafeHandle (true);

			sf.ChangeHandle (new IntPtr (dummyHandle));
			Assert.AreEqual ((int)sf.DangerousGetHandle(), dummyHandle, "handle");

			sf.SetHandleAsInvalid();
			sf.Dispose ();

			//In Ms.Net SafeHandle does not change the value of the handle after being SetInvalid or Disposed.
			Assert.AreEqual ((int)sf.DangerousGetHandle(), dummyHandle, "handle");
			//Released == false since handle was not released, Set Invalid was called before it could be released.
			Assert.IsFalse (sf.released, "released");
			//IsClosed == true since handle is pointing to a disposed or invalid object.
			Assert.IsTrue (sf.IsClosed, "closed");
			//Handle value is not changed, so the value itself is still valid (not 0 or -1)
			Assert.IsFalse (sf.IsInvalid, "invalid");
		}
コード例 #13
0
ファイル: SafeHandleTest.cs プロジェクト: psni/mono
		public void GoodDispose ()
		{
			int dummyHandle = 0xDEAD;
			FakeSafeHandle sf = new FakeSafeHandle ();
			sf.ChangeHandle (new IntPtr (dummyHandle));
			Assert.AreEqual ((int)sf.DangerousGetHandle(), dummyHandle, "handle");

			sf.DangerousRelease ();

			try {
				sf.Close ();
				Assert.Fail ("#1");
			} catch (ObjectDisposedException) {
			}

			try {
				sf.Dispose ();
				Assert.Fail ("#2");
			} catch (ObjectDisposedException) {
			}

			//In Ms.Net SafeHandle does not change the value of the handle after being SetInvalid or Disposed.
			Assert.AreEqual ((int)sf.DangerousGetHandle(), dummyHandle, "handle");
			//Handle was closed properly.
			Assert.IsTrue (sf.released, "released");
			Assert.IsTrue (sf.IsClosed, "closed");
			//Handle value is not changed, so the value itself is still valid (not 0 or -1)
			Assert.IsFalse (sf.IsInvalid, "invalid");

			GC.SuppressFinalize (sf);
		}
コード例 #14
0
        public void SimpleDispose()
        {
            FakeSafeHandle sf = new FakeSafeHandle();

            sf.Dispose();
        }