[KBM] decoupling editor and engine (#11133)

This commit is contained in:
Mykhailo Pylyp
2021-05-07 11:16:31 +03:00
committed by GitHub
parent 9461909321
commit 8785fca309
77 changed files with 2509 additions and 2775 deletions

View File

@@ -1,7 +1,7 @@
#include "pch.h"
#include "CppUnitTest.h"
#include "MockedInput.h"
#include <keyboardmanager/common/KeyboardManagerState.h>
#include <keyboardmanager/KeyboardManagerEngineLibrary/State.h>
#include <keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.h>
#include "TestHelpers.h"
#include <common/interop/shared_constants.h>
@@ -15,7 +15,7 @@ namespace RemappingLogicTests
{
private:
KeyboardManagerInput::MockedInput mockedInputHandler;
KeyboardManagerState testState;
State testState;
std::wstring testApp1 = L"testtrocess1.exe";
std::wstring testApp2 = L"testprocess2.exe";

View File

@@ -1,143 +0,0 @@
#include "pch.h"
#include "CppUnitTest.h"
#include <keyboardmanager/common/ErrorTypes.h>
#include <keyboardmanager/common/Helpers.h>
#include "TestHelpers.h"
#include <common/interop/keyboard_layout.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace KeyboardManagerCommonTests
{
// Tests for methods in the KeyboardManagerHelper namespace
TEST_CLASS (KeyboardManagerHelperTests)
{
public:
TEST_METHOD_INITIALIZE(InitializeTestEnv)
{
}
// Test if the DoKeysOverlap method returns SameKeyPreviouslyMapped on passing the same key for both arguments
TEST_METHOD (DoKeysOverlap_ShouldReturnSameKeyPreviouslyMapped_OnPassingSameKeyForBothArguments)
{
// Arrange
DWORD key1 = 0x41;
DWORD key2 = key1;
// Act
auto result = KeyboardManagerHelper::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::SameKeyPreviouslyMapped);
}
// Test if the DoKeysOverlap method returns ConflictingModifierKey on passing left modifier and common modifier
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierKey_OnPassingLeftModifierAndCommonModifierOfSameType)
{
// Arrange
DWORD key1 = VK_LCONTROL;
DWORD key2 = VK_CONTROL;
// Act
auto result = KeyboardManagerHelper::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::ConflictingModifierKey);
}
// Test if the DoKeysOverlap method returns ConflictingModifierKey on passing right modifier and common modifier
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierKey_OnPassingRightModifierAndCommonModifierOfSameType)
{
// Arrange
DWORD key1 = VK_RCONTROL;
DWORD key2 = VK_CONTROL;
// Act
auto result = KeyboardManagerHelper::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::ConflictingModifierKey);
}
// Test if the DoKeysOverlap method returns NoError on passing left modifier and right modifier
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingLeftModifierAndRightModifierOfSameType)
{
// Arrange
DWORD key1 = VK_LCONTROL;
DWORD key2 = VK_RCONTROL;
// Act
auto result = KeyboardManagerHelper::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::NoError);
}
// Test if the DoKeysOverlap method returns NoError on passing keys of different types
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingKeysOfDifferentTypes)
{
// Arrange
DWORD key1 = VK_CONTROL;
DWORD key2 = VK_SHIFT;
// Act
auto result = KeyboardManagerHelper::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::NoError);
}
// Test if the DoKeysOverlap method returns NoError on passing different action keys
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingDifferentActionKeys)
{
// Arrange
DWORD key1 = 0x41;
DWORD key2 = 0x42;
// Act
auto result = KeyboardManagerHelper::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::NoError);
}
// Test if the CheckRepeatedModifier method returns true on passing vector with same modifier repeated
TEST_METHOD (CheckRepeatedModifier_ShouldReturnTrue_OnPassingSameModifierRepeated)
{
// Arrange
std::vector<int32_t> keys = { VK_CONTROL, VK_CONTROL, 0x41 };
// Act
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, VK_CONTROL);
// Assert
Assert::IsTrue(result);
}
// Test if the CheckRepeatedModifier method returns true on passing vector with conflicting modifier repeated
TEST_METHOD (CheckRepeatedModifier_ShouldReturnTrue_OnPassingConflictingModifierRepeated)
{
// Arrange
std::vector<int32_t> keys = { VK_CONTROL, VK_LCONTROL, 0x41 };
// Act
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, VK_LCONTROL);
// Assert
Assert::IsTrue(result);
}
// Test if the CheckRepeatedModifier method returns false on passing vector with different modifiers
TEST_METHOD (CheckRepeatedModifier_ShouldReturnFalse_OnPassingDifferentModifiers)
{
// Arrange
std::vector<int32_t> keys = { VK_CONTROL, VK_SHIFT, 0x41 };
// Act
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, VK_SHIFT);
// Assert
Assert::IsFalse(result);
}
};
}

View File

@@ -47,9 +47,7 @@
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(CIBuild)'!='true'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="ShortcutTests.cpp" />
<ClCompile Include="SingleKeyRemappingTests.cpp" />
<ClCompile Include="HelperTests.cpp" />
<ClCompile Include="TestHelpers.cpp" />
</ItemGroup>
<ItemGroup>

View File

@@ -39,12 +39,6 @@
<ClCompile Include="AppSpecificShortcutRemappingTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HelperTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ShortcutTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">

View File

@@ -1,7 +1,7 @@
#include "pch.h"
#include "CppUnitTest.h"
#include "MockedInput.h"
#include <keyboardmanager/common/KeyboardManagerState.h>
#include <keyboardmanager/KeyboardManagerEngineLibrary/State.h>
#include <keyboardmanager/common/KeyboardEventHandlers.h>
#include "TestHelpers.h"
@@ -14,7 +14,7 @@ namespace RemappingLogicTests
{
private:
KeyboardManagerInput::MockedInput mockedInputHandler;
KeyboardManagerState testState;
State testState;
public:
TEST_METHOD_INITIALIZE(InitializeTestEnv)

View File

@@ -1,7 +1,7 @@
#include "pch.h"
#include "CppUnitTest.h"
#include "MockedInput.h"
#include <keyboardmanager/common/KeyboardManagerState.h>
#include <keyboardmanager/KeyboardManagerEngineLibrary/State.h>
#include <keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.h>
#include "TestHelpers.h"
#include <common/interop/shared_constants.h>
@@ -15,7 +15,7 @@ namespace RemappingLogicTests
{
private:
KeyboardManagerInput::MockedInput mockedInputHandler;
KeyboardManagerState testState;
State testState;
public:
TEST_METHOD_INITIALIZE(InitializeTestEnv)

View File

@@ -1,7 +1,7 @@
#include "pch.h"
#include "CppUnitTest.h"
#include "MockedInput.h"
#include <keyboardmanager/common/KeyboardManagerState.h>
#include <keyboardmanager/KeyboardManagerEngineLibrary/State.h>
#include <keyboardmanager/common/KeyboardEventHandlers.h>
#include <keyboardmanager/common/Helpers.h>
#include "TestHelpers.h"
@@ -15,7 +15,7 @@ namespace RemappingLogicTests
{
private:
KeyboardManagerInput::MockedInput mockedInputHandler;
KeyboardManagerState testState;
State testState;
public:
TEST_METHOD_INITIALIZE(InitializeTestEnv)
@@ -36,7 +36,7 @@ namespace RemappingLogicTests
for (int i = 0; i < nInputs; i++)
{
// Set key events for all the extended keys
KeyboardManagerHelper::SetKeyEvent(input, i, INPUT_KEYBOARD, keyCodes[i], 0, 0);
Helpers::SetKeyEvent(input, i, INPUT_KEYBOARD, keyCodes[i], 0, 0);
// Extended key flag should be set
Assert::AreEqual(true, bool(input[i].ki.dwFlags & KEYEVENTF_EXTENDEDKEY));
}
@@ -49,7 +49,7 @@ namespace RemappingLogicTests
INPUT input[nInputs] = {};
int index = 0;
KeyboardManagerHelper::SetDummyKeyEvent(input, index, 0);
Helpers::SetDummyKeyEvent(input, index, 0);
// Assert that wScan for both inputs is 0
Assert::AreEqual<unsigned int>(0, input[0].ki.wScan);

View File

@@ -1,177 +0,0 @@
#include "pch.h"
#include "CppUnitTest.h"
#include <keyboardmanager/common/ErrorTypes.h>
#include <keyboardmanager/common/Shortcut.h>
#include <keyboardmanager/common/Helpers.h>
#include "TestHelpers.h"
#include <common/interop/keyboard_layout.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace KeyboardManagerCommonTests
{
// Tests for methods in the Shortcut class
TEST_CLASS (KeyboardManagerHelperTests)
{
public:
TEST_METHOD_INITIALIZE(InitializeTestEnv)
{
}
// Test if the IsValidShortcut method returns false on passing shortcut with null action key
TEST_METHOD (IsValidShortcut_ShouldReturnFalse_OnPassingShortcutWithNullActionKey)
{
// Arrange
Shortcut s;
s.SetKey(NULL);
// Act
bool result = s.IsValidShortcut();
// Assert
Assert::IsFalse(result);
}
// Test if the IsValidShortcut method returns false on passing shortcut with only action key
TEST_METHOD (IsValidShortcut_ShouldReturnFalse_OnPassingShortcutWithOnlyActionKey)
{
// Arrange
Shortcut s;
s.SetKey(0x41);
// Act
bool result = s.IsValidShortcut();
// Assert
Assert::IsFalse(result);
}
// Test if the IsValidShortcut method returns false on passing shortcut with only modifier keys
TEST_METHOD (IsValidShortcut_ShouldReturnFalse_OnPassingShortcutWithOnlyModifierKeys)
{
// Arrange
Shortcut s;
s.SetKey(VK_CONTROL);
s.SetKey(VK_SHIFT);
// Act
bool result = s.IsValidShortcut();
// Assert
Assert::IsFalse(result);
}
// Test if the IsValidShortcut method returns true on passing shortcut with modifier and action key
TEST_METHOD (IsValidShortcut_ShouldReturnFalse_OnPassingShortcutWithModifierAndActionKey)
{
// Arrange
Shortcut s;
s.SetKey(VK_CONTROL);
s.SetKey(0x41);
// Act
bool result = s.IsValidShortcut();
// Assert
Assert::IsTrue(result);
}
// Test if the DoKeysOverlap method returns NoError on passing invalid shortcut for one of the arguments
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingInvalidShortcutForOneOfTheArguments)
{
// Arrange
Shortcut s1(std::vector<int32_t>{ NULL });
Shortcut s2(std::vector<int32_t>{ VK_CONTROL, 0x41 });
// Act
auto result = Shortcut::DoKeysOverlap(s1, s2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::NoError);
}
// Test if the DoKeysOverlap method returns SameShortcutPreviouslyMapped on passing same shortcut for both arguments
TEST_METHOD (DoKeysOverlap_ShouldReturnSameShortcutPreviouslyMapped_OnPassingSameShortcutForBothArguments)
{
// Arrange
Shortcut s1(std::vector<int32_t>{ VK_CONTROL, 0x41 });
Shortcut s2 = s1;
// Act
auto result = Shortcut::DoKeysOverlap(s1, s2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::SameShortcutPreviouslyMapped);
}
// Test if the DoKeysOverlap method returns NoError on passing shortcuts with different action keys
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingShortcutsWithDifferentActionKeys)
{
// Arrange
Shortcut s1(std::vector<int32_t>{ VK_CONTROL, 0x42 });
Shortcut s2(std::vector<int32_t>{ VK_CONTROL, 0x41 });
// Act
auto result = Shortcut::DoKeysOverlap(s1, s2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::NoError);
}
// Test if the DoKeysOverlap method returns NoError on passing shortcuts with different modifiers
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingShortcutsWithDifferentModifiers)
{
// Arrange
Shortcut s1(std::vector<int32_t>{ VK_CONTROL, 0x42 });
Shortcut s2(std::vector<int32_t>{ VK_SHIFT, 0x42 });
// Act
auto result = Shortcut::DoKeysOverlap(s1, s2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::NoError);
}
// Test if the DoKeysOverlap method returns ConflictingModifierShortcut on passing shortcuts with left modifier and common modifier
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithLeftModifierAndCommonModifierOfSameType)
{
// Arrange
Shortcut s1(std::vector<int32_t>{ VK_LCONTROL, 0x42 });
Shortcut s2(std::vector<int32_t>{ VK_CONTROL, 0x42 });
// Act
auto result = Shortcut::DoKeysOverlap(s1, s2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::ConflictingModifierShortcut);
}
// Test if the DoKeysOverlap method returns ConflictingModifierShortcut on passing shortcuts with right modifier and common modifier
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithRightModifierAndCommonModifierOfSameType)
{
// Arrange
Shortcut s1(std::vector<int32_t>{ VK_RCONTROL, 0x42 });
Shortcut s2(std::vector<int32_t>{ VK_CONTROL, 0x42 });
// Act
auto result = Shortcut::DoKeysOverlap(s1, s2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::ConflictingModifierShortcut);
}
// Test if the DoKeysOverlap method returns ConflictingModifierShortcut on passing shortcuts with left modifier and right modifier
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithLeftModifierAndRightModifierOfSameType)
{
// Arrange
Shortcut s1(std::vector<int32_t>{ VK_LCONTROL, 0x42 });
Shortcut s2(std::vector<int32_t>{ VK_RCONTROL, 0x42 });
// Act
auto result = Shortcut::DoKeysOverlap(s1, s2);
// Assert
Assert::IsTrue(result == KeyboardManagerHelper::ErrorType::NoError);
}
};
}

View File

@@ -1,7 +1,7 @@
#include "pch.h"
#include "CppUnitTest.h"
#include "MockedInput.h"
#include <keyboardmanager/common/KeyboardManagerState.h>
#include <keyboardmanager/KeyboardManagerEngineLibrary/State.h>
#include <keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.h>
#include "TestHelpers.h"
#include <common/interop/shared_constants.h>
@@ -15,7 +15,7 @@ namespace RemappingLogicTests
{
private:
KeyboardManagerInput::MockedInput mockedInputHandler;
KeyboardManagerState testState;
State testState;
public:
TEST_METHOD_INITIALIZE(InitializeTestEnv)

View File

@@ -1,12 +1,12 @@
#include "pch.h"
#include "TestHelpers.h"
#include "MockedInput.h"
#include "keyboardmanager/common/KeyboardManagerState.h"
#include <keyboardmanager/KeyboardManagerEngineLibrary/State.h>
namespace TestHelpers
{
// Function to reset the environment variables for tests
void ResetTestEnv(KeyboardManagerInput::MockedInput& input, KeyboardManagerState& state)
void ResetTestEnv(KeyboardManagerInput::MockedInput& input, State& state)
{
input.ResetKeyboardState();
input.SetHookProc(nullptr);

View File

@@ -4,12 +4,12 @@ namespace KeyboardManagerInput
{
class MockedInput;
}
class KeyboardManagerState;
class State;
namespace TestHelpers
{
// Function to reset the environment variables for tests
void ResetTestEnv(KeyboardManagerInput::MockedInput& input, KeyboardManagerState& state);
void ResetTestEnv(KeyboardManagerInput::MockedInput& input, State& state);
// Function to return the index of the given key code from the drop down key list
int GetDropDownIndexFromDropDownList(DWORD key, const std::vector<DWORD>& keyList);