Get rid of indexes in dropdowns (#7278)

This commit is contained in:
Mykhailo Pylyp
2020-10-19 12:27:47 +03:00
committed by GitHub
parent b80578b1b9
commit 7e0574cba2
18 changed files with 469 additions and 628 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -104,11 +104,10 @@ namespace KeyboardManagerCommonTests
TEST_METHOD (CheckRepeatedModifier_ShouldReturnTrue_OnPassingSameModifierRepeated)
{
// Arrange
std::vector<DWORD> keyList = LayoutMap().GetKeyCodeList(true);
std::vector<DWORD> keys = { VK_CONTROL, VK_CONTROL, 0x41 };
std::vector<int32_t> keys = { VK_CONTROL, VK_CONTROL, 0x41 };
// Act
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, TestHelpers::GetDropDownIndexFromDropDownList(VK_CONTROL, keyList), keyList);
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, VK_CONTROL);
// Assert
Assert::IsTrue(result);
@@ -118,11 +117,10 @@ namespace KeyboardManagerCommonTests
TEST_METHOD (CheckRepeatedModifier_ShouldReturnTrue_OnPassingConflictingModifierRepeated)
{
// Arrange
std::vector<DWORD> keyList = LayoutMap().GetKeyCodeList(true);
std::vector<DWORD> keys = { VK_CONTROL, VK_LCONTROL, 0x41 };
std::vector<int32_t> keys = { VK_CONTROL, VK_LCONTROL, 0x41 };
// Act
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, TestHelpers::GetDropDownIndexFromDropDownList(VK_LCONTROL, keyList), keyList);
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, VK_LCONTROL);
// Assert
Assert::IsTrue(result);
@@ -132,42 +130,13 @@ namespace KeyboardManagerCommonTests
TEST_METHOD (CheckRepeatedModifier_ShouldReturnFalse_OnPassingDifferentModifiers)
{
// Arrange
std::vector<DWORD> keyList = LayoutMap().GetKeyCodeList(true);
std::vector<DWORD> keys = { VK_CONTROL, VK_SHIFT, 0x41 };
std::vector<int32_t> keys = { VK_CONTROL, VK_SHIFT, 0x41 };
// Act
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, TestHelpers::GetDropDownIndexFromDropDownList(VK_SHIFT, keyList), keyList);
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, VK_SHIFT);
// Assert
Assert::IsFalse(result);
}
// Test if the GetKeyCodesFromSelectedIndices method ignores -1 and 0 from argument in return value
TEST_METHOD (GetKeyCodesFromSelectedIndices_ShouldIgnoreMinus1And0_OnPassingArgumentWithMinus1Or0)
{
// Arrange
std::vector<DWORD> keyList = LayoutMap().GetKeyCodeList(true);
std::vector<int32_t> indices = { -1, 0, -1, 0 };
// Act
auto result = KeyboardManagerHelper::GetKeyCodesFromSelectedIndices(indices, keyList);
// Assert
Assert::IsTrue(result.empty());
}
// Test if the GetKeyCodesFromSelectedIndices method returns vector with key codes from vector with indices as per key code list
TEST_METHOD (GetKeyCodesFromSelectedIndices_ShouldReturnVectorWithKeyCodes_OnPassingVectorWithIndicesAsPerKeyCodeList)
{
// Arrange
std::vector<DWORD> keyList = LayoutMap().GetKeyCodeList(true);
std::vector<int32_t> indices = { TestHelpers::GetDropDownIndexFromDropDownList(0x41, keyList), TestHelpers::GetDropDownIndexFromDropDownList(0x42, keyList) };
// Act
auto result = KeyboardManagerHelper::GetKeyCodesFromSelectedIndices(indices, keyList);
// Assert
Assert::IsTrue(result == std::vector<DWORD>{ 0x41, 0x42 });
}
};
}

View File

@@ -79,8 +79,8 @@ namespace KeyboardManagerCommonTests
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingInvalidShortcutForOneOfTheArguments)
{
// Arrange
Shortcut s1(std::vector<DWORD>{ NULL });
Shortcut s2(std::vector<DWORD>{ VK_CONTROL, 0x41 });
Shortcut s1(std::vector<int32_t>{ NULL });
Shortcut s2(std::vector<int32_t>{ VK_CONTROL, 0x41 });
// Act
auto result = Shortcut::DoKeysOverlap(s1, s2);
@@ -93,7 +93,7 @@ namespace KeyboardManagerCommonTests
TEST_METHOD (DoKeysOverlap_ShouldReturnSameShortcutPreviouslyMapped_OnPassingSameShortcutForBothArguments)
{
// Arrange
Shortcut s1(std::vector<DWORD>{ VK_CONTROL, 0x41 });
Shortcut s1(std::vector<int32_t>{ VK_CONTROL, 0x41 });
Shortcut s2 = s1;
// Act
@@ -107,8 +107,8 @@ namespace KeyboardManagerCommonTests
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingShortcutsWithDifferentActionKeys)
{
// Arrange
Shortcut s1(std::vector<DWORD>{ VK_CONTROL, 0x42 });
Shortcut s2(std::vector<DWORD>{ VK_CONTROL, 0x41 });
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);
@@ -121,8 +121,8 @@ namespace KeyboardManagerCommonTests
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingShortcutsWithDifferentModifiers)
{
// Arrange
Shortcut s1(std::vector<DWORD>{ VK_CONTROL, 0x42 });
Shortcut s2(std::vector<DWORD>{ VK_SHIFT, 0x42 });
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);
@@ -135,8 +135,8 @@ namespace KeyboardManagerCommonTests
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithLeftModifierAndCommonModifierOfSameType)
{
// Arrange
Shortcut s1(std::vector<DWORD>{ VK_LCONTROL, 0x42 });
Shortcut s2(std::vector<DWORD>{ VK_CONTROL, 0x42 });
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);
@@ -149,8 +149,8 @@ namespace KeyboardManagerCommonTests
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithRightModifierAndCommonModifierOfSameType)
{
// Arrange
Shortcut s1(std::vector<DWORD>{ VK_RCONTROL, 0x42 });
Shortcut s2(std::vector<DWORD>{ VK_CONTROL, 0x42 });
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);
@@ -163,8 +163,8 @@ namespace KeyboardManagerCommonTests
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithLeftModifierAndRightModifierOfSameType)
{
// Arrange
Shortcut s1(std::vector<DWORD>{ VK_LCONTROL, 0x42 });
Shortcut s2(std::vector<DWORD>{ VK_RCONTROL, 0x42 });
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);

View File

@@ -22,10 +22,4 @@ namespace TestHelpers
state.SetActivatedApp(maxLengthString);
state.SetActivatedApp(KeyboardManagerConstants::NoActivatedApp);
}
// 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)
{
return (int)std::distance(keyList.begin(), std::find(keyList.begin(), keyList.end(), key));
}
}