Ejemplo n.º 1
0
        public void ReferenceCountingTest(TestMethodRecord tmr)
        {
            //
            // In this test we are observing how the various mouse 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.
            //
            MouseHookTestImpl testImpl = new MouseHookTestImpl();

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

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

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

                    using (IMouseHookLite hook3 = HookFactory.CreateMouseHookLite(testImpl))
                    {
                        tmr.RunTest(testImpl.ReferenceCount == 3, "Now references count is 3.");
                        tmr.RunTest(testImpl.Disposed == false, "Not disposed.");
                    }

                    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.");
        }
Ejemplo n.º 2
0
        public void EventSinkTest(TestMethodRecord tmr)
        {
            MouseHookEventArgs[] mouseArgs = GenerateRandomClickArgs();

            MouseHookTestImpl mouseImpl = new MouseHookTestImpl();

            using (IMouseHookExt mouseHook = HookFactory.CreateMouseHookExt(mouseImpl))
            {
                mouseHook.LeftButtonDown += new MouseEventHandlerExt(EventSinkTest_LeftButtonDown);
                mouseHook.InstallHook();

                //
                // Trigger a bunch of mouse down events. The event handler will
                // capture the output and we will then compare it here.
                //
                foreach (MouseHookEventArgs mea in mouseArgs)
                {
                    mouseImpl.TriggerMouseAction(MouseEvents.LeftButtonDown, mea);
                }
            }

            tmr.RunTest(mouseArgs.Length == eventTest_ArgsList.Count, "The proper number of events were caught.");

            bool same = true;

            for (int i = 0; i < mouseArgs.Length; i++)
            {
                MouseHookEventArgs mea1 = mouseArgs[i];
                MouseHookEventArgs mea2 = (MouseHookEventArgs)eventTest_ArgsList[i];

                if (!CompareMouseArgs(mea1, mea2))
                {
                    tmr.WriteLine("Failed event results comparison at index " + i);
                    same = false;
                    break;
                }
            }

            tmr.RunTest(same, "The event callback captured all the events successfully.");
        }