From cffe0196e2793fe1b7c4b44266c380119d49f5f8 Mon Sep 17 00:00:00 2001 From: Arjun Date: Thu, 2 Jul 2020 15:18:27 -0700 Subject: [PATCH] Added unit tests --- .../test/OSLevelShortcutRemappingTests.cpp | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/src/modules/keyboardmanager/test/OSLevelShortcutRemappingTests.cpp b/src/modules/keyboardmanager/test/OSLevelShortcutRemappingTests.cpp index 2d546130de..a270f7bd54 100644 --- a/src/modules/keyboardmanager/test/OSLevelShortcutRemappingTests.cpp +++ b/src/modules/keyboardmanager/test/OSLevelShortcutRemappingTests.cpp @@ -1009,5 +1009,100 @@ namespace RemappingLogicTests Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(VK_MENU), true); Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(VK_TAB), false); } + + // Test if invoking two remapped shortcuts (with different modifiers between original and new shortcut) that share modifiers in succession sets the correct keyboard states + TEST_METHOD (TwoRemappedShortcutsWithDifferentModifiersThatShareModifiers_ShouldSetRemappedKeyStates_OnPressingSecondShortcutActionKeyAfterInvokingFirstShortcutRemap) + { + // Remap Alt+A to Ctrl+C + Shortcut src; + src.SetKey(VK_MENU); + src.SetKey(0x41); + Shortcut dest; + dest.SetKey(VK_CONTROL); + dest.SetKey(0x43); + testState.AddOSLevelShortcut(src, dest); + + // Remap Alt+V to Ctrl+X + Shortcut src1; + src1.SetKey(VK_MENU); + src1.SetKey(0x56); + Shortcut dest1; + dest1.SetKey(VK_CONTROL); + dest1.SetKey(0x58); + testState.AddOSLevelShortcut(src1, dest1); + + const int nInputs = 4; + INPUT input[nInputs] = {}; + input[0].type = INPUT_KEYBOARD; + input[0].ki.wVk = VK_MENU; + input[0].ki.dwFlags = 0; + input[1].type = INPUT_KEYBOARD; + input[1].ki.wVk = 0x41; + input[1].ki.dwFlags = 0; + input[2].type = INPUT_KEYBOARD; + input[2].ki.wVk = 0x41; + input[2].ki.dwFlags = KEYEVENTF_KEYUP; + input[3].type = INPUT_KEYBOARD; + input[3].ki.wVk = 0x56; + input[3].ki.dwFlags = 0; + + // Send Alt+A, release A, press V + mockedInputHandler.SendVirtualInput(nInputs, input, sizeof(INPUT)); + + // Alt, A, C, V key states should be unchanged, Ctrl, X should be true + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(VK_MENU), false); + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x41), false); + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x43), false); + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x56), false); + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(VK_CONTROL), true); + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x58), true); + } + + // Test if invoking two remapped shortcuts (with same modifiers between original and new shortcut) that share modifiers in succession sets the correct keyboard states + TEST_METHOD (TwoRemappedShortcutsWithSameModifiersThatShareModifiers_ShouldSetRemappedKeyStates_OnPressingSecondShortcutActionKeyAfterInvokingFirstShortcutRemap) + { + // Remap Ctrl+A to Ctrl+C + Shortcut src; + src.SetKey(VK_CONTROL); + src.SetKey(0x41); + Shortcut dest; + dest.SetKey(VK_CONTROL); + dest.SetKey(0x43); + testState.AddOSLevelShortcut(src, dest); + + // Remap Ctrl+V to Ctrl+X + Shortcut src1; + src1.SetKey(VK_CONTROL); + src1.SetKey(0x56); + Shortcut dest1; + dest1.SetKey(VK_CONTROL); + dest1.SetKey(0x58); + testState.AddOSLevelShortcut(src1, dest1); + + const int nInputs = 4; + INPUT input[nInputs] = {}; + input[0].type = INPUT_KEYBOARD; + input[0].ki.wVk = VK_CONTROL; + input[0].ki.dwFlags = 0; + input[1].type = INPUT_KEYBOARD; + input[1].ki.wVk = 0x41; + input[1].ki.dwFlags = 0; + input[2].type = INPUT_KEYBOARD; + input[2].ki.wVk = 0x41; + input[2].ki.dwFlags = KEYEVENTF_KEYUP; + input[3].type = INPUT_KEYBOARD; + input[3].ki.wVk = 0x56; + input[3].ki.dwFlags = 0; + + // Send Ctrl+A, release A, press V + mockedInputHandler.SendVirtualInput(nInputs, input, sizeof(INPUT)); + + // A, C, V key states should be unchanged, Ctrl, X should be true + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x41), false); + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x43), false); + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x56), false); + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(VK_CONTROL), true); + Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x58), true); + } }; }