public void ConstructionUnsupportedTypeTests(TestMethodRecord tmr) { HookTypes type = HookTypes.Hardware; tmr.WriteLine("If you implement the hook type HookTypes." + type + ", change the type parameter to continue testing this senario."); tmr.RegisterException("An unimplemented hook type will cause an exception.", typeof(HookTypeNotImplementedException)); SystemHookTestWrapper hook = new SystemHookTestWrapper(type); }
private void TestInstallHook(TestMethodRecord tmr, ISystemHook hook, string name) { tmr.WriteLine("Testing keyboard hook of type: " + name); tmr.RunTest(hook.IsHooked == false, "Hook is not installed."); hook.InstallHook(); tmr.RunTest(hook.IsHooked, "Hook installed successfully."); hook.UninstallHook(); tmr.RunTest(hook.IsHooked == false, "Hook is unstalled successfully."); }
public void UnsupportedFilterTypesTest1(TestMethodRecord tmr) { HookTypes type = HookTypes.Hardware; tmr.WriteLine("If you implement the hook type HookTypes." + type + ", change the type parameter to continue testing this senario."); using (SystemHookTestWrapper hook = new SystemHookTestWrapper(HookTypes.MouseLL)) { tmr.RegisterException("An unimplemented hook type will cause an exception (filter message).", typeof(ManagedHooksException)); hook.FilterMessageWrapper(type, 12345); } }
public void EventTest(TestMethodRecord tmr) { KeyboardHookEventArgs[] keyArgs = GenerateRandomKeyData(); KeyboardHookTestImpl hookImpl = new KeyboardHookTestImpl(); using (IKeyboardHookExt keyboard = HookFactory.CreateKeyboardHookExt(hookImpl)) { keyboard.InstallHook(); keyboard.KeyDown += new KeyboardEventHandlerExt(EventTest_KeyDown); // // Trigger a bunch of keyboard events. The event handler will // capture the output and we will then compare it here. // foreach (KeyboardHookEventArgs keyArg in keyArgs) { hookImpl.TriggerKeyAction(KeyboardEvents.KeyDown, keyArg); } } tmr.RunTest(keyArgs.Length == eventTest_ArgsList.Count, "The proper number of events were caught."); bool same = true; for (int i = 0; i < keyArgs.Length; i++) { KeyboardHookEventArgs kea1 = keyArgs[i]; KeyboardHookEventArgs kea2 = (KeyboardHookEventArgs)eventTest_ArgsList[i]; if (!CompareKeyArgs(kea1, kea2)) { tmr.WriteLine("Failed event results comparison at index " + i); same = false; break; } } tmr.RunTest(same, "The event callback captured all the events successfully."); }
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."); }