public void ReferenceCountingTest(TestMethodRecord tmr)
        {
            //
            // In this test we are observing how the various keyboard hook
            // classes are interacting with their implementation classes. They
            // should add references in their constructor and release them when
            // disposed. The implementation should only be disposed when the ref
            // count is zero.
            //
            KeyboardHookTestImpl testImpl = new KeyboardHookTestImpl();

            tmr.RunTest(testImpl.ReferenceCount == 0, "Now references count is 0.");
            tmr.RunTest(testImpl.Disposed == false, "Not initially disposed.");

            using (IKeyboardHook hook1 = HookFactory.CreateKeyboardHook(testImpl))
            {
                tmr.RunTest(testImpl.ReferenceCount == 1, "Now references count is 1.");
                tmr.RunTest(testImpl.Disposed == false, "Not disposed.");

                using (IKeyboardHookExt hook2 = HookFactory.CreateKeyboardHookExt(testImpl))
                {
                    tmr.RunTest(testImpl.ReferenceCount == 2, "Now references count is 2.");
                    tmr.RunTest(testImpl.Disposed == false, "Not disposed.");
                }

                tmr.RunTest(testImpl.ReferenceCount == 1, "Now references count is 1.");
                tmr.RunTest(testImpl.Disposed == false, "Not disposed.");
            }

            tmr.RunTest(testImpl.ReferenceCount == 0, "Now references count is 0.");
            tmr.RunTest(testImpl.Disposed == true, "Disposed.");
        }
示例#2
0
        public void CreateKeyboardHookTests(TestMethodRecord tmr)
        {
            using (IKeyboardHook hook = HookFactory.CreateKeyboardHook())
            {
                tmr.RunTest(hook != null, "IKeyboardHook created successfully with default options.");
            }

            using (IKeyboardHookExt hookExt = HookFactory.CreateKeyboardHookExt())
            {
                tmr.RunTest(hookExt != null, "IKeyboardHookExt created successfully with default options.");
            }
        }
        public void InstallHookTests(TestMethodRecord tmr)
        {
            using (IKeyboardHook kHook = HookFactory.CreateKeyboardHook())
            {
                TestInstallHook(tmr, kHook, "IKeyboardHook");
            }

            using (IKeyboardHookExt kHookExt = HookFactory.CreateKeyboardHookExt())
            {
                TestInstallHook(tmr, kHookExt, "IKeyboardHookExt");
            }
        }