public void EqualsTest()
        {
            InteropBuffer_Accessor target;
            InteropBuffer_Accessor obj;
            bool expected;
            bool actual;

            target = new InteropBuffer_Accessor(1);

            obj = null;
            expected = false;
            actual = target.Equals(obj);
            Assert.AreEqual(expected, actual, "Virtuoso.Miranda.Plugins.Native.InteropBuffer.Equals did not return the expected value.");

            obj = new InteropBuffer_Accessor(1);
            expected = false;
            actual = target.Equals(obj);
            obj.Lock();
            ((IDisposable)obj).Dispose();
            obj.Unlock();
            Assert.AreEqual(expected, actual, "Virtuoso.Miranda.Plugins.Native.InteropBuffer.Equals did not return the expected value.");

            obj = target;
            expected = true;
            actual = target.Equals(obj);

            target.Lock();
            ((IDisposable)target).Dispose();
            target.Unlock();

            Assert.AreEqual(expected, actual, "Virtuoso.Miranda.Plugins.Native.InteropBuffer.Equals did not return the expected value.");
        }
        public void ZeroTest()
        {
            InteropBuffer_Accessor target = new InteropBuffer_Accessor(1);

            try
            {
                target.Zero();
                Assert.Fail("InteropBuffer::Zero allows unlocked use.");
            }
            catch { }

            target.Lock();

            Marshal.WriteByte(target.IntPtr, 0xaf);
            target.Zero();

            try
            {
                Assert.AreEqual<byte>(0, Marshal.ReadByte(target.IntPtr));
            }
            finally
            {
                ((IDisposable)target).Dispose();
                target.Unlock();
            }
        }
        public void UnlockTest()
        {
            InteropBuffer_Accessor target = new InteropBuffer_Accessor(1);

            try
            {
                target.Unlock();
                Assert.Fail("InteropBuffer::Unlock allows to unlock non-locked buffers.");
            }
            catch { }

            target.Lock();
            target.Unlock();
            Assert.IsFalse(target.Locked, "InteropBuffer::Unlock does not update the Locked property.");

            Thread t = new Thread(new ParameterizedThreadStart(delegate(object obj)
            {
                target.Lock();
            }));
            t.Start();
            t.Join();

            try
            {
                target.Unlock();
                Assert.Fail("InteropBuffer::Unlock allows an unlock from a different thread.");
            }
            catch { }
            finally
            {
                target.Dispose(true);
            }
        }
        public void LockedTest()
        {
            InteropBuffer_Accessor target = new InteropBuffer_Accessor(1);
            Assert.IsFalse(target.Locked, "InteropBuffer::Locked returned wrong result.");

            target.Lock();
            Assert.IsTrue(target.Locked, "InteropBuffer::Locked returned wrong result.");
            target.Unlock();
        }
        public void LockTest()
        {
            InteropBuffer_Accessor target = new InteropBuffer_Accessor(1);

            try
            {
                target.Lock();
                Thread t = new Thread(new ThreadStart(delegate { target.Lock(); }));
                t.Start();
                Thread.Sleep(250);

                Assert.IsFalse(t.Join(1000), "InteropBuffer::Lock does not block other threads.");
                Assert.IsTrue(target.Locked, "InteropBuffer::Lock did not set the lock owner.");
            }
            finally
            {
                ((IDisposable)target).Dispose();
                target.Unlock();
            }
        }
        public void IntPtrTest()
        {
            InteropBuffer_Accessor target = new InteropBuffer_Accessor(1);

            target.Lock();
            IntPtr ptr = target.IntPtr;
            target.Unlock();

            try
            {
                ptr = target.IntPtr;
                Assert.Fail("InteropBuffer::IntPtr succeded without locking.");
            }
            catch { }

            try
            {
                target.Lock();
                ((IDisposable)target).Dispose();

                ptr = target.IntPtr;
                target.Unlock();

                Assert.Fail("InteropBuffer::IntPtr succeded after disposal.");
            }
            catch { }
        }