refactor: port deskflow/keyMapTest to QtTests
remove TEST_ENV items from KeyMap KeyMap and KeyMapTests are friends
This commit is contained in:
parent
632be4b240
commit
9d867f6146
4 changed files with 94 additions and 104 deletions
|
|
@ -14,10 +14,6 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef TEST_ENV
|
|
||||||
#include "gtest/gtest_prod.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace deskflow {
|
namespace deskflow {
|
||||||
|
|
||||||
//! Key map
|
//! Key map
|
||||||
|
|
@ -27,6 +23,9 @@ This class provides a keyboard mapping.
|
||||||
class KeyMap
|
class KeyMap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// Class used for testing
|
||||||
|
friend class KeyMapTests;
|
||||||
|
|
||||||
KeyMap();
|
KeyMap();
|
||||||
virtual ~KeyMap() = default;
|
virtual ~KeyMap() = default;
|
||||||
|
|
||||||
|
|
@ -320,16 +319,6 @@ public:
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
#ifdef TEST_ENV
|
|
||||||
private:
|
|
||||||
FRIEND_TEST(KeyMapTests, findBestKey_requiredDown_matchExactFirstItem);
|
|
||||||
FRIEND_TEST(KeyMapTests, findBestKey_requiredAndExtraSensitiveDown_matchExactFirstItem);
|
|
||||||
FRIEND_TEST(KeyMapTests, findBestKey_requiredAndExtraSensitiveDown_matchExactSecondItem);
|
|
||||||
FRIEND_TEST(KeyMapTests, findBestKey_extraSensitiveDown_matchExactSecondItem);
|
|
||||||
FRIEND_TEST(KeyMapTests, findBestKey_noRequiredDown_matchOneRequiredChangeItem);
|
|
||||||
FRIEND_TEST(KeyMapTests, findBestKey_onlyOneRequiredDown_matchTwoRequiredChangesItem);
|
|
||||||
FRIEND_TEST(KeyMapTests, findBestKey_noRequiredDown_cannotMatch);
|
|
||||||
#endif
|
|
||||||
private:
|
private:
|
||||||
//! Ways to synthesize a key
|
//! Ways to synthesize a key
|
||||||
enum EKeystroke
|
enum EKeystroke
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,13 @@ create_test(
|
||||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
create_test(
|
||||||
|
NAME KeyMapTests
|
||||||
|
DEPENDS app
|
||||||
|
LIBS arch base ${extra_libs}
|
||||||
|
SOURCE KeyMapTests.cpp
|
||||||
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
||||||
|
)
|
||||||
|
|
||||||
create_test(
|
create_test(
|
||||||
NAME test_LanguageManagerTests
|
NAME test_LanguageManagerTests
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,22 @@
|
||||||
/*
|
/*
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||||
* SPDX-FileCopyrightText: (C) 2016 Symless Ltd.
|
* SPDX-FileCopyrightText: (C) 2016 Symless Ltd.
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
*/
|
*/
|
||||||
|
#include "KeyMapTests.h"
|
||||||
|
|
||||||
#define TEST_ENV
|
#include "../../lib/deskflow/KeyMap.h"
|
||||||
|
|
||||||
#include "deskflow/KeyMap.h"
|
using namespace deskflow;
|
||||||
|
using KeyItemList = KeyMap::KeyItemList;
|
||||||
|
using KeyEntryList = std::vector<KeyItemList>;
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
void KeyMapTests::findBestKey_requiredDown_matchExactFirstItem()
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
using ::testing::_;
|
|
||||||
using ::testing::Invoke;
|
|
||||||
using ::testing::NiceMock;
|
|
||||||
using ::testing::Return;
|
|
||||||
using ::testing::ReturnRef;
|
|
||||||
using ::testing::SaveArg;
|
|
||||||
|
|
||||||
namespace deskflow {
|
|
||||||
|
|
||||||
TEST(KeyMapTests, findBestKey_requiredDown_matchExactFirstItem)
|
|
||||||
{
|
{
|
||||||
KeyMap keyMap;
|
KeyMap keyMap;
|
||||||
KeyMap::KeyEntryList entryList;
|
KeyEntryList entryList;
|
||||||
KeyMap::KeyItemList itemList;
|
KeyItemList itemList;
|
||||||
KeyMap::KeyItem item;
|
KeyMap::KeyItem item;
|
||||||
item.m_required = KeyModifierShift;
|
item.m_required = KeyModifierShift;
|
||||||
item.m_sensitive = KeyModifierShift;
|
item.m_sensitive = KeyModifierShift;
|
||||||
|
|
@ -32,14 +24,14 @@ TEST(KeyMapTests, findBestKey_requiredDown_matchExactFirstItem)
|
||||||
itemList.push_back(item);
|
itemList.push_back(item);
|
||||||
entryList.push_back(itemList);
|
entryList.push_back(itemList);
|
||||||
|
|
||||||
EXPECT_EQ(0, keyMap.findBestKey(entryList, desiredState));
|
QCOMPARE(keyMap.findBestKey(entryList, desiredState), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(KeyMapTests, findBestKey_requiredAndExtraSensitiveDown_matchExactFirstItem)
|
void KeyMapTests::findBestKey_requiredAndExtraSensitiveDown_matchExactFirstItem()
|
||||||
{
|
{
|
||||||
KeyMap keyMap;
|
KeyMap keyMap;
|
||||||
KeyMap::KeyEntryList entryList;
|
KeyEntryList entryList;
|
||||||
KeyMap::KeyItemList itemList;
|
KeyItemList itemList;
|
||||||
KeyMap::KeyItem item;
|
KeyMap::KeyItem item;
|
||||||
item.m_required = KeyModifierShift;
|
item.m_required = KeyModifierShift;
|
||||||
item.m_sensitive = KeyModifierShift | KeyModifierAlt;
|
item.m_sensitive = KeyModifierShift | KeyModifierAlt;
|
||||||
|
|
@ -47,14 +39,14 @@ TEST(KeyMapTests, findBestKey_requiredAndExtraSensitiveDown_matchExactFirstItem)
|
||||||
itemList.push_back(item);
|
itemList.push_back(item);
|
||||||
entryList.push_back(itemList);
|
entryList.push_back(itemList);
|
||||||
|
|
||||||
EXPECT_EQ(0, keyMap.findBestKey(entryList, desiredState));
|
QCOMPARE(keyMap.findBestKey(entryList, desiredState), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(KeyMapTests, findBestKey_requiredAndExtraSensitiveDown_matchExactSecondItem)
|
void KeyMapTests::findBestKey_requiredAndExtraSensitiveDown_matchExactSecondItem()
|
||||||
{
|
{
|
||||||
KeyMap keyMap;
|
KeyMap keyMap;
|
||||||
KeyMap::KeyEntryList entryList;
|
KeyEntryList entryList;
|
||||||
KeyMap::KeyItemList itemList1;
|
KeyItemList itemList1;
|
||||||
KeyMap::KeyItem item1;
|
KeyMap::KeyItem item1;
|
||||||
item1.m_required = KeyModifierAlt;
|
item1.m_required = KeyModifierAlt;
|
||||||
item1.m_sensitive = KeyModifierShift | KeyModifierAlt;
|
item1.m_sensitive = KeyModifierShift | KeyModifierAlt;
|
||||||
|
|
@ -67,15 +59,14 @@ TEST(KeyMapTests, findBestKey_requiredAndExtraSensitiveDown_matchExactSecondItem
|
||||||
itemList2.push_back(item2);
|
itemList2.push_back(item2);
|
||||||
entryList.push_back(itemList1);
|
entryList.push_back(itemList1);
|
||||||
entryList.push_back(itemList2);
|
entryList.push_back(itemList2);
|
||||||
|
QCOMPARE(keyMap.findBestKey(entryList, desiredState), 1);
|
||||||
EXPECT_EQ(1, keyMap.findBestKey(entryList, desiredState));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(KeyMapTests, findBestKey_extraSensitiveDown_matchExactSecondItem)
|
void KeyMapTests::findBestKey_extraSensitiveDown_matchExactSecondItem()
|
||||||
{
|
{
|
||||||
KeyMap keyMap;
|
KeyMap keyMap;
|
||||||
KeyMap::KeyEntryList entryList;
|
KeyEntryList entryList;
|
||||||
KeyMap::KeyItemList itemList1;
|
KeyItemList itemList1;
|
||||||
KeyMap::KeyItem item1;
|
KeyMap::KeyItem item1;
|
||||||
item1.m_required = 0;
|
item1.m_required = 0;
|
||||||
item1.m_sensitive = KeyModifierAlt;
|
item1.m_sensitive = KeyModifierAlt;
|
||||||
|
|
@ -89,14 +80,14 @@ TEST(KeyMapTests, findBestKey_extraSensitiveDown_matchExactSecondItem)
|
||||||
entryList.push_back(itemList1);
|
entryList.push_back(itemList1);
|
||||||
entryList.push_back(itemList2);
|
entryList.push_back(itemList2);
|
||||||
|
|
||||||
EXPECT_EQ(1, keyMap.findBestKey(entryList, desiredState));
|
QCOMPARE(keyMap.findBestKey(entryList, desiredState), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(KeyMapTests, findBestKey_noRequiredDown_matchOneRequiredChangeItem)
|
void KeyMapTests::findBestKey_noRequiredDown_matchOneRequiredChangeItem()
|
||||||
{
|
{
|
||||||
KeyMap keyMap;
|
KeyMap keyMap;
|
||||||
KeyMap::KeyEntryList entryList;
|
KeyEntryList entryList;
|
||||||
KeyMap::KeyItemList itemList1;
|
KeyItemList itemList1;
|
||||||
KeyMap::KeyItem item1;
|
KeyMap::KeyItem item1;
|
||||||
item1.m_required = KeyModifierShift | KeyModifierAlt;
|
item1.m_required = KeyModifierShift | KeyModifierAlt;
|
||||||
item1.m_sensitive = KeyModifierShift | KeyModifierAlt;
|
item1.m_sensitive = KeyModifierShift | KeyModifierAlt;
|
||||||
|
|
@ -110,18 +101,18 @@ TEST(KeyMapTests, findBestKey_noRequiredDown_matchOneRequiredChangeItem)
|
||||||
entryList.push_back(itemList1);
|
entryList.push_back(itemList1);
|
||||||
entryList.push_back(itemList2);
|
entryList.push_back(itemList2);
|
||||||
|
|
||||||
EXPECT_EQ(1, keyMap.findBestKey(entryList, desiredState));
|
QCOMPARE(keyMap.findBestKey(entryList, desiredState), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(KeyMapTests, findBestKey_onlyOneRequiredDown_matchTwoRequiredChangesItem)
|
void KeyMapTests::findBestKey_onlyOneRequiredDown_matchTwoRequiredChangesItem()
|
||||||
{
|
{
|
||||||
KeyMap keyMap;
|
KeyMap keyMap;
|
||||||
KeyMap::KeyEntryList entryList;
|
KeyEntryList entryList;
|
||||||
KeyMap::KeyItemList itemList1;
|
KeyItemList itemList1;
|
||||||
KeyMap::KeyItem item1;
|
KeyMap::KeyItem item1;
|
||||||
item1.m_required = KeyModifierShift | KeyModifierAlt | KeyModifierControl;
|
item1.m_required = KeyModifierShift | KeyModifierAlt | KeyModifierControl;
|
||||||
item1.m_sensitive = KeyModifierShift | KeyModifierAlt | KeyModifierControl;
|
item1.m_sensitive = KeyModifierShift | KeyModifierAlt | KeyModifierControl;
|
||||||
KeyMap::KeyItemList itemList2;
|
KeyItemList itemList2;
|
||||||
KeyMap::KeyItem item2;
|
KeyMap::KeyItem item2;
|
||||||
item2.m_required = KeyModifierShift | KeyModifierAlt;
|
item2.m_required = KeyModifierShift | KeyModifierAlt;
|
||||||
item2.m_sensitive = KeyModifierShift | KeyModifierAlt | KeyModifierControl;
|
item2.m_sensitive = KeyModifierShift | KeyModifierAlt | KeyModifierControl;
|
||||||
|
|
@ -131,14 +122,14 @@ TEST(KeyMapTests, findBestKey_onlyOneRequiredDown_matchTwoRequiredChangesItem)
|
||||||
entryList.push_back(itemList1);
|
entryList.push_back(itemList1);
|
||||||
entryList.push_back(itemList2);
|
entryList.push_back(itemList2);
|
||||||
|
|
||||||
EXPECT_EQ(1, keyMap.findBestKey(entryList, desiredState));
|
QCOMPARE(keyMap.findBestKey(entryList, desiredState), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(KeyMapTests, findBestKey_noRequiredDown_cannotMatch)
|
void KeyMapTests::findBestKey_noRequiredDown_cannotMatch()
|
||||||
{
|
{
|
||||||
KeyMap keyMap;
|
KeyMap keyMap;
|
||||||
KeyMap::KeyEntryList entryList;
|
KeyEntryList entryList;
|
||||||
KeyMap::KeyItemList itemList;
|
KeyItemList itemList;
|
||||||
KeyMap::KeyItem item;
|
KeyMap::KeyItem item;
|
||||||
item.m_required = 0xffffffff;
|
item.m_required = 0xffffffff;
|
||||||
item.m_sensitive = 0xffffffff;
|
item.m_sensitive = 0xffffffff;
|
||||||
|
|
@ -146,58 +137,32 @@ TEST(KeyMapTests, findBestKey_noRequiredDown_cannotMatch)
|
||||||
itemList.push_back(item);
|
itemList.push_back(item);
|
||||||
entryList.push_back(itemList);
|
entryList.push_back(itemList);
|
||||||
|
|
||||||
EXPECT_EQ(-1, keyMap.findBestKey(entryList, desiredState));
|
QCOMPARE(keyMap.findBestKey(entryList, desiredState), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(KeyMapTests, isCommand_shiftMask_returnFalse)
|
void KeyMapTests::isCommand()
|
||||||
{
|
{
|
||||||
KeyMap keyMap;
|
KeyMap keyMap;
|
||||||
KeyModifierMask mask = KeyModifierShift;
|
KeyModifierMask mask = KeyModifierShift;
|
||||||
|
QVERIFY(!keyMap.isCommand(mask));
|
||||||
|
|
||||||
EXPECT_FALSE(keyMap.isCommand(mask));
|
mask = KeyModifierControl;
|
||||||
|
QVERIFY(keyMap.isCommand(mask));
|
||||||
|
|
||||||
|
mask = KeyModifierAlt;
|
||||||
|
QVERIFY(keyMap.isCommand(mask));
|
||||||
|
|
||||||
|
mask = KeyModifierAltGr;
|
||||||
|
QVERIFY(keyMap.isCommand(mask));
|
||||||
|
|
||||||
|
mask = KeyModifierMeta;
|
||||||
|
QVERIFY(keyMap.isCommand(mask));
|
||||||
|
|
||||||
|
mask = KeyModifierSuper;
|
||||||
|
QVERIFY(keyMap.isCommand(mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(KeyMapTests, isCommand_controlMask_returnTrue)
|
void KeyMapTests::mapkey()
|
||||||
{
|
|
||||||
KeyMap keyMap;
|
|
||||||
KeyModifierMask mask = KeyModifierControl;
|
|
||||||
|
|
||||||
EXPECT_EQ(true, keyMap.isCommand(mask));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(KeyMapTests, isCommand_alternateMask_returnTrue)
|
|
||||||
{
|
|
||||||
KeyMap keyMap;
|
|
||||||
KeyModifierMask mask = KeyModifierAlt;
|
|
||||||
|
|
||||||
EXPECT_EQ(true, keyMap.isCommand(mask));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(KeyMapTests, isCommand_alternateGraphicMask_returnTrue)
|
|
||||||
{
|
|
||||||
KeyMap keyMap;
|
|
||||||
KeyModifierMask mask = KeyModifierAltGr;
|
|
||||||
|
|
||||||
EXPECT_EQ(true, keyMap.isCommand(mask));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(KeyMapTests, isCommand_metaMask_returnTrue)
|
|
||||||
{
|
|
||||||
KeyMap keyMap;
|
|
||||||
KeyModifierMask mask = KeyModifierMeta;
|
|
||||||
|
|
||||||
EXPECT_EQ(true, keyMap.isCommand(mask));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(KeyMapTests, isCommand_superMask_returnTrue)
|
|
||||||
{
|
|
||||||
KeyMap keyMap;
|
|
||||||
KeyModifierMask mask = KeyModifierSuper;
|
|
||||||
|
|
||||||
EXPECT_EQ(true, keyMap.isCommand(mask));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(KeyMapTests, mapkey_handles_setmodifier_with_no_mapped)
|
|
||||||
{
|
{
|
||||||
KeyMap keyMap{};
|
KeyMap keyMap{};
|
||||||
KeyMap::Keystroke stroke('A', true, false, 1);
|
KeyMap::Keystroke stroke('A', true, false, 1);
|
||||||
|
|
@ -212,10 +177,10 @@ TEST(KeyMapTests, mapkey_handles_setmodifier_with_no_mapped)
|
||||||
KeyModifierMask currentState{};
|
KeyModifierMask currentState{};
|
||||||
KeyModifierMask desiredMask{};
|
KeyModifierMask desiredMask{};
|
||||||
auto result = keyMap.mapKey(strokes, kKeySetModifiers, 1, activeModifiers, currentState, desiredMask, false, "en");
|
auto result = keyMap.mapKey(strokes, kKeySetModifiers, 1, activeModifiers, currentState, desiredMask, false, "en");
|
||||||
EXPECT_FALSE(result == nullptr);
|
QVERIFY(result != nullptr);
|
||||||
desiredMask = KeyModifierControl;
|
desiredMask = KeyModifierControl;
|
||||||
result = keyMap.mapKey(strokes, kKeySetModifiers, 1, activeModifiers, currentState, desiredMask, false, "en");
|
result = keyMap.mapKey(strokes, kKeySetModifiers, 1, activeModifiers, currentState, desiredMask, false, "en");
|
||||||
EXPECT_TRUE(result == nullptr);
|
QVERIFY(result == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace deskflow
|
QTEST_MAIN(KeyMapTests)
|
||||||
29
src/unittests/deskflow/KeyMapTests.h
Normal file
29
src/unittests/deskflow/KeyMapTests.h
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
|
*/
|
||||||
|
#include "base/Log.h"
|
||||||
|
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
namespace deskflow {
|
||||||
|
class KeyMapTests : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private slots:
|
||||||
|
void findBestKey_requiredDown_matchExactFirstItem();
|
||||||
|
void findBestKey_requiredAndExtraSensitiveDown_matchExactFirstItem();
|
||||||
|
void findBestKey_requiredAndExtraSensitiveDown_matchExactSecondItem();
|
||||||
|
void findBestKey_extraSensitiveDown_matchExactSecondItem();
|
||||||
|
void findBestKey_noRequiredDown_matchOneRequiredChangeItem();
|
||||||
|
void findBestKey_onlyOneRequiredDown_matchTwoRequiredChangesItem();
|
||||||
|
void findBestKey_noRequiredDown_cannotMatch();
|
||||||
|
void isCommand();
|
||||||
|
void mapkey();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Arch m_arch;
|
||||||
|
Log m_log;
|
||||||
|
};
|
||||||
|
} // namespace deskflow
|
||||||
Loading…
Reference in a new issue