예제 #1
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");
        }
예제 #2
0
        public void DangerousAddRefOnNewInstance()
        {
            FakeSafeHandle sf = new FakeSafeHandle();

            sf.ChangeHandle(IntPtr.Zero);
            Assert.IsTrue(sf.IsInvalid, "invalid");

            bool success = false;

            sf.DangerousAddRef(ref success);
            Assert.IsTrue(success, "daroni");
        }
예제 #3
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();
        }
예제 #4
0
        public void SetInvalidRelease1()
        {
            FakeSafeHandle sf = new FakeSafeHandle(true);

            bool success = false;

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

            sf.SetHandleAsInvalid();

            Assert.IsFalse(sf.released, "released");
            Assert.IsTrue(sf.IsClosed, "closed");

            //Allow remaining refs to be released after SetHandleAsInvalid
            sf.DangerousRelease();
            sf.DangerousRelease();

            Assert.IsFalse(sf.released, "released");
            Assert.IsTrue(sf.IsClosed, "closed");
        }
예제 #5
0
파일: SafeHandleTest.cs 프로젝트: psni/mono
		public void DangerousAddRefOnNewInstance ()
		{
			FakeSafeHandle sf = new FakeSafeHandle ();
			sf.ChangeHandle (IntPtr.Zero);
			Assert.IsTrue (sf.IsInvalid, "invalid");

			bool success = false;
			sf.DangerousAddRef (ref success);
			Assert.IsTrue (success, "daroni");
		}
예제 #6
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 ();
		}
예제 #7
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");
		}
예제 #8
0
파일: SafeHandleTest.cs 프로젝트: psni/mono
		public void SetInvalidRelease1 ()
		{
			FakeSafeHandle sf = new FakeSafeHandle (true);

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

			sf.SetHandleAsInvalid();

			Assert.IsFalse (sf.released, "released");
			Assert.IsTrue (sf.IsClosed, "closed");

			//Allow remaining refs to be released after SetHandleAsInvalid
			sf.DangerousRelease ();
			sf.DangerousRelease ();

			Assert.IsFalse (sf.released, "released");
			Assert.IsTrue (sf.IsClosed, "closed");
		}