public void SetInvalidRelease2()
        {
            FakeSafeHandle sf = new FakeSafeHandle(true);

            bool success = false;

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

            sf.SetHandleAsInvalid();
            sf.DangerousRelease();
            sf.DangerousRelease();

            //This release need to throw ObjectDisposedException.
            //No more ref to release.
            sf.DangerousRelease();
        }
        public void SetHandleAsInvalid()
        {
            int            dummyHandle = 0xDEAD;
            FakeSafeHandle sf          = new FakeSafeHandle();

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

            sf.SetHandleAsInvalid();

            //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");
        }
        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");
        }
Beispiel #4
0
		public void SetInvalidRelease2 ()
		{
			FakeSafeHandle sf = new FakeSafeHandle (true);

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

			sf.SetHandleAsInvalid();
			sf.DangerousRelease ();
			sf.DangerousRelease ();

			//This release need to throw ObjectDisposedException.
			//No more ref to release.
			sf.DangerousRelease ();
		}
Beispiel #5
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");
		}
Beispiel #6
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");
		}