[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,14 +1,12 @@
#include "pch.h"
#include "CppUnitTest.h"
#include <keyboardmanager/KeyboardManagerEditorLibrary/BufferValidationHelpers.h>
#include "TestHelpers.h"
#include <common/interop/keyboard_layout.h>
#include <common/interop/shared_constants.h>
#include <functional>
#include <keyboardmanager/common/ErrorTypes.h>
#include <keyboardmanager/KeyboardManagerEditorLibrary/ShortcutErrorType.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace TestHelpers;
namespace RemappingUITests
{
@@ -61,10 +59,10 @@ namespace RemappingUITests
// Validate and update the element when -1 i.e. null selection is made on an empty row.
ValidateAndUpdateKeyBufferElementArgs args = { 0, 0, -1 };
KeyboardManagerHelper::ErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
ShortcutErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
// Assert that the element is validated and buffer is updated
Assert::AreEqual(true, error == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, error == ShortcutErrorType::NoError);
Assert::AreEqual((DWORD)NULL, std::get<DWORD>(remapBuffer[0].first[0]));
Assert::AreEqual((DWORD)NULL, std::get<DWORD>(remapBuffer[0].first[1]));
Assert::AreEqual((DWORD)NULL, std::get<DWORD>(remapBuffer[1].first[0]));
@@ -81,10 +79,10 @@ namespace RemappingUITests
// Validate and update the element when selecting B on an empty row
ValidateAndUpdateKeyBufferElementArgs args = { 0, 0, 0x42 };
KeyboardManagerHelper::ErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
ShortcutErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
// Assert that the element is validated and buffer is updated
Assert::AreEqual(true, error == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, error == ShortcutErrorType::NoError);
Assert::AreEqual((DWORD)0x42, std::get<DWORD>(remapBuffer[0].first[0]));
Assert::AreEqual((DWORD)NULL, std::get<DWORD>(remapBuffer[0].first[1]));
}
@@ -99,10 +97,10 @@ namespace RemappingUITests
// Validate and update the element when selecting B on a row
ValidateAndUpdateKeyBufferElementArgs args = { 0, 0, 0x42 };
KeyboardManagerHelper::ErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
ShortcutErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
// Assert that the element is validated and buffer is updated
Assert::AreEqual(true, error == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, error == ShortcutErrorType::NoError);
Assert::AreEqual((DWORD)0x42, std::get<DWORD>(remapBuffer[0].first[0]));
Assert::AreEqual((DWORD)0x41, std::get<DWORD>(remapBuffer[0].first[1]));
}
@@ -117,10 +115,10 @@ namespace RemappingUITests
// Validate and update the element when selecting B on a row
ValidateAndUpdateKeyBufferElementArgs args = { 0, 0, 0x42 };
KeyboardManagerHelper::ErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
ShortcutErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
// Assert that the element is validated and buffer is updated
Assert::AreEqual(true, error == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, error == ShortcutErrorType::NoError);
Assert::AreEqual((DWORD)0x42, std::get<DWORD>(remapBuffer[0].first[0]));
Assert::AreEqual(true, Shortcut(std::vector<int32_t>{ VK_CONTROL, 0x41 }) == std::get<Shortcut>(remapBuffer[0].first[1]));
}
@@ -135,10 +133,10 @@ namespace RemappingUITests
// Validate and update the element when selecting A on a row
ValidateAndUpdateKeyBufferElementArgs args = { 0, 0, 0x41 };
KeyboardManagerHelper::ErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
ShortcutErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
// Assert that the element is invalid and buffer is not updated
Assert::AreEqual(true, error == KeyboardManagerHelper::ErrorType::MapToSameKey);
Assert::AreEqual(true, error == ShortcutErrorType::MapToSameKey);
Assert::AreEqual((DWORD)NULL, std::get<DWORD>(remapBuffer[0].first[0]));
Assert::AreEqual((DWORD)0x41, std::get<DWORD>(remapBuffer[0].first[1]));
}
@@ -154,10 +152,10 @@ namespace RemappingUITests
// Validate and update the element when selecting A on second row
ValidateAndUpdateKeyBufferElementArgs args = { 1, 0, 0x41 };
KeyboardManagerHelper::ErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
ShortcutErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
// Assert that the element is invalid and buffer is not updated
Assert::AreEqual(true, error == KeyboardManagerHelper::ErrorType::SameKeyPreviouslyMapped);
Assert::AreEqual(true, error == ShortcutErrorType::SameKeyPreviouslyMapped);
Assert::AreEqual((DWORD)NULL, std::get<DWORD>(remapBuffer[1].first[0]));
Assert::AreEqual((DWORD)0x43, std::get<DWORD>(remapBuffer[1].first[1]));
}
@@ -173,10 +171,10 @@ namespace RemappingUITests
// Validate and update the element when selecting A on second row
ValidateAndUpdateKeyBufferElementArgs args = { 1, 0, 0x41 };
KeyboardManagerHelper::ErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
ShortcutErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
// Assert that the element is invalid and buffer is not updated
Assert::AreEqual(true, error == KeyboardManagerHelper::ErrorType::SameKeyPreviouslyMapped);
Assert::AreEqual(true, error == ShortcutErrorType::SameKeyPreviouslyMapped);
Assert::AreEqual((DWORD)NULL, std::get<DWORD>(remapBuffer[1].first[0]));
Assert::AreEqual(true, Shortcut(std::vector<int32_t>{ VK_CONTROL, 0x41 }) == std::get<Shortcut>(remapBuffer[1].first[1]));
}
@@ -192,10 +190,10 @@ namespace RemappingUITests
// Validate and update the element when selecting LCtrl on second row
ValidateAndUpdateKeyBufferElementArgs args = { 1, 0, VK_LCONTROL };
KeyboardManagerHelper::ErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
ShortcutErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
// Assert that the element is invalid and buffer is not updated
Assert::AreEqual(true, error == KeyboardManagerHelper::ErrorType::ConflictingModifierKey);
Assert::AreEqual(true, error == ShortcutErrorType::ConflictingModifierKey);
Assert::AreEqual((DWORD)NULL, std::get<DWORD>(remapBuffer[1].first[0]));
Assert::AreEqual((DWORD)0x43, std::get<DWORD>(remapBuffer[1].first[1]));
}
@@ -211,10 +209,10 @@ namespace RemappingUITests
// Validate and update the element when selecting LCtrl on second row
ValidateAndUpdateKeyBufferElementArgs args = { 1, 0, VK_LCONTROL };
KeyboardManagerHelper::ErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
ShortcutErrorType error = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(args.elementRowIndex, args.elementColIndex, args.selectedCodeFromDropDown, remapBuffer);
// Assert that the element is invalid and buffer is not updated
Assert::AreEqual(true, error == KeyboardManagerHelper::ErrorType::ConflictingModifierKey);
Assert::AreEqual(true, error == ShortcutErrorType::ConflictingModifierKey);
Assert::AreEqual((DWORD)NULL, std::get<DWORD>(remapBuffer[1].first[0]));
Assert::AreEqual(true, Shortcut(std::vector<int32_t>{ VK_CONTROL, 0x41 }) == std::get<Shortcut>(remapBuffer[1].first[1]));
}
@@ -268,10 +266,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid and no drop down action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -295,10 +293,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no drop down action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutStartWithModifier);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutStartWithModifier);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -318,10 +316,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid and no drop down action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -341,10 +339,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no drop down action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutNotMoreThanOneActionKey);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutNotMoreThanOneActionKey);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -364,10 +362,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no drop down action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutNotMoreThanOneActionKey);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutNotMoreThanOneActionKey);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -395,10 +393,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid and no drop down action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -426,10 +424,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid and ClearUnusedDropDowns action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::ClearUnusedDropDowns);
});
}
@@ -447,10 +445,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid and ClearUnusedDropDowns action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::ClearUnusedDropDowns);
});
}
@@ -482,10 +480,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid and AddDropDown action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::AddDropDown);
});
}
@@ -509,10 +507,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutCannotHaveRepeatedModifier);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutCannotHaveRepeatedModifier);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -546,10 +544,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutMaxShortcutSizeOneActionKey);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutMaxShortcutSizeOneActionKey);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -577,10 +575,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutMaxShortcutSizeOneActionKey);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutMaxShortcutSizeOneActionKey);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -614,10 +612,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid and no action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -651,10 +649,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutCannotHaveRepeatedModifier);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutCannotHaveRepeatedModifier);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -674,10 +672,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutStartWithModifier);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutStartWithModifier);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -695,10 +693,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutOneActionKey);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutOneActionKey);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -722,10 +720,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutAtleast2Keys);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutAtleast2Keys);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -749,10 +747,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutOneActionKey);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutOneActionKey);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -776,10 +774,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid and DeleteDropDown action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::DeleteDropDown);
});
}
@@ -819,10 +817,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid and DeleteDropDown action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::DeleteDropDown);
});
}
@@ -850,10 +848,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid and no action is required
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutOneActionKey);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutOneActionKey);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
});
}
@@ -889,10 +887,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::WinL);
Assert::AreEqual(true, result.first == ShortcutErrorType::WinL);
});
}
@@ -921,10 +919,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::WinL);
Assert::AreEqual(true, result.first == ShortcutErrorType::WinL);
});
}
@@ -953,10 +951,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::CtrlAltDel);
Assert::AreEqual(true, result.first == ShortcutErrorType::CtrlAltDel);
});
}
@@ -987,10 +985,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::MapToSameKey);
Assert::AreEqual(true, result.first == ShortcutErrorType::MapToSameKey);
});
}
@@ -1025,10 +1023,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::MapToSameShortcut);
Assert::AreEqual(true, result.first == ShortcutErrorType::MapToSameShortcut);
});
}
@@ -1103,10 +1101,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::MapToSameShortcut);
Assert::AreEqual(true, result.first == ShortcutErrorType::MapToSameShortcut);
});
}
@@ -1129,10 +1127,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::SameShortcutPreviouslyMapped);
Assert::AreEqual(true, result.first == ShortcutErrorType::SameShortcutPreviouslyMapped);
});
}
@@ -1157,10 +1155,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
});
}
@@ -1183,10 +1181,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ConflictingModifierShortcut);
Assert::AreEqual(true, result.first == ShortcutErrorType::ConflictingModifierShortcut);
});
}
@@ -1209,10 +1207,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
});
}
@@ -1249,10 +1247,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::SameShortcutPreviouslyMapped);
Assert::AreEqual(true, result.first == ShortcutErrorType::SameShortcutPreviouslyMapped);
});
}
@@ -1289,10 +1287,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
});
}
@@ -1329,10 +1327,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is invalid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ConflictingModifierShortcut);
Assert::AreEqual(true, result.first == ShortcutErrorType::ConflictingModifierShortcut);
});
}
@@ -1369,10 +1367,10 @@ namespace RemappingUITests
remapBuffer.push_back(testCase.bufferRow);
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(testCase.elementRowIndex, testCase.elementColIndex, testCase.indexOfDropDownLastModified, testCase.selectedCodesOnDropDowns, testCase.targetAppNameInTextBox, testCase.isHybridColumn, remapBuffer, true);
// Assert that the element is valid
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::NoError);
Assert::AreEqual(true, result.first == ShortcutErrorType::NoError);
});
}
@@ -1388,10 +1386,10 @@ namespace RemappingUITests
};
// Act
std::pair<KeyboardManagerHelper::ErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(0, 1, 1, selectedCodes, testApp1, true, remapBuffer, true);
std::pair<ShortcutErrorType, BufferValidationHelpers::DropDownAction> result = BufferValidationHelpers::ValidateShortcutBufferElement(0, 1, 1, selectedCodes, testApp1, true, remapBuffer, true);
// Assert
Assert::AreEqual(true, result.first == KeyboardManagerHelper::ErrorType::ShortcutDisableAsActionKey);
Assert::AreEqual(true, result.first == ShortcutErrorType::ShortcutDisableAsActionKey);
Assert::AreEqual(true, result.second == BufferValidationHelpers::DropDownAction::NoAction);
}
};

View File

@@ -0,0 +1,295 @@
#include "pch.h"
#include "CppUnitTest.h"
#include <keyboardmanager/KeyboardManagerEditorLibrary/ShortcutErrorType.h>
#include <keyboardmanager/common/Helpers.h>
#include <common/interop/keyboard_layout.h>
#include <keyboardmanager/KeyboardManagerEditorLibrary/EditorHelpers.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace EditorHelpersTests
{
TEST_CLASS (EditorHelpersTests)
{
public:
// 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 = EditorHelpers::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoKeysOverlap(key1, key2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::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 = EditorHelpers::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 = EditorHelpers::CheckRepeatedModifier(keys, VK_SHIFT);
// Assert
Assert::IsFalse(result);
}
// 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 = EditorHelpers::IsValidShortcut(s);
// 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 = EditorHelpers::IsValidShortcut(s);
// 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 = EditorHelpers::IsValidShortcut(s);
// 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 = EditorHelpers::IsValidShortcut(s);
// 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 = EditorHelpers::DoShortcutsOverlap(s1, s2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoShortcutsOverlap(s1, s2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoShortcutsOverlap(s1, s2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoShortcutsOverlap(s1, s2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoShortcutsOverlap(s1, s2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoShortcutsOverlap(s1, s2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::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 = EditorHelpers::DoShortcutsOverlap(s1, s2);
// Assert
Assert::IsTrue(result == ShortcutErrorType::NoError);
}
};
}

View File

@@ -40,17 +40,14 @@
<ItemGroup>
<ClCompile Include="BufferValidationTests.cpp" />
<ClCompile Include="LoadingAndSavingRemappingTests.cpp" />
<ClCompile Include="MockedInput.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(CIBuild)'!='true'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TestHelpers.cpp" />
<ClCompile Include="EditorHelpersTests.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="MockedInput.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="TestHelpers.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\SettingsAPI\SetttingsAPI.vcxproj">

View File

@@ -24,10 +24,7 @@
<ClCompile Include="BufferValidationTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TestHelpers.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MockedInput.cpp">
<ClCompile Include="EditorHelpersTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@@ -35,15 +32,9 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MockedInput.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TestHelpers.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="KeyboardManagerEditorTest.rc">

View File

@@ -1,10 +1,9 @@
#include "pch.h"
#include "CppUnitTest.h"
#include <keyboardmanager/common/KeyboardManagerState.h>
#include <keyboardmanager/common/MappingConfiguration.h>
#include <keyboardmanager/KeyboardManagerEditorLibrary/LoadingAndSavingRemappingHelper.h>
#include "TestHelpers.h"
#include <common/interop/shared_constants.h>
#include <keyboardmanager/common/ErrorTypes.h>
#include <keyboardmanager/KeyboardManagerEditorLibrary/ShortcutErrorType.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
@@ -27,7 +26,7 @@ namespace RemappingUITests
RemapBuffer remapBuffer;
// Assert that remapping set is valid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::NoError);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::NoError);
Assert::AreEqual(true, isSuccess);
}
@@ -41,7 +40,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ 0x42, 0x43 }), std::wstring()));
// Assert that remapping set is valid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::NoError);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::NoError);
Assert::AreEqual(true, isSuccess);
}
@@ -61,7 +60,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ 0x42, s2 }), std::wstring()));
// Assert that remapping set is valid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::NoError);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::NoError);
Assert::AreEqual(true, isSuccess);
}
@@ -81,7 +80,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ s2, 0x42 }), std::wstring()));
// Assert that remapping set is valid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::NoError);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::NoError);
Assert::AreEqual(true, isSuccess);
}
@@ -107,7 +106,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ src2, dest2 }), std::wstring()));
// Assert that remapping set is valid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::NoError);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::NoError);
Assert::AreEqual(true, isSuccess);
}
@@ -135,7 +134,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ 0x42, dest2 }), std::wstring()));
// Assert that remapping set is valid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::NoError);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::NoError);
Assert::AreEqual(true, isSuccess);
}
@@ -148,7 +147,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ 0x41, NULL }), std::wstring()));
// Assert that remapping set is invalid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::RemapUnsuccessful);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::RemapUnsuccessful);
Assert::AreEqual(true, isSuccess);
}
@@ -163,7 +162,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ 0x41, src1 }), std::wstring()));
// Assert that remapping set is invalid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::RemapUnsuccessful);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::RemapUnsuccessful);
Assert::AreEqual(true, isSuccess);
}
@@ -180,7 +179,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ 0x41, src1 }), std::wstring()));
// Assert that remapping set is invalid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::RemapUnsuccessful);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::RemapUnsuccessful);
Assert::AreEqual(true, isSuccess);
}
@@ -200,7 +199,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ src1, dest1 }), std::wstring()));
// Assert that remapping set is invalid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::RemapUnsuccessful);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::RemapUnsuccessful);
Assert::AreEqual(true, isSuccess);
}
@@ -220,7 +219,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ src1, dest1 }), testApp1));
// Assert that remapping set is invalid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::RemapUnsuccessful);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::RemapUnsuccessful);
Assert::AreEqual(true, isSuccess);
}
@@ -240,7 +239,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ src1, dest1 }), testApp2));
// Assert that remapping set is valid
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == KeyboardManagerHelper::ErrorType::NoError);
bool isSuccess = (LoadingAndSavingRemappingHelper::CheckIfRemappingsAreValid(remapBuffer) == ShortcutErrorType::NoError);
Assert::AreEqual(true, isSuccess);
}
@@ -361,23 +360,23 @@ namespace RemappingUITests
// Test if the ApplySingleKeyRemappings method resets the keyboard manager state's single key remappings on passing an empty buffer
TEST_METHOD (ApplySingleKeyRemappings_ShouldResetSingleKeyRemappings_OnPassingEmptyBuffer)
{
KeyboardManagerState testState;
MappingConfiguration testShortcuts;
RemapBuffer remapBuffer;
// Remap A to B
testState.AddSingleKeyRemap(0x41, 0x42);
testShortcuts.AddSingleKeyRemap(0x41, 0x42);
// Apply the single key remaps from the buffer to the keyboard manager state variable
LoadingAndSavingRemappingHelper::ApplySingleKeyRemappings(testState, remapBuffer, false);
LoadingAndSavingRemappingHelper::ApplySingleKeyRemappings(testShortcuts, remapBuffer, false);
// Assert that single key remapping in the kbm state variable is empty
Assert::AreEqual((size_t)0, testState.singleKeyReMap.size());
Assert::AreEqual((size_t)0, testShortcuts.singleKeyReMap.size());
}
// Test if the ApplySingleKeyRemappings method copies only the valid remappings to the keyboard manager state variable when some of the remappings are invalid
TEST_METHOD (ApplySingleKeyRemappings_ShouldCopyOnlyValidRemappings_OnPassingBufferWithSomeInvalidRemappings)
{
KeyboardManagerState testState;
MappingConfiguration testShortcuts;
RemapBuffer remapBuffer;
// Add A->B, B->Ctrl+V, C to incomplete shortcut and D to incomplete key remappings to the buffer
@@ -392,21 +391,21 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ 0x44, s2 }), std::wstring()));
// Apply the single key remaps from the buffer to the keyboard manager state variable
LoadingAndSavingRemappingHelper::ApplySingleKeyRemappings(testState, remapBuffer, false);
LoadingAndSavingRemappingHelper::ApplySingleKeyRemappings(testShortcuts, remapBuffer, false);
// Expected A remapped to B, B remapped to Ctrl+V
SingleKeyRemapTable expectedTable;
expectedTable[0x41] = 0x42;
expectedTable[0x42] = s1;
bool areTablesEqual = (expectedTable == testState.singleKeyReMap);
bool areTablesEqual = (expectedTable == testShortcuts.singleKeyReMap);
Assert::AreEqual(true, areTablesEqual);
}
// Test if the ApplySingleKeyRemappings method splits common modifiers to their left and right version when copying to the keyboard manager state variable if remappings from common modifiers are passed
TEST_METHOD (ApplySingleKeyRemappings_ShouldSplitRemappingsFromCommonModifiers_OnPassingBufferWithSomeMappingsFromCommonModifiers)
{
KeyboardManagerState testState;
MappingConfiguration testShortcuts;
RemapBuffer remapBuffer;
// Add Ctrl->A, Alt->B, Shift->C and Win->D remappings to the buffer
@@ -416,7 +415,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ CommonSharedConstants::VK_WIN_BOTH, 0x44 }), std::wstring()));
// Apply the single key remaps from the buffer to the keyboard manager state variable
LoadingAndSavingRemappingHelper::ApplySingleKeyRemappings(testState, remapBuffer, false);
LoadingAndSavingRemappingHelper::ApplySingleKeyRemappings(testShortcuts, remapBuffer, false);
// Expected LCtrl/RCtrl remapped to A, LAlt/RAlt to B, LShift/RShift to C, LWin/RWin to D
SingleKeyRemapTable expectedTable;
@@ -429,14 +428,14 @@ namespace RemappingUITests
expectedTable[VK_LWIN] = 0x44;
expectedTable[VK_RWIN] = 0x44;
bool areTablesEqual = (expectedTable == testState.singleKeyReMap);
bool areTablesEqual = (expectedTable == testShortcuts.singleKeyReMap);
Assert::AreEqual(true, areTablesEqual);
}
// Test if the ApplyShortcutRemappings method resets the keyboard manager state's os level and app specific shortcut remappings on passing an empty buffer
TEST_METHOD (ApplyShortcutRemappings_ShouldResetShortcutRemappings_OnPassingEmptyBuffer)
{
KeyboardManagerState testState;
MappingConfiguration testShortcuts;
RemapBuffer remapBuffer;
// Remap Ctrl+A to Ctrl+B for all apps and Ctrl+C to Alt+V for testApp1
@@ -452,21 +451,21 @@ namespace RemappingUITests
Shortcut dest2;
dest2.SetKey(VK_MENU);
dest2.SetKey(0x56);
testState.AddOSLevelShortcut(src1, dest1);
testState.AddAppSpecificShortcut(testApp1, src1, dest1);
testShortcuts.AddOSLevelShortcut(src1, dest1);
testShortcuts.AddAppSpecificShortcut(testApp1, src1, dest1);
// Apply the shortcut remaps from the buffer to the keyboard manager state variable
LoadingAndSavingRemappingHelper::ApplyShortcutRemappings(testState, remapBuffer, false);
LoadingAndSavingRemappingHelper::ApplyShortcutRemappings(testShortcuts, remapBuffer, false);
// Assert that shortcut remappings in the kbm state variable is empty
Assert::AreEqual((size_t)0, testState.osLevelShortcutReMap.size());
Assert::AreEqual((size_t)0, testState.appSpecificShortcutReMap.size());
Assert::AreEqual((size_t)0, testShortcuts.osLevelShortcutReMap.size());
Assert::AreEqual((size_t)0, testShortcuts.appSpecificShortcutReMap.size());
}
// Test if the ApplyShortcutRemappings method copies only the valid remappings to the keyboard manager state variable when some of the remappings are invalid
TEST_METHOD (ApplyShortcutRemappings_ShouldCopyOnlyValidRemappings_OnPassingBufferWithSomeInvalidRemappings)
{
KeyboardManagerState testState;
MappingConfiguration testShortcuts;
RemapBuffer remapBuffer;
// Add Ctrl+A->Ctrl+B, Ctrl+C->Alt+V, Ctrl+F->incomplete shortcut and Ctrl+G->incomplete key os level remappings to buffer
@@ -501,7 +500,7 @@ namespace RemappingUITests
remapBuffer.push_back(std::make_pair(RemapBufferItem({ src2, dest4 }), testApp1));
// Apply the shortcut remaps from the buffer to the keyboard manager state variable
LoadingAndSavingRemappingHelper::ApplyShortcutRemappings(testState, remapBuffer, false);
LoadingAndSavingRemappingHelper::ApplyShortcutRemappings(testShortcuts, remapBuffer, false);
// Ctrl+A->Ctrl+B and Ctrl+C->Alt+V
ShortcutRemapTable expectedOSLevelTable;
@@ -513,8 +512,8 @@ namespace RemappingUITests
expectedAppSpecificLevelTable[testApp1][src3] = RemapShortcut(dest2);
expectedAppSpecificLevelTable[testApp1][src4] = RemapShortcut(dest1);
bool areOSLevelTablesEqual = (expectedOSLevelTable == testState.osLevelShortcutReMap);
bool areAppSpecificTablesEqual = (expectedAppSpecificLevelTable == testState.appSpecificShortcutReMap);
bool areOSLevelTablesEqual = (expectedOSLevelTable == testShortcuts.osLevelShortcutReMap);
bool areAppSpecificTablesEqual = (expectedAppSpecificLevelTable == testShortcuts.appSpecificShortcutReMap);
Assert::AreEqual(true, areOSLevelTablesEqual);
Assert::AreEqual(true, areAppSpecificTablesEqual);
}

View File

@@ -1,161 +0,0 @@
#include "pch.h"
#include "MockedInput.h"
// Set the keyboard hook procedure to be tested
void MockedInput::SetHookProc(std::function<intptr_t(LowlevelKeyboardEvent*)> hookProcedure)
{
hookProc = hookProcedure;
}
// Function to simulate keyboard input - arguments and return value based on SendInput function (https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput)
UINT MockedInput::SendVirtualInput(UINT cInputs, LPINPUT pInputs, int cbSize)
{
// Iterate over inputs
for (UINT i = 0; i < cInputs; i++)
{
LowlevelKeyboardEvent keyEvent;
// Distinguish between key and sys key by checking if the key is either F10 (for syskeydown) or if the key message is sent while Alt is held down. SYSKEY messages are also sent if there is no window in focus, but that has not been mocked since it would require many changes. More details on key messages at https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-syskeydown
if (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP)
{
if (keyboardState[VK_MENU] == true)
{
keyEvent.wParam = WM_SYSKEYUP;
}
else
{
keyEvent.wParam = WM_KEYUP;
}
}
else
{
if (pInputs[i].ki.wVk == VK_F10 || keyboardState[VK_MENU] == true)
{
keyEvent.wParam = WM_SYSKEYDOWN;
}
else
{
keyEvent.wParam = WM_KEYDOWN;
}
}
KBDLLHOOKSTRUCT lParam = {};
// Set only vkCode and dwExtraInfo since other values are unused
lParam.vkCode = pInputs[i].ki.wVk;
lParam.dwExtraInfo = pInputs[i].ki.dwExtraInfo;
keyEvent.lParam = &lParam;
// If the SendVirtualInput call condition is true, increment the count. If no condition is set then always increment the count
if (sendVirtualInputCallCondition == nullptr || sendVirtualInputCallCondition(&keyEvent))
{
sendVirtualInputCallCount++;
}
// Call low level hook handler
intptr_t result = MockedKeyboardHook(&keyEvent);
// Set keyboard state if the hook does not suppress the input
if (result == 0)
{
// If key up flag is set, then set keyboard state to false
keyboardState[pInputs[i].ki.wVk] = (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP) ? false : true;
// Handling modifier key codes
switch (pInputs[i].ki.wVk)
{
case VK_CONTROL:
if (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP)
{
keyboardState[VK_LCONTROL] = false;
keyboardState[VK_RCONTROL] = false;
}
break;
case VK_LCONTROL:
keyboardState[VK_CONTROL] = (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP) ? false : true;
break;
case VK_RCONTROL:
keyboardState[VK_CONTROL] = (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP) ? false : true;
break;
case VK_MENU:
if (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP)
{
keyboardState[VK_LMENU] = false;
keyboardState[VK_RMENU] = false;
}
break;
case VK_LMENU:
keyboardState[VK_MENU] = (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP) ? false : true;
break;
case VK_RMENU:
keyboardState[VK_MENU] = (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP) ? false : true;
break;
case VK_SHIFT:
if (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP)
{
keyboardState[VK_LSHIFT] = false;
keyboardState[VK_RSHIFT] = false;
}
break;
case VK_LSHIFT:
keyboardState[VK_SHIFT] = (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP) ? false : true;
break;
case VK_RSHIFT:
keyboardState[VK_SHIFT] = (pInputs[i].ki.dwFlags & KEYEVENTF_KEYUP) ? false : true;
break;
}
}
}
return cInputs;
}
// Function to simulate keyboard hook behavior
intptr_t MockedInput::MockedKeyboardHook(LowlevelKeyboardEvent* data)
{
// If the hookProc is set to null, then skip the hook
if (hookProc != nullptr)
{
return hookProc(data);
}
else
{
return 0;
}
}
// Function to get the state of a particular key
bool MockedInput::GetVirtualKeyState(int key)
{
return keyboardState[key];
}
// Function to reset the mocked keyboard state
void MockedInput::ResetKeyboardState()
{
std::fill(keyboardState.begin(), keyboardState.end(), false);
}
// Function to set SendVirtualInput call count condition
void MockedInput::SetSendVirtualInputTestHandler(std::function<bool(LowlevelKeyboardEvent*)> condition)
{
sendVirtualInputCallCount = 0;
sendVirtualInputCallCondition = condition;
}
// Function to get SendVirtualInput call count
int MockedInput::GetSendVirtualInputCallCount()
{
return sendVirtualInputCallCount;
}
// Function to get the foreground process name
void MockedInput::SetForegroundProcess(std::wstring process)
{
currentProcess = process;
}
// Function to get the foreground process name
void MockedInput::GetForegroundProcess(_Out_ std::wstring& foregroundProcess)
{
foregroundProcess = currentProcess;
}

View File

@@ -1,57 +0,0 @@
#pragma once
#include <keyboardmanager/common/InputInterface.h>
#include <vector>
#include <functional>
#include <common/hooks/LowlevelKeyboardEvent.h>
// Class for mocked keyboard input
class MockedInput :
public KeyboardManagerInput::InputInterface
{
private:
// Stores the states for all the keys - false for key up, and true for key down
std::vector<bool> keyboardState;
// Function to be executed as a low level hook. By default it is nullptr so the hook is skipped
std::function<intptr_t(LowlevelKeyboardEvent*)> hookProc;
// Stores the count of sendVirtualInput calls given if the condition sendVirtualInputCallCondition is satisfied
int sendVirtualInputCallCount = 0;
std::function<bool(LowlevelKeyboardEvent*)> sendVirtualInputCallCondition;
std::wstring currentProcess;
public:
MockedInput()
{
keyboardState.resize(256, false);
}
// Set the keyboard hook procedure to be tested
void SetHookProc(std::function<intptr_t(LowlevelKeyboardEvent*)> hookProcedure);
// Function to simulate keyboard input
UINT SendVirtualInput(UINT cInputs, LPINPUT pInputs, int cbSize);
// Function to simulate keyboard hook behavior
intptr_t MockedKeyboardHook(LowlevelKeyboardEvent* data);
// Function to get the state of a particular key
bool GetVirtualKeyState(int key);
// Function to reset the mocked keyboard state
void ResetKeyboardState();
// Function to set SendVirtualInput call count condition
void SetSendVirtualInputTestHandler(std::function<bool(LowlevelKeyboardEvent*)> condition);
// Function to get SendVirtualInput call count
int GetSendVirtualInputCallCount();
// Function to get the foreground process name
void SetForegroundProcess(std::wstring process);
// Function to get the foreground process name
void GetForegroundProcess(_Out_ std::wstring& foregroundProcess);
};

View File

@@ -1,25 +0,0 @@
#include "pch.h"
#include "TestHelpers.h"
#include "MockedInput.h"
#include "keyboardmanager/common/KeyboardManagerState.h"
namespace TestHelpers
{
// Function to reset the environment variables for tests
void ResetTestEnv(MockedInput& input, KeyboardManagerState& state)
{
input.ResetKeyboardState();
input.SetHookProc(nullptr);
input.SetSendVirtualInputTestHandler(nullptr);
input.SetForegroundProcess(L"");
state.ClearSingleKeyRemaps();
state.ClearOSLevelShortcuts();
state.ClearAppSpecificShortcuts();
// Allocate memory for the keyboardManagerState activatedApp member to avoid CRT assert errors
std::wstring maxLengthString;
maxLengthString.resize(MAX_PATH);
state.SetActivatedApp(maxLengthString);
state.SetActivatedApp(KeyboardManagerConstants::NoActivatedApp);
}
}

View File

@@ -1,12 +0,0 @@
#pragma once
class MockedInput;
class KeyboardManagerState;
namespace TestHelpers
{
// Function to reset the environment variables for tests
void ResetTestEnv(MockedInput& input, KeyboardManagerState& 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);
}