MockedInputSanityTests.cpp
1 #include "pch.h" 2 3 // Suppressing 26466 - Don't use static_cast downcasts - in CppUnitTest.h 4 #pragma warning(push) 5 #pragma warning(disable : 26466) 6 #include "CppUnitTest.h" 7 #pragma warning(pop) 8 9 #include "MockedInput.h" 10 #include <keyboardmanager/KeyboardManagerEngineLibrary/State.h> 11 #include <keyboardmanager/common/KeyboardEventHandlers.h> 12 #include "TestHelpers.h" 13 14 using namespace Microsoft::VisualStudio::CppUnitTestFramework; 15 16 namespace RemappingLogicTests 17 { 18 // Tests for MockedInput test helper - to ensure simulated keyboard input behaves as expected 19 TEST_CLASS (MockedInputSanityTests) 20 { 21 private: 22 KeyboardManagerInput::MockedInput mockedInputHandler; 23 State testState; 24 25 public: 26 TEST_METHOD_INITIALIZE(InitializeTestEnv) 27 { 28 // Reset test environment 29 TestHelpers::ResetTestEnv(mockedInputHandler, testState); 30 } 31 32 // Test if mocked input is working 33 TEST_METHOD (MockedInput_ShouldSetKeyboardState_OnKeyEvent) 34 { 35 // Send key down and key up for A key (0x41) and check keyboard state both times 36 std::vector<INPUT> inputs1{ 37 { .type = INPUT_KEYBOARD, .ki = { .wVk = 'A' } }, 38 }; 39 40 // Send A keydown 41 mockedInputHandler.SendVirtualInput(inputs1); 42 43 // A key state should be true 44 Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x41), true); 45 46 std::vector<INPUT> inputs2{ 47 { .type = INPUT_KEYBOARD, .ki = { .wVk = 'A', .dwFlags = KEYEVENTF_KEYUP } }, 48 }; 49 50 // Send A keyup 51 mockedInputHandler.SendVirtualInput(inputs2); 52 53 // A key state should be false 54 Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x41), false); 55 } 56 }; 57 }