Ejemplo n.º 1
0
		public void BadDispose2 ()
		{
			FakeSafeHandle sf = new FakeSafeHandle ();

			sf.Close ();
			sf.DangerousRelease ();
		}
Ejemplo n.º 2
0
        public void Dispose3()
        {
            FakeSafeHandle sf = new FakeSafeHandle();

            sf.Close();
            sf.DangerousRelease();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void CloseWillDispose()
        {
            FakeSafeHandle sf = new FakeSafeHandle();

            sf.Close();
            Assert.IsTrue(sf.disposed, "disposed");
        }
Ejemplo n.º 5
0
        public void NoReleaseUnowned()
        {
            FakeSafeHandle sf = new FakeSafeHandle(false);

            sf.Close();
            Assert.AreEqual(sf.released, false, "r1");

            sf = new FakeSafeHandle(false);
            sf.DangerousRelease();
            Assert.AreEqual(sf.released, false, "r2");

            sf = new FakeSafeHandle(false);
            ((IDisposable)sf).Dispose();
            Assert.AreEqual(sf.released, false, "r3");
        }
Ejemplo n.º 6
0
		public void NoReleaseUnowned ()
		{
			FakeSafeHandle sf = new FakeSafeHandle (false);

			sf.Close ();
			Assert.AreEqual (sf.released, false, "r1");

			sf = new FakeSafeHandle (false);
			sf.DangerousRelease ();
			Assert.AreEqual (sf.released, false, "r2");

			sf = new FakeSafeHandle (false);
			((IDisposable) sf).Dispose ();
			Assert.AreEqual (sf.released, false, "r3");
		}
Ejemplo n.º 7
0
        public void NoReleaseUnowned()
        {
            FakeSafeHandle sf = new FakeSafeHandle(false);

            sf.Close();
            Assert.IsFalse(sf.released, "r1");
            Assert.IsTrue(sf.IsClosed, "c1");

            sf = new FakeSafeHandle(false);
            sf.DangerousRelease();
            Assert.IsFalse(sf.released, "r2");
            Assert.IsTrue(sf.IsClosed, "c2");

            sf = new FakeSafeHandle(false);
            ((IDisposable)sf).Dispose();
            Assert.IsFalse(sf.released, "r3");
            Assert.IsTrue(sf.IsClosed, "c3");
        }
Ejemplo n.º 8
0
		public void NoReleaseUnowned ()
		{
			FakeSafeHandle sf = new FakeSafeHandle (false);

			sf.Close ();
			Assert.IsFalse (sf.released, "r1");
			Assert.IsTrue (sf.IsClosed, "c1");

			sf = new FakeSafeHandle (false);
			sf.DangerousRelease ();
			Assert.IsFalse (sf.released, "r2");
			Assert.IsTrue (sf.IsClosed, "c2");

			sf = new FakeSafeHandle (false);
			((IDisposable) sf).Dispose ();
			Assert.IsFalse (sf.released, "r3");
			Assert.IsTrue (sf.IsClosed, "c3");
		}
Ejemplo n.º 9
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);
		}
Ejemplo n.º 10
0
		public void CloseWillDispose ()
		{
			FakeSafeHandle sf = new FakeSafeHandle ();

			sf.Close ();
			Assert.IsTrue (sf.disposed, "disposed");
		}