#include "pch.h" #include "CppUnitTest.h" #include "MockedInput.h" #include #include #include "TestHelpers.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; namespace RemappingLogicTests { // Tests for MockedInput test helper - to ensure simulated keyboard input behaves as expected TEST_CLASS (MockedInputSanityTests) { private: KeyboardManagerInput::MockedInput mockedInputHandler; State testState; public: TEST_METHOD_INITIALIZE(InitializeTestEnv) { // Reset test environment TestHelpers::ResetTestEnv(mockedInputHandler, testState); } // Test if mocked input is working TEST_METHOD (MockedInput_ShouldSetKeyboardState_OnKeyEvent) { // Send key down and key up for A key (0x41) and check keyboard state both times const int nInputs = 1; INPUT input[nInputs] = {}; input[0].type = INPUT_KEYBOARD; input[0].ki.wVk = 0x41; // Send A keydown mockedInputHandler.SendVirtualInput(nInputs, input, sizeof(INPUT)); // A key state should be true Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x41), true); input[0].ki.dwFlags = KEYEVENTF_KEYUP; // Send A keyup mockedInputHandler.SendVirtualInput(nInputs, input, sizeof(INPUT)); // A key state should be false Assert::AreEqual(mockedInputHandler.GetVirtualKeyState(0x41), false); } }; }