mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
Moved each test class to a separate file (#4592)
This commit is contained in:
49
src/modules/keyboardmanager/test/MockedInputSanityTests.cpp
Normal file
49
src/modules/keyboardmanager/test/MockedInputSanityTests.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "pch.h"
|
||||
#include "CppUnitTest.h"
|
||||
#include "MockedInput.h"
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
#include <keyboardmanager/dll/KeyboardEventHandlers.h>
|
||||
#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:
|
||||
MockedInput mockedInputHandler;
|
||||
KeyboardManagerState 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);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user