refactor: port deskflow/keyMapTest to QtTests
remove TEST_ENV items from KeyMap KeyMap and KeyMapTests are friends
This commit is contained in:
@ -14,10 +14,6 @@
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#ifdef TEST_ENV
|
||||
#include "gtest/gtest_prod.h"
|
||||
#endif
|
||||
|
||||
namespace deskflow {
|
||||
|
||||
//! Key map
|
||||
@ -27,6 +23,9 @@ This class provides a keyboard mapping.
|
||||
class KeyMap
|
||||
{
|
||||
public:
|
||||
// Class used for testing
|
||||
friend class KeyMapTests;
|
||||
|
||||
KeyMap();
|
||||
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:
|
||||
//! Ways to synthesize a key
|
||||
enum EKeystroke
|
||||
|
||||
@ -45,6 +45,13 @@ create_test(
|
||||
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(
|
||||
NAME test_LanguageManagerTests
|
||||
|
||||
@ -1,30 +1,22 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
* SPDX-FileCopyrightText: (C) 2016 Symless Ltd.
|
||||
* 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>
|
||||
#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)
|
||||
void KeyMapTests::findBestKey_requiredDown_matchExactFirstItem()
|
||||
{
|
||||
KeyMap keyMap;
|
||||
KeyMap::KeyEntryList entryList;
|
||||
KeyMap::KeyItemList itemList;
|
||||
KeyEntryList entryList;
|
||||
KeyItemList itemList;
|
||||
KeyMap::KeyItem item;
|
||||
item.m_required = KeyModifierShift;
|
||||
item.m_sensitive = KeyModifierShift;
|
||||
@ -32,14 +24,14 @@ TEST(KeyMapTests, findBestKey_requiredDown_matchExactFirstItem)
|
||||
itemList.push_back(item);
|
||||
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::KeyEntryList entryList;
|
||||
KeyMap::KeyItemList itemList;
|
||||
KeyEntryList entryList;
|
||||
KeyItemList itemList;
|
||||
KeyMap::KeyItem item;
|
||||
item.m_required = KeyModifierShift;
|
||||
item.m_sensitive = KeyModifierShift | KeyModifierAlt;
|
||||
@ -47,14 +39,14 @@ TEST(KeyMapTests, findBestKey_requiredAndExtraSensitiveDown_matchExactFirstItem)
|
||||
itemList.push_back(item);
|
||||
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::KeyEntryList entryList;
|
||||
KeyMap::KeyItemList itemList1;
|
||||
KeyEntryList entryList;
|
||||
KeyItemList itemList1;
|
||||
KeyMap::KeyItem item1;
|
||||
item1.m_required = KeyModifierAlt;
|
||||
item1.m_sensitive = KeyModifierShift | KeyModifierAlt;
|
||||
@ -67,15 +59,14 @@ TEST(KeyMapTests, findBestKey_requiredAndExtraSensitiveDown_matchExactSecondItem
|
||||
itemList2.push_back(item2);
|
||||
entryList.push_back(itemList1);
|
||||
entryList.push_back(itemList2);
|
||||
|
||||
EXPECT_EQ(1, keyMap.findBestKey(entryList, desiredState));
|
||||
QCOMPARE(keyMap.findBestKey(entryList, desiredState), 1);
|
||||
}
|
||||
|
||||
TEST(KeyMapTests, findBestKey_extraSensitiveDown_matchExactSecondItem)
|
||||
void KeyMapTests::findBestKey_extraSensitiveDown_matchExactSecondItem()
|
||||
{
|
||||
KeyMap keyMap;
|
||||
KeyMap::KeyEntryList entryList;
|
||||
KeyMap::KeyItemList itemList1;
|
||||
KeyEntryList entryList;
|
||||
KeyItemList itemList1;
|
||||
KeyMap::KeyItem item1;
|
||||
item1.m_required = 0;
|
||||
item1.m_sensitive = KeyModifierAlt;
|
||||
@ -89,14 +80,14 @@ TEST(KeyMapTests, findBestKey_extraSensitiveDown_matchExactSecondItem)
|
||||
entryList.push_back(itemList1);
|
||||
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::KeyEntryList entryList;
|
||||
KeyMap::KeyItemList itemList1;
|
||||
KeyEntryList entryList;
|
||||
KeyItemList itemList1;
|
||||
KeyMap::KeyItem item1;
|
||||
item1.m_required = KeyModifierShift | KeyModifierAlt;
|
||||
item1.m_sensitive = KeyModifierShift | KeyModifierAlt;
|
||||
@ -110,18 +101,18 @@ TEST(KeyMapTests, findBestKey_noRequiredDown_matchOneRequiredChangeItem)
|
||||
entryList.push_back(itemList1);
|
||||
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::KeyEntryList entryList;
|
||||
KeyMap::KeyItemList itemList1;
|
||||
KeyEntryList entryList;
|
||||
KeyItemList itemList1;
|
||||
KeyMap::KeyItem item1;
|
||||
item1.m_required = KeyModifierShift | KeyModifierAlt | KeyModifierControl;
|
||||
item1.m_sensitive = KeyModifierShift | KeyModifierAlt | KeyModifierControl;
|
||||
KeyMap::KeyItemList itemList2;
|
||||
KeyItemList itemList2;
|
||||
KeyMap::KeyItem item2;
|
||||
item2.m_required = KeyModifierShift | KeyModifierAlt;
|
||||
item2.m_sensitive = KeyModifierShift | KeyModifierAlt | KeyModifierControl;
|
||||
@ -131,14 +122,14 @@ TEST(KeyMapTests, findBestKey_onlyOneRequiredDown_matchTwoRequiredChangesItem)
|
||||
entryList.push_back(itemList1);
|
||||
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::KeyEntryList entryList;
|
||||
KeyMap::KeyItemList itemList;
|
||||
KeyEntryList entryList;
|
||||
KeyItemList itemList;
|
||||
KeyMap::KeyItem item;
|
||||
item.m_required = 0xffffffff;
|
||||
item.m_sensitive = 0xffffffff;
|
||||
@ -146,58 +137,32 @@ TEST(KeyMapTests, findBestKey_noRequiredDown_cannotMatch)
|
||||
itemList.push_back(item);
|
||||
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;
|
||||
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)
|
||||
{
|
||||
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)
|
||||
void KeyMapTests::mapkey()
|
||||
{
|
||||
KeyMap keyMap{};
|
||||
KeyMap::Keystroke stroke('A', true, false, 1);
|
||||
@ -212,10 +177,10 @@ TEST(KeyMapTests, mapkey_handles_setmodifier_with_no_mapped)
|
||||
KeyModifierMask currentState{};
|
||||
KeyModifierMask desiredMask{};
|
||||
auto result = keyMap.mapKey(strokes, kKeySetModifiers, 1, activeModifiers, currentState, desiredMask, false, "en");
|
||||
EXPECT_FALSE(result == nullptr);
|
||||
QVERIFY(result != nullptr);
|
||||
desiredMask = KeyModifierControl;
|
||||
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
|
||||
Reference in New Issue
Block a user