From 975feacf5e91cae42eb83b1c8957ba8306190938 Mon Sep 17 00:00:00 2001 From: taj_ny Date: Wed, 11 Mar 2026 21:36:42 +0100 Subject: [PATCH] tests: remove useless headers --- tests/libinputactions/TestRange.cpp | 70 +- tests/libinputactions/TestRange.h | 18 - tests/libinputactions/TestValue.cpp | 94 +- tests/libinputactions/TestValue.h | 27 - tests/libinputactions/actions/TestAction.cpp | 55 +- tests/libinputactions/actions/TestAction.h | 17 - .../actions/TestActionExecutor.cpp | 171 ++-- .../actions/TestActionExecutor.h | 27 - .../actions/TestActionGroup.cpp | 83 +- .../libinputactions/actions/TestActionGroup.h | 17 - .../actions/TestActionInterval.cpp | 65 +- .../actions/TestActionInterval.h | 17 - .../actions/TestTriggerAction.cpp | 177 ++-- .../actions/TestTriggerAction.h | 22 - .../conditions/TestConditionGroup.cpp | 113 +-- .../conditions/TestConditionGroup.h | 17 - .../config/parsers/TestBaseNodeParser.cpp | 575 +++++++------ .../config/parsers/TestBaseNodeParser.h | 51 -- .../parsers/TestDeviceRuleNodeParser.cpp | 405 ++++----- .../config/parsers/TestDeviceRuleNodeParser.h | 31 - .../config/parsers/TestEnumNodeParser.cpp | 43 +- .../config/parsers/TestEnumNodeParser.h | 18 - .../config/parsers/TestFlagsNodeParser.cpp | 77 +- .../config/parsers/TestFlagsNodeParser.h | 21 - .../config/parsers/TestRangeNodeParser.cpp | 37 +- .../config/parsers/TestRangeNodeParser.h | 17 - .../parsers/TestSeparatedStringNodeParser.cpp | 97 ++- .../parsers/TestSeparatedStringNodeParser.h | 21 - .../parsers/TestTriggerActionNodeParser.cpp | 191 ++-- .../parsers/TestTriggerActionNodeParser.h | 24 - .../parsers/TestTriggerGroupNodeParser.cpp | 455 +++++----- .../parsers/TestTriggerGroupNodeParser.h | 30 - .../config/parsers/TestTriggerNodeParser.cpp | 521 +++++------ .../config/parsers/TestTriggerNodeParser.h | 39 - .../actions/TestActionGroupNodeParser.cpp | 57 +- .../actions/TestActionGroupNodeParser.h | 16 - .../actions/TestInputActionNodeParser.cpp | 401 ++++----- .../actions/TestInputActionNodeParser.h | 34 - .../TestPlasmaShortcutActionNodeParser.cpp | 37 +- .../TestPlasmaShortcutActionNodeParser.h | 17 - .../TestConditionGroupNodeParser.cpp | 153 ++-- .../conditions/TestConditionGroupNodeParser.h | 23 - .../conditions/TestConditionNodeParser.cpp | 29 +- .../conditions/TestConditionNodeParser.h | 17 - .../TestVariableConditionNodeParser.cpp | 531 ++++++------ .../TestVariableConditionNodeParser.h | 45 - .../parsers/containers/TestSetNodeParser.cpp | 47 +- .../parsers/containers/TestSetNodeParser.h | 19 - .../containers/TestVectorNodeParser.cpp | 47 +- .../parsers/containers/TestVectorNodeParser.h | 19 - .../parsers/qt/TestQPointFNodeParser.cpp | 31 +- .../config/parsers/qt/TestQPointFNodeParser.h | 17 - .../qt/TestQRegularExpressionNodeParser.cpp | 33 +- .../qt/TestQRegularExpressionNodeParser.h | 17 - .../parsers/qt/TestQStringListNodeParser.cpp | 25 +- .../parsers/qt/TestQStringListNodeParser.h | 16 - .../parsers/qt/TestQStringNodeParser.cpp | 19 +- .../config/parsers/qt/TestQStringNodeParser.h | 16 - .../handlers/TestInputTriggerHandler.cpp | 77 +- .../handlers/TestInputTriggerHandler.h | 25 - .../handlers/TestKeyboardTriggerHandler.cpp | 51 +- .../handlers/TestKeyboardTriggerHandler.h | 16 - .../handlers/TestMotionTriggerHandler.cpp | 287 +++--- .../handlers/TestMotionTriggerHandler.h | 31 - .../handlers/TestTouchpadTriggerHandler.cpp | 814 +++++++++--------- .../handlers/TestTouchpadTriggerHandler.h | 67 -- .../handlers/TestTriggerHandler.cpp | 109 +-- .../handlers/TestTriggerHandler.h | 28 - .../triggers/TestDirectionalMotionTrigger.cpp | 140 +-- .../triggers/TestDirectionalMotionTrigger.h | 17 - .../triggers/TestMotionTrigger.cpp | 69 +- .../triggers/TestMotionTrigger.h | 17 - .../triggers/TestSwipeTrigger.cpp | 347 ++++---- .../triggers/TestSwipeTrigger.h | 30 - .../libinputactions/triggers/TestTrigger.cpp | 190 ++-- tests/libinputactions/triggers/TestTrigger.h | 26 - 76 files changed, 3509 insertions(+), 4141 deletions(-) delete mode 100644 tests/libinputactions/TestRange.h delete mode 100644 tests/libinputactions/TestValue.h delete mode 100644 tests/libinputactions/actions/TestAction.h delete mode 100644 tests/libinputactions/actions/TestActionExecutor.h delete mode 100644 tests/libinputactions/actions/TestActionGroup.h delete mode 100644 tests/libinputactions/actions/TestActionInterval.h delete mode 100644 tests/libinputactions/actions/TestTriggerAction.h delete mode 100644 tests/libinputactions/conditions/TestConditionGroup.h delete mode 100644 tests/libinputactions/config/parsers/TestBaseNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/TestEnumNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/TestFlagsNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/TestRangeNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/TestSeparatedStringNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/TestTriggerActionNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/TestTriggerGroupNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/TestTriggerNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/actions/TestActionGroupNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/actions/TestInputActionNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/actions/TestPlasmaShortcutActionNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/conditions/TestConditionGroupNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/conditions/TestConditionNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/containers/TestSetNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/containers/TestVectorNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/qt/TestQPointFNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/qt/TestQRegularExpressionNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/qt/TestQStringListNodeParser.h delete mode 100644 tests/libinputactions/config/parsers/qt/TestQStringNodeParser.h delete mode 100644 tests/libinputactions/handlers/TestInputTriggerHandler.h delete mode 100644 tests/libinputactions/handlers/TestKeyboardTriggerHandler.h delete mode 100644 tests/libinputactions/handlers/TestMotionTriggerHandler.h delete mode 100644 tests/libinputactions/handlers/TestTouchpadTriggerHandler.h delete mode 100644 tests/libinputactions/handlers/TestTriggerHandler.h delete mode 100644 tests/libinputactions/triggers/TestDirectionalMotionTrigger.h delete mode 100644 tests/libinputactions/triggers/TestMotionTrigger.h delete mode 100644 tests/libinputactions/triggers/TestSwipeTrigger.h delete mode 100644 tests/libinputactions/triggers/TestTrigger.h diff --git a/tests/libinputactions/TestRange.cpp b/tests/libinputactions/TestRange.cpp index a386ee2..4913ea4 100644 --- a/tests/libinputactions/TestRange.cpp +++ b/tests/libinputactions/TestRange.cpp @@ -1,41 +1,49 @@ -#include "TestRange.h" +#include "Test.h" +#include namespace InputActions { -void TestRange::contains_qreal_data() +class TestRange : public Test { - QTest::addColumn>("min"); - QTest::addColumn>("max"); - QTest::addColumn("value"); - QTest::addColumn("result"); - - QTest::addRow("none, 0") << std::optional() << std::optional() << 0 << true; - QTest::addRow("none, positive") << std::optional() << std::optional() << 1 << true; - QTest::addRow("none, negative") << std::optional() << std::optional() << -1 << true; - QTest::addRow("min, below") << std::optional{1} << std::optional() << -1 << false; - QTest::addRow("min, equal") << std::optional{1} << std::optional() << 1 << true; - QTest::addRow("min, above") << std::optional{1} << std::optional() << 2 << true; - QTest::addRow("max, below") << std::optional() << std::optional{1} << -1 << true; - QTest::addRow("max, equal") << std::optional() << std::optional{1} << 1 << true; - QTest::addRow("max, above") << std::optional() << std::optional{1} << 2 << false; - QTest::addRow("minmax, below") << std::optional{-1} << std::optional{1} << -2 << false; - QTest::addRow("minmax, equal to min") << std::optional{-1} << std::optional{1} << -1 << true; - QTest::addRow("minmax, between") << std::optional{-1} << std::optional{1} << 0 << true; - QTest::addRow("minmax, equal to max") << std::optional{-1} << std::optional{1} << 1 << true; - QTest::addRow("minmax, above") << std::optional{-1} << std::optional{1} << 2 << false; -} + Q_OBJECT -void TestRange::contains_qreal() -{ - QFETCH(std::optional, min); - QFETCH(std::optional, max); - QFETCH(int, value); - QFETCH(bool, result); +private slots: + void contains_qreal_data() + { + QTest::addColumn>("min"); + QTest::addColumn>("max"); + QTest::addColumn("value"); + QTest::addColumn("result"); - QCOMPARE(Range(min, max).contains(value), result); -} + QTest::addRow("none, 0") << std::optional() << std::optional() << 0 << true; + QTest::addRow("none, positive") << std::optional() << std::optional() << 1 << true; + QTest::addRow("none, negative") << std::optional() << std::optional() << -1 << true; + QTest::addRow("min, below") << std::optional{1} << std::optional() << -1 << false; + QTest::addRow("min, equal") << std::optional{1} << std::optional() << 1 << true; + QTest::addRow("min, above") << std::optional{1} << std::optional() << 2 << true; + QTest::addRow("max, below") << std::optional() << std::optional{1} << -1 << true; + QTest::addRow("max, equal") << std::optional() << std::optional{1} << 1 << true; + QTest::addRow("max, above") << std::optional() << std::optional{1} << 2 << false; + QTest::addRow("minmax, below") << std::optional{-1} << std::optional{1} << -2 << false; + QTest::addRow("minmax, equal to min") << std::optional{-1} << std::optional{1} << -1 << true; + QTest::addRow("minmax, between") << std::optional{-1} << std::optional{1} << 0 << true; + QTest::addRow("minmax, equal to max") << std::optional{-1} << std::optional{1} << 1 << true; + QTest::addRow("minmax, above") << std::optional{-1} << std::optional{1} << 2 << false; + } + + void contains_qreal() + { + QFETCH(std::optional, min); + QFETCH(std::optional, max); + QFETCH(int, value); + QFETCH(bool, result); + + QCOMPARE(Range(min, max).contains(value), result); + } +}; } -QTEST_MAIN(InputActions::TestRange) \ No newline at end of file +QTEST_MAIN(InputActions::TestRange) +#include "TestRange.moc" \ No newline at end of file diff --git a/tests/libinputactions/TestRange.h b/tests/libinputactions/TestRange.h deleted file mode 100644 index db99008..0000000 --- a/tests/libinputactions/TestRange.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "Test.h" -#include - -namespace InputActions -{ - -class TestRange : public Test -{ - Q_OBJECT - -private slots: - void contains_qreal_data(); - void contains_qreal(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/TestValue.cpp b/tests/libinputactions/TestValue.cpp index 2ba1690..de2c111 100644 --- a/tests/libinputactions/TestValue.cpp +++ b/tests/libinputactions/TestValue.cpp @@ -1,62 +1,66 @@ -#include "TestValue.h" +#include "Test.h" #include #include namespace InputActions { -void TestValue::init() +class TestValue : public Test { - g_variableManager = std::make_shared(); -} + Q_OBJECT -void TestValue::get_defaultConstructor_returnsNullopt() -{ - const Value value; - QVERIFY(!value.get().has_value()); -} +private slots: + void init() { g_variableManager = std::make_shared(); } -void TestValue::get_valueConstructor() -{ - const Value value(true); - QVERIFY(value.get().value()); -} + void get_defaultConstructor_returnsNullopt() + { + const Value value; + QVERIFY(!value.get().has_value()); + } -void TestValue::get_command() -{ - const auto value = Value::command(Value("echo -n a")); - QCOMPARE(value.get().value(), "a"); -} + void get_valueConstructor() + { + const Value value(true); + QVERIFY(value.get().value()); + } -void TestValue::get_commandNullValue_returnsNullopt() -{ - const auto value = Value::command({}); - QVERIFY(!value.get().has_value()); -} + void get_command() + { + const auto value = Value::command(Value("echo -n a")); + QCOMPARE(value.get().value(), "a"); + } -void TestValue::get_function() -{ - const auto value = Value::function([]() { - return true; - }); - QVERIFY(value.get().value()); -} + void get_commandNullValue_returnsNullopt() + { + const auto value = Value::command({}); + QVERIFY(!value.get().has_value()); + } -void TestValue::get_existentVariable() -{ - g_variableManager->registerRemoteVariable("_test", [](auto &value) { - value = true; - }); - const auto value = Value::variable("_test"); - QVERIFY(value.get().value()); -} + void get_function() + { + const auto value = Value::function([]() { + return true; + }); + QVERIFY(value.get().value()); + } -void TestValue::get_nonExistentVariable_returnsNullopt() -{ - const auto value = Value::variable("_test"); - QVERIFY(!value.get().has_value()); -} + void get_existentVariable() + { + g_variableManager->registerRemoteVariable("_test", [](auto &value) { + value = true; + }); + const auto value = Value::variable("_test"); + QVERIFY(value.get().value()); + } + + void get_nonExistentVariable_returnsNullopt() + { + const auto value = Value::variable("_test"); + QVERIFY(!value.get().has_value()); + } +}; } -QTEST_MAIN(InputActions::TestValue) \ No newline at end of file +QTEST_MAIN(InputActions::TestValue) +#include "TestValue.moc" \ No newline at end of file diff --git a/tests/libinputactions/TestValue.h b/tests/libinputactions/TestValue.h deleted file mode 100644 index 5c5894e..0000000 --- a/tests/libinputactions/TestValue.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestValue : public Test -{ - Q_OBJECT - -private slots: - void init(); - - void get_defaultConstructor_returnsNullopt(); - void get_valueConstructor(); - - void get_command(); - void get_commandNullValue_returnsNullopt(); - - void get_function(); - - void get_existentVariable(); - void get_nonExistentVariable_returnsNullopt(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/actions/TestAction.cpp b/tests/libinputactions/actions/TestAction.cpp index 2f9425e..c6ec6e3 100644 --- a/tests/libinputactions/actions/TestAction.cpp +++ b/tests/libinputactions/actions/TestAction.cpp @@ -1,34 +1,41 @@ -#include "TestAction.h" +#include "Test.h" #include #include namespace InputActions { -void TestAction::canExecute_noLimit() +class TestAction : public Test { - Action action; + Q_OBJECT + +private slots: + void canExecute_noLimit() + { + Action action; + + QVERIFY(action.canExecute()); + g_actionExecutor->execute(action); + QVERIFY(action.canExecute()); + } + + void canExecute_withLimit() + { + Action action; + action.setExecutionLimit(1); + + QVERIFY(action.canExecute()); + g_actionExecutor->execute(action); + QVERIFY(!action.canExecute()); + + action.reset(); + QVERIFY(action.canExecute()); + g_actionExecutor->execute(action); + QVERIFY(!action.canExecute()); + } +}; - QVERIFY(action.canExecute()); - g_actionExecutor->execute(action); - QVERIFY(action.canExecute()); } -void TestAction::canExecute_withLimit() -{ - Action action; - action.setExecutionLimit(1); - - QVERIFY(action.canExecute()); - g_actionExecutor->execute(action); - QVERIFY(!action.canExecute()); - - action.reset(); - QVERIFY(action.canExecute()); - g_actionExecutor->execute(action); - QVERIFY(!action.canExecute()); -} - -} - -QTEST_MAIN(InputActions::TestAction) \ No newline at end of file +QTEST_MAIN(InputActions::TestAction) +#include "TestAction.moc" \ No newline at end of file diff --git a/tests/libinputactions/actions/TestAction.h b/tests/libinputactions/actions/TestAction.h deleted file mode 100644 index 1777c11..0000000 --- a/tests/libinputactions/actions/TestAction.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestAction : public Test -{ - Q_OBJECT - -private slots: - void canExecute_noLimit(); - void canExecute_withLimit(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/actions/TestActionExecutor.cpp b/tests/libinputactions/actions/TestActionExecutor.cpp index a0a672b..4ba93db 100644 --- a/tests/libinputactions/actions/TestActionExecutor.cpp +++ b/tests/libinputactions/actions/TestActionExecutor.cpp @@ -1,101 +1,106 @@ -#include "TestActionExecutor.h" +#include "Test.h" +#include #include #include namespace InputActions { -void TestActionExecutor::init() +class TestActionExecutor : public Test { - m_executor = std::make_unique(); -} - -void TestActionExecutor::execute_syncAction_executedOnMainThread() -{ - CustomAction assertAction([](auto) { - QCOMPARE(isMainThread(), true); - }); - - m_executor->execute(assertAction); + Q_OBJECT - QCOMPARE(assertAction.executions(), 1); -} - -void TestActionExecutor::execute_asyncAction_executedOnActionThread() -{ - CustomAction assertAction( - [](auto) { - QCOMPARE(isMainThread(), false); - }, - true); +private slots: + void init() { m_executor = std::make_unique(); } - m_executor->execute(assertAction); - m_executor->waitForDone(); + void execute_syncAction_executedOnMainThread() + { + CustomAction assertAction([](auto) { + QCOMPARE(isMainThread(), true); + }); - QCOMPARE(assertAction.executions(), 1); -} + m_executor->execute(assertAction); -void TestActionExecutor::execute_syncActionWhileActionThreadIsBusy_executedOnActionThread() -{ - SleepAction sleepAction(std::chrono::milliseconds(100U)); - CustomAction assertAction([](auto) { - QCOMPARE(isMainThread(), false); - }); + QCOMPARE(assertAction.executions(), 1); + } - m_executor->execute(sleepAction); - m_executor->execute(assertAction); - m_executor->waitForDone(); + void execute_asyncAction_executedOnActionThread() + { + CustomAction assertAction( + [](auto) { + QCOMPARE(isMainThread(), false); + }, + true); - QCOMPARE(sleepAction.executions(), 1); - QCOMPARE(assertAction.executions(), 1); -} + m_executor->execute(assertAction); + m_executor->waitForDone(); -void TestActionExecutor::execute_syncAndAsyncActions_orderPreserved() -{ - std::vector results; - - CustomAction action1([&results](auto) { - results.push_back(1); - }); - CustomAction action2( - [&results](auto) { - QTest::qWait(20); - results.push_back(2); - }, - true); - CustomAction action3([&results](auto) { - results.push_back(3); - }); - CustomAction action4( - [&results](auto) { - QTest::qWait(10); - results.push_back(4); - }, - true); - CustomAction action5([&results](auto) { - results.push_back(5); - }); - - m_executor->execute(action1); - m_executor->execute(action2); - m_executor->execute(action3); - m_executor->execute(action4); - m_executor->execute(action5); - m_executor->waitForDone(); - - QCOMPARE(action1.executions(), 1); - QCOMPARE(action2.executions(), 1); - QCOMPARE(action3.executions(), 1); - QCOMPARE(action4.executions(), 1); - QCOMPARE(action5.executions(), 1); - QVERIFY((results == std::vector{1, 2, 3, 4, 5})); -} + QCOMPARE(assertAction.executions(), 1); + } -bool TestActionExecutor::isMainThread() -{ - return QThread::currentThread() == QCoreApplication::instance()->thread(); -} + void execute_syncActionWhileActionThreadIsBusy_executedOnActionThread() + { + SleepAction sleepAction(std::chrono::milliseconds(100U)); + CustomAction assertAction([](auto) { + QCOMPARE(isMainThread(), false); + }); + + m_executor->execute(sleepAction); + m_executor->execute(assertAction); + m_executor->waitForDone(); + + QCOMPARE(sleepAction.executions(), 1); + QCOMPARE(assertAction.executions(), 1); + } + + void execute_syncAndAsyncActions_orderPreserved() + { + std::vector results; + + CustomAction action1([&results](auto) { + results.push_back(1); + }); + CustomAction action2( + [&results](auto) { + QTest::qWait(20); + results.push_back(2); + }, + true); + CustomAction action3([&results](auto) { + results.push_back(3); + }); + CustomAction action4( + [&results](auto) { + QTest::qWait(10); + results.push_back(4); + }, + true); + CustomAction action5([&results](auto) { + results.push_back(5); + }); + + m_executor->execute(action1); + m_executor->execute(action2); + m_executor->execute(action3); + m_executor->execute(action4); + m_executor->execute(action5); + m_executor->waitForDone(); + + QCOMPARE(action1.executions(), 1); + QCOMPARE(action2.executions(), 1); + QCOMPARE(action3.executions(), 1); + QCOMPARE(action4.executions(), 1); + QCOMPARE(action5.executions(), 1); + QVERIFY((results == std::vector{1, 2, 3, 4, 5})); + } + +private: + static bool isMainThread() { return QThread::currentThread() == QCoreApplication::instance()->thread(); } + + std::unique_ptr m_executor; +}; } -QTEST_MAIN(InputActions::TestActionExecutor) \ No newline at end of file +QTEST_MAIN(InputActions::TestActionExecutor) +#include "TestActionExecutor.moc" \ No newline at end of file diff --git a/tests/libinputactions/actions/TestActionExecutor.h b/tests/libinputactions/actions/TestActionExecutor.h deleted file mode 100644 index 32e0597..0000000 --- a/tests/libinputactions/actions/TestActionExecutor.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "Test.h" -#include - -namespace InputActions -{ - -class TestActionExecutor : public Test -{ - Q_OBJECT - -private slots: - void init(); - - void execute_syncAction_executedOnMainThread(); - void execute_asyncAction_executedOnActionThread(); - void execute_syncActionWhileActionThreadIsBusy_executedOnActionThread(); - void execute_syncAndAsyncActions_orderPreserved(); - -private: - static bool isMainThread(); - - std::unique_ptr m_executor; -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/actions/TestActionGroup.cpp b/tests/libinputactions/actions/TestActionGroup.cpp index 356b566..a691452 100644 --- a/tests/libinputactions/actions/TestActionGroup.cpp +++ b/tests/libinputactions/actions/TestActionGroup.cpp @@ -1,4 +1,4 @@ -#include "TestActionGroup.h" +#include "Test.h" #include #include #include @@ -6,44 +6,51 @@ namespace InputActions { -void TestActionGroup::all_execute__propagatesArgumentsToSubActions() +class TestActionGroup : public Test { - auto *assertAction = new CustomAction([](const auto &args) { - QCOMPARE(args.inputActionArgs.motionPointDelta, QPointF(12, 34)); - }); - - auto group = std::make_shared(ActionGroupExecutionMode::All); - group->append(std::unique_ptr(assertAction)); - - g_actionExecutor->execute(*group, { - .actionArgs = { - .inputActionArgs = { - .motionPointDelta = QPointF(12, 34), - }, - }}); - - QCOMPARE(assertAction->executions(), 1); -} - -void TestActionGroup::first_execute__propagatesArgumentsToSubActions() -{ - auto *assertAction = new CustomAction([](const auto &args) { - QCOMPARE(args.inputActionArgs.motionPointDelta, QPointF(12, 34)); - }); - - auto group = std::make_shared(ActionGroupExecutionMode::First); - group->append(std::unique_ptr(assertAction)); - - g_actionExecutor->execute(*group, { - .actionArgs = { - .inputActionArgs = { - .motionPointDelta = QPointF(12, 34), - }, - }}); - - QCOMPARE(assertAction->executions(), 1); -} + Q_OBJECT + +private slots: + void all_execute__propagatesArgumentsToSubActions() + { + auto *assertAction = new CustomAction([](const auto &args) { + QCOMPARE(args.inputActionArgs.motionPointDelta, QPointF(12, 34)); + }); + + auto group = std::make_shared(ActionGroupExecutionMode::All); + group->append(std::unique_ptr(assertAction)); + + g_actionExecutor->execute(*group, { + .actionArgs = { + .inputActionArgs = { + .motionPointDelta = QPointF(12, 34), + }, + }}); + + QCOMPARE(assertAction->executions(), 1); + } + + void first_execute__propagatesArgumentsToSubActions() + { + auto *assertAction = new CustomAction([](const auto &args) { + QCOMPARE(args.inputActionArgs.motionPointDelta, QPointF(12, 34)); + }); + + auto group = std::make_shared(ActionGroupExecutionMode::First); + group->append(std::unique_ptr(assertAction)); + + g_actionExecutor->execute(*group, { + .actionArgs = { + .inputActionArgs = { + .motionPointDelta = QPointF(12, 34), + }, + }}); + + QCOMPARE(assertAction->executions(), 1); + } +}; } -QTEST_MAIN(InputActions::TestActionGroup) \ No newline at end of file +QTEST_MAIN(InputActions::TestActionGroup) +#include "TestActionGroup.moc" \ No newline at end of file diff --git a/tests/libinputactions/actions/TestActionGroup.h b/tests/libinputactions/actions/TestActionGroup.h deleted file mode 100644 index 62fb7d4..0000000 --- a/tests/libinputactions/actions/TestActionGroup.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestActionGroup : public Test -{ - Q_OBJECT - -private slots: - void all_execute__propagatesArgumentsToSubActions(); - void first_execute__propagatesArgumentsToSubActions(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/actions/TestActionInterval.cpp b/tests/libinputactions/actions/TestActionInterval.cpp index b4c5c75..c5afa0b 100644 --- a/tests/libinputactions/actions/TestActionInterval.cpp +++ b/tests/libinputactions/actions/TestActionInterval.cpp @@ -1,38 +1,45 @@ -#include "TestActionInterval.h" +#include "Test.h" #include namespace InputActions { -void TestActionInterval::matches_data() +class TestActionInterval : public Test { - QTest::addColumn("direction"); - QTest::addColumn("value"); - QTest::addColumn("result"); - - QTest::addRow("any, positive") << IntervalDirection::Any << 1 << true; - QTest::addRow("any, negative") << IntervalDirection::Any << -1 << true; - QTest::addRow("any, zero") << IntervalDirection::Any << 0 << true; - QTest::addRow("positive, positive") << IntervalDirection::Positive << 1 << true; - QTest::addRow("positive, negative") << IntervalDirection::Positive << -1 << false; - QTest::addRow("positive, zero") << IntervalDirection::Positive << 0 << false; - QTest::addRow("negative, positive") << IntervalDirection::Negative << 1 << false; - QTest::addRow("negative, negative") << IntervalDirection::Negative << -1 << true; - QTest::addRow("negative, zero") << IntervalDirection::Negative << 0 << false; -} - -void TestActionInterval::matches() -{ - QFETCH(IntervalDirection, direction); - QFETCH(int, value); - QFETCH(bool, result); - - ActionInterval actionInterval; - actionInterval.setDirection(direction); - - QCOMPARE(actionInterval.matches(value), result); -} + Q_OBJECT + +private slots: + void matches_data() + { + QTest::addColumn("direction"); + QTest::addColumn("value"); + QTest::addColumn("result"); + + QTest::addRow("any, positive") << IntervalDirection::Any << 1 << true; + QTest::addRow("any, negative") << IntervalDirection::Any << -1 << true; + QTest::addRow("any, zero") << IntervalDirection::Any << 0 << true; + QTest::addRow("positive, positive") << IntervalDirection::Positive << 1 << true; + QTest::addRow("positive, negative") << IntervalDirection::Positive << -1 << false; + QTest::addRow("positive, zero") << IntervalDirection::Positive << 0 << false; + QTest::addRow("negative, positive") << IntervalDirection::Negative << 1 << false; + QTest::addRow("negative, negative") << IntervalDirection::Negative << -1 << true; + QTest::addRow("negative, zero") << IntervalDirection::Negative << 0 << false; + } + + void matches() + { + QFETCH(IntervalDirection, direction); + QFETCH(int, value); + QFETCH(bool, result); + + ActionInterval actionInterval; + actionInterval.setDirection(direction); + + QCOMPARE(actionInterval.matches(value), result); + } +}; } -QTEST_MAIN(InputActions::TestActionInterval) \ No newline at end of file +QTEST_MAIN(InputActions::TestActionInterval) +#include "TestActionInterval.moc" \ No newline at end of file diff --git a/tests/libinputactions/actions/TestActionInterval.h b/tests/libinputactions/actions/TestActionInterval.h deleted file mode 100644 index 98af430..0000000 --- a/tests/libinputactions/actions/TestActionInterval.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestActionInterval : public Test -{ - Q_OBJECT - -private slots: - void matches_data(); - void matches(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/actions/TestTriggerAction.cpp b/tests/libinputactions/actions/TestTriggerAction.cpp index 70a8f11..401f83a 100644 --- a/tests/libinputactions/actions/TestTriggerAction.cpp +++ b/tests/libinputactions/actions/TestTriggerAction.cpp @@ -1,4 +1,4 @@ -#include "TestTriggerAction.h" +#include "Test.h" #include #include #include @@ -8,103 +8,110 @@ namespace InputActions { -void TestTriggerAction::triggerUpdated_intervals_data() +class TestTriggerAction : public Test { - QTest::addColumn>("deltas"); - QTest::addColumn("interval"); - QTest::addColumn("executions"); - - ActionInterval interval{}; - QTest::newRow("zeroes") << std::vector{0, 0, 0} << interval << 3; - interval.setValue(2); - QTest::newRow("accumulation") << std::vector{1, 1, 1, 1} << interval << 2; - QTest::newRow("multiple executions") << std::vector{4, 4} << interval << 4; - QTest::newRow("direction change (any)") << std::vector{-4, 1, -4, 1} << interval << 4; - interval.setDirection(IntervalDirection::Positive); - QTest::newRow("direction change (positive)") << std::vector{-4, 1, -4, 1} << interval << 0; - interval.setDirection(IntervalDirection::Negative); - QTest::newRow("direction change (negative)") << std::vector{4, -1, 4, -1} << interval << 0; - - interval.setValue(0); - interval.setDirection(IntervalDirection::Positive); - QTest::newRow("no infinite loop") << std::vector{1, 0} << interval << 1; -} + Q_OBJECT + +private slots: + void triggerUpdated_intervals_data() + { + QTest::addColumn>("deltas"); + QTest::addColumn("interval"); + QTest::addColumn("executions"); + + ActionInterval interval{}; + QTest::newRow("zeroes") << std::vector{0, 0, 0} << interval << 3; + interval.setValue(2); + QTest::newRow("accumulation") << std::vector{1, 1, 1, 1} << interval << 2; + QTest::newRow("multiple executions") << std::vector{4, 4} << interval << 4; + QTest::newRow("direction change (any)") << std::vector{-4, 1, -4, 1} << interval << 4; + interval.setDirection(IntervalDirection::Positive); + QTest::newRow("direction change (positive)") << std::vector{-4, 1, -4, 1} << interval << 0; + interval.setDirection(IntervalDirection::Negative); + QTest::newRow("direction change (negative)") << std::vector{4, -1, 4, -1} << interval << 0; + + interval.setValue(0); + interval.setDirection(IntervalDirection::Positive); + QTest::newRow("no infinite loop") << std::vector{1, 0} << interval << 1; + } -void TestTriggerAction::triggerUpdated_intervals() -{ - QFETCH(std::vector, deltas); - QFETCH(ActionInterval, interval); - QFETCH(int, executions); - - auto action = std::make_unique(); - action->setOn(On::Update); - action->setInterval(interval); - for (const auto &delta : deltas) { - TriggerUpdateEvent event; - event.setDelta(delta); - action->triggerUpdated(event); + void triggerUpdated_intervals() + { + QFETCH(std::vector, deltas); + QFETCH(ActionInterval, interval); + QFETCH(int, executions); + + auto action = std::make_unique(); + action->setOn(On::Update); + action->setInterval(interval); + for (const auto &delta : deltas) { + TriggerUpdateEvent event; + event.setDelta(delta); + action->triggerUpdated(event); + } + + QCOMPARE(action->action()->executions(), executions); } - QCOMPARE(action->action()->executions(), executions); -} + void triggerUpdated_mergeable() + { + uint32_t actualExecutions{}; + auto action = std::make_unique(std::make_unique( + [&actualExecutions](const auto &args) { + actualExecutions = args.executions; + }, + false, + true)); + + ActionInterval interval{}; + interval.setValue(1); + action->setOn(On::Update); + action->setInterval(interval); -void TestTriggerAction::triggerUpdated_mergeable() -{ - uint32_t actualExecutions{}; - auto action = std::make_unique(std::make_unique( - [&actualExecutions](const auto &args) { - actualExecutions = args.executions; - }, - false, - true)); - - ActionInterval interval{}; - interval.setValue(1); - action->setOn(On::Update); - action->setInterval(interval); - - TriggerUpdateEvent event; - event.setDelta(10); - action->triggerUpdated(event); - - QCOMPARE(actualExecutions, 10); -} + TriggerUpdateEvent event; + event.setDelta(10); + action->triggerUpdated(event); -void TestTriggerAction::tryExecute_motion_accelerated__passesMotionPointDeltaToAction() -{ - auto *assertAction = new CustomAction([](const auto &args) { - QCOMPARE(args.inputActionArgs.motionPointDelta, QPointF(20, 20)); - }); + QCOMPARE(actualExecutions, 10); + } - TriggerAction action{std::unique_ptr(assertAction)}; - action.setAccelerated(true); + void tryExecute_motion_accelerated__passesMotionPointDeltaToAction() + { + auto *assertAction = new CustomAction([](const auto &args) { + QCOMPARE(args.inputActionArgs.motionPointDelta, QPointF(20, 20)); + }); - action.triggerStarted(); - MotionTriggerUpdateEvent event; - event.setPointDelta({{20, 20}, {10, 10}}); - action.triggerUpdated(event); + TriggerAction action{std::unique_ptr(assertAction)}; + action.setAccelerated(true); - action.tryExecute(); - QCOMPARE(assertAction->executions(), 1); -} + action.triggerStarted(); + MotionTriggerUpdateEvent event; + event.setPointDelta({{20, 20}, {10, 10}}); + action.triggerUpdated(event); -void TestTriggerAction::tryExecute_motion_unaccelerated__passesMotionPointDeltaToAction() -{ - auto *assertAction = new CustomAction([](const auto &args) { - QCOMPARE(args.inputActionArgs.motionPointDelta, QPointF(10, 10)); - }); + action.tryExecute(); + QCOMPARE(assertAction->executions(), 1); + } - TriggerAction action{std::unique_ptr(assertAction)}; + void tryExecute_motion_unaccelerated__passesMotionPointDeltaToAction() + { + auto *assertAction = new CustomAction([](const auto &args) { + QCOMPARE(args.inputActionArgs.motionPointDelta, QPointF(10, 10)); + }); - action.triggerStarted(); - MotionTriggerUpdateEvent event; - event.setPointDelta({{20, 20}, {10, 10}}); - action.triggerUpdated(event); + TriggerAction action{std::unique_ptr(assertAction)}; - action.tryExecute(); - QCOMPARE(assertAction->executions(), 1); -} + action.triggerStarted(); + MotionTriggerUpdateEvent event; + event.setPointDelta({{20, 20}, {10, 10}}); + action.triggerUpdated(event); + + action.tryExecute(); + QCOMPARE(assertAction->executions(), 1); + } +}; } -QTEST_MAIN(InputActions::TestTriggerAction) \ No newline at end of file +QTEST_MAIN(InputActions::TestTriggerAction) +#include "TestTriggerAction.moc" \ No newline at end of file diff --git a/tests/libinputactions/actions/TestTriggerAction.h b/tests/libinputactions/actions/TestTriggerAction.h deleted file mode 100644 index c874236..0000000 --- a/tests/libinputactions/actions/TestTriggerAction.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestTriggerAction : public Test -{ - Q_OBJECT - -private slots: - void triggerUpdated_intervals_data(); - void triggerUpdated_intervals(); - - void triggerUpdated_mergeable(); - - void tryExecute_motion_accelerated__passesMotionPointDeltaToAction(); - void tryExecute_motion_unaccelerated__passesMotionPointDeltaToAction(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/conditions/TestConditionGroup.cpp b/tests/libinputactions/conditions/TestConditionGroup.cpp index 8a313bf..e084fe7 100644 --- a/tests/libinputactions/conditions/TestConditionGroup.cpp +++ b/tests/libinputactions/conditions/TestConditionGroup.cpp @@ -1,4 +1,4 @@ -#include "TestConditionGroup.h" +#include "Test.h" #include "utils.h" #include @@ -12,67 +12,74 @@ enum class ConditionEvaluationResult Error }; -void TestConditionGroup::evaluate_data() +class TestConditionGroup : public Test { - QTest::addColumn("mode"); - QTest::addColumn>>("conditions"); - QTest::addColumn("result"); + Q_OBJECT - std::vector allTrue{TRUE_CONDITION, TRUE_CONDITION}; - std::vector allFalse{FALSE_CONDITION, FALSE_CONDITION}; - std::vector trueFalse{TRUE_CONDITION, FALSE_CONDITION}; - std::vector trueError{TRUE_CONDITION, ERROR_CONDITION}; - std::vector falseError{FALSE_CONDITION, ERROR_CONDITION}; - std::vector errorTrue{ERROR_CONDITION, TRUE_CONDITION}; - std::vector errorFalse{ERROR_CONDITION, FALSE_CONDITION}; - std::vector error{ERROR_CONDITION}; +private slots: + void evaluate_data() + { + QTest::addColumn("mode"); + QTest::addColumn>>("conditions"); + QTest::addColumn("result"); - QTest::newRow("all, allTrue - satisfied") << ConditionGroupMode::All << allTrue << ConditionEvaluationResult::Satisfied; - QTest::newRow("all, allFalse - not satisfied") << ConditionGroupMode::All << allFalse << ConditionEvaluationResult::NotSatisfied; - QTest::newRow("all, trueFalse - not satisfied") << ConditionGroupMode::All << trueFalse << ConditionEvaluationResult::NotSatisfied; - QTest::newRow("all, trueError - error") << ConditionGroupMode::All << trueError << ConditionEvaluationResult::Error; - QTest::newRow("all, falseError - not satisfied") << ConditionGroupMode::All << falseError << ConditionEvaluationResult::NotSatisfied; - QTest::newRow("all, errorTrue - error") << ConditionGroupMode::All << errorTrue << ConditionEvaluationResult::Error; - QTest::newRow("all, errorFalse - error") << ConditionGroupMode::All << errorFalse << ConditionEvaluationResult::Error; - QTest::newRow("all, error - error") << ConditionGroupMode::All << error << ConditionEvaluationResult::Error; + std::vector allTrue{TRUE_CONDITION, TRUE_CONDITION}; + std::vector allFalse{FALSE_CONDITION, FALSE_CONDITION}; + std::vector trueFalse{TRUE_CONDITION, FALSE_CONDITION}; + std::vector trueError{TRUE_CONDITION, ERROR_CONDITION}; + std::vector falseError{FALSE_CONDITION, ERROR_CONDITION}; + std::vector errorTrue{ERROR_CONDITION, TRUE_CONDITION}; + std::vector errorFalse{ERROR_CONDITION, FALSE_CONDITION}; + std::vector error{ERROR_CONDITION}; - QTest::newRow("any, allTrue - satisfied") << ConditionGroupMode::Any << allTrue << ConditionEvaluationResult::Satisfied; - QTest::newRow("any, allFalse - not satisfied") << ConditionGroupMode::Any << allFalse << ConditionEvaluationResult::NotSatisfied; - QTest::newRow("any, trueFalse - satisfied") << ConditionGroupMode::Any << trueFalse << ConditionEvaluationResult::Satisfied; - QTest::newRow("any, trueError - satisfied") << ConditionGroupMode::Any << trueError << ConditionEvaluationResult::Satisfied; - QTest::newRow("any, falseError - error") << ConditionGroupMode::Any << falseError << ConditionEvaluationResult::Error; - QTest::newRow("any, errorTrue - satisfied") << ConditionGroupMode::Any << errorTrue << ConditionEvaluationResult::Satisfied; - QTest::newRow("any, errorFalse - error") << ConditionGroupMode::Any << errorFalse << ConditionEvaluationResult::Error; - QTest::newRow("any, error - error") << ConditionGroupMode::Any << error << ConditionEvaluationResult::Error; + QTest::newRow("all, allTrue - satisfied") << ConditionGroupMode::All << allTrue << ConditionEvaluationResult::Satisfied; + QTest::newRow("all, allFalse - not satisfied") << ConditionGroupMode::All << allFalse << ConditionEvaluationResult::NotSatisfied; + QTest::newRow("all, trueFalse - not satisfied") << ConditionGroupMode::All << trueFalse << ConditionEvaluationResult::NotSatisfied; + QTest::newRow("all, trueError - error") << ConditionGroupMode::All << trueError << ConditionEvaluationResult::Error; + QTest::newRow("all, falseError - not satisfied") << ConditionGroupMode::All << falseError << ConditionEvaluationResult::NotSatisfied; + QTest::newRow("all, errorTrue - error") << ConditionGroupMode::All << errorTrue << ConditionEvaluationResult::Error; + QTest::newRow("all, errorFalse - error") << ConditionGroupMode::All << errorFalse << ConditionEvaluationResult::Error; + QTest::newRow("all, error - error") << ConditionGroupMode::All << error << ConditionEvaluationResult::Error; - QTest::newRow("none, allTrue - not satisfied") << ConditionGroupMode::None << allTrue << ConditionEvaluationResult::NotSatisfied; - QTest::newRow("none, allFalse - satisfied") << ConditionGroupMode::None << allFalse << ConditionEvaluationResult::Satisfied; - QTest::newRow("none, trueFalse - not satisfied") << ConditionGroupMode::None << trueFalse << ConditionEvaluationResult::NotSatisfied; - QTest::newRow("none, trueError - not satisfied") << ConditionGroupMode::None << trueError << ConditionEvaluationResult::NotSatisfied; - QTest::newRow("none, falseError - error") << ConditionGroupMode::None << falseError << ConditionEvaluationResult::Error; - QTest::newRow("none, errorTrue - error") << ConditionGroupMode::None << errorTrue << ConditionEvaluationResult::Error; - QTest::newRow("none, errorFalse - error") << ConditionGroupMode::None << errorFalse << ConditionEvaluationResult::Error; - QTest::newRow("none, error - error") << ConditionGroupMode::None << error << ConditionEvaluationResult::Error; -} - -void TestConditionGroup::evaluate() -{ - QFETCH(ConditionGroupMode, mode); - QFETCH(std::vector>, conditions); - QFETCH(ConditionEvaluationResult, result); + QTest::newRow("any, allTrue - satisfied") << ConditionGroupMode::Any << allTrue << ConditionEvaluationResult::Satisfied; + QTest::newRow("any, allFalse - not satisfied") << ConditionGroupMode::Any << allFalse << ConditionEvaluationResult::NotSatisfied; + QTest::newRow("any, trueFalse - satisfied") << ConditionGroupMode::Any << trueFalse << ConditionEvaluationResult::Satisfied; + QTest::newRow("any, trueError - satisfied") << ConditionGroupMode::Any << trueError << ConditionEvaluationResult::Satisfied; + QTest::newRow("any, falseError - error") << ConditionGroupMode::Any << falseError << ConditionEvaluationResult::Error; + QTest::newRow("any, errorTrue - satisfied") << ConditionGroupMode::Any << errorTrue << ConditionEvaluationResult::Satisfied; + QTest::newRow("any, errorFalse - error") << ConditionGroupMode::Any << errorFalse << ConditionEvaluationResult::Error; + QTest::newRow("any, error - error") << ConditionGroupMode::Any << error << ConditionEvaluationResult::Error; - ConditionGroup conditionGroup(mode); - for (const auto &condition : conditions) { - conditionGroup.append(condition); + QTest::newRow("none, allTrue - not satisfied") << ConditionGroupMode::None << allTrue << ConditionEvaluationResult::NotSatisfied; + QTest::newRow("none, allFalse - satisfied") << ConditionGroupMode::None << allFalse << ConditionEvaluationResult::Satisfied; + QTest::newRow("none, trueFalse - not satisfied") << ConditionGroupMode::None << trueFalse << ConditionEvaluationResult::NotSatisfied; + QTest::newRow("none, trueError - not satisfied") << ConditionGroupMode::None << trueError << ConditionEvaluationResult::NotSatisfied; + QTest::newRow("none, falseError - error") << ConditionGroupMode::None << falseError << ConditionEvaluationResult::Error; + QTest::newRow("none, errorTrue - error") << ConditionGroupMode::None << errorTrue << ConditionEvaluationResult::Error; + QTest::newRow("none, errorFalse - error") << ConditionGroupMode::None << errorFalse << ConditionEvaluationResult::Error; + QTest::newRow("none, error - error") << ConditionGroupMode::None << error << ConditionEvaluationResult::Error; } - if (result == ConditionEvaluationResult::Error) { - QVERIFY_THROWS_EXCEPTION(std::exception, conditionGroup.evaluate()); - } else { - QCOMPARE(conditionGroup.evaluate(), result == ConditionEvaluationResult::Satisfied); + void evaluate() + { + QFETCH(ConditionGroupMode, mode); + QFETCH(std::vector>, conditions); + QFETCH(ConditionEvaluationResult, result); + + ConditionGroup conditionGroup(mode); + for (const auto &condition : conditions) { + conditionGroup.append(condition); + } + + if (result == ConditionEvaluationResult::Error) { + QVERIFY_THROWS_EXCEPTION(std::exception, conditionGroup.evaluate()); + } else { + QCOMPARE(conditionGroup.evaluate(), result == ConditionEvaluationResult::Satisfied); + } } -} +}; } -QTEST_MAIN(InputActions::TestConditionGroup) \ No newline at end of file +QTEST_MAIN(InputActions::TestConditionGroup) +#include "TestConditionGroup.moc" \ No newline at end of file diff --git a/tests/libinputactions/conditions/TestConditionGroup.h b/tests/libinputactions/conditions/TestConditionGroup.h deleted file mode 100644 index b7b4d1d..0000000 --- a/tests/libinputactions/conditions/TestConditionGroup.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestConditionGroup : public Test -{ - Q_OBJECT - -private slots: - void evaluate_data(); - void evaluate(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestBaseNodeParser.cpp b/tests/libinputactions/config/parsers/TestBaseNodeParser.cpp index b4aa7d3..9b455f8 100644 --- a/tests/libinputactions/config/parsers/TestBaseNodeParser.cpp +++ b/tests/libinputactions/config/parsers/TestBaseNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestBaseNodeParser.h" +#include "Test.h" #include #include #include @@ -6,290 +6,297 @@ namespace InputActions { -void TestBaseNodeParser::boolean_valid__parsesNodeCorrectly_data() +class TestBaseNodeParser : public Test { - QTest::addColumn("raw"); - QTest::addColumn("result"); + Q_OBJECT + +private slots: + void boolean_valid__parsesNodeCorrectly_data() + { + QTest::addColumn("raw"); + QTest::addColumn("result"); + + // Those are the only values officially defined as valid + QTest::addRow("true") << "true" << true; + QTest::addRow("false") << "false" << false; + } + + void boolean_valid__parsesNodeCorrectly() + { + QFETCH(QString, raw); + QFETCH(bool, result); + + const auto node = Node::create(raw); + QCOMPARE(node->as(), result); + } + + void boolean_invalid__throwsInvalidValueConfigException_data() + { + QTest::addColumn("raw"); + + QTest::addRow("empty") << ""; + QTest::addRow("space") << "\" \""; + QTest::addRow("char") << "a"; + QTest::addRow("number") << "1"; + } + + void boolean_invalid__throwsInvalidValueConfigException() + { + QFETCH(QString, raw); + + const auto node = Node::create(raw); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } + + void int8_valid__parsesNodeCorrectly_data() + { + QTest::addColumn("raw"); + QTest::addColumn("result"); + + QTest::addRow("min") << "-128" << static_cast(-128); + QTest::addRow("-1") << "-1" << static_cast(-1); + QTest::addRow("0") << "0" << static_cast(0); + QTest::addRow("1") << "1" << static_cast(1); + QTest::addRow("max") << "127" << static_cast(127); + QTest::addRow("quoted") << "\"1\"" << static_cast(1); + } + + void int8_valid__parsesNodeCorrectly() + { + QFETCH(QString, raw); + QFETCH(int8_t, result); + + const auto node = Node::create(raw); + QCOMPARE(node->as(), result); + } + + void int8_invalid__throwsInvalidValueConfigException_data() + { + QTest::addColumn("raw"); + + QTest::addRow("empty") << ""; + QTest::addRow("space") << "\" \""; + QTest::addRow("char") << "a"; + QTest::addRow("float") << "1.0"; + QTest::addRow("min-1") << "-129"; + QTest::addRow("max+1") << "128"; + } + + void int8_invalid__throwsInvalidValueConfigException() + { + QFETCH(QString, raw); + + const auto node = Node::create(raw); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } + + void uint8_valid__parsesNodeCorrectly_data() + { + QTest::addColumn("raw"); + QTest::addColumn("result"); + + QTest::addRow("min") << "0" << static_cast(0); + QTest::addRow("1") << "1" << static_cast(1); + QTest::addRow("max") << "255" << static_cast(255); + QTest::addRow("quoted") << "\"1\"" << static_cast(1); + } + + void uint8_valid__parsesNodeCorrectly() + { + QFETCH(QString, raw); + QFETCH(uint8_t, result); + + const auto node = Node::create(raw); + QCOMPARE(node->as(), result); + } + + void uint8_invalid__throwsInvalidValueConfigException_data() + { + QTest::addColumn("raw"); + + QTest::addRow("empty") << ""; + QTest::addRow("space") << "\" \""; + QTest::addRow("char") << "a"; + QTest::addRow("float") << "1.0"; + QTest::addRow("min-1") << "-1"; + QTest::addRow("max+1") << "256"; + } + + void uint8_invalid__throwsInvalidValueConfigException() + { + QFETCH(QString, raw); + + const auto node = Node::create(raw); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } + + void uint32_valid__parsesNodeCorrectly_data() + { + QTest::addColumn("raw"); + QTest::addColumn("result"); + + QTest::addRow("min") << "0" << static_cast(0); + QTest::addRow("1") << "1" << static_cast(1); + QTest::addRow("max") << "4294967295" << static_cast(4294967295); + QTest::addRow("quoted") << "\"1\"" << static_cast(1); + } + + void uint32_valid__parsesNodeCorrectly() + { + QFETCH(QString, raw); + QFETCH(uint32_t, result); + + const auto node = Node::create(raw); + QCOMPARE(node->as(), result); + } + + void uint32_invalid__throwsInvalidValueConfigException_data() + { + QTest::addColumn("raw"); + + QTest::addRow("empty") << ""; + QTest::addRow("space") << "\" \""; + QTest::addRow("char") << "a"; + QTest::addRow("float") << "1.0"; + QTest::addRow("min-1") << "-1"; + QTest::addRow("max+1") << "4294967296"; + } + + void uint32_invalid__throwsInvalidValueConfigException() + { + QFETCH(QString, raw); + + const auto node = Node::create(raw); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } + + void uint64_valid__parsesNodeCorrectly_data() + { + QTest::addColumn("raw"); + QTest::addColumn("result"); + + QTest::addRow("min") << "0" << static_cast(0); + QTest::addRow("1") << "1" << static_cast(1); + QTest::addRow("max") << "18446744073709551615" << static_cast(18446744073709551615U); + QTest::addRow("quoted") << "\"1\"" << static_cast(1); + } + + void uint64_valid__parsesNodeCorrectly() + { + QFETCH(QString, raw); + QFETCH(uint64_t, result); + + const auto node = Node::create(raw); + QCOMPARE(node->as(), result); + } + + void uint64_invalid__throwsInvalidValueConfigException_data() + { + QTest::addColumn("raw"); + + QTest::addRow("empty") << ""; + QTest::addRow("space") << "\" \""; + QTest::addRow("char") << "a"; + QTest::addRow("float") << "1.0"; + QTest::addRow("min-1") << "-1"; + QTest::addRow("max+1") << "18446744073709551616"; + } + + void uint64_invalid__throwsInvalidValueConfigException() + { + QFETCH(QString, raw); + + const auto node = Node::create(raw); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } + + void qreal_valid__parsesNodeCorrectly_data() + { + QTest::addColumn("raw"); + QTest::addColumn("result"); + + QTest::addRow("-1") << "-1" << static_cast(-1); + QTest::addRow("0") << "0" << static_cast(0); + QTest::addRow("1") << "1" << static_cast(1); + + QTest::addRow("trailingDot") << "2." << static_cast(2); + QTest::addRow("leadingDot") << ".2" << static_cast(0.2); + + QTest::addRow("-123.456") << "-123.456" << static_cast(-123.456); + QTest::addRow("123.456") << "123.456" << static_cast(123.456); + + QTest::addRow("quoted") << "\"1.1\"" << static_cast(1.1); + } + + void qreal_valid__parsesNodeCorrectly() + { + QFETCH(QString, raw); + QFETCH(qreal, result); + + const auto node = Node::create(raw); + QCOMPARE(node->as(), result); + } + + void qreal_invalid__throwsInvalidValueConfigException_data() + { + QTest::addColumn("raw"); + + QTest::addRow("empty") << ""; + QTest::addRow("space") << "\" \""; + QTest::addRow("char") << "a"; + } + + void qreal_invalid__throwsInvalidValueConfigException() + { + QFETCH(QString, raw); + + const auto node = Node::create(raw); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } + + void string_valid__parsesNodeCorrectly_data() + { + QTest::addColumn("raw"); + + QTest::addRow("bool") << "true"; + QTest::addRow("number") << "2"; + QTest::addRow("float") << "2"; + } + + void string_valid__parsesNodeCorrectly() + { + QFETCH(QString, raw); + + const auto node = Node::create(raw); + QCOMPARE(node->as(), raw); + } + + void map__throwsInvalidNodeTypeConfigException() + { + const auto node = Node::create("_: _"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as(), InvalidNodeTypeConfigException, 0, 0, e); + QCOMPARE(e->expected(), NodeType::Scalar); + QCOMPARE(e->actual(), NodeType::Map); + } + + void null__throwsInvalidNodeTypeConfigException() + { + const auto node = Node::create("_:")->at("_")->shared_from_this(); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } + + void sequence__throwsInvalidNodeTypeConfigException() + { + const auto node = Node::create("[]"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as(), InvalidNodeTypeConfigException, 0, 0, e); + QCOMPARE(e->expected(), NodeType::Scalar); + QCOMPARE(e->actual(), NodeType::Sequence); + } +}; - // Those are the only values officially defined as valid - QTest::addRow("true") << "true" << true; - QTest::addRow("false") << "false" << false; } -void TestBaseNodeParser::boolean_valid__parsesNodeCorrectly() -{ - QFETCH(QString, raw); - QFETCH(bool, result); - - const auto node = Node::create(raw); - QCOMPARE(node->as(), result); -} - -void TestBaseNodeParser::boolean_invalid__throwsInvalidValueConfigException_data() -{ - QTest::addColumn("raw"); - - QTest::addRow("empty") << ""; - QTest::addRow("space") << "\" \""; - QTest::addRow("char") << "a"; - QTest::addRow("number") << "1"; -} - -void TestBaseNodeParser::boolean_invalid__throwsInvalidValueConfigException() -{ - QFETCH(QString, raw); - - const auto node = Node::create(raw); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} - -void TestBaseNodeParser::int8_valid__parsesNodeCorrectly_data() -{ - QTest::addColumn("raw"); - QTest::addColumn("result"); - - QTest::addRow("min") << "-128" << static_cast(-128); - QTest::addRow("-1") << "-1" << static_cast(-1); - QTest::addRow("0") << "0" << static_cast(0); - QTest::addRow("1") << "1" << static_cast(1); - QTest::addRow("max") << "127" << static_cast(127); - QTest::addRow("quoted") << "\"1\"" << static_cast(1); -} - -void TestBaseNodeParser::int8_valid__parsesNodeCorrectly() -{ - QFETCH(QString, raw); - QFETCH(int8_t, result); - - const auto node = Node::create(raw); - QCOMPARE(node->as(), result); -} - -void TestBaseNodeParser::int8_invalid__throwsInvalidValueConfigException_data() -{ - QTest::addColumn("raw"); - - QTest::addRow("empty") << ""; - QTest::addRow("space") << "\" \""; - QTest::addRow("char") << "a"; - QTest::addRow("float") << "1.0"; - QTest::addRow("min-1") << "-129"; - QTest::addRow("max+1") << "128"; -} - -void TestBaseNodeParser::int8_invalid__throwsInvalidValueConfigException() -{ - QFETCH(QString, raw); - - const auto node = Node::create(raw); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} - -void TestBaseNodeParser::uint8_valid__parsesNodeCorrectly_data() -{ - QTest::addColumn("raw"); - QTest::addColumn("result"); - - QTest::addRow("min") << "0" << static_cast(0); - QTest::addRow("1") << "1" << static_cast(1); - QTest::addRow("max") << "255" << static_cast(255); - QTest::addRow("quoted") << "\"1\"" << static_cast(1); -} - -void TestBaseNodeParser::uint8_valid__parsesNodeCorrectly() -{ - QFETCH(QString, raw); - QFETCH(uint8_t, result); - - const auto node = Node::create(raw); - QCOMPARE(node->as(), result); -} - -void TestBaseNodeParser::uint8_invalid__throwsInvalidValueConfigException_data() -{ - QTest::addColumn("raw"); - - QTest::addRow("empty") << ""; - QTest::addRow("space") << "\" \""; - QTest::addRow("char") << "a"; - QTest::addRow("float") << "1.0"; - QTest::addRow("min-1") << "-1"; - QTest::addRow("max+1") << "256"; -} - -void TestBaseNodeParser::uint8_invalid__throwsInvalidValueConfigException() -{ - QFETCH(QString, raw); - - const auto node = Node::create(raw); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} - -void TestBaseNodeParser::uint32_valid__parsesNodeCorrectly_data() -{ - QTest::addColumn("raw"); - QTest::addColumn("result"); - - QTest::addRow("min") << "0" << static_cast(0); - QTest::addRow("1") << "1" << static_cast(1); - QTest::addRow("max") << "4294967295" << static_cast(4294967295); - QTest::addRow("quoted") << "\"1\"" << static_cast(1); -} - -void TestBaseNodeParser::uint32_valid__parsesNodeCorrectly() -{ - QFETCH(QString, raw); - QFETCH(uint32_t, result); - - const auto node = Node::create(raw); - QCOMPARE(node->as(), result); -} - -void TestBaseNodeParser::uint32_invalid__throwsInvalidValueConfigException_data() -{ - QTest::addColumn("raw"); - - QTest::addRow("empty") << ""; - QTest::addRow("space") << "\" \""; - QTest::addRow("char") << "a"; - QTest::addRow("float") << "1.0"; - QTest::addRow("min-1") << "-1"; - QTest::addRow("max+1") << "4294967296"; -} - -void TestBaseNodeParser::uint32_invalid__throwsInvalidValueConfigException() -{ - QFETCH(QString, raw); - - const auto node = Node::create(raw); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} - -void TestBaseNodeParser::uint64_valid__parsesNodeCorrectly_data() -{ - QTest::addColumn("raw"); - QTest::addColumn("result"); - - QTest::addRow("min") << "0" << static_cast(0); - QTest::addRow("1") << "1" << static_cast(1); - QTest::addRow("max") << "18446744073709551615" << static_cast(18446744073709551615U); - QTest::addRow("quoted") << "\"1\"" << static_cast(1); -} - -void TestBaseNodeParser::uint64_valid__parsesNodeCorrectly() -{ - QFETCH(QString, raw); - QFETCH(uint64_t, result); - - const auto node = Node::create(raw); - QCOMPARE(node->as(), result); -} - -void TestBaseNodeParser::uint64_invalid__throwsInvalidValueConfigException_data() -{ - QTest::addColumn("raw"); - - QTest::addRow("empty") << ""; - QTest::addRow("space") << "\" \""; - QTest::addRow("char") << "a"; - QTest::addRow("float") << "1.0"; - QTest::addRow("min-1") << "-1"; - QTest::addRow("max+1") << "18446744073709551616"; -} - -void TestBaseNodeParser::uint64_invalid__throwsInvalidValueConfigException() -{ - QFETCH(QString, raw); - - const auto node = Node::create(raw); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} - -void TestBaseNodeParser::qreal_valid__parsesNodeCorrectly_data() -{ - QTest::addColumn("raw"); - QTest::addColumn("result"); - - QTest::addRow("-1") << "-1" << static_cast(-1); - QTest::addRow("0") << "0" << static_cast(0); - QTest::addRow("1") << "1" << static_cast(1); - - QTest::addRow("trailingDot") << "2." << static_cast(2); - QTest::addRow("leadingDot") << ".2" << static_cast(0.2); - - QTest::addRow("-123.456") << "-123.456" << static_cast(-123.456); - QTest::addRow("123.456") << "123.456" << static_cast(123.456); - - QTest::addRow("quoted") << "\"1.1\"" << static_cast(1.1); -} - -void TestBaseNodeParser::qreal_valid__parsesNodeCorrectly() -{ - QFETCH(QString, raw); - QFETCH(qreal, result); - - const auto node = Node::create(raw); - QCOMPARE(node->as(), result); -} - -void TestBaseNodeParser::qreal_invalid__throwsInvalidValueConfigException_data() -{ - QTest::addColumn("raw"); - - QTest::addRow("empty") << ""; - QTest::addRow("space") << "\" \""; - QTest::addRow("char") << "a"; -} - -void TestBaseNodeParser::qreal_invalid__throwsInvalidValueConfigException() -{ - QFETCH(QString, raw); - - const auto node = Node::create(raw); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} - -void TestBaseNodeParser::string_valid__parsesNodeCorrectly_data() -{ - QTest::addColumn("raw"); - - QTest::addRow("bool") << "true"; - QTest::addRow("number") << "2"; - QTest::addRow("float") << "2"; -} - -void TestBaseNodeParser::string_valid__parsesNodeCorrectly() -{ - QFETCH(QString, raw); - - const auto node = Node::create(raw); - QCOMPARE(node->as(), raw); -} - -void TestBaseNodeParser::map__throwsInvalidNodeTypeConfigException() -{ - const auto node = Node::create("_: _"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as(), InvalidNodeTypeConfigException, 0, 0, e); - QCOMPARE(e->expected(), NodeType::Scalar); - QCOMPARE(e->actual(), NodeType::Map); -} - -void TestBaseNodeParser::null__throwsInvalidNodeTypeConfigException() -{ - const auto node = Node::create("_:")->at("_")->shared_from_this(); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} - -void TestBaseNodeParser::sequence__throwsInvalidNodeTypeConfigException() -{ - const auto node = Node::create("[]"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as(), InvalidNodeTypeConfigException, 0, 0, e); - QCOMPARE(e->expected(), NodeType::Scalar); - QCOMPARE(e->actual(), NodeType::Sequence); -} - -} - -QTEST_MAIN(InputActions::TestBaseNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestBaseNodeParser) +#include "TestBaseNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestBaseNodeParser.h b/tests/libinputactions/config/parsers/TestBaseNodeParser.h deleted file mode 100644 index e6364fc..0000000 --- a/tests/libinputactions/config/parsers/TestBaseNodeParser.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestBaseNodeParser : public Test -{ - Q_OBJECT - -private slots: - void boolean_valid__parsesNodeCorrectly_data(); - void boolean_valid__parsesNodeCorrectly(); - void boolean_invalid__throwsInvalidValueConfigException_data(); - void boolean_invalid__throwsInvalidValueConfigException(); - - void int8_valid__parsesNodeCorrectly_data(); - void int8_valid__parsesNodeCorrectly(); - void int8_invalid__throwsInvalidValueConfigException_data(); - void int8_invalid__throwsInvalidValueConfigException(); - - void uint8_valid__parsesNodeCorrectly_data(); - void uint8_valid__parsesNodeCorrectly(); - void uint8_invalid__throwsInvalidValueConfigException_data(); - void uint8_invalid__throwsInvalidValueConfigException(); - - void uint32_valid__parsesNodeCorrectly_data(); - void uint32_valid__parsesNodeCorrectly(); - void uint32_invalid__throwsInvalidValueConfigException_data(); - void uint32_invalid__throwsInvalidValueConfigException(); - - void uint64_valid__parsesNodeCorrectly_data(); - void uint64_valid__parsesNodeCorrectly(); - void uint64_invalid__throwsInvalidValueConfigException_data(); - void uint64_invalid__throwsInvalidValueConfigException(); - - void qreal_valid__parsesNodeCorrectly_data(); - void qreal_valid__parsesNodeCorrectly(); - void qreal_invalid__throwsInvalidValueConfigException_data(); - void qreal_invalid__throwsInvalidValueConfigException(); - - void string_valid__parsesNodeCorrectly_data(); - void string_valid__parsesNodeCorrectly(); - - void map__throwsInvalidNodeTypeConfigException(); - void null__throwsInvalidNodeTypeConfigException(); - void sequence__throwsInvalidNodeTypeConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.cpp b/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.cpp index 87d7a49..d33b2ab 100644 --- a/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.cpp +++ b/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestDeviceRuleNodeParser.h" +#include "Test.h" #include #include #include @@ -8,205 +8,212 @@ namespace InputActions { -void TestDeviceRuleNodeParser::valid__parsesNodeCorrectly() +class TestDeviceRuleNodeParser : public Test { - const auto node = Node::create(R"( - device_rules: - - conditions: $mouse - grab: true - - - conditions: $touchpad - ignore: true - )"); - - const auto rules = node->as>(); - QCOMPARE(rules.size(), 2); - - const auto &mouseRule = rules[0]; - QVERIFY(mouseRule.condition()); - QCOMPARE(mouseRule.properties().m_grab, true); - QCOMPARE(mouseRule.properties().m_ignore, std::nullopt); - - const auto &touchpadRule = rules[1]; - QVERIFY(touchpadRule.condition()); - QCOMPARE(touchpadRule.properties().m_grab, std::nullopt); - QCOMPARE(touchpadRule.properties().m_ignore, true); -} - -void TestDeviceRuleNodeParser::mouse_triggerHandlerSetting_motionTimeout__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - mouse: - motion_timeout: 3735928559 - )"); - - const auto rules = node->as>(); - QCOMPARE(rules.size(), 1); - - const auto &rule = rules[0]; - QCOMPARE(rule.properties().m_mouseMotionTimeout, std::chrono::milliseconds(3735928559)); - - const auto condition = std::dynamic_pointer_cast(rule.condition()); - QVERIFY(condition); - QCOMPARE(condition->variableName(), "mouse"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &conditionValues = condition->values(); - QCOMPARE(conditionValues.size(), 1); - QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); -} - -void TestDeviceRuleNodeParser::mouse_triggerHandlerSetting_motionTimeout__addsDeprecatedFeatureConfigIssue() -{ - const auto node = Node::create(R"( - mouse: - motion_timeout: 1 - )"); - - INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 2, 26, issue); - QCOMPARE(issue->feature(), DeprecatedFeature::TriggerHandlerSettings); -} - -void TestDeviceRuleNodeParser::mouse_triggerHandlerSetting_pressTimeout__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - mouse: - press_timeout: 3735928559 - )"); - - const auto rules = node->as>(); - QCOMPARE(rules.size(), 1); - - const auto &rule = rules[0]; - QCOMPARE(rule.properties().m_mousePressTimeout, std::chrono::milliseconds(3735928559)); - - const auto condition = std::dynamic_pointer_cast(rule.condition()); - QVERIFY(condition); - QCOMPARE(condition->variableName(), "mouse"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &conditionValues = condition->values(); - QCOMPARE(conditionValues.size(), 1); - QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); -} - -void TestDeviceRuleNodeParser::mouse_triggerHandlerSetting_pressTimeout__addsDeprecatedFeatureConfigIssue() -{ - const auto node = Node::create(R"( - mouse: - press_timeout: 1 - )"); - - INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 2, 25, issue); - QCOMPARE(issue->feature(), DeprecatedFeature::TriggerHandlerSettings); -} - -void TestDeviceRuleNodeParser::mouse_triggerHandlerSetting_unblockButtonsOnTimeout__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - mouse: - unblock_buttons_on_timeout: true - )"); - - const auto rules = node->as>(); - QCOMPARE(rules.size(), 1); - - const auto &rule = rules[0]; - QCOMPARE(rule.properties().m_mouseUnblockButtonsOnTimeout, true); - - const auto condition = std::dynamic_pointer_cast(rule.condition()); - QVERIFY(condition); - QCOMPARE(condition->variableName(), "mouse"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &conditionValues = condition->values(); - QCOMPARE(conditionValues.size(), 1); - QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); -} - -void TestDeviceRuleNodeParser::mouse_triggerHandlerSetting_unblockButtonsOnTimeout__addsDeprecatedFeatureConfigIssue() -{ - const auto node = Node::create(R"( - mouse: - unblock_buttons_on_timeout: true - )"); - - INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 2, 38, issue); - QCOMPARE(issue->feature(), DeprecatedFeature::TriggerHandlerSettings); -} - -void TestDeviceRuleNodeParser::touchpad_devicesNode__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - touchpad: - devices: - a: - ignore: true - )"); - - const auto rules = node->as>(); - QCOMPARE(rules.size(), 1); - - const auto &rule = rules[0]; - QCOMPARE(rule.properties().m_ignore, true); - - const auto condition = std::dynamic_pointer_cast(rule.condition()); - QVERIFY(condition); - QCOMPARE(condition->variableName(), "name"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &conditionValues = condition->values(); - QCOMPARE(conditionValues.size(), 1); - QCOMPARE(std::any_cast(conditionValues[0].get().value()), "a"); -} - -void TestDeviceRuleNodeParser::touchpad_devicesNode__addsDeprecatedFeatureConfigIssue() -{ - const auto node = Node::create(R"( - touchpad: - devices: - a: - ignore: true - )"); - - INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 3, 12, issue); - QCOMPARE(issue->feature(), DeprecatedFeature::TouchpadDevicesNode); -} - -void TestDeviceRuleNodeParser::touchpad_triggerHandlerSetting_clickTimeout__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - touchpad: - click_timeout: 3735928559 - )"); - - const auto rules = node->as>(); - QCOMPARE(rules.size(), 1); - - const auto &rule = rules[0]; - QCOMPARE(rule.properties().m_touchpadClickTimeout, std::chrono::milliseconds(3735928559)); - - const auto condition = std::dynamic_pointer_cast(rule.condition()); - QVERIFY(condition); - QCOMPARE(condition->variableName(), "touchpad"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &conditionValues = condition->values(); - QCOMPARE(conditionValues.size(), 1); - QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); -} - -void TestDeviceRuleNodeParser::touchpad_triggerHandlerSetting_clickTimeout__addsDeprecatedFeatureConfigIssue() -{ - const auto node = Node::create(R"( - touchpad: - click_timeout: 1 - )"); - - INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 2, 25, issue); - QCOMPARE(issue->feature(), DeprecatedFeature::TriggerHandlerSettings); -} + Q_OBJECT + +private slots: + void valid__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + device_rules: + - conditions: $mouse + grab: true + + - conditions: $touchpad + ignore: true + )"); + + const auto rules = node->as>(); + QCOMPARE(rules.size(), 2); + + const auto &mouseRule = rules[0]; + QVERIFY(mouseRule.condition()); + QCOMPARE(mouseRule.properties().m_grab, true); + QCOMPARE(mouseRule.properties().m_ignore, std::nullopt); + + const auto &touchpadRule = rules[1]; + QVERIFY(touchpadRule.condition()); + QCOMPARE(touchpadRule.properties().m_grab, std::nullopt); + QCOMPARE(touchpadRule.properties().m_ignore, true); + } + + void mouse_triggerHandlerSetting_motionTimeout__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + mouse: + motion_timeout: 3735928559 + )"); + + const auto rules = node->as>(); + QCOMPARE(rules.size(), 1); + + const auto &rule = rules[0]; + QCOMPARE(rule.properties().m_mouseMotionTimeout, std::chrono::milliseconds(3735928559)); + + const auto condition = std::dynamic_pointer_cast(rule.condition()); + QVERIFY(condition); + QCOMPARE(condition->variableName(), "mouse"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &conditionValues = condition->values(); + QCOMPARE(conditionValues.size(), 1); + QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); + } + + void mouse_triggerHandlerSetting_motionTimeout__addsDeprecatedFeatureConfigIssue() + { + const auto node = Node::create(R"( + mouse: + motion_timeout: 1 + )"); + + INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 2, 30, issue); + QCOMPARE(issue->feature(), DeprecatedFeature::TriggerHandlerSettings); + } + + void mouse_triggerHandlerSetting_pressTimeout__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + mouse: + press_timeout: 3735928559 + )"); + + const auto rules = node->as>(); + QCOMPARE(rules.size(), 1); + + const auto &rule = rules[0]; + QCOMPARE(rule.properties().m_mousePressTimeout, std::chrono::milliseconds(3735928559)); + + const auto condition = std::dynamic_pointer_cast(rule.condition()); + QVERIFY(condition); + QCOMPARE(condition->variableName(), "mouse"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &conditionValues = condition->values(); + QCOMPARE(conditionValues.size(), 1); + QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); + } + + void mouse_triggerHandlerSetting_pressTimeout__addsDeprecatedFeatureConfigIssue() + { + const auto node = Node::create(R"( + mouse: + press_timeout: 1 + )"); + + INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 2, 29, issue); + QCOMPARE(issue->feature(), DeprecatedFeature::TriggerHandlerSettings); + } + + void mouse_triggerHandlerSetting_unblockButtonsOnTimeout__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + mouse: + unblock_buttons_on_timeout: true + )"); + + const auto rules = node->as>(); + QCOMPARE(rules.size(), 1); + + const auto &rule = rules[0]; + QCOMPARE(rule.properties().m_mouseUnblockButtonsOnTimeout, true); + + const auto condition = std::dynamic_pointer_cast(rule.condition()); + QVERIFY(condition); + QCOMPARE(condition->variableName(), "mouse"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &conditionValues = condition->values(); + QCOMPARE(conditionValues.size(), 1); + QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); + } + + void mouse_triggerHandlerSetting_unblockButtonsOnTimeout__addsDeprecatedFeatureConfigIssue() + { + const auto node = Node::create(R"( + mouse: + unblock_buttons_on_timeout: true + )"); + + INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 2, 42, issue); + QCOMPARE(issue->feature(), DeprecatedFeature::TriggerHandlerSettings); + } + + void touchpad_devicesNode__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + touchpad: + devices: + a: + ignore: true + )"); + + const auto rules = node->as>(); + QCOMPARE(rules.size(), 1); + + const auto &rule = rules[0]; + QCOMPARE(rule.properties().m_ignore, true); + + const auto condition = std::dynamic_pointer_cast(rule.condition()); + QVERIFY(condition); + QCOMPARE(condition->variableName(), "name"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &conditionValues = condition->values(); + QCOMPARE(conditionValues.size(), 1); + QCOMPARE(std::any_cast(conditionValues[0].get().value()), "a"); + } + + void touchpad_devicesNode__addsDeprecatedFeatureConfigIssue() + { + const auto node = Node::create(R"( + touchpad: + devices: + a: + ignore: true + )"); + + INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 3, 16, issue); + QCOMPARE(issue->feature(), DeprecatedFeature::TouchpadDevicesNode); + } + + void touchpad_triggerHandlerSetting_clickTimeout__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + touchpad: + click_timeout: 3735928559 + )"); + + const auto rules = node->as>(); + QCOMPARE(rules.size(), 1); + + const auto &rule = rules[0]; + QCOMPARE(rule.properties().m_touchpadClickTimeout, std::chrono::milliseconds(3735928559)); + + const auto condition = std::dynamic_pointer_cast(rule.condition()); + QVERIFY(condition); + QCOMPARE(condition->variableName(), "touchpad"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &conditionValues = condition->values(); + QCOMPARE(conditionValues.size(), 1); + QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); + } + + void touchpad_triggerHandlerSetting_clickTimeout__addsDeprecatedFeatureConfigIssue() + { + const auto node = Node::create(R"( + touchpad: + click_timeout: 1 + )"); + + INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 2, 29, issue); + QCOMPARE(issue->feature(), DeprecatedFeature::TriggerHandlerSettings); + } +}; } -QTEST_MAIN(InputActions::TestDeviceRuleNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestDeviceRuleNodeParser) +#include "TestDeviceRuleNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.h b/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.h deleted file mode 100644 index 354aac5..0000000 --- a/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestDeviceRuleNodeParser : public Test -{ - Q_OBJECT - -private slots: - void valid__parsesNodeCorrectly(); - - void mouse_triggerHandlerSetting_motionTimeout__parsesNodeCorrectly(); - void mouse_triggerHandlerSetting_motionTimeout__addsDeprecatedFeatureConfigIssue(); - - void mouse_triggerHandlerSetting_pressTimeout__parsesNodeCorrectly(); - void mouse_triggerHandlerSetting_pressTimeout__addsDeprecatedFeatureConfigIssue(); - - void mouse_triggerHandlerSetting_unblockButtonsOnTimeout__parsesNodeCorrectly(); - void mouse_triggerHandlerSetting_unblockButtonsOnTimeout__addsDeprecatedFeatureConfigIssue(); - - void touchpad_devicesNode__parsesNodeCorrectly(); - void touchpad_devicesNode__addsDeprecatedFeatureConfigIssue(); - - void touchpad_triggerHandlerSetting_clickTimeout__parsesNodeCorrectly(); - void touchpad_triggerHandlerSetting_clickTimeout__addsDeprecatedFeatureConfigIssue(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestEnumNodeParser.cpp b/tests/libinputactions/config/parsers/TestEnumNodeParser.cpp index 8ac2a81..16416da 100644 --- a/tests/libinputactions/config/parsers/TestEnumNodeParser.cpp +++ b/tests/libinputactions/config/parsers/TestEnumNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestEnumNodeParser.h" +#include "Test.h" #include #include #include @@ -16,24 +16,31 @@ NODEPARSER_ENUM(TestEnum, "", {"a", TestEnum::A}, })) -void TestEnumNodeParser::valid__parsesNodeCorrectly() +class TestEnumNodeParser : public Test { - const auto node = Node::create("a"); - QCOMPARE(node->as(), TestEnum::A); -} - -void TestEnumNodeParser::invalid_differentCase__throwsInvalidValueConfigException() -{ - const auto node = Node::create("A"); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} - -void TestEnumNodeParser::invalid__throwsInvalidValueConfigException() -{ - const auto node = Node::create("d"); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} + Q_OBJECT + +private slots: + void valid__parsesNodeCorrectly() + { + const auto node = Node::create("a"); + QCOMPARE(node->as(), TestEnum::A); + } + + void invalid_differentCase__throwsInvalidValueConfigException() + { + const auto node = Node::create("A"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } + + void invalid__throwsInvalidValueConfigException() + { + const auto node = Node::create("d"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } +}; } -QTEST_MAIN(InputActions::TestEnumNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestEnumNodeParser) +#include "TestEnumNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestEnumNodeParser.h b/tests/libinputactions/config/parsers/TestEnumNodeParser.h deleted file mode 100644 index 152e64e..0000000 --- a/tests/libinputactions/config/parsers/TestEnumNodeParser.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestEnumNodeParser : public Test -{ - Q_OBJECT - -private slots: - void valid__parsesNodeCorrectly(); - void invalid_differentCase__throwsInvalidValueConfigException(); - void invalid__throwsInvalidValueConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestFlagsNodeParser.cpp b/tests/libinputactions/config/parsers/TestFlagsNodeParser.cpp index 3f8cfde..671d163 100644 --- a/tests/libinputactions/config/parsers/TestFlagsNodeParser.cpp +++ b/tests/libinputactions/config/parsers/TestFlagsNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestFlagsNodeParser.h" +#include "Test.h" #include #include #include @@ -6,41 +6,48 @@ namespace InputActions { -void TestFlagsNodeParser::empty__parsesNodeCorrectly() +class TestFlagsNodeParser : public Test { - const auto node = Node::create("[]"); - QCOMPARE(node->as(), Qt::KeyboardModifier::NoModifier); -} - -void TestFlagsNodeParser::oneItem__parsesNodeCorrectly() -{ - const auto node = Node::create("[ ctrl ]"); - QCOMPARE(node->as(), Qt::KeyboardModifier::ControlModifier); -} - -void TestFlagsNodeParser::twoItems__parsesNodeCorrectly() -{ - const auto node = Node::create("[ ctrl, meta ]"); - QCOMPARE(node->as(), Qt::KeyboardModifier::ControlModifier | Qt::KeyboardModifier::MetaModifier); -} - -void TestFlagsNodeParser::invalid_duplicateItem__throwsInvalidNodeTypeConfigException() -{ - const auto node = Node::create("[ meta, meta ]"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as(), DuplicateSetItemConfigException, 0, 8, e); - QCOMPARE(e->index(), 1); -} - -void TestFlagsNodeParser::invalid_scalar__throwsInvalidNodeTypeConfigException() -{ - const auto node = Node::create("meta"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as(), InvalidNodeTypeConfigException, 0, 0, e); - QCOMPARE(e->expected(), NodeType::Sequence); - QCOMPARE(e->actual(), NodeType::Scalar); -} + Q_OBJECT + +private slots: + void empty__parsesNodeCorrectly() + { + const auto node = Node::create("[]"); + QCOMPARE(node->as(), Qt::KeyboardModifier::NoModifier); + } + + void oneItem__parsesNodeCorrectly() + { + const auto node = Node::create("[ ctrl ]"); + QCOMPARE(node->as(), Qt::KeyboardModifier::ControlModifier); + } + + void twoItems__parsesNodeCorrectly() + { + const auto node = Node::create("[ ctrl, meta ]"); + QCOMPARE(node->as(), Qt::KeyboardModifier::ControlModifier | Qt::KeyboardModifier::MetaModifier); + } + + void invalid_duplicateItem__throwsInvalidNodeTypeConfigException() + { + const auto node = Node::create("[ meta, meta ]"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as(), DuplicateSetItemConfigException, 0, 8, e); + QCOMPARE(e->index(), 1); + } + + void invalid_scalar__throwsInvalidNodeTypeConfigException() + { + const auto node = Node::create("meta"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as(), InvalidNodeTypeConfigException, 0, 0, e); + QCOMPARE(e->expected(), NodeType::Sequence); + QCOMPARE(e->actual(), NodeType::Scalar); + } +}; } -QTEST_MAIN(InputActions::TestFlagsNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestFlagsNodeParser) +#include "TestFlagsNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestFlagsNodeParser.h b/tests/libinputactions/config/parsers/TestFlagsNodeParser.h deleted file mode 100644 index 3bc430f..0000000 --- a/tests/libinputactions/config/parsers/TestFlagsNodeParser.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestFlagsNodeParser : public Test -{ - Q_OBJECT - -private slots: - void empty__parsesNodeCorrectly(); - void oneItem__parsesNodeCorrectly(); - void twoItems__parsesNodeCorrectly(); - - void invalid_duplicateItem__throwsInvalidNodeTypeConfigException(); - void invalid_scalar__throwsInvalidNodeTypeConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestRangeNodeParser.cpp b/tests/libinputactions/config/parsers/TestRangeNodeParser.cpp index afd02ee..dc7f706 100644 --- a/tests/libinputactions/config/parsers/TestRangeNodeParser.cpp +++ b/tests/libinputactions/config/parsers/TestRangeNodeParser.cpp @@ -1,28 +1,35 @@ -#include "TestRangeNodeParser.h" +#include "Test.h" #include #include namespace InputActions { -void TestRangeNodeParser::valid__parsesNodeCorrectly() +class TestRangeNodeParser : public Test { - const auto node = Node::create("12.34-43.21"); - const auto range = node->as>(); + Q_OBJECT - QCOMPARE(range.min(), 12.34); - QCOMPARE(range.max(), 43.21); -} +private slots: + void valid__parsesNodeCorrectly() + { + const auto node = Node::create("12.34-43.21"); + const auto range = node->as>(); -void TestRangeNodeParser::singularValue__parsesNodeCorrectly() -{ - const auto node = Node::create("1"); - const auto range = node->as>(); + QCOMPARE(range.min(), 12.34); + QCOMPARE(range.max(), 43.21); + } - QCOMPARE(range.min(), 1); - QCOMPARE(range.max(), std::nullopt); -} + void singularValue__parsesNodeCorrectly() + { + const auto node = Node::create("1"); + const auto range = node->as>(); + + QCOMPARE(range.min(), 1); + QCOMPARE(range.max(), std::nullopt); + } +}; } -QTEST_MAIN(InputActions::TestRangeNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestRangeNodeParser) +#include "TestRangeNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestRangeNodeParser.h b/tests/libinputactions/config/parsers/TestRangeNodeParser.h deleted file mode 100644 index c3926fe..0000000 --- a/tests/libinputactions/config/parsers/TestRangeNodeParser.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestRangeNodeParser : public Test -{ - Q_OBJECT - -private slots: - void valid__parsesNodeCorrectly(); - void singularValue__parsesNodeCorrectly(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestSeparatedStringNodeParser.cpp b/tests/libinputactions/config/parsers/TestSeparatedStringNodeParser.cpp index de71901..c5953f1 100644 --- a/tests/libinputactions/config/parsers/TestSeparatedStringNodeParser.cpp +++ b/tests/libinputactions/config/parsers/TestSeparatedStringNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestSeparatedStringNodeParser.h" +#include "Test.h" #include #include #include @@ -6,51 +6,58 @@ namespace InputActions { -void TestSeparatedStringNodeParser::number__parsesNodeCorrectly() +class TestSeparatedStringNodeParser : public Test { - const auto node = Node::create("12.34,43.21"); - const auto values = parseSeparatedString2(node.get(), ','); + Q_OBJECT + +private slots: + void number__parsesNodeCorrectly() + { + const auto node = Node::create("12.34,43.21"); + const auto values = parseSeparatedString2(node.get(), ','); + + QCOMPARE(values.first, 12.34); + QCOMPARE(values.second, 43.21); + } + + void point__parsesNodeCorrectly() + { + const auto node = Node::create("12.34,43.21;67.89,98.76"); + const auto values = parseSeparatedString2(node.get(), ';'); + + QCOMPARE(values.first, QPointF(12.34, 43.21)); + QCOMPARE(values.second, QPointF(67.89, 98.76)); + } + + void string__parsesNodeCorrectly() + { + const auto node = Node::create("ab,ba"); + const auto values = parseSeparatedString2(node.get(), ','); + + QCOMPARE(values.first, "ab"); + QCOMPARE(values.second, "ba"); + } + + void invalid__throwsInvalidValueConfigException_data() + { + QTest::addColumn("raw"); + + QTest::addRow("empty") << ""; + QTest::addRow("space") << " "; + QTest::addRow("leftOnly") << "a,"; + QTest::addRow("rightOnly") << ",a"; + } + + void invalid__throwsInvalidValueConfigException() + { + QFETCH(QString, raw); + + const auto node = Node::create(QStringHelpers::quoted(raw)); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(parseSeparatedString2(node.get(), ','), InvalidValueConfigException, 0, 0); + } +}; - QCOMPARE(values.first, 12.34); - QCOMPARE(values.second, 43.21); } -void TestSeparatedStringNodeParser::point__parsesNodeCorrectly() -{ - const auto node = Node::create("12.34,43.21;67.89,98.76"); - const auto values = parseSeparatedString2(node.get(), ';'); - - QCOMPARE(values.first, QPointF(12.34, 43.21)); - QCOMPARE(values.second, QPointF(67.89, 98.76)); -} - -void TestSeparatedStringNodeParser::string__parsesNodeCorrectly() -{ - const auto node = Node::create("ab,ba"); - const auto values = parseSeparatedString2(node.get(), ','); - - QCOMPARE(values.first, "ab"); - QCOMPARE(values.second, "ba"); -} - -void TestSeparatedStringNodeParser::invalid__throwsInvalidValueConfigException_data() -{ - QTest::addColumn("raw"); - - QTest::addRow("empty") << ""; - QTest::addRow("space") << " "; - QTest::addRow("leftOnly") << "a,"; - QTest::addRow("rightOnly") << ",a"; -} - -void TestSeparatedStringNodeParser::invalid__throwsInvalidValueConfigException() -{ - QFETCH(QString, raw); - - const auto node = Node::create(QStringHelpers::quoted(raw)); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(parseSeparatedString2(node.get(), ','), InvalidValueConfigException, 0, 0); -} - -} - -QTEST_MAIN(InputActions::TestSeparatedStringNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestSeparatedStringNodeParser) +#include "TestSeparatedStringNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestSeparatedStringNodeParser.h b/tests/libinputactions/config/parsers/TestSeparatedStringNodeParser.h deleted file mode 100644 index a7b3809..0000000 --- a/tests/libinputactions/config/parsers/TestSeparatedStringNodeParser.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestSeparatedStringNodeParser : public Test -{ - Q_OBJECT - -private slots: - void number__parsesNodeCorrectly(); - void point__parsesNodeCorrectly(); - void string__parsesNodeCorrectly(); - - void invalid__throwsInvalidValueConfigException_data(); - void invalid__throwsInvalidValueConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestTriggerActionNodeParser.cpp b/tests/libinputactions/config/parsers/TestTriggerActionNodeParser.cpp index 938b7c8..6d8f9b8 100644 --- a/tests/libinputactions/config/parsers/TestTriggerActionNodeParser.cpp +++ b/tests/libinputactions/config/parsers/TestTriggerActionNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestTriggerActionNodeParser.h" +#include "Test.h" #include #include #include @@ -6,98 +6,105 @@ namespace InputActions { -void TestTriggerActionNodeParser::interval_validOn__doesNotThrow_data() +class TestTriggerActionNodeParser : public Test { - QTest::addColumn("on"); + Q_OBJECT + +private slots: + void interval_validOn__doesNotThrow_data() + { + QTest::addColumn("on"); + + QTest::addRow("tick") << "tick"; + QTest::addRow("update") << "update"; + } + + void interval_validOn__doesNotThrow() + { + QFETCH(QString, on); + + const auto node = Node::create(QString(R"( + on: %1 + interval: 1 + command: _ + )") + .arg(on)); + + QVERIFY_THROWS_NO_EXCEPTION(node->as>()); + } + + void interval_invalidOn__throwsInvalidValueConfigException_data() + { + QTest::addColumn("on"); + + QTest::addRow("begin") << "begin"; + QTest::addRow("cancel") << "cancel"; + QTest::addRow("end") << "end"; + QTest::addRow("end_cancel") << "end_cancel"; + } + + void interval_invalidOn__throwsInvalidValueConfigException() + { + QFETCH(QString, on); + + const auto node = Node::create(QString(R"( + on: %1 + interval: 1 + command: _ + )") + .arg(on)); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueContextConfigException, 2, 22); + } + + void threshold_validOn__doesNotThrow_data() + { + QTest::addColumn("on"); + + QTest::addRow("cancel") << "cancel"; + QTest::addRow("end") << "end"; + QTest::addRow("end_cancel") << "end_cancel"; + QTest::addRow("tick") << "tick"; + QTest::addRow("update") << "update"; + } + + void threshold_validOn__doesNotThrow() + { + QFETCH(QString, on); + + const auto node = Node::create(QString(R"( + on: %1 + threshold: 1 + command: _ + )") + .arg(on)); + + QVERIFY_THROWS_NO_EXCEPTION(node->as>()); + } + + void threshold_invalidOn__throwsInvalidValueConfigException_data() + { + QTest::addColumn("on"); + + QTest::addRow("begin") << "begin"; + } + + void threshold_invalidOn__throwsInvalidValueConfigException() + { + QFETCH(QString, on); + + const auto node = Node::create(QString(R"( + on: %1 + threshold: 1 + command: _ + )") + .arg(on)); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueContextConfigException, 2, 23); + } +}; - QTest::addRow("tick") << "tick"; - QTest::addRow("update") << "update"; } -void TestTriggerActionNodeParser::interval_validOn__doesNotThrow() -{ - QFETCH(QString, on); - - const auto node = Node::create(QString(R"( - on: %1 - interval: 1 - command: _ - )") - .arg(on)); - - QVERIFY_THROWS_NO_EXCEPTION(node->as>()); -} - -void TestTriggerActionNodeParser::interval_invalidOn__throwsInvalidValueConfigException_data() -{ - QTest::addColumn("on"); - - QTest::addRow("begin") << "begin"; - QTest::addRow("cancel") << "cancel"; - QTest::addRow("end") << "end"; - QTest::addRow("end_cancel") << "end_cancel"; -} - -void TestTriggerActionNodeParser::interval_invalidOn__throwsInvalidValueConfigException() -{ - QFETCH(QString, on); - - const auto node = Node::create(QString(R"( - on: %1 - interval: 1 - command: _ - )") - .arg(on)); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueContextConfigException, 2, 18); -} - -void TestTriggerActionNodeParser::threshold_validOn__doesNotThrow_data() -{ - QTest::addColumn("on"); - - QTest::addRow("cancel") << "cancel"; - QTest::addRow("end") << "end"; - QTest::addRow("end_cancel") << "end_cancel"; - QTest::addRow("tick") << "tick"; - QTest::addRow("update") << "update"; -} - -void TestTriggerActionNodeParser::threshold_validOn__doesNotThrow() -{ - QFETCH(QString, on); - - const auto node = Node::create(QString(R"( - on: %1 - threshold: 1 - command: _ - )") - .arg(on)); - - QVERIFY_THROWS_NO_EXCEPTION(node->as>()); -} - -void TestTriggerActionNodeParser::threshold_invalidOn__throwsInvalidValueConfigException_data() -{ - QTest::addColumn("on"); - - QTest::addRow("begin") << "begin"; -} - -void TestTriggerActionNodeParser::threshold_invalidOn__throwsInvalidValueConfigException() -{ - QFETCH(QString, on); - - const auto node = Node::create(QString(R"( - on: %1 - threshold: 1 - command: _ - )") - .arg(on)); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueContextConfigException, 2, 19); -} - -} - -QTEST_MAIN(InputActions::TestTriggerActionNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestTriggerActionNodeParser) +#include "TestTriggerActionNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestTriggerActionNodeParser.h b/tests/libinputactions/config/parsers/TestTriggerActionNodeParser.h deleted file mode 100644 index 9509512..0000000 --- a/tests/libinputactions/config/parsers/TestTriggerActionNodeParser.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestTriggerActionNodeParser : public Test -{ - Q_OBJECT - -private slots: - void interval_validOn__doesNotThrow_data(); - void interval_validOn__doesNotThrow(); - void interval_invalidOn__throwsInvalidValueConfigException_data(); - void interval_invalidOn__throwsInvalidValueConfigException(); - - void threshold_validOn__doesNotThrow_data(); - void threshold_validOn__doesNotThrow(); - void threshold_invalidOn__throwsInvalidValueConfigException_data(); - void threshold_invalidOn__throwsInvalidValueConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestTriggerGroupNodeParser.cpp b/tests/libinputactions/config/parsers/TestTriggerGroupNodeParser.cpp index e5fdd91..47bbe5d 100644 --- a/tests/libinputactions/config/parsers/TestTriggerGroupNodeParser.cpp +++ b/tests/libinputactions/config/parsers/TestTriggerGroupNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestTriggerGroupNodeParser.h" +#include "Test.h" #include #include #include @@ -10,251 +10,258 @@ namespace InputActions { -void TestTriggerGroupNodeParser::init() +class TestTriggerGroupNodeParser : public Test { - g_variableManager = std::make_shared(); - g_variableManager->registerLocalVariable("a"); - g_variableManager->registerLocalVariable("b"); - g_variableManager->registerLocalVariable("c"); - g_variableManager->registerLocalVariable("d"); -} - -void TestTriggerGroupNodeParser::oneProperty__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - - id: test - gestures: - - type: press - )"); - const auto triggers = node->as>>(); - - QCOMPARE(triggers.size(), 1); - QCOMPARE(triggers[0]->id(), "test"); -} - -void TestTriggerGroupNodeParser::twoTriggers__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - - id: test - gestures: - - type: press - - type: press - )"); - const auto triggers = node->as>>(); - - QCOMPARE(triggers.size(), 2); - QCOMPARE(triggers[0]->id(), "test"); - QCOMPARE(triggers[1]->id(), "test"); -} - -void TestTriggerGroupNodeParser::nested_propertyInFirstGroup__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - - id: test - gestures: - - gestures: + Q_OBJECT + +private slots: + void init() + { + g_variableManager = std::make_shared(); + g_variableManager->registerLocalVariable("a"); + g_variableManager->registerLocalVariable("b"); + g_variableManager->registerLocalVariable("c"); + g_variableManager->registerLocalVariable("d"); + } + + void oneProperty__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + - id: test + gestures: - type: press - )"); - const auto triggers = node->as>>(); + )"); + const auto triggers = node->as>>(); - QCOMPARE(triggers.size(), 1); - QCOMPARE(triggers[0]->id(), "test"); -} + QCOMPARE(triggers.size(), 1); + QCOMPARE(triggers[0]->id(), "test"); + } -void TestTriggerGroupNodeParser::nested_propertyInSecondGroup__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - - gestures: + void twoTriggers__parsesNodeCorrectly() + { + const auto node = Node::create(R"( - id: test gestures: - type: press - )"); - const auto triggers = node->as>>(); - - QCOMPARE(triggers.size(), 1); - QCOMPARE(triggers[0]->id(), "test"); -} - -void TestTriggerGroupNodeParser::condition_triggerWithoutCondition__appliesConditionToTrigger() -{ - const auto node = Node::create(R"( - - conditions: $a - gestures: - - type: press - )"); - const auto triggers = node->as>>(); - - QCOMPARE(triggers.size(), 1); - QVERIFY(dynamic_pointer_cast(triggers[0]->activationCondition())); -} + - type: press + )"); + const auto triggers = node->as>>(); -void TestTriggerGroupNodeParser::condition_triggerWithSingleCondition__mergesConditionsIntoAllGroup() -{ - const auto node = Node::create(R"( - - conditions: $a - gestures: - - type: press - conditions: $b - )"); - const auto triggers = node->as>>(); - - QCOMPARE(triggers.size(), 1); - - const auto condition = std::dynamic_pointer_cast(triggers[0]->activationCondition()); - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->mode(), ConditionGroupMode::All); - - const auto &items = condition->conditions(); - QCOMPARE(items.size(), 2); - - const auto firstCondition = std::dynamic_pointer_cast(items[0]); - QVERIFY(firstCondition); - QCOMPARE(firstCondition->variableName(), "a"); - - const auto secondCondition = std::dynamic_pointer_cast(items[1]); - QVERIFY(secondCondition); - QCOMPARE(secondCondition->variableName(), "b"); -} + QCOMPARE(triggers.size(), 2); + QCOMPARE(triggers[0]->id(), "test"); + QCOMPARE(triggers[1]->id(), "test"); + } -void TestTriggerGroupNodeParser::nested_condition_triggerWithSingleCondition__mergesConditionsIntoAllGroup() -{ - const auto node = Node::create(R"( - - conditions: $a - gestures: - - conditions: $b + void nested_propertyInFirstGroup__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + - id: test + gestures: + - gestures: + - type: press + )"); + const auto triggers = node->as>>(); + + QCOMPARE(triggers.size(), 1); + QCOMPARE(triggers[0]->id(), "test"); + } + + void nested_propertyInSecondGroup__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + - gestures: + - id: test + gestures: + - type: press + )"); + const auto triggers = node->as>>(); + + QCOMPARE(triggers.size(), 1); + QCOMPARE(triggers[0]->id(), "test"); + } + + void condition_triggerWithoutCondition__appliesConditionToTrigger() + { + const auto node = Node::create(R"( + - conditions: $a gestures: - type: press - conditions: $c - )"); - const auto triggers = node->as>>(); + )"); + const auto triggers = node->as>>(); - QCOMPARE(triggers.size(), 1); + QCOMPARE(triggers.size(), 1); + QVERIFY(dynamic_pointer_cast(triggers[0]->activationCondition())); + } - const auto condition = std::dynamic_pointer_cast(triggers[0]->activationCondition()); - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->mode(), ConditionGroupMode::All); + void condition_triggerWithSingleCondition__mergesConditionsIntoAllGroup() + { + const auto node = Node::create(R"( + - conditions: $a + gestures: + - type: press + conditions: $b + )"); + const auto triggers = node->as>>(); - const auto &items = condition->conditions(); - QCOMPARE(items.size(), 3); + QCOMPARE(triggers.size(), 1); - const auto firstCondition = std::dynamic_pointer_cast(items[0]); - QVERIFY(firstCondition); - QCOMPARE(firstCondition->variableName(), "a"); + const auto condition = std::dynamic_pointer_cast(triggers[0]->activationCondition()); + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->mode(), ConditionGroupMode::All); - const auto secondCondition = std::dynamic_pointer_cast(items[1]); - QVERIFY(secondCondition); - QCOMPARE(secondCondition->variableName(), "b"); + const auto &items = condition->conditions(); + QCOMPARE(items.size(), 2); - const auto thirdCondition = std::dynamic_pointer_cast(items[2]); - QVERIFY(thirdCondition); - QCOMPARE(thirdCondition->variableName(), "c"); -} + const auto firstCondition = std::dynamic_pointer_cast(items[0]); + QVERIFY(firstCondition); + QCOMPARE(firstCondition->variableName(), "a"); -void TestTriggerGroupNodeParser::condition_triggerWithAllConditionGroup__prependsConditionToTrigger() -{ - const auto node = Node::create(R"( - - conditions: $a - gestures: - - type: press - conditions: - - $b - - $c - )"); - const auto triggers = node->as>>(); - - QCOMPARE(triggers.size(), 1); - - const auto condition = std::dynamic_pointer_cast(triggers[0]->activationCondition()); - QVERIFY(condition); - - const auto &items = condition->conditions(); - QCOMPARE(items.size(), 3); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->mode(), ConditionGroupMode::All); - - const auto firstCondition = std::dynamic_pointer_cast(items[0]); - QVERIFY(firstCondition); - QCOMPARE(firstCondition->variableName(), "a"); - - const auto secondCondition = std::dynamic_pointer_cast(items[1]); - QVERIFY(secondCondition); - QCOMPARE(secondCondition->variableName(), "b"); - - const auto thirdCondition = std::dynamic_pointer_cast(items[2]); - QVERIFY(thirdCondition); - QCOMPARE(thirdCondition->variableName(), "c"); -} + const auto secondCondition = std::dynamic_pointer_cast(items[1]); + QVERIFY(secondCondition); + QCOMPARE(secondCondition->variableName(), "b"); + } -void TestTriggerGroupNodeParser::condition_triggerWithAnyConditionGroup__mergesConditionsIntoAllGroup() -{ - const auto node = Node::create(R"( - - conditions: $a - gestures: - - type: press - conditions: - any: - - $b - - $c - )"); - const auto triggers = node->as>>(); - - QCOMPARE(triggers.size(), 1); - - const auto condition = std::dynamic_pointer_cast(triggers[0]->activationCondition()); - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->mode(), ConditionGroupMode::All); - - const auto &items = condition->conditions(); - QCOMPARE(items.size(), 2); - - const auto firstCondition = std::dynamic_pointer_cast(items[0]); - QVERIFY(firstCondition); - QCOMPARE(firstCondition->variableName(), "a"); - - const auto secondCondition = std::dynamic_pointer_cast(items[1]); - QVERIFY(secondCondition); - QCOMPARE(secondCondition->negate(), false); - QCOMPARE(secondCondition->mode(), ConditionGroupMode::Any); - - const auto &secondConditionItems = secondCondition->conditions(); - QCOMPARE(secondConditionItems.size(), 2); - - const auto thirdCondition = std::dynamic_pointer_cast(secondConditionItems[0]); - QVERIFY(thirdCondition); - QCOMPARE(thirdCondition->variableName(), "b"); - - const auto fourthCondition = std::dynamic_pointer_cast(secondConditionItems[1]); - QVERIFY(fourthCondition); - QCOMPARE(fourthCondition->variableName(), "c"); -} + void nested_condition_triggerWithSingleCondition__mergesConditionsIntoAllGroup() + { + const auto node = Node::create(R"( + - conditions: $a + gestures: + - conditions: $b + gestures: + - type: press + conditions: $c + )"); + const auto triggers = node->as>>(); + + QCOMPARE(triggers.size(), 1); + + const auto condition = std::dynamic_pointer_cast(triggers[0]->activationCondition()); + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->mode(), ConditionGroupMode::All); + + const auto &items = condition->conditions(); + QCOMPARE(items.size(), 3); + + const auto firstCondition = std::dynamic_pointer_cast(items[0]); + QVERIFY(firstCondition); + QCOMPARE(firstCondition->variableName(), "a"); + + const auto secondCondition = std::dynamic_pointer_cast(items[1]); + QVERIFY(secondCondition); + QCOMPARE(secondCondition->variableName(), "b"); + + const auto thirdCondition = std::dynamic_pointer_cast(items[2]); + QVERIFY(thirdCondition); + QCOMPARE(thirdCondition->variableName(), "c"); + } + + void condition_triggerWithAllConditionGroup__prependsConditionToTrigger() + { + const auto node = Node::create(R"( + - conditions: $a + gestures: + - type: press + conditions: + - $b + - $c + )"); + const auto triggers = node->as>>(); + + QCOMPARE(triggers.size(), 1); + + const auto condition = std::dynamic_pointer_cast(triggers[0]->activationCondition()); + QVERIFY(condition); + + const auto &items = condition->conditions(); + QCOMPARE(items.size(), 3); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->mode(), ConditionGroupMode::All); + + const auto firstCondition = std::dynamic_pointer_cast(items[0]); + QVERIFY(firstCondition); + QCOMPARE(firstCondition->variableName(), "a"); + + const auto secondCondition = std::dynamic_pointer_cast(items[1]); + QVERIFY(secondCondition); + QCOMPARE(secondCondition->variableName(), "b"); + + const auto thirdCondition = std::dynamic_pointer_cast(items[2]); + QVERIFY(thirdCondition); + QCOMPARE(thirdCondition->variableName(), "c"); + } + + void condition_triggerWithAnyConditionGroup__mergesConditionsIntoAllGroup() + { + const auto node = Node::create(R"( + - conditions: $a + gestures: + - type: press + conditions: + any: + - $b + - $c + )"); + const auto triggers = node->as>>(); + + QCOMPARE(triggers.size(), 1); + + const auto condition = std::dynamic_pointer_cast(triggers[0]->activationCondition()); + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->mode(), ConditionGroupMode::All); + + const auto &items = condition->conditions(); + QCOMPARE(items.size(), 2); + + const auto firstCondition = std::dynamic_pointer_cast(items[0]); + QVERIFY(firstCondition); + QCOMPARE(firstCondition->variableName(), "a"); + + const auto secondCondition = std::dynamic_pointer_cast(items[1]); + QVERIFY(secondCondition); + QCOMPARE(secondCondition->negate(), false); + QCOMPARE(secondCondition->mode(), ConditionGroupMode::Any); + + const auto &secondConditionItems = secondCondition->conditions(); + QCOMPARE(secondConditionItems.size(), 2); + + const auto thirdCondition = std::dynamic_pointer_cast(secondConditionItems[0]); + QVERIFY(thirdCondition); + QCOMPARE(thirdCondition->variableName(), "b"); + + const auto fourthCondition = std::dynamic_pointer_cast(secondConditionItems[1]); + QVERIFY(fourthCondition); + QCOMPARE(fourthCondition->variableName(), "c"); + } + + void invalidPropertyValue__throwsExceptionAtCorrectPosition() + { + const auto node = Node::create(R"( + - instant: _ + gestures: + - type: press + )"); -void TestTriggerGroupNodeParser::invalidPropertyValue__throwsExceptionAtCorrectPosition() -{ - const auto node = Node::create(R"( - - instant: _ - gestures: - - type: press - )"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>>(), InvalidValueConfigException, 1, 23); + } - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>>(), InvalidValueConfigException, 1, 19); -} + void unusedProperty__addsConfigIssueAtCorrectPosition() + { + const auto node = Node::create(R"( + - _: _ + gestures: + - type: press + )"); -void TestTriggerGroupNodeParser::unusedProperty__addsConfigIssueAtCorrectPosition() -{ - const auto node = Node::create(R"( - - _: _ - gestures: - - type: press - )"); - - node->as>>(); - INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->addUnusedMapPropertyIssues(), UnusedPropertyConfigIssue, 1, 10, issue); - QCOMPARE(issue->property(), "_"); -} + node->as>>(); + INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->addUnusedMapPropertyIssues(), UnusedPropertyConfigIssue, 1, 14, issue); + QCOMPARE(issue->property(), "_"); + } +}; } -QTEST_MAIN(InputActions::TestTriggerGroupNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestTriggerGroupNodeParser) +#include "TestTriggerGroupNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestTriggerGroupNodeParser.h b/tests/libinputactions/config/parsers/TestTriggerGroupNodeParser.h deleted file mode 100644 index 075952a..0000000 --- a/tests/libinputactions/config/parsers/TestTriggerGroupNodeParser.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestTriggerGroupNodeParser : public Test -{ - Q_OBJECT - -private slots: - void init(); - - void oneProperty__parsesNodeCorrectly(); - void twoTriggers__parsesNodeCorrectly(); - void nested_propertyInFirstGroup__parsesNodeCorrectly(); - void nested_propertyInSecondGroup__parsesNodeCorrectly(); - - void condition_triggerWithoutCondition__appliesConditionToTrigger(); - void condition_triggerWithSingleCondition__mergesConditionsIntoAllGroup(); - void nested_condition_triggerWithSingleCondition__mergesConditionsIntoAllGroup(); - void condition_triggerWithAllConditionGroup__prependsConditionToTrigger(); - void condition_triggerWithAnyConditionGroup__mergesConditionsIntoAllGroup(); - - void invalidPropertyValue__throwsExceptionAtCorrectPosition(); - void unusedProperty__addsConfigIssueAtCorrectPosition(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestTriggerNodeParser.cpp b/tests/libinputactions/config/parsers/TestTriggerNodeParser.cpp index b3c5c58..90242ed 100644 --- a/tests/libinputactions/config/parsers/TestTriggerNodeParser.cpp +++ b/tests/libinputactions/config/parsers/TestTriggerNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestTriggerNodeParser.h" +#include "Test.h" #include #include #include @@ -10,263 +10,270 @@ namespace InputActions { -void TestTriggerNodeParser::stroke_withConflictingBeginAction__throwsInvalidValueContextConfigException() +class TestTriggerNodeParser : public Test { - const auto node = Node::create(R"( - type: stroke - strokes: [ 'MgAAMjJkZAA=' ] - - actions: - - on: begin - command: _ - )"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueContextConfigException, 5, 12); -} - -void TestTriggerNodeParser::stroke_withNonConflictingBeginAction__doesNotThrow() -{ - const auto node = Node::create(R"( - type: stroke - strokes: [ 'MgAAMjJkZAA=' ] - - actions: - - on: begin - conflicting: false - command: _ - )"); - - QVERIFY_THROWS_NO_EXCEPTION(node->as>()); -} - -void TestTriggerNodeParser::stroke_withEndAction__doesNotThrow() -{ - const auto node = Node::create(R"( - type: stroke - strokes: [ 'MgAAMjJkZAA=' ] - - actions: - - on: end - command: _ - )"); - - QVERIFY_THROWS_NO_EXCEPTION(node->as>()); -} - -void TestTriggerNodeParser::stroke_invalidStroke__throwsInvalidValueConfigException() -{ - const auto node = Node::create(R"( - type: stroke - strokes: [ 'MgAAMjJkZA=' ] - - actions: - - on: end - command: _ - )"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 2, 19); -} - -void TestTriggerNodeParser::swipe_angle__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - type: swipe - angle: 30-60 - )"); - const auto trigger = node->as>(); - - const auto *swipeTrigger = dynamic_cast(trigger.get()); - QVERIFY(swipeTrigger); - QCOMPARE(swipeTrigger->minAngle(), 30); - QCOMPARE(swipeTrigger->maxAngle(), 60); -} - -void TestTriggerNodeParser::swipe_direction__doesNotThrow() -{ - const auto node = Node::create(R"( - type: swipe - direction: right - )"); - - QVERIFY_THROWS_NO_EXCEPTION(node->as>()); -} - -void TestTriggerNodeParser::swipe_invalidAngle__throwsInvalidValueConfigException() -{ - const auto node = Node::create(R"( - type: swipe - angle: 1-361 - )"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 2, 15); -} - -void TestTriggerNodeParser::fingers__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - type: press - fingers: 2 - )"); - const auto trigger = node->as>(); - - const auto condition = std::dynamic_pointer_cast(trigger->activationCondition()); - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "fingers"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), 2); -} - -void TestTriggerNodeParser::fingers_range__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - type: press - fingers: 2-3 - )"); - const auto trigger = node->as>(); - - const auto condition = std::dynamic_pointer_cast(trigger->activationCondition()); - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "fingers"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Between); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 2); - QCOMPARE(std::any_cast(values[0].get().value()), 2); - QCOMPARE(std::any_cast(values[1].get().value()), 3); -} - -void TestTriggerNodeParser::mouseButtons_duplicateItem__throwsDuplicateSetItemConfigException() -{ - const auto node = Node::create(R"( - type: press - mouse_buttons: [ left, left ] - )"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), DuplicateSetItemConfigException, 2, 31, e); - QCOMPARE(e->index(), 1); -} - -void TestTriggerNodeParser::keyboardModifiers__addsDeprecatedFeatureConfigIssue() -{ - const auto node = Node::create(R"( - type: press - keyboard_modifiers: none - )"); - - INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 2, 28, e); - QCOMPARE(e->feature(), DeprecatedFeature::TriggerKeyboardModifiers); -} - -void TestTriggerNodeParser::keyboardModifiers_any__doesNotAddCondition() -{ - const auto node = Node::create(R"( - type: press - keyboard_modifiers: any - )"); - const auto trigger = node->as>(); - - QVERIFY(!trigger->activationCondition()); -} - -void TestTriggerNodeParser::keyboardModifiers_metaAlt__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - type: press - keyboard_modifiers: [ meta, alt ] - )"); - const auto trigger = node->as>(); - - const auto condition = std::dynamic_pointer_cast(trigger->activationCondition()); - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "keyboard_modifiers"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::MetaModifier | Qt::KeyboardModifier::AltModifier); -} - -void TestTriggerNodeParser::keyboardModifiers_none__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - type: press - keyboard_modifiers: none - )"); - const auto trigger = node->as>(); - - const auto condition = std::dynamic_pointer_cast(trigger->activationCondition()); - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "keyboard_modifiers"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::NoModifier); -} - -void TestTriggerNodeParser::keyboardModifiers_invalid__throwsInvalidValueConfigException() -{ - const auto node = Node::create(R"( - type: press - keyboard_modifiers: e - )"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 2, 28); -} - -void TestTriggerNodeParser::fingers_keyboardModifiers_triggerCondition__mergedIntoAllGroup() -{ - const auto node = Node::create(R"( - type: press - fingers: 2-3 - conditions: $window_maximized - keyboard_modifiers: none - )"); - const auto trigger = node->as>(); - - const auto condition = std::dynamic_pointer_cast(trigger->activationCondition()); - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->mode(), ConditionGroupMode::All); - QCOMPARE(condition->conditions().size(), 3); - - const auto fingersCondition = std::dynamic_pointer_cast(condition->conditions()[0]); - QVERIFY(fingersCondition); - QCOMPARE(fingersCondition->negate(), false); - QCOMPARE(fingersCondition->variableName(), "fingers"); - - const auto keyboardModifiersCondition = std::dynamic_pointer_cast(condition->conditions()[1]); - QVERIFY(keyboardModifiersCondition); - QCOMPARE(keyboardModifiersCondition->negate(), false); - QCOMPARE(keyboardModifiersCondition->variableName(), "keyboard_modifiers"); - - const auto windowMaximizedCondition = std::dynamic_pointer_cast(condition->conditions()[2]); - QVERIFY(windowMaximizedCondition); - QCOMPARE(windowMaximizedCondition->negate(), false); - QCOMPARE(windowMaximizedCondition->variableName(), "window_maximized"); -} - -void TestTriggerNodeParser::invalid_noType__throwsMissingRequiredPropertyConfigException() -{ - const auto node = Node::create("_: _"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), MissingRequiredPropertyConfigException, 0, 0, e); - QCOMPARE(e->property(), "type"); -} - -void TestTriggerNodeParser::invalid_invalidType__throwsInvalidValueConfigException() -{ - const auto node = Node::create("type: _"); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 6); -} + Q_OBJECT + +private slots: + void stroke_withConflictingBeginAction__throwsInvalidValueContextConfigException() + { + const auto node = Node::create(R"( + type: stroke + strokes: [ 'MgAAMjJkZAA=' ] + + actions: + - on: begin + command: _ + )"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueContextConfigException, 5, 16); + } + + void stroke_withNonConflictingBeginAction__doesNotThrow() + { + const auto node = Node::create(R"( + type: stroke + strokes: [ 'MgAAMjJkZAA=' ] + + actions: + - on: begin + conflicting: false + command: _ + )"); + + QVERIFY_THROWS_NO_EXCEPTION(node->as>()); + } + + void stroke_withEndAction__doesNotThrow() + { + const auto node = Node::create(R"( + type: stroke + strokes: [ 'MgAAMjJkZAA=' ] + + actions: + - on: end + command: _ + )"); + + QVERIFY_THROWS_NO_EXCEPTION(node->as>()); + } + + void stroke_invalidStroke__throwsInvalidValueConfigException() + { + const auto node = Node::create(R"( + type: stroke + strokes: [ 'MgAAMjJkZA=' ] + + actions: + - on: end + command: _ + )"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 2, 23); + } + + void swipe_angle__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + type: swipe + angle: 30-60 + )"); + const auto trigger = node->as>(); + + const auto *swipeTrigger = dynamic_cast(trigger.get()); + QVERIFY(swipeTrigger); + QCOMPARE(swipeTrigger->minAngle(), 30); + QCOMPARE(swipeTrigger->maxAngle(), 60); + } + + void swipe_direction__doesNotThrow() + { + const auto node = Node::create(R"( + type: swipe + direction: right + )"); + + QVERIFY_THROWS_NO_EXCEPTION(node->as>()); + } + + void swipe_invalidAngle__throwsInvalidValueConfigException() + { + const auto node = Node::create(R"( + type: swipe + angle: 1-361 + )"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 2, 19); + } + + void fingers__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + type: press + fingers: 2 + )"); + const auto trigger = node->as>(); + + const auto condition = std::dynamic_pointer_cast(trigger->activationCondition()); + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "fingers"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), 2); + } + + void fingers_range__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + type: press + fingers: 2-3 + )"); + const auto trigger = node->as>(); + + const auto condition = std::dynamic_pointer_cast(trigger->activationCondition()); + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "fingers"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Between); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 2); + QCOMPARE(std::any_cast(values[0].get().value()), 2); + QCOMPARE(std::any_cast(values[1].get().value()), 3); + } + + void mouseButtons_duplicateItem__throwsDuplicateSetItemConfigException() + { + const auto node = Node::create(R"( + type: press + mouse_buttons: [ left, left ] + )"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), DuplicateSetItemConfigException, 2, 35, e); + QCOMPARE(e->index(), 1); + } + + void keyboardModifiers__addsDeprecatedFeatureConfigIssue() + { + const auto node = Node::create(R"( + type: press + keyboard_modifiers: none + )"); + + INPUTACTIONS_VERIFY_ADDS_CONFIG_ISSUE_SAVE(node->as>(), DeprecatedFeatureConfigIssue, 2, 32, e); + QCOMPARE(e->feature(), DeprecatedFeature::TriggerKeyboardModifiers); + } + + void keyboardModifiers_any__doesNotAddCondition() + { + const auto node = Node::create(R"( + type: press + keyboard_modifiers: any + )"); + const auto trigger = node->as>(); + + QVERIFY(!trigger->activationCondition()); + } + + void keyboardModifiers_metaAlt__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + type: press + keyboard_modifiers: [ meta, alt ] + )"); + const auto trigger = node->as>(); + + const auto condition = std::dynamic_pointer_cast(trigger->activationCondition()); + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "keyboard_modifiers"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::MetaModifier | Qt::KeyboardModifier::AltModifier); + } + + void keyboardModifiers_none__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + type: press + keyboard_modifiers: none + )"); + const auto trigger = node->as>(); + + const auto condition = std::dynamic_pointer_cast(trigger->activationCondition()); + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "keyboard_modifiers"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::NoModifier); + } + + void keyboardModifiers_invalid__throwsInvalidValueConfigException() + { + const auto node = Node::create(R"( + type: press + keyboard_modifiers: e + )"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 2, 32); + } + + void fingers_keyboardModifiers_triggerCondition__mergedIntoAllGroup() + { + const auto node = Node::create(R"( + type: press + fingers: 2-3 + conditions: $window_maximized + keyboard_modifiers: none + )"); + const auto trigger = node->as>(); + + const auto condition = std::dynamic_pointer_cast(trigger->activationCondition()); + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->mode(), ConditionGroupMode::All); + QCOMPARE(condition->conditions().size(), 3); + + const auto fingersCondition = std::dynamic_pointer_cast(condition->conditions()[0]); + QVERIFY(fingersCondition); + QCOMPARE(fingersCondition->negate(), false); + QCOMPARE(fingersCondition->variableName(), "fingers"); + + const auto keyboardModifiersCondition = std::dynamic_pointer_cast(condition->conditions()[1]); + QVERIFY(keyboardModifiersCondition); + QCOMPARE(keyboardModifiersCondition->negate(), false); + QCOMPARE(keyboardModifiersCondition->variableName(), "keyboard_modifiers"); + + const auto windowMaximizedCondition = std::dynamic_pointer_cast(condition->conditions()[2]); + QVERIFY(windowMaximizedCondition); + QCOMPARE(windowMaximizedCondition->negate(), false); + QCOMPARE(windowMaximizedCondition->variableName(), "window_maximized"); + } + + void invalid_noType__throwsMissingRequiredPropertyConfigException() + { + const auto node = Node::create("_: _"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), MissingRequiredPropertyConfigException, 0, 0, e); + QCOMPARE(e->property(), "type"); + } + + void invalid_invalidType__throwsInvalidValueConfigException() + { + const auto node = Node::create("type: _"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 6); + } +}; } -QTEST_MAIN(InputActions::TestTriggerNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestTriggerNodeParser) +#include "TestTriggerNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/TestTriggerNodeParser.h b/tests/libinputactions/config/parsers/TestTriggerNodeParser.h deleted file mode 100644 index 6c52f91..0000000 --- a/tests/libinputactions/config/parsers/TestTriggerNodeParser.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestTriggerNodeParser : public Test -{ - Q_OBJECT - -private slots: - void stroke_withConflictingBeginAction__throwsInvalidValueContextConfigException(); - void stroke_withNonConflictingBeginAction__doesNotThrow(); - void stroke_withEndAction__doesNotThrow(); - void stroke_invalidStroke__throwsInvalidValueConfigException(); - - void swipe_angle__parsesNodeCorrectly(); - void swipe_direction__doesNotThrow(); - void swipe_invalidAngle__throwsInvalidValueConfigException(); - - void fingers__parsesNodeCorrectly(); - void fingers_range__parsesNodeCorrectly(); - - void mouseButtons_duplicateItem__throwsDuplicateSetItemConfigException(); - - void keyboardModifiers__addsDeprecatedFeatureConfigIssue(); - void keyboardModifiers_any__doesNotAddCondition(); - void keyboardModifiers_metaAlt__parsesNodeCorrectly(); - void keyboardModifiers_none__parsesNodeCorrectly(); - void keyboardModifiers_invalid__throwsInvalidValueConfigException(); - - void fingers_keyboardModifiers_triggerCondition__mergedIntoAllGroup(); - - void invalid_noType__throwsMissingRequiredPropertyConfigException(); - void invalid_invalidType__throwsInvalidValueConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/actions/TestActionGroupNodeParser.cpp b/tests/libinputactions/config/parsers/actions/TestActionGroupNodeParser.cpp index 066c657..d9ce487 100644 --- a/tests/libinputactions/config/parsers/actions/TestActionGroupNodeParser.cpp +++ b/tests/libinputactions/config/parsers/actions/TestActionGroupNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestActionGroupNodeParser.h" +#include "Test.h" #include #include #include @@ -6,31 +6,38 @@ namespace InputActions { -void TestActionGroupNodeParser::one__parsesNodeCorrectly() +class TestActionGroupNodeParser : public Test { - const auto node = Node::create(R"( - one: - - sleep: 1 - - sleep: 2 - )"); - const auto action = node->as>(); - - const auto *actionGroup = dynamic_cast(action.get()); - QVERIFY(actionGroup); - QCOMPARE(actionGroup->mode(), ActionGroupExecutionMode::First); - - const auto actions = actionGroup->actions(); - QCOMPARE(actions.size(), 2); - - const auto *action1 = dynamic_cast(actions[0]); - QVERIFY(action1); - QCOMPARE(action1->time(), std::chrono::milliseconds(1)); - - const auto *action2 = dynamic_cast(actions[1]); - QVERIFY(action2); - QCOMPARE(action2->time(), std::chrono::milliseconds(2)); -} + Q_OBJECT + +private slots: + void one__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + one: + - sleep: 1 + - sleep: 2 + )"); + const auto action = node->as>(); + + const auto *actionGroup = dynamic_cast(action.get()); + QVERIFY(actionGroup); + QCOMPARE(actionGroup->mode(), ActionGroupExecutionMode::First); + + const auto actions = actionGroup->actions(); + QCOMPARE(actions.size(), 2); + + const auto *action1 = dynamic_cast(actions[0]); + QVERIFY(action1); + QCOMPARE(action1->time(), std::chrono::milliseconds(1)); + + const auto *action2 = dynamic_cast(actions[1]); + QVERIFY(action2); + QCOMPARE(action2->time(), std::chrono::milliseconds(2)); + } +}; } -QTEST_MAIN(InputActions::TestActionGroupNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestActionGroupNodeParser) +#include "TestActionGroupNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/actions/TestActionGroupNodeParser.h b/tests/libinputactions/config/parsers/actions/TestActionGroupNodeParser.h deleted file mode 100644 index 7e8dfb3..0000000 --- a/tests/libinputactions/config/parsers/actions/TestActionGroupNodeParser.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestActionGroupNodeParser : public Test -{ - Q_OBJECT - -private slots: - void one__parsesNodeCorrectly(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/actions/TestInputActionNodeParser.cpp b/tests/libinputactions/config/parsers/actions/TestInputActionNodeParser.cpp index 95f8e55..994ddd6 100644 --- a/tests/libinputactions/config/parsers/actions/TestInputActionNodeParser.cpp +++ b/tests/libinputactions/config/parsers/actions/TestInputActionNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestInputActionNodeParser.h" +#include "Test.h" #include #include #include @@ -7,199 +7,206 @@ namespace InputActions { -void TestInputActionNodeParser::keyboardKey_twoSeparate__parsesNodeCorrectly() -{ - const auto node = Node::create("- keyboard: [ a, b ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 4); - QCOMPARE(items[0].keyboardPress, KEY_A); - QCOMPARE(items[1].keyboardRelease, KEY_A); - QCOMPARE(items[2].keyboardPress, KEY_B); - QCOMPARE(items[3].keyboardRelease, KEY_B); -} - -void TestInputActionNodeParser::keyboardKey_twoCombined__parsesNodeCorrectly() -{ - const auto node = Node::create("- keyboard: [ a+b ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 4); - QCOMPARE(items[0].keyboardPress, KEY_A); - QCOMPARE(items[1].keyboardPress, KEY_B); - QCOMPARE(items[2].keyboardRelease, KEY_B); - QCOMPARE(items[3].keyboardRelease, KEY_A); -} - -void TestInputActionNodeParser::keyboardKeyPress_two__parsesNodeCorrectly() -{ - const auto node = Node::create("- keyboard: [ +a, +b ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 2); - QCOMPARE(items[0].keyboardPress, KEY_A); - QCOMPARE(items[1].keyboardPress, KEY_B); -} - -void TestInputActionNodeParser::keyboardKeyRelease_two__parsesNodeCorrectly() -{ - const auto node = Node::create("- keyboard: [ -a, -b ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 2); - QCOMPARE(items[0].keyboardRelease, KEY_A); - QCOMPARE(items[1].keyboardRelease, KEY_B); -} - -void TestInputActionNodeParser::keyboardText__parsesNodeCorrectly() -{ - const auto node = Node::create("- keyboard: [ text: aaa ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 1); - QCOMPARE(items[0].keyboardText.get(), "aaa"); -} - -void TestInputActionNodeParser::keyboardText_command__parsesNodeCorrectly() -{ - const auto node = Node::create("- keyboard: [ text: { command: echo a } ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 1); - QCOMPARE(items[0].keyboardText.get(), "a\n"); -} - -void TestInputActionNodeParser::mouseButton_twoSeparate__parsesNodeCorrectly() -{ - const auto node = Node::create("- mouse: [ left, right ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 4); - QCOMPARE(items[0].mousePress, BTN_LEFT); - QCOMPARE(items[1].mouseRelease, BTN_LEFT); - QCOMPARE(items[2].mousePress, BTN_RIGHT); - QCOMPARE(items[3].mouseRelease, BTN_RIGHT); -} - -void TestInputActionNodeParser::mouseButton_twoCombined__parsesNodeCorrectly() -{ - const auto node = Node::create("- mouse: [ left+right ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 4); - QCOMPARE(items[0].mousePress, BTN_LEFT); - QCOMPARE(items[1].mousePress, BTN_RIGHT); - QCOMPARE(items[2].mouseRelease, BTN_RIGHT); - QCOMPARE(items[3].mouseRelease, BTN_LEFT); -} - -void TestInputActionNodeParser::mouseButtonPress_two__parsesNodeCorrectly() -{ - const auto node = Node::create("- mouse: [ +left, +right ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 2); - QCOMPARE(items[0].mousePress, BTN_LEFT); - QCOMPARE(items[1].mousePress, BTN_RIGHT); -} - -void TestInputActionNodeParser::mouseButtonRelease_two__parsesNodeCorrectly() -{ - const auto node = Node::create("- mouse: [ -left, -right ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 2); - QCOMPARE(items[0].mouseRelease, BTN_LEFT); - QCOMPARE(items[1].mouseRelease, BTN_RIGHT); -} - -void TestInputActionNodeParser::mouseMoveAbsolute__parsesNodeCorrectly() -{ - const auto node = Node::create("- mouse: [ move_to -1.2 1.2 ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 1); - QCOMPARE(items[0].mouseMoveAbsolute, QPointF(-1.2, 1.2)); -} - -void TestInputActionNodeParser::mouseMoveByDelta_noMultiplier__parsesNodeCorrectly() -{ - const auto node = Node::create("- mouse: [ move_by_delta ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 1); - QCOMPARE(items[0].mouseMoveRelativeByDelta, static_cast(1)); -} - -void TestInputActionNodeParser::mouseMoveByDelta_multiplier__parsesNodeCorrectly() -{ - const auto node = Node::create("- mouse: [ move_by_delta 1.25 ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 1); - QCOMPARE(items[0].mouseMoveRelativeByDelta, static_cast(1.25)); -} - -void TestInputActionNodeParser::mouseMoveRelative__parsesNodeCorrectly() -{ - const auto node = Node::create("- mouse: [ move_by -1.2 1.2 ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 1); - QCOMPARE(items[0].mouseMoveRelative, QPointF(-1.2, 1.2)); -} - -void TestInputActionNodeParser::mouseWheel__parsesNodeCorrectly() -{ - const auto node = Node::create("- mouse: [ wheel -1.2 1.2 ]"); - const auto items = node->as>(); - - QCOMPARE(items.size(), 1); - QCOMPARE(items[0].mouseAxis, QPointF(-1.2, 1.2)); -} - -void TestInputActionNodeParser::invalid__throwsInvalidValueConfigException_data() -{ - QTest::addColumn("config"); - QTest::addColumn("column"); - - QTest::newRow("keyboardKey_invalid") << "- keyboard: [ aa ]" << 14; - QTest::newRow("keyboardKey_twoSeparatedBySpace") << "- keyboard: [ a a ]" << 14; - QTest::newRow("keyboardKey_twoSeparatedByTwoPluses") << "- keyboard: [ a++b ]" << 14; - QTest::newRow("keyboardKey_twoLeadingPluses") << "- keyboard: [ ++a ]" << 15; - QTest::newRow("keyboardKey_twoTrailingPluses") << "- keyboard: [ a++ ]" << 14; - QTest::newRow("keyboardKey_twoLeadingMinuses") << "- keyboard: [ --a ]" << 15; - QTest::newRow("keyboardKey_twoTrailingMinuses") << "- keyboard: [ a-- ]" << 14; - QTest::newRow("mouseButton_invalid") << "- mouse: [ aa ]" << 11; - QTest::newRow("mouseButton_twoSeparatedBySpace") << "- mouse: [ left right ]" << 11; - QTest::newRow("mouseButton_twoSeparatedByTwoPluses") << "- mouse: [ left++right ]" << 11; - QTest::newRow("mouseButton_combined_twoPluses") << "- mouse: [ left++right ]" << 11; - QTest::newRow("mouseButton_twoLeadingPluses") << "- mouse: [ ++left ]" << 12; - QTest::newRow("mouseButton_twoTrailingPluses") << "- mouse: [ left++ ]" << 11; - QTest::newRow("mouseButton_twoLeadingMinuses") << "- mouse: [ --left ]" << 12; - QTest::newRow("mouseButton_twoTrailingMinuses") << "- mouse: [ left-- ]" << 11; - QTest::newRow("mouseMoveByDelta_multiplierNotANumber") << "- mouse: [ move_by_delta x ]" << 25; - QTest::newRow("mouseMoveRelative_empty") << "- mouse: [ move_by ]" << 11; - QTest::newRow("mouseMoveRelative_spaces") << "- mouse: [ \"move_by \" ]" << 11; - QTest::newRow("mouseMoveRelative_oneArgument") << "- mouse: [ move_by 1 ]" << 19; - QTest::newRow("mouseMoveRelative_twoSpacesBetweenArguments") << "- mouse: [ move_by 1 1 ]" << 11; - QTest::newRow("mouseMoveRelative_nonNumericArguments") << "- mouse: [ move_by x x ]" << 11; - QTest::newRow("mouseWheel_empty") << "- mouse: [ wheel ]" << 11; - QTest::newRow("mouseWheel_spaces") << "- mouse: [ \"wheel \" ]" << 11; - QTest::newRow("mouseWheel_oneArgument") << "- mouse: [ wheel 1 ]" << 17; - QTest::newRow("mouseWheel_twoSpacesBetweenArguments") << "- mouse: [ wheel 1 1 ]" << 11; - QTest::newRow("mouseWheel_nonNumericArguments") << "- mouse: [ wheel x x ]" << 11; -} - -void TestInputActionNodeParser::invalid__throwsInvalidValueConfigException() -{ - QFETCH(QString, config); - QFETCH(int, column); - - const auto node = Node::create(config); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, column); -} - -} - -QTEST_MAIN(InputActions::TestInputActionNodeParser) \ No newline at end of file +class TestInputActionNodeParser : public Test +{ + Q_OBJECT + +private slots: + void keyboardKey_twoSeparate__parsesNodeCorrectly() + { + const auto node = Node::create("- keyboard: [ a, b ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 4); + QCOMPARE(items[0].keyboardPress, KEY_A); + QCOMPARE(items[1].keyboardRelease, KEY_A); + QCOMPARE(items[2].keyboardPress, KEY_B); + QCOMPARE(items[3].keyboardRelease, KEY_B); + } + + void keyboardKey_twoCombined__parsesNodeCorrectly() + { + const auto node = Node::create("- keyboard: [ a+b ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 4); + QCOMPARE(items[0].keyboardPress, KEY_A); + QCOMPARE(items[1].keyboardPress, KEY_B); + QCOMPARE(items[2].keyboardRelease, KEY_B); + QCOMPARE(items[3].keyboardRelease, KEY_A); + } + + void keyboardKeyPress_two__parsesNodeCorrectly() + { + const auto node = Node::create("- keyboard: [ +a, +b ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 2); + QCOMPARE(items[0].keyboardPress, KEY_A); + QCOMPARE(items[1].keyboardPress, KEY_B); + } + + void keyboardKeyRelease_two__parsesNodeCorrectly() + { + const auto node = Node::create("- keyboard: [ -a, -b ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 2); + QCOMPARE(items[0].keyboardRelease, KEY_A); + QCOMPARE(items[1].keyboardRelease, KEY_B); + } + + void keyboardText__parsesNodeCorrectly() + { + const auto node = Node::create("- keyboard: [ text: aaa ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 1); + QCOMPARE(items[0].keyboardText.get(), "aaa"); + } + + void keyboardText_command__parsesNodeCorrectly() + { + const auto node = Node::create("- keyboard: [ text: { command: echo a } ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 1); + QCOMPARE(items[0].keyboardText.get(), "a\n"); + } + + void mouseButton_twoSeparate__parsesNodeCorrectly() + { + const auto node = Node::create("- mouse: [ left, right ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 4); + QCOMPARE(items[0].mousePress, BTN_LEFT); + QCOMPARE(items[1].mouseRelease, BTN_LEFT); + QCOMPARE(items[2].mousePress, BTN_RIGHT); + QCOMPARE(items[3].mouseRelease, BTN_RIGHT); + } + + void mouseButton_twoCombined__parsesNodeCorrectly() + { + const auto node = Node::create("- mouse: [ left+right ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 4); + QCOMPARE(items[0].mousePress, BTN_LEFT); + QCOMPARE(items[1].mousePress, BTN_RIGHT); + QCOMPARE(items[2].mouseRelease, BTN_RIGHT); + QCOMPARE(items[3].mouseRelease, BTN_LEFT); + } + + void mouseButtonPress_two__parsesNodeCorrectly() + { + const auto node = Node::create("- mouse: [ +left, +right ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 2); + QCOMPARE(items[0].mousePress, BTN_LEFT); + QCOMPARE(items[1].mousePress, BTN_RIGHT); + } + + void mouseButtonRelease_two__parsesNodeCorrectly() + { + const auto node = Node::create("- mouse: [ -left, -right ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 2); + QCOMPARE(items[0].mouseRelease, BTN_LEFT); + QCOMPARE(items[1].mouseRelease, BTN_RIGHT); + } + + void mouseMoveAbsolute__parsesNodeCorrectly() + { + const auto node = Node::create("- mouse: [ move_to -1.2 1.2 ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 1); + QCOMPARE(items[0].mouseMoveAbsolute, QPointF(-1.2, 1.2)); + } + + void mouseMoveByDelta_noMultiplier__parsesNodeCorrectly() + { + const auto node = Node::create("- mouse: [ move_by_delta ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 1); + QCOMPARE(items[0].mouseMoveRelativeByDelta, static_cast(1)); + } + + void mouseMoveByDelta_multiplier__parsesNodeCorrectly() + { + const auto node = Node::create("- mouse: [ move_by_delta 1.25 ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 1); + QCOMPARE(items[0].mouseMoveRelativeByDelta, static_cast(1.25)); + } + + void mouseMoveRelative__parsesNodeCorrectly() + { + const auto node = Node::create("- mouse: [ move_by -1.2 1.2 ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 1); + QCOMPARE(items[0].mouseMoveRelative, QPointF(-1.2, 1.2)); + } + + void mouseWheel__parsesNodeCorrectly() + { + const auto node = Node::create("- mouse: [ wheel -1.2 1.2 ]"); + const auto items = node->as>(); + + QCOMPARE(items.size(), 1); + QCOMPARE(items[0].mouseAxis, QPointF(-1.2, 1.2)); + } + + void invalid__throwsInvalidValueConfigException_data() + { + QTest::addColumn("config"); + QTest::addColumn("column"); + + QTest::newRow("keyboardKey_invalid") << "- keyboard: [ aa ]" << 14; + QTest::newRow("keyboardKey_twoSeparatedBySpace") << "- keyboard: [ a a ]" << 14; + QTest::newRow("keyboardKey_twoSeparatedByTwoPluses") << "- keyboard: [ a++b ]" << 14; + QTest::newRow("keyboardKey_twoLeadingPluses") << "- keyboard: [ ++a ]" << 15; + QTest::newRow("keyboardKey_twoTrailingPluses") << "- keyboard: [ a++ ]" << 14; + QTest::newRow("keyboardKey_twoLeadingMinuses") << "- keyboard: [ --a ]" << 15; + QTest::newRow("keyboardKey_twoTrailingMinuses") << "- keyboard: [ a-- ]" << 14; + QTest::newRow("mouseButton_invalid") << "- mouse: [ aa ]" << 11; + QTest::newRow("mouseButton_twoSeparatedBySpace") << "- mouse: [ left right ]" << 11; + QTest::newRow("mouseButton_twoSeparatedByTwoPluses") << "- mouse: [ left++right ]" << 11; + QTest::newRow("mouseButton_combined_twoPluses") << "- mouse: [ left++right ]" << 11; + QTest::newRow("mouseButton_twoLeadingPluses") << "- mouse: [ ++left ]" << 12; + QTest::newRow("mouseButton_twoTrailingPluses") << "- mouse: [ left++ ]" << 11; + QTest::newRow("mouseButton_twoLeadingMinuses") << "- mouse: [ --left ]" << 12; + QTest::newRow("mouseButton_twoTrailingMinuses") << "- mouse: [ left-- ]" << 11; + QTest::newRow("mouseMoveByDelta_multiplierNotANumber") << "- mouse: [ move_by_delta x ]" << 25; + QTest::newRow("mouseMoveRelative_empty") << "- mouse: [ move_by ]" << 11; + QTest::newRow("mouseMoveRelative_spaces") << "- mouse: [ \"move_by \" ]" << 11; + QTest::newRow("mouseMoveRelative_oneArgument") << "- mouse: [ move_by 1 ]" << 19; + QTest::newRow("mouseMoveRelative_twoSpacesBetweenArguments") << "- mouse: [ move_by 1 1 ]" << 11; + QTest::newRow("mouseMoveRelative_nonNumericArguments") << "- mouse: [ move_by x x ]" << 11; + QTest::newRow("mouseWheel_empty") << "- mouse: [ wheel ]" << 11; + QTest::newRow("mouseWheel_spaces") << "- mouse: [ \"wheel \" ]" << 11; + QTest::newRow("mouseWheel_oneArgument") << "- mouse: [ wheel 1 ]" << 17; + QTest::newRow("mouseWheel_twoSpacesBetweenArguments") << "- mouse: [ wheel 1 1 ]" << 11; + QTest::newRow("mouseWheel_nonNumericArguments") << "- mouse: [ wheel x x ]" << 11; + } + + void invalid__throwsInvalidValueConfigException() + { + QFETCH(QString, config); + QFETCH(int, column); + + const auto node = Node::create(config); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, column); + } +}; + +} + +QTEST_MAIN(InputActions::TestInputActionNodeParser) +#include "TestInputActionNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/actions/TestInputActionNodeParser.h b/tests/libinputactions/config/parsers/actions/TestInputActionNodeParser.h deleted file mode 100644 index dff4c88..0000000 --- a/tests/libinputactions/config/parsers/actions/TestInputActionNodeParser.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestInputActionNodeParser : public Test -{ - Q_OBJECT - -private slots: - void keyboardKey_twoSeparate__parsesNodeCorrectly(); - void keyboardKey_twoCombined__parsesNodeCorrectly(); - void keyboardKeyPress_two__parsesNodeCorrectly(); - void keyboardKeyRelease_two__parsesNodeCorrectly(); - void keyboardText__parsesNodeCorrectly(); - void keyboardText_command__parsesNodeCorrectly(); - - void mouseButton_twoSeparate__parsesNodeCorrectly(); - void mouseButton_twoCombined__parsesNodeCorrectly(); - void mouseButtonPress_two__parsesNodeCorrectly(); - void mouseButtonRelease_two__parsesNodeCorrectly(); - void mouseMoveAbsolute__parsesNodeCorrectly(); - void mouseMoveByDelta_noMultiplier__parsesNodeCorrectly(); - void mouseMoveByDelta_multiplier__parsesNodeCorrectly(); - void mouseMoveRelative__parsesNodeCorrectly(); - void mouseWheel__parsesNodeCorrectly(); - - void invalid__throwsInvalidValueConfigException_data(); - void invalid__throwsInvalidValueConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/actions/TestPlasmaShortcutActionNodeParser.cpp b/tests/libinputactions/config/parsers/actions/TestPlasmaShortcutActionNodeParser.cpp index 46ecd0c..41694bf 100644 --- a/tests/libinputactions/config/parsers/actions/TestPlasmaShortcutActionNodeParser.cpp +++ b/tests/libinputactions/config/parsers/actions/TestPlasmaShortcutActionNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestPlasmaShortcutActionNodeParser.h" +#include "Test.h" #include #include #include @@ -6,24 +6,31 @@ namespace InputActions { -void TestPlasmaShortcutActionNodeParser::valid__parsesNodeCorrectly() +class TestPlasmaShortcutActionNodeParser : public Test { - const auto node = Node::create("plasma_shortcut: a,b"); - const auto action = node->as>(); + Q_OBJECT - const auto *plasmaAction = dynamic_cast(action.get()); - QVERIFY(plasmaAction); +private slots: + void valid__parsesNodeCorrectly() + { + const auto node = Node::create("plasma_shortcut: a,b"); + const auto action = node->as>(); - QCOMPARE(plasmaAction->component(), "a"); - QCOMPARE(plasmaAction->shortcut(), "b"); -} + const auto *plasmaAction = dynamic_cast(action.get()); + QVERIFY(plasmaAction); -void TestPlasmaShortcutActionNodeParser::invalid__throwsInvalidValueConfigException() -{ - const auto node = Node::create("plasma_shortcut: _"); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 17); -} + QCOMPARE(plasmaAction->component(), "a"); + QCOMPARE(plasmaAction->shortcut(), "b"); + } + + void invalid__throwsInvalidValueConfigException() + { + const auto node = Node::create("plasma_shortcut: _"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 17); + } +}; } -QTEST_MAIN(InputActions::TestPlasmaShortcutActionNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestPlasmaShortcutActionNodeParser) +#include "TestPlasmaShortcutActionNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/actions/TestPlasmaShortcutActionNodeParser.h b/tests/libinputactions/config/parsers/actions/TestPlasmaShortcutActionNodeParser.h deleted file mode 100644 index 1cf6212..0000000 --- a/tests/libinputactions/config/parsers/actions/TestPlasmaShortcutActionNodeParser.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestPlasmaShortcutActionNodeParser : public Test -{ - Q_OBJECT - -private slots: - void valid__parsesNodeCorrectly(); - void invalid__throwsInvalidValueConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/conditions/TestConditionGroupNodeParser.cpp b/tests/libinputactions/config/parsers/conditions/TestConditionGroupNodeParser.cpp index 793347a..9b59e40 100644 --- a/tests/libinputactions/config/parsers/conditions/TestConditionGroupNodeParser.cpp +++ b/tests/libinputactions/config/parsers/conditions/TestConditionGroupNodeParser.cpp @@ -1,83 +1,90 @@ -#include "TestConditionGroupNodeParser.h" +#include "Test.h" #include #include namespace InputActions { -void TestConditionGroupNodeParser::all__parsesNodeCorrectly() +class TestConditionGroupNodeParser : public Test { - const auto node = Node::create("all: []"); - const auto condition = std::dynamic_pointer_cast(node->as>()); + Q_OBJECT + +private slots: + void all__parsesNodeCorrectly() + { + const auto node = Node::create("all: []"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->mode(), ConditionGroupMode::All); + QCOMPARE(condition->conditions().size(), 0); + } + + void any__parsesNodeCorrectly() + { + const auto node = Node::create("any: []"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->mode(), ConditionGroupMode::Any); + QCOMPARE(condition->conditions().size(), 0); + } + + void none__parsesNodeCorrectly() + { + const auto node = Node::create("none: []"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->mode(), ConditionGroupMode::None); + QCOMPARE(condition->conditions().size(), 0); + } + + void list__parsesNodeAsAllGroup() + { + const auto node = Node::create("[]"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->mode(), ConditionGroupMode::All); + QCOMPARE(condition->conditions().size(), 0); + } + + void nested__parsesNodeCorrectly() + { + const auto node = Node::create(R"( + all: + - any: + - none: [] + )"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->mode(), ConditionGroupMode::All); + QCOMPARE(condition->conditions().size(), 1); + + const auto any = std::dynamic_pointer_cast(condition->conditions()[0]); + QVERIFY(any); + QCOMPARE(any->mode(), ConditionGroupMode::Any); + QCOMPARE(any->conditions().size(), 1); + + const auto none = std::dynamic_pointer_cast(any->conditions()[0]); + QVERIFY(none); + QCOMPARE(none->mode(), ConditionGroupMode::None); + QCOMPARE(none->conditions().size(), 0); + } + + void invalid_scalarAsChild__throwsInvalidNodeTypeConfigException() + { + const auto node = Node::create("all: a"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), InvalidNodeTypeConfigException, 0, 5, e); + QCOMPARE(e->expected(), NodeType::Sequence); + QCOMPARE(e->actual(), NodeType::Scalar); + } +}; - QVERIFY(condition); - QCOMPARE(condition->mode(), ConditionGroupMode::All); - QCOMPARE(condition->conditions().size(), 0); } -void TestConditionGroupNodeParser::any__parsesNodeCorrectly() -{ - const auto node = Node::create("any: []"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->mode(), ConditionGroupMode::Any); - QCOMPARE(condition->conditions().size(), 0); -} - -void TestConditionGroupNodeParser::none__parsesNodeCorrectly() -{ - const auto node = Node::create("none: []"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->mode(), ConditionGroupMode::None); - QCOMPARE(condition->conditions().size(), 0); -} - -void TestConditionGroupNodeParser::list__parsesNodeAsAllGroup() -{ - const auto node = Node::create("[]"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->mode(), ConditionGroupMode::All); - QCOMPARE(condition->conditions().size(), 0); -} - -void TestConditionGroupNodeParser::nested__parsesNodeCorrectly() -{ - const auto node = Node::create(R"( - all: - - any: - - none: [] - )"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->mode(), ConditionGroupMode::All); - QCOMPARE(condition->conditions().size(), 1); - - const auto any = std::dynamic_pointer_cast(condition->conditions()[0]); - QVERIFY(any); - QCOMPARE(any->mode(), ConditionGroupMode::Any); - QCOMPARE(any->conditions().size(), 1); - - const auto none = std::dynamic_pointer_cast(any->conditions()[0]); - QVERIFY(none); - QCOMPARE(none->mode(), ConditionGroupMode::None); - QCOMPARE(none->conditions().size(), 0); -} - -void TestConditionGroupNodeParser::invalid_scalarAsChild__throwsInvalidNodeTypeConfigException() -{ - const auto node = Node::create("all: a"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), InvalidNodeTypeConfigException, 0, 5, e); - QCOMPARE(e->expected(), NodeType::Sequence); - QCOMPARE(e->actual(), NodeType::Scalar); -} - -} - -QTEST_MAIN(InputActions::TestConditionGroupNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestConditionGroupNodeParser) +#include "TestConditionGroupNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/conditions/TestConditionGroupNodeParser.h b/tests/libinputactions/config/parsers/conditions/TestConditionGroupNodeParser.h deleted file mode 100644 index b7c1284..0000000 --- a/tests/libinputactions/config/parsers/conditions/TestConditionGroupNodeParser.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestConditionGroupNodeParser : public Test -{ - Q_OBJECT - -private slots: - void all__parsesNodeCorrectly(); - void any__parsesNodeCorrectly(); - void none__parsesNodeCorrectly(); - - void list__parsesNodeAsAllGroup(); - void nested__parsesNodeCorrectly(); - - void invalid_scalarAsChild__throwsInvalidNodeTypeConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/conditions/TestConditionNodeParser.cpp b/tests/libinputactions/config/parsers/conditions/TestConditionNodeParser.cpp index ecd9b17..53668a9 100644 --- a/tests/libinputactions/config/parsers/conditions/TestConditionNodeParser.cpp +++ b/tests/libinputactions/config/parsers/conditions/TestConditionNodeParser.cpp @@ -1,22 +1,29 @@ -#include "TestConditionNodeParser.h" +#include "Test.h" #include #include namespace InputActions { -void TestConditionNodeParser::invalid_map__throwsInvalidValueConfigException() +class TestConditionNodeParser : public Test { - const auto node = Node::create("a:"); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 0); -} + Q_OBJECT -void TestConditionNodeParser::invalid_scalar__throwsInvalidValueConfigException() -{ - const auto node = Node::create("a"); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 0); -} +private slots: + void invalid_map__throwsInvalidValueConfigException() + { + const auto node = Node::create("a:"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 0); + } + + void invalid_scalar__throwsInvalidValueConfigException() + { + const auto node = Node::create("a"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 0); + } +}; } -QTEST_MAIN(InputActions::TestConditionNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestConditionNodeParser) +#include "TestConditionNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/conditions/TestConditionNodeParser.h b/tests/libinputactions/config/parsers/conditions/TestConditionNodeParser.h deleted file mode 100644 index 770e5f7..0000000 --- a/tests/libinputactions/config/parsers/conditions/TestConditionNodeParser.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestConditionNodeParser : public Test -{ - Q_OBJECT - -private slots: - void invalid_map__throwsInvalidValueConfigException(); - void invalid_scalar__throwsInvalidValueConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.cpp b/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.cpp index 7f2b675..a394edf 100644 --- a/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.cpp +++ b/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestVariableConditionNodeParser.h" +#include "Test.h" #include #include #include @@ -8,268 +8,275 @@ namespace InputActions { -void TestVariableConditionNodeParser::init() +class TestVariableConditionNodeParser : public Test { - g_variableManager = std::make_shared(); - g_variableManager->registerLocalVariable("bool"); - g_variableManager->registerLocalVariable("number"); - g_variableManager->registerLocalVariable("point"); - g_variableManager->registerLocalVariable("string"); - g_variableManager->registerLocalVariable("keyboard_modifiers"); -} - -void TestVariableConditionNodeParser::boolVariableWithoutOperator__parsesNodeCorrectly() -{ - const auto node = Node::create("$bool"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "bool"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), true); -} - -void TestVariableConditionNodeParser::negatedBoolVariableWithoutOperator__parsesNodeCorrectly() -{ - const auto node = Node::create("_: !$bool")->at("_")->shared_from_this(); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), true); - QCOMPARE(condition->variableName(), "bool"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), true); -} - -void TestVariableConditionNodeParser::negated__parsesNodeCorrectly() -{ - const auto node = Node::create("!$number == 1"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), true); - QCOMPARE(condition->variableName(), "number"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), 1); -} - -void TestVariableConditionNodeParser::between__parsesNodeCorrectly() -{ - const auto node = Node::create("$number between 1;2"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "number"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Between); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 2); - QCOMPARE(std::any_cast(values[0].get().value()), 1); - QCOMPARE(std::any_cast(values[1].get().value()), 2); -} - -void TestVariableConditionNodeParser::between_point__parsesNodeCorrectly() -{ - const auto node = Node::create("$point between 0.1,0.2;0.3,0.4"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "point"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Between); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 2); - QCOMPARE(std::any_cast(values[0].get().value()), QPointF(0.1, 0.2)); - QCOMPARE(std::any_cast(values[1].get().value()), QPointF(0.3, 0.4)); -} - -void TestVariableConditionNodeParser::between_invalid_oneValue__throwsInvalidValueConfigException() -{ - const auto node = Node::create("$number between 1"); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 16); -} - -void TestVariableConditionNodeParser::between_invalid_threeValues__throwsInvalidValueConfigException() -{ - const auto node = Node::create("$number between 1;2;3"); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 16); -} - -void TestVariableConditionNodeParser::contains_string__parsesNodeCorrectly() -{ - const auto node = Node::create("$string contains a"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "string"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Contains); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), "a"); -} - -void TestVariableConditionNodeParser::contains_flags_sequence__parsesNodeCorrectly() -{ - const auto node = Node::create("$keyboard_modifiers contains [ ctrl, meta ]"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "keyboard_modifiers"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Contains); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::ControlModifier | Qt::KeyboardModifier::MetaModifier); -} - -void TestVariableConditionNodeParser::contains_flags_scalar__parsesNodeCorrectly() -{ - const auto node = Node::create("$keyboard_modifiers contains meta"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "keyboard_modifiers"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Contains); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::MetaModifier); -} - -void TestVariableConditionNodeParser::oneOf_sequence__parsesNodeCorrectly() -{ - const auto node = Node::create("$string one_of [ a, b ]"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "string"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::OneOf); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 2); - QCOMPARE(std::any_cast(values[0].get().value()), "a"); - QCOMPARE(std::any_cast(values[1].get().value()), "b"); -} - -void TestVariableConditionNodeParser::oneOf_scalar__parsesNodeCorrectly() -{ - const auto node = Node::create("$string one_of a"); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "string"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::OneOf); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), "a"); -} - -void TestVariableConditionNodeParser::matches__parsesNodeCorrectly() -{ - const auto node = Node::create("$string matches \"[a]\""); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "string"); - QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Regex); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), "[a]"); -} - -void TestVariableConditionNodeParser::matches_invalidRegex__throwsInvalidValueConfigException() -{ - const auto node = Node::create("$string matches ("); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 16); -} - -void TestVariableConditionNodeParser::simpleOperators__parsesNodeCorrectly_data() -{ - QTest::addColumn("comparisonOperator"); - QTest::addColumn("raw"); - - QTest::addRow("==") << ComparisonOperator::EqualTo << "=="; - QTest::addRow("!=") << ComparisonOperator::NotEqualTo << "!="; - QTest::addRow(">") << ComparisonOperator::GreaterThan << ">"; - QTest::addRow(">=") << ComparisonOperator::GreaterThanOrEqual << ">="; - QTest::addRow("<") << ComparisonOperator::LessThan << "<"; - QTest::addRow("<=") << ComparisonOperator::LessThanOrEqual << "<="; -} - -void TestVariableConditionNodeParser::simpleOperators__parsesNodeCorrectly() -{ - QFETCH(ComparisonOperator, comparisonOperator); - QFETCH(QString, raw); - - const auto node = Node::create(QString("$number %1 1").arg(raw)); - const auto condition = std::dynamic_pointer_cast(node->as>()); - - QVERIFY(condition); - QCOMPARE(condition->negate(), false); - QCOMPARE(condition->variableName(), "number"); - QCOMPARE(condition->comparisonOperator(), comparisonOperator); - - const auto &values = condition->values(); - QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), 1); -} - -void TestVariableConditionNodeParser::inGroups__variableManagerPropagated_doesNotThrow() -{ - const auto node = Node::create(R"( - all: - - any: - - none: - - $b - )"); - - VariableManager variableManager; - variableManager.registerLocalVariable("b"); - - QVERIFY_THROWS_NO_EXCEPTION(parseCondition(node.get(), &variableManager)); -} - -void TestVariableConditionNodeParser::invalid_invalidVariable__throwsInvalidValueConfigException() -{ - const auto node = Node::create("$_"); - - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), InvalidVariableConfigException, 0, 0, e); - QCOMPARE(e->variableName(), "_"); -} - -void TestVariableConditionNodeParser::invalid_noOperator__throwsInvalidValueConfigException() -{ - const auto node = Node::create("$number"); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 1); -} - -void TestVariableConditionNodeParser::invalid_noValue__throwsInvalidValueConfigException() -{ - const auto node = Node::create("$number =="); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 0); -} + Q_OBJECT + +private slots: + void init() + { + g_variableManager = std::make_shared(); + g_variableManager->registerLocalVariable("bool"); + g_variableManager->registerLocalVariable("number"); + g_variableManager->registerLocalVariable("point"); + g_variableManager->registerLocalVariable("string"); + g_variableManager->registerLocalVariable("keyboard_modifiers"); + } + + void boolVariableWithoutOperator__parsesNodeCorrectly() + { + const auto node = Node::create("$bool"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "bool"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), true); + } + + void negatedBoolVariableWithoutOperator__parsesNodeCorrectly() + { + const auto node = Node::create("_: !$bool")->at("_")->shared_from_this(); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), true); + QCOMPARE(condition->variableName(), "bool"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), true); + } + + void negated__parsesNodeCorrectly() + { + const auto node = Node::create("!$number == 1"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), true); + QCOMPARE(condition->variableName(), "number"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::EqualTo); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), 1); + } + + void between__parsesNodeCorrectly() + { + const auto node = Node::create("$number between 1;2"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "number"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Between); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 2); + QCOMPARE(std::any_cast(values[0].get().value()), 1); + QCOMPARE(std::any_cast(values[1].get().value()), 2); + } + + void between_point__parsesNodeCorrectly() + { + const auto node = Node::create("$point between 0.1,0.2;0.3,0.4"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "point"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Between); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 2); + QCOMPARE(std::any_cast(values[0].get().value()), QPointF(0.1, 0.2)); + QCOMPARE(std::any_cast(values[1].get().value()), QPointF(0.3, 0.4)); + } + + void between_invalid_oneValue__throwsInvalidValueConfigException() + { + const auto node = Node::create("$number between 1"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 16); + } + + void between_invalid_threeValues__throwsInvalidValueConfigException() + { + const auto node = Node::create("$number between 1;2;3"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 16); + } + + void contains_string__parsesNodeCorrectly() + { + const auto node = Node::create("$string contains a"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "string"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Contains); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), "a"); + } + + void contains_flags_sequence__parsesNodeCorrectly() + { + const auto node = Node::create("$keyboard_modifiers contains [ ctrl, meta ]"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "keyboard_modifiers"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Contains); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::ControlModifier | Qt::KeyboardModifier::MetaModifier); + } + + void contains_flags_scalar__parsesNodeCorrectly() + { + const auto node = Node::create("$keyboard_modifiers contains meta"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "keyboard_modifiers"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Contains); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::MetaModifier); + } + + void oneOf_sequence__parsesNodeCorrectly() + { + const auto node = Node::create("$string one_of [ a, b ]"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "string"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::OneOf); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 2); + QCOMPARE(std::any_cast(values[0].get().value()), "a"); + QCOMPARE(std::any_cast(values[1].get().value()), "b"); + } + + void oneOf_scalar__parsesNodeCorrectly() + { + const auto node = Node::create("$string one_of a"); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "string"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::OneOf); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), "a"); + } + + void matches__parsesNodeCorrectly() + { + const auto node = Node::create("$string matches \"[a]\""); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "string"); + QCOMPARE(condition->comparisonOperator(), ComparisonOperator::Regex); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), "[a]"); + } + + void matches_invalidRegex__throwsInvalidValueConfigException() + { + const auto node = Node::create("$string matches ("); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 16); + } + + void simpleOperators__parsesNodeCorrectly_data() + { + QTest::addColumn("comparisonOperator"); + QTest::addColumn("raw"); + + QTest::addRow("==") << ComparisonOperator::EqualTo << "=="; + QTest::addRow("!=") << ComparisonOperator::NotEqualTo << "!="; + QTest::addRow(">") << ComparisonOperator::GreaterThan << ">"; + QTest::addRow(">=") << ComparisonOperator::GreaterThanOrEqual << ">="; + QTest::addRow("<") << ComparisonOperator::LessThan << "<"; + QTest::addRow("<=") << ComparisonOperator::LessThanOrEqual << "<="; + } + + void simpleOperators__parsesNodeCorrectly() + { + QFETCH(ComparisonOperator, comparisonOperator); + QFETCH(QString, raw); + + const auto node = Node::create(QString("$number %1 1").arg(raw)); + const auto condition = std::dynamic_pointer_cast(node->as>()); + + QVERIFY(condition); + QCOMPARE(condition->negate(), false); + QCOMPARE(condition->variableName(), "number"); + QCOMPARE(condition->comparisonOperator(), comparisonOperator); + + const auto &values = condition->values(); + QCOMPARE(values.size(), 1); + QCOMPARE(std::any_cast(values[0].get().value()), 1); + } + + void inGroups__variableManagerPropagated_doesNotThrow() + { + const auto node = Node::create(R"( + all: + - any: + - none: + - $b + )"); + + VariableManager variableManager; + variableManager.registerLocalVariable("b"); + + QVERIFY_THROWS_NO_EXCEPTION(parseCondition(node.get(), &variableManager)); + } + + void invalid_invalidVariable__throwsInvalidValueConfigException() + { + const auto node = Node::create("$_"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), InvalidVariableConfigException, 0, 0, e); + QCOMPARE(e->variableName(), "_"); + } + + void invalid_noOperator__throwsInvalidValueConfigException() + { + const auto node = Node::create("$number"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 1); + } + + void invalid_noValue__throwsInvalidValueConfigException() + { + const auto node = Node::create("$number =="); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as>(), InvalidValueConfigException, 0, 0); + } +}; } -QTEST_MAIN(InputActions::TestVariableConditionNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestVariableConditionNodeParser) +#include "TestVariableConditionNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.h b/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.h deleted file mode 100644 index 06cb449..0000000 --- a/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestVariableConditionNodeParser : public Test -{ - Q_OBJECT - -private slots: - void init(); - - void boolVariableWithoutOperator__parsesNodeCorrectly(); - void negatedBoolVariableWithoutOperator__parsesNodeCorrectly(); - - void negated__parsesNodeCorrectly(); - - void between__parsesNodeCorrectly(); - void between_point__parsesNodeCorrectly(); - void between_invalid_oneValue__throwsInvalidValueConfigException(); - void between_invalid_threeValues__throwsInvalidValueConfigException(); - - void contains_string__parsesNodeCorrectly(); - void contains_flags_sequence__parsesNodeCorrectly(); - void contains_flags_scalar__parsesNodeCorrectly(); - - void oneOf_sequence__parsesNodeCorrectly(); - void oneOf_scalar__parsesNodeCorrectly(); - - void matches__parsesNodeCorrectly(); - void matches_invalidRegex__throwsInvalidValueConfigException(); - - void simpleOperators__parsesNodeCorrectly_data(); - void simpleOperators__parsesNodeCorrectly(); - - void inGroups__variableManagerPropagated_doesNotThrow(); - - void invalid_invalidVariable__throwsInvalidValueConfigException(); - void invalid_noOperator__throwsInvalidValueConfigException(); - void invalid_noValue__throwsInvalidValueConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/containers/TestSetNodeParser.cpp b/tests/libinputactions/config/parsers/containers/TestSetNodeParser.cpp index 223f6dc..1197dfe 100644 --- a/tests/libinputactions/config/parsers/containers/TestSetNodeParser.cpp +++ b/tests/libinputactions/config/parsers/containers/TestSetNodeParser.cpp @@ -1,35 +1,42 @@ -#include "TestSetNodeParser.h" +#include "Test.h" #include #include namespace InputActions { -void TestSetNodeParser::valid__parsesNodeCorrectly() +class TestSetNodeParser : public Test { - const auto node = Node::create("[ 1, 2, 3 ]"); - const auto set = node->as>(); + Q_OBJECT - QCOMPARE(set, (std::set{1, 2, 3})); -} +private slots: + void valid__parsesNodeCorrectly() + { + const auto node = Node::create("[ 1, 2, 3 ]"); + const auto set = node->as>(); -void TestSetNodeParser::invalid_duplicateItem__throwsDuplicateSetItemConfigException() -{ - const auto node = Node::create("[ 1, 1 ]"); + QCOMPARE(set, (std::set{1, 2, 3})); + } - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), DuplicateSetItemConfigException, 0, 5, e); - QCOMPARE(e->index(), 1); -} + void invalid_duplicateItem__throwsDuplicateSetItemConfigException() + { + const auto node = Node::create("[ 1, 1 ]"); -void TestSetNodeParser::invalid_scalar__throwsInvalidNodeTypeConfigException() -{ - const auto node = Node::create("1"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), DuplicateSetItemConfigException, 0, 5, e); + QCOMPARE(e->index(), 1); + } - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), InvalidNodeTypeConfigException, 0, 0, e); - QCOMPARE(e->expected(), NodeType::Sequence); - QCOMPARE(e->actual(), NodeType::Scalar); -} + void invalid_scalar__throwsInvalidNodeTypeConfigException() + { + const auto node = Node::create("1"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), InvalidNodeTypeConfigException, 0, 0, e); + QCOMPARE(e->expected(), NodeType::Sequence); + QCOMPARE(e->actual(), NodeType::Scalar); + } +}; } -QTEST_MAIN(InputActions::TestSetNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestSetNodeParser) +#include "TestSetNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/containers/TestSetNodeParser.h b/tests/libinputactions/config/parsers/containers/TestSetNodeParser.h deleted file mode 100644 index a08f39a..0000000 --- a/tests/libinputactions/config/parsers/containers/TestSetNodeParser.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestSetNodeParser : public Test -{ - Q_OBJECT - -private slots: - void valid__parsesNodeCorrectly(); - - void invalid_duplicateItem__throwsDuplicateSetItemConfigException(); - void invalid_scalar__throwsInvalidNodeTypeConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/containers/TestVectorNodeParser.cpp b/tests/libinputactions/config/parsers/containers/TestVectorNodeParser.cpp index 4d9aa8f..426e424 100644 --- a/tests/libinputactions/config/parsers/containers/TestVectorNodeParser.cpp +++ b/tests/libinputactions/config/parsers/containers/TestVectorNodeParser.cpp @@ -1,35 +1,42 @@ -#include "TestVectorNodeParser.h" +#include "Test.h" #include #include namespace InputActions { -void TestVectorNodeParser::valid__parsesNodeCorrectly() +class TestVectorNodeParser : public Test { - const auto node = Node::create("[ 1, 2, 3 ]"); - const auto vector = node->as>(); + Q_OBJECT - QCOMPARE(vector, (std::vector{1, 2, 3})); -} +private slots: + void valid__parsesNodeCorrectly() + { + const auto node = Node::create("[ 1, 2, 3 ]"); + const auto vector = node->as>(); -void TestVectorNodeParser::duplicateItem__parsesNodeCorrectly() -{ - const auto node = Node::create("[ 1, 1 ]"); - const auto vector = node->as>(); + QCOMPARE(vector, (std::vector{1, 2, 3})); + } - QCOMPARE(vector, (std::vector{1, 1})); -} + void duplicateItem__parsesNodeCorrectly() + { + const auto node = Node::create("[ 1, 1 ]"); + const auto vector = node->as>(); -void TestVectorNodeParser::invalid_scalar__throwsInvalidNodeTypeConfigException() -{ - const auto node = Node::create("1"); + QCOMPARE(vector, (std::vector{1, 1})); + } - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), InvalidNodeTypeConfigException, 0, 0, e); - QCOMPARE(e->expected(), NodeType::Sequence); - QCOMPARE(e->actual(), NodeType::Scalar); -} + void invalid_scalar__throwsInvalidNodeTypeConfigException() + { + const auto node = Node::create("1"); + + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION_SAVE(node->as>(), InvalidNodeTypeConfigException, 0, 0, e); + QCOMPARE(e->expected(), NodeType::Sequence); + QCOMPARE(e->actual(), NodeType::Scalar); + } +}; } -QTEST_MAIN(InputActions::TestVectorNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestVectorNodeParser) +#include "TestVectorNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/containers/TestVectorNodeParser.h b/tests/libinputactions/config/parsers/containers/TestVectorNodeParser.h deleted file mode 100644 index 3ff605b..0000000 --- a/tests/libinputactions/config/parsers/containers/TestVectorNodeParser.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestVectorNodeParser : public Test -{ - Q_OBJECT - -private slots: - void valid__parsesNodeCorrectly(); - void duplicateItem__parsesNodeCorrectly(); - - void invalid_scalar__throwsInvalidNodeTypeConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/qt/TestQPointFNodeParser.cpp b/tests/libinputactions/config/parsers/qt/TestQPointFNodeParser.cpp index caf8638..5973b59 100644 --- a/tests/libinputactions/config/parsers/qt/TestQPointFNodeParser.cpp +++ b/tests/libinputactions/config/parsers/qt/TestQPointFNodeParser.cpp @@ -1,23 +1,30 @@ -#include "TestQPointFNodeParser.h" +#include "Test.h" #include namespace InputActions { -void TestQPointFNodeParser::valid__parsesNodeCorrectly() +class TestQPointFNodeParser : public Test { - const auto node = Node::create("12.34,43.21"); - const auto point = node->as(); + Q_OBJECT - QCOMPARE(point, QPointF(12.34, 43.21)); -} +private slots: + void valid__parsesNodeCorrectly() + { + const auto node = Node::create("12.34,43.21"); + const auto point = node->as(); -void TestQPointFNodeParser::invalid__throwsInvalidValueConfigException() -{ - const auto node = Node::create("12.34"); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} + QCOMPARE(point, QPointF(12.34, 43.21)); + } + + void invalid__throwsInvalidValueConfigException() + { + const auto node = Node::create("12.34"); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } +}; } -QTEST_MAIN(InputActions::TestQPointFNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestQPointFNodeParser) +#include "TestQPointFNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/qt/TestQPointFNodeParser.h b/tests/libinputactions/config/parsers/qt/TestQPointFNodeParser.h deleted file mode 100644 index 493cc36..0000000 --- a/tests/libinputactions/config/parsers/qt/TestQPointFNodeParser.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestQPointFNodeParser : public Test -{ - Q_OBJECT - -private slots: - void valid__parsesNodeCorrectly(); - void invalid__throwsInvalidValueConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/qt/TestQRegularExpressionNodeParser.cpp b/tests/libinputactions/config/parsers/qt/TestQRegularExpressionNodeParser.cpp index a8be1b4..09beb73 100644 --- a/tests/libinputactions/config/parsers/qt/TestQRegularExpressionNodeParser.cpp +++ b/tests/libinputactions/config/parsers/qt/TestQRegularExpressionNodeParser.cpp @@ -1,4 +1,4 @@ -#include "TestQRegularExpressionNodeParser.h" +#include "Test.h" #include #include #include @@ -6,21 +6,28 @@ namespace InputActions { -void TestQRegularExpressionNodeParser::valid__parsesNodeCorrectly() +class TestQRegularExpressionNodeParser : public Test { - const auto node = Node::create("\"[a]\""); - const auto regex = node->as(); + Q_OBJECT - QVERIFY(regex.isValid()); - QCOMPARE(regex.pattern(), "[a]"); -} +private slots: + void valid__parsesNodeCorrectly() + { + const auto node = Node::create("\"[a]\""); + const auto regex = node->as(); -void TestQRegularExpressionNodeParser::invalid__throwsInvalidValueConfigException() -{ - const auto node = Node::create("\"[a\""); - INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); -} + QVERIFY(regex.isValid()); + QCOMPARE(regex.pattern(), "[a]"); + } + + void invalid__throwsInvalidValueConfigException() + { + const auto node = Node::create("\"[a\""); + INPUTACTIONS_VERIFY_THROWS_CONFIG_EXCEPTION(node->as(), InvalidValueConfigException, 0, 0); + } +}; } -QTEST_MAIN(InputActions::TestQRegularExpressionNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestQRegularExpressionNodeParser) +#include "TestQRegularExpressionNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/qt/TestQRegularExpressionNodeParser.h b/tests/libinputactions/config/parsers/qt/TestQRegularExpressionNodeParser.h deleted file mode 100644 index 61674b4..0000000 --- a/tests/libinputactions/config/parsers/qt/TestQRegularExpressionNodeParser.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestQRegularExpressionNodeParser : public Test -{ - Q_OBJECT - -private slots: - void valid__parsesNodeCorrectly(); - void invalid__throwsInvalidValueConfigException(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/qt/TestQStringListNodeParser.cpp b/tests/libinputactions/config/parsers/qt/TestQStringListNodeParser.cpp index dcb36a9..ddff9a6 100644 --- a/tests/libinputactions/config/parsers/qt/TestQStringListNodeParser.cpp +++ b/tests/libinputactions/config/parsers/qt/TestQStringListNodeParser.cpp @@ -1,19 +1,26 @@ -#include "TestQStringListNodeParser.h" +#include "Test.h" #include namespace InputActions { -void TestQStringListNodeParser::valid__parsesNodeCorrectly() +class TestQStringListNodeParser : public Test { - const auto node = Node::create("[ aaa, 123 ]"); - const auto list = node->as(); + Q_OBJECT - QCOMPARE(list.size(), 2); - QCOMPARE(list.at(0), "aaa"); - QCOMPARE(list.at(1), "123"); -} +private slots: + void valid__parsesNodeCorrectly() + { + const auto node = Node::create("[ aaa, 123 ]"); + const auto list = node->as(); + + QCOMPARE(list.size(), 2); + QCOMPARE(list.at(0), "aaa"); + QCOMPARE(list.at(1), "123"); + } +}; } -QTEST_MAIN(InputActions::TestQStringListNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestQStringListNodeParser) +#include "TestQStringListNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/qt/TestQStringListNodeParser.h b/tests/libinputactions/config/parsers/qt/TestQStringListNodeParser.h deleted file mode 100644 index ae67444..0000000 --- a/tests/libinputactions/config/parsers/qt/TestQStringListNodeParser.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestQStringListNodeParser : public Test -{ - Q_OBJECT - -private slots: - void valid__parsesNodeCorrectly(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/qt/TestQStringNodeParser.cpp b/tests/libinputactions/config/parsers/qt/TestQStringNodeParser.cpp index c89d67f..580f3b7 100644 --- a/tests/libinputactions/config/parsers/qt/TestQStringNodeParser.cpp +++ b/tests/libinputactions/config/parsers/qt/TestQStringNodeParser.cpp @@ -1,15 +1,22 @@ -#include "TestQStringNodeParser.h" +#include "Test.h" #include namespace InputActions { -void TestQStringNodeParser::valid__parsesNodeCorrectly() +class TestQStringNodeParser : public Test { - const auto node = Node::create("aaa123"); - QCOMPARE(node->as(), "aaa123"); -} + Q_OBJECT + +private slots: + void valid__parsesNodeCorrectly() + { + const auto node = Node::create("aaa123"); + QCOMPARE(node->as(), "aaa123"); + } +}; } -QTEST_MAIN(InputActions::TestQStringNodeParser) \ No newline at end of file +QTEST_MAIN(InputActions::TestQStringNodeParser) +#include "TestQStringNodeParser.moc" \ No newline at end of file diff --git a/tests/libinputactions/config/parsers/qt/TestQStringNodeParser.h b/tests/libinputactions/config/parsers/qt/TestQStringNodeParser.h deleted file mode 100644 index 740ddc3..0000000 --- a/tests/libinputactions/config/parsers/qt/TestQStringNodeParser.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestQStringNodeParser : public Test -{ - Q_OBJECT - -private slots: - void valid__parsesNodeCorrectly(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/handlers/TestInputTriggerHandler.cpp b/tests/libinputactions/handlers/TestInputTriggerHandler.cpp index 2226468..b36d093 100644 --- a/tests/libinputactions/handlers/TestInputTriggerHandler.cpp +++ b/tests/libinputactions/handlers/TestInputTriggerHandler.cpp @@ -1,6 +1,8 @@ -#include "TestInputTriggerHandler.h" +#include "Test.h" #include +#include #include +#include #include #include #include @@ -8,48 +10,59 @@ namespace InputActions { -void TestInputTriggerHandler::init() +class TestInputTriggerHandler : public Test { - m_handler = std::unique_ptr(new InputTriggerHandler); + Q_OBJECT - g_inputBackend = std::make_unique(); - g_inputBackend->initialize(); +private slots: + void init() + { + m_handler = std::unique_ptr(new InputTriggerHandler); - m_keyboard = std::make_unique(InputDeviceType::Keyboard); - g_inputBackend->addDevice(m_keyboard.get()); -} + g_inputBackend = std::make_unique(); + g_inputBackend->initialize(); -void TestInputTriggerHandler::keyboardKey__modifierReleased_pressedBeforeTriggerActivation__triggersEnded() -{ - QSignalSpy spy(m_handler.get(), &TriggerHandler::endingTriggers); - m_handler->addTrigger(std::make_unique(TriggerType::Press)); + m_keyboard = std::make_unique(InputDeviceType::Keyboard); + g_inputBackend->addDevice(m_keyboard.get()); + } - g_inputBackend->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, true)); - m_handler->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, true)); + void keyboardKey__modifierReleased_pressedBeforeTriggerActivation__triggersEnded() + { + QSignalSpy spy(m_handler.get(), &TriggerHandler::endingTriggers); + m_handler->addTrigger(std::make_unique(TriggerType::Press)); - m_handler->activateTriggers(TriggerType::Press); - QCOMPARE(spy.count(), 0); + g_inputBackend->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, true)); + m_handler->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, true)); - g_inputBackend->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, false)); - m_handler->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, false)); - QCOMPARE(spy.count(), 1); -} + m_handler->activateTriggers(TriggerType::Press); + QCOMPARE(spy.count(), 0); -void TestInputTriggerHandler::keyboardKey__modifierReleased_pressedAfterTriggerActivation__triggersNotEnded() -{ - QSignalSpy spy(m_handler.get(), &TriggerHandler::endingTriggers); - m_handler->addTrigger(std::make_unique(TriggerType::Press)); + g_inputBackend->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, false)); + m_handler->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, false)); + QCOMPARE(spy.count(), 1); + } - m_handler->activateTriggers(TriggerType::Press); + void keyboardKey__modifierReleased_pressedAfterTriggerActivation__triggersNotEnded() + { + QSignalSpy spy(m_handler.get(), &TriggerHandler::endingTriggers); + m_handler->addTrigger(std::make_unique(TriggerType::Press)); - g_inputBackend->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, true)); - m_handler->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, true)); + m_handler->activateTriggers(TriggerType::Press); - g_inputBackend->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, false)); - m_handler->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, false)); - QCOMPARE(spy.count(), 0); -} + g_inputBackend->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, true)); + m_handler->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, true)); + + g_inputBackend->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, false)); + m_handler->handleEvent(KeyboardKeyEvent(m_keyboard.get(), KEY_LEFTCTRL, false)); + QCOMPARE(spy.count(), 0); + } + +private: + std::unique_ptr m_keyboard; + std::unique_ptr m_handler; +}; } -QTEST_MAIN(InputActions::TestInputTriggerHandler) \ No newline at end of file +QTEST_MAIN(InputActions::TestInputTriggerHandler) +#include "TestInputTriggerHandler.moc" \ No newline at end of file diff --git a/tests/libinputactions/handlers/TestInputTriggerHandler.h b/tests/libinputactions/handlers/TestInputTriggerHandler.h deleted file mode 100644 index edd44ba..0000000 --- a/tests/libinputactions/handlers/TestInputTriggerHandler.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "Test.h" -#include -#include - -namespace InputActions -{ - -class TestInputTriggerHandler : public Test -{ - Q_OBJECT - -private slots: - void init(); - - void keyboardKey__modifierReleased_pressedBeforeTriggerActivation__triggersEnded(); - void keyboardKey__modifierReleased_pressedAfterTriggerActivation__triggersNotEnded(); - -private: - std::unique_ptr m_keyboard; - std::unique_ptr m_handler; -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/handlers/TestKeyboardTriggerHandler.cpp b/tests/libinputactions/handlers/TestKeyboardTriggerHandler.cpp index 0b484b0..84d84f6 100644 --- a/tests/libinputactions/handlers/TestKeyboardTriggerHandler.cpp +++ b/tests/libinputactions/handlers/TestKeyboardTriggerHandler.cpp @@ -1,4 +1,4 @@ -#include "TestKeyboardTriggerHandler.h" +#include "Test.h" #include #include #include @@ -9,33 +9,40 @@ namespace InputActions { -void TestKeyboardTriggerHandler::handleEvent_keyboardKey() +class TestKeyboardTriggerHandler : public Test { - auto handler = std::make_unique(); - QSignalSpy activatingSpy(handler.get(), &TriggerHandler::activatingTrigger); - QSignalSpy endingSpy(handler.get(), &TriggerHandler::endingTriggers); - handler->addTrigger(std::make_unique(KeyboardShortcut{.keys = {KEY_LEFTCTRL, KEY_A}})); + Q_OBJECT - InputDevice device(InputDeviceType::Keyboard); - QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_A, true)), false); - QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_LEFTCTRL, true)), false); - QCOMPARE(activatingSpy.count(), 0); +private slots: + void handleEvent_keyboardKey() + { + auto handler = std::make_unique(); + QSignalSpy activatingSpy(handler.get(), &TriggerHandler::activatingTrigger); + QSignalSpy endingSpy(handler.get(), &TriggerHandler::endingTriggers); + handler->addTrigger(std::make_unique(KeyboardShortcut{.keys = {KEY_LEFTCTRL, KEY_A}})); - QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_LEFTCTRL, false)), false); - QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_A, false)), false); + InputDevice device(InputDeviceType::Keyboard); + QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_A, true)), false); + QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_LEFTCTRL, true)), false); + QCOMPARE(activatingSpy.count(), 0); - QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_LEFTCTRL, true)), false); - QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_A, true)), true); - QCOMPARE(activatingSpy.count(), 1); + QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_LEFTCTRL, false)), false); + QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_A, false)), false); - QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_A, false)), true); - QCOMPARE(endingSpy.count(), 1); - QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_LEFTCTRL, false)), false); + QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_LEFTCTRL, true)), false); + QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_A, true)), true); + QCOMPARE(activatingSpy.count(), 1); - QCOMPARE(activatingSpy.count(), 1); - QCOMPARE(endingSpy.count(), 1); -} + QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_A, false)), true); + QCOMPARE(endingSpy.count(), 1); + QCOMPARE(handler->handleEvent(KeyboardKeyEvent(&device, KEY_LEFTCTRL, false)), false); + + QCOMPARE(activatingSpy.count(), 1); + QCOMPARE(endingSpy.count(), 1); + } +}; } -QTEST_MAIN(InputActions::TestKeyboardTriggerHandler) \ No newline at end of file +QTEST_MAIN(InputActions::TestKeyboardTriggerHandler) +#include "TestKeyboardTriggerHandler.moc" \ No newline at end of file diff --git a/tests/libinputactions/handlers/TestKeyboardTriggerHandler.h b/tests/libinputactions/handlers/TestKeyboardTriggerHandler.h deleted file mode 100644 index 2039c67..0000000 --- a/tests/libinputactions/handlers/TestKeyboardTriggerHandler.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestKeyboardTriggerHandler : public Test -{ - Q_OBJECT - -private slots: - void handleEvent_keyboardKey(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/handlers/TestMotionTriggerHandler.cpp b/tests/libinputactions/handlers/TestMotionTriggerHandler.cpp index 976e264..5f43aaa 100644 --- a/tests/libinputactions/handlers/TestMotionTriggerHandler.cpp +++ b/tests/libinputactions/handlers/TestMotionTriggerHandler.cpp @@ -1,7 +1,8 @@ -#include "TestMotionTriggerHandler.h" +#include "Test.h" #include "mocks/MockMotionTriggerHandler.h" #include #include +#include #include using namespace ::testing; @@ -9,144 +10,154 @@ using namespace ::testing; namespace InputActions { -void TestMotionTriggerHandler::init() +class TestMotionTriggerHandler : public Test { - m_handler = std::make_unique(); - m_mouse = std::make_unique(InputDeviceType::Mouse); - m_mouse->properties().setMotionThreshold(10); -} - -void TestMotionTriggerHandler::handleMotion_swipe__calculatesAnglesCorrectly_data() -{ - QTest::addColumn("delta"); - QTest::addColumn("expectedAngles"); - - QTest::addRow("[10, 0] => 0") << QPointF(10, 0) << 0.0; - QTest::addRow("[10, -10] => 45") << QPointF(10, -10) << 45.0; - QTest::addRow("[0, -10] => 90") << QPointF(0, -10) << 90.0; - QTest::addRow("[-10, -10] => 90") << QPointF(-10, -10) << 135.0; - QTest::addRow("[-10, 0] => 180") << QPointF(-10, 0) << 180.0; - QTest::addRow("[-10, 10] => 225") << QPointF(-10, 10) << 225.0; - QTest::addRow("[0, 10] => 270") << QPointF(0, 10) << 270.0; - QTest::addRow("[10, 10] => 315") << QPointF(10, 10) << 315.0; -} - -void TestMotionTriggerHandler::handleMotion_swipe__calculatesAnglesCorrectly() -{ - QFETCH(QPointF, delta); - QFETCH(qreal, expectedAngles); - - EXPECT_CALL(*m_handler, - updateTriggers(Contains(Pair(TriggerType::Swipe, - WhenDynamicCastTo(Pointee(AllOf(Property(&SwipeTriggerUpdateEvent::angle, - expectedAngles), - Property(&SwipeTriggerUpdateEvent::averageAngle, - expectedAngles)))))))) - .Times(1); - - ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::SinglePointMotion))).WillByDefault(Return(true)); - ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::Swipe))).WillByDefault(Return(true)); - - m_handler->handleMotion(m_mouse.get(), PointDelta(delta)); - - QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); -} - -void TestMotionTriggerHandler::handleMotion_swipe__calculatesAverageAngleCorrectly() -{ - ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::SinglePointMotion))).WillByDefault(Return(true)); - ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::Swipe))).WillByDefault(Return(true)); - - EXPECT_CALL(*m_handler, - updateTriggers(Contains(Pair(TriggerType::Swipe, - WhenDynamicCastTo(Pointee(Property(&SwipeTriggerUpdateEvent::averageAngle, - 0))))))) - .Times(1); - m_handler->handleMotion(m_mouse.get(), PointDelta({10, 0})); - QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); - - EXPECT_CALL(*m_handler, - updateTriggers(Contains(Pair(TriggerType::Swipe, - WhenDynamicCastTo(Pointee(Property(&SwipeTriggerUpdateEvent::averageAngle, - 0))))))) - .Times(1); - m_handler->handleMotion(m_mouse.get(), PointDelta({8, 0})); - QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); - - EXPECT_CALL(*m_handler, - updateTriggers(Contains(Pair(TriggerType::Swipe, - WhenDynamicCastTo(Pointee(Property(&SwipeTriggerUpdateEvent::averageAngle, - Math::atan2deg360({4, 4})))))))) - .Times(1); - m_handler->handleMotion(m_mouse.get(), PointDelta({0, -8})); - QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); - - EXPECT_CALL(*m_handler, - updateTriggers(Contains(Pair(TriggerType::Swipe, - WhenDynamicCastTo(Pointee(Property(&SwipeTriggerUpdateEvent::averageAngle, - Math::atan2deg360({0, 8})))))))) - .Times(1); - m_handler->handleMotion(m_mouse.get(), PointDelta({0, -8})); - QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); -} - -void TestMotionTriggerHandler::handleMotion_swipe__motionBeforeThresholdIsTakenIntoAccountWhenCalculatingAverageAngle() -{ - ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::SinglePointMotion))).WillByDefault(Return(true)); - ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::Swipe))).WillByDefault(Return(true)); - - m_handler->handleMotion(m_mouse.get(), PointDelta({3, 0})); - m_handler->handleMotion(m_mouse.get(), PointDelta({3, 0})); - - EXPECT_CALL(*m_handler, - updateTriggers(Contains(Pair(TriggerType::Swipe, - WhenDynamicCastTo(Pointee(Property(&SwipeTriggerUpdateEvent::averageAngle, - Math::atan2deg360({2, 3})))))))) - .Times(1); - - m_handler->handleMotion(m_mouse.get(), PointDelta({0, -9})); - - QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); -} - -void TestMotionTriggerHandler::handleMotion_swipe_updatedOnceThenCancelled__activatesSwipeTriggers() -{ - ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::SinglePointMotion))).WillByDefault(Return(true)); - ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::Swipe))).WillByDefault(Return(true)); - - EXPECT_CALL(*m_handler, updateTriggers(_)) - .Times(3) - .WillOnce(Return(TriggerManagementOperationResult{ - .success = true, - })) - .WillRepeatedly(Return(TriggerManagementOperationResult{ - .success = false, - })); - - m_handler->handleMotion(m_mouse.get(), PointDelta({10, 0})); - - EXPECT_CALL(*m_handler, activateTriggers(static_cast(TriggerType::Swipe), _)).Times(1); - m_handler->handleMotion(m_mouse.get(), PointDelta({10, 0})); - QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); -} - -void TestMotionTriggerHandler::handleMotion_swipe_cancelledWithoutUpdate__doesNotActivateSwipeTriggers() -{ - ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::SinglePointMotion))).WillByDefault(Return(true)); - ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::Swipe))).WillByDefault(Return(true)); - - EXPECT_CALL(*m_handler, updateTriggers(_)) - .Times(1) - .WillRepeatedly(Return(TriggerManagementOperationResult{ - .success = false, - })); - EXPECT_CALL(*m_handler, activateTriggers(_, _)).Times(0); - - m_handler->handleMotion(m_mouse.get(), PointDelta({10, 0})); - - QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); -} + Q_OBJECT + +private slots: + void init() + { + m_handler = std::make_unique(); + m_mouse = std::make_unique(InputDeviceType::Mouse); + m_mouse->properties().setMotionThreshold(10); + } + + void handleMotion_swipe__calculatesAnglesCorrectly_data() + { + QTest::addColumn("delta"); + QTest::addColumn("expectedAngles"); + + QTest::addRow("[10, 0] => 0") << QPointF(10, 0) << 0.0; + QTest::addRow("[10, -10] => 45") << QPointF(10, -10) << 45.0; + QTest::addRow("[0, -10] => 90") << QPointF(0, -10) << 90.0; + QTest::addRow("[-10, -10] => 90") << QPointF(-10, -10) << 135.0; + QTest::addRow("[-10, 0] => 180") << QPointF(-10, 0) << 180.0; + QTest::addRow("[-10, 10] => 225") << QPointF(-10, 10) << 225.0; + QTest::addRow("[0, 10] => 270") << QPointF(0, 10) << 270.0; + QTest::addRow("[10, 10] => 315") << QPointF(10, 10) << 315.0; + } + + void handleMotion_swipe__calculatesAnglesCorrectly() + { + QFETCH(QPointF, delta); + QFETCH(qreal, expectedAngles); + + EXPECT_CALL(*m_handler, + updateTriggers(Contains(Pair(TriggerType::Swipe, + WhenDynamicCastTo(Pointee(AllOf(Property(&SwipeTriggerUpdateEvent::angle, expectedAngles), + Property(&SwipeTriggerUpdateEvent::averageAngle, expectedAngles)))))))) + .Times(1); + + ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::SinglePointMotion))).WillByDefault(Return(true)); + ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::Swipe))).WillByDefault(Return(true)); + + m_handler->handleMotion(m_mouse.get(), PointDelta(delta)); + + QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); + } + + void handleMotion_swipe__calculatesAverageAngleCorrectly() + { + ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::SinglePointMotion))).WillByDefault(Return(true)); + ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::Swipe))).WillByDefault(Return(true)); + + EXPECT_CALL(*m_handler, + updateTriggers(Contains(Pair(TriggerType::Swipe, + WhenDynamicCastTo(Pointee(Property(&SwipeTriggerUpdateEvent::averageAngle, + 0))))))) + .Times(1); + m_handler->handleMotion(m_mouse.get(), PointDelta({10, 0})); + QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); + + EXPECT_CALL(*m_handler, + updateTriggers(Contains(Pair(TriggerType::Swipe, + WhenDynamicCastTo(Pointee(Property(&SwipeTriggerUpdateEvent::averageAngle, + 0))))))) + .Times(1); + m_handler->handleMotion(m_mouse.get(), PointDelta({8, 0})); + QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); + + EXPECT_CALL(*m_handler, + updateTriggers(Contains(Pair(TriggerType::Swipe, + WhenDynamicCastTo(Pointee(Property(&SwipeTriggerUpdateEvent::averageAngle, + Math::atan2deg360({4, 4})))))))) + .Times(1); + m_handler->handleMotion(m_mouse.get(), PointDelta({0, -8})); + QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); + + EXPECT_CALL(*m_handler, + updateTriggers(Contains(Pair(TriggerType::Swipe, + WhenDynamicCastTo(Pointee(Property(&SwipeTriggerUpdateEvent::averageAngle, + Math::atan2deg360({0, 8})))))))) + .Times(1); + m_handler->handleMotion(m_mouse.get(), PointDelta({0, -8})); + QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); + } + + void handleMotion_swipe__motionBeforeThresholdIsTakenIntoAccountWhenCalculatingAverageAngle() + { + ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::SinglePointMotion))).WillByDefault(Return(true)); + ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::Swipe))).WillByDefault(Return(true)); + + m_handler->handleMotion(m_mouse.get(), PointDelta({3, 0})); + m_handler->handleMotion(m_mouse.get(), PointDelta({3, 0})); + + EXPECT_CALL(*m_handler, + updateTriggers(Contains(Pair(TriggerType::Swipe, + WhenDynamicCastTo(Pointee(Property(&SwipeTriggerUpdateEvent::averageAngle, + Math::atan2deg360({2, 3})))))))) + .Times(1); + + m_handler->handleMotion(m_mouse.get(), PointDelta({0, -9})); + + QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); + } + + void handleMotion_swipe_updatedOnceThenCancelled__activatesSwipeTriggers() + { + ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::SinglePointMotion))).WillByDefault(Return(true)); + ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::Swipe))).WillByDefault(Return(true)); + + EXPECT_CALL(*m_handler, updateTriggers(_)) + .Times(3) + .WillOnce(Return(TriggerManagementOperationResult{ + .success = true, + })) + .WillRepeatedly(Return(TriggerManagementOperationResult{ + .success = false, + })); + + m_handler->handleMotion(m_mouse.get(), PointDelta({10, 0})); + + EXPECT_CALL(*m_handler, activateTriggers(static_cast(TriggerType::Swipe), _)).Times(1); + m_handler->handleMotion(m_mouse.get(), PointDelta({10, 0})); + QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); + } + + void handleMotion_swipe_cancelledWithoutUpdate__doesNotActivateSwipeTriggers() + { + ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::SinglePointMotion))).WillByDefault(Return(true)); + ON_CALL(*m_handler, hasActiveTriggers(static_cast(TriggerType::Swipe))).WillByDefault(Return(true)); + + EXPECT_CALL(*m_handler, updateTriggers(_)) + .Times(1) + .WillRepeatedly(Return(TriggerManagementOperationResult{ + .success = false, + })); + EXPECT_CALL(*m_handler, activateTriggers(_, _)).Times(0); + + m_handler->handleMotion(m_mouse.get(), PointDelta({10, 0})); + + QVERIFY(Mock::VerifyAndClearExpectations(m_handler.get())); + } + +private: + std::unique_ptr m_handler; + std::unique_ptr m_mouse; +}; } -QTEST_MAIN(InputActions::TestMotionTriggerHandler) \ No newline at end of file +QTEST_MAIN(InputActions::TestMotionTriggerHandler) +#include "TestMotionTriggerHandler.moc" \ No newline at end of file diff --git a/tests/libinputactions/handlers/TestMotionTriggerHandler.h b/tests/libinputactions/handlers/TestMotionTriggerHandler.h deleted file mode 100644 index baddfbb..0000000 --- a/tests/libinputactions/handlers/TestMotionTriggerHandler.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "Test.h" -#include "mocks/MockMotionTriggerHandler.h" -#include - -namespace InputActions -{ - -class TestMotionTriggerHandler : public Test -{ - Q_OBJECT - -private slots: - void init(); - - void handleMotion_swipe__calculatesAnglesCorrectly_data(); - void handleMotion_swipe__calculatesAnglesCorrectly(); - - void handleMotion_swipe__calculatesAverageAngleCorrectly(); - void handleMotion_swipe__motionBeforeThresholdIsTakenIntoAccountWhenCalculatingAverageAngle(); - - void handleMotion_swipe_updatedOnceThenCancelled__activatesSwipeTriggers(); - void handleMotion_swipe_cancelledWithoutUpdate__doesNotActivateSwipeTriggers(); - -private: - std::unique_ptr m_handler; - std::unique_ptr m_mouse; -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/handlers/TestTouchpadTriggerHandler.cpp b/tests/libinputactions/handlers/TestTouchpadTriggerHandler.cpp index 09a9b57..54f9009 100644 --- a/tests/libinputactions/handlers/TestTouchpadTriggerHandler.cpp +++ b/tests/libinputactions/handlers/TestTouchpadTriggerHandler.cpp @@ -1,9 +1,11 @@ -#include "TestTouchpadTriggerHandler.h" +#include "Test.h" +#include "mocks/MockTouchpadTriggerHandler.h" #include #include #include #include #include +#include #include #include #include @@ -16,521 +18,543 @@ using namespace ::testing; namespace InputActions { -void TestTouchpadTriggerHandler::init() +class TestTouchpadTriggerHandler : public Test { - g_inputBackend = std::make_unique(); - g_inputBackend->setTouchpadTriggerHandlerFactory([this](InputDevice *device) { - auto handler = std::make_unique(device); - m_handler = handler.get(); - return handler; - }); - g_inputBackend->initialize(); - - m_touchpad = std::make_unique(InputDeviceType::Touchpad); - m_touchpad->properties().setSize({100, 100}); - g_inputBackend->addDevice(m_touchpad.get()); - - m_activatingTriggerSpy = std::make_unique(m_handler, &TriggerHandler::activatingTrigger); - m_activatingTriggersSpy = std::make_unique(m_handler, &TriggerHandler::activatingTriggers); - m_cancellingTriggersSpy = std::make_unique(m_handler, &TriggerHandler::cancellingTriggers); - m_endingTriggersSpy = std::make_unique(m_handler, &TriggerHandler::endingTriggers); -} + Q_OBJECT -void TestTouchpadTriggerHandler::click_withoutLibinputButton() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Click)); +private slots: + void init() + { + g_inputBackend = std::make_unique(); + g_inputBackend->setTouchpadTriggerHandlerFactory([this](InputDevice *device) { + auto handler = std::make_unique(device); + m_handler = handler.get(); + return handler; + }); + g_inputBackend->initialize(); - g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), true)); - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Click); + m_touchpad = std::make_unique(InputDeviceType::Touchpad); + m_touchpad->properties().setSize({100, 100}); + g_inputBackend->addDevice(m_touchpad.get()); - g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), false)); - QCOMPARE(m_endingTriggersSpy->count(), 1); - QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::Click); + m_activatingTriggerSpy = std::make_unique(m_handler, &TriggerHandler::activatingTrigger); + m_activatingTriggersSpy = std::make_unique(m_handler, &TriggerHandler::activatingTriggers); + m_cancellingTriggersSpy = std::make_unique(m_handler, &TriggerHandler::cancellingTriggers); + m_endingTriggersSpy = std::make_unique(m_handler, &TriggerHandler::endingTriggers); + } - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + void click_withoutLibinputButton() + { + m_handler->addTrigger(std::make_unique(TriggerType::Click)); -void TestTouchpadTriggerHandler::click_withLibinputButton_data() -{ - QTest::addColumn("button"); + g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), true)); + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Click); - QTest::addRow("left") << BTN_LEFT; - QTest::addRow("right") << BTN_RIGHT; - QTest::addRow("middle") << BTN_MIDDLE; -} + g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), false)); + QCOMPARE(m_endingTriggersSpy->count(), 1); + QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::Click); -void TestTouchpadTriggerHandler::click_withLibinputButton() -{ - QFETCH(int, button); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - m_handler->addTrigger(std::make_unique(TriggerType::Click)); + void click_withLibinputButton_data() + { + QTest::addColumn("button"); - g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), true)); - QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), button, true)), true); - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Click); + QTest::addRow("left") << BTN_LEFT; + QTest::addRow("right") << BTN_RIGHT; + QTest::addRow("middle") << BTN_MIDDLE; + } - g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), false)); - QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), button, false)), true); - QCOMPARE(m_endingTriggersSpy->count(), 1); - QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::Click); + void click_withLibinputButton() + { + QFETCH(int, button); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + m_handler->addTrigger(std::make_unique(TriggerType::Click)); -void TestTouchpadTriggerHandler::press1_notDelayedOrBlocked() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Press)); + g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), true)); + QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), button, true)), true); + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Click); - QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press, 1)), - false); + g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), false)); + QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), button, false)), true); + QCOMPARE(m_endingTriggersSpy->count(), 1); + QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::Click); - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Press); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::End, TriggerType::Press)), false); + void press1_notDelayedOrBlocked() + { + m_handler->addTrigger(std::make_unique(TriggerType::Press)); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press, 1)), + false); -void TestTouchpadTriggerHandler::press1_hasClickTrigger_delayed() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Press)); - m_handler->addTrigger(std::make_unique(TriggerType::Click)); + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Press); - g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press)); - QCOMPARE(m_activatingTriggersSpy->count(), 0); + QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::End, TriggerType::Press)), + false); - QTest::qWait(500); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Press); + void press1_hasClickTrigger_delayed() + { + m_handler->addTrigger(std::make_unique(TriggerType::Press)); + m_handler->addTrigger(std::make_unique(TriggerType::Click)); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press)); + QCOMPARE(m_activatingTriggersSpy->count(), 0); -void TestTouchpadTriggerHandler::press1_hasTapTrigger_delayed() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Press)); - m_handler->addTrigger(std::make_unique(TriggerType::Tap)); + QTest::qWait(500); - g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press)); - QCOMPARE(m_activatingTriggersSpy->count(), 0); + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Press); - QTest::qWait(500); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Press); + void press1_hasTapTrigger_delayed() + { + m_handler->addTrigger(std::make_unique(TriggerType::Press)); + m_handler->addTrigger(std::make_unique(TriggerType::Tap)); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press)); + QCOMPARE(m_activatingTriggersSpy->count(), 0); -void TestTouchpadTriggerHandler::press1_clickedDuringPress_pressCancelledAndClickActivated() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Press)); - m_handler->addTrigger(std::make_unique(TriggerType::Click)); + QTest::qWait(500); - g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press)); - QTest::qWait(500); - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Press); + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Press); - g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), true)); - g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::End, TriggerType::Press)); // libinput + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - QCOMPARE(m_cancellingTriggersSpy->count(), 1); - QCOMPARE(m_cancellingTriggersSpy->at(0).at(0).value(), TriggerType::Press); - QCOMPARE(m_endingTriggersSpy->count(), 0); - QCOMPARE(m_activatingTriggersSpy->count(), 2); - QCOMPARE(m_activatingTriggersSpy->at(1).at(0).value(), TriggerType::Click); + void press1_clickedDuringPress_pressCancelledAndClickActivated() + { + m_handler->addTrigger(std::make_unique(TriggerType::Press)); + m_handler->addTrigger(std::make_unique(TriggerType::Click)); - g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), false)); + g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press)); + QTest::qWait(500); + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Press); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), true)); + g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::End, TriggerType::Press)); // libinput -void TestTouchpadTriggerHandler::press2_notDelayedOrBlocked() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Press)); + QCOMPARE(m_cancellingTriggersSpy->count(), 1); + QCOMPARE(m_cancellingTriggersSpy->at(0).at(0).value(), TriggerType::Press); + QCOMPARE(m_endingTriggersSpy->count(), 0); + QCOMPARE(m_activatingTriggersSpy->count(), 2); + QCOMPARE(m_activatingTriggersSpy->at(1).at(0).value(), TriggerType::Click); - QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press, 2)), - false); + g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), false)); - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Press); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::End, TriggerType::Press)), false); + void press2_notDelayedOrBlocked() + { + m_handler->addTrigger(std::make_unique(TriggerType::Press)); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press, 2)), + false); -void TestTouchpadTriggerHandler::press3_blocked() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Press)); + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Press); - QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press, 3)), - true); - QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::End, TriggerType::Press)), true); + QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::End, TriggerType::Press)), + false); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } -void TestTouchpadTriggerHandler::swipe1() -{ - auto trigger = std::make_unique(TriggerType::Swipe); - trigger->setActivationCondition(std::make_shared("fingers", InputActions::Value(1), ComparisonOperator::EqualTo)); - m_handler->addTrigger(std::move(trigger)); + void press3_blocked() + { + m_handler->addTrigger(std::make_unique(TriggerType::Press)); - addPoints(1); - movePoints({0.05, 0}); - QCOMPARE(g_inputBackend->handleEvent(MotionEvent(m_touchpad.get(), InputEventType::PointerMotion, {{10, 0}})), true); - QCOMPARE(m_activatingTriggerSpy->count(), 1); + QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::Begin, TriggerType::Press, 3)), + true); + QCOMPARE(g_inputBackend->handleEvent(TouchpadGestureLifecyclePhaseEvent(m_touchpad.get(), TouchpadGestureLifecyclePhase::End, TriggerType::Press)), + true); - removePoints(); - QCOMPARE(m_endingTriggersSpy->count(), 1); - QVERIFY(m_endingTriggersSpy->at(0).at(0).value() & TriggerType::SinglePointMotion); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + void swipe1() + { + auto trigger = std::make_unique(TriggerType::Swipe); + trigger->setActivationCondition(std::make_shared("fingers", InputActions::Value(1), ComparisonOperator::EqualTo)); + m_handler->addTrigger(std::move(trigger)); -void TestTouchpadTriggerHandler::swipe2() -{ - auto trigger = std::make_unique(TriggerType::Swipe); - trigger->setActivationCondition(std::make_shared("fingers", InputActions::Value(2), ComparisonOperator::EqualTo)); - m_handler->addTrigger(std::move(trigger)); - - addPoints(2); - movePoints({0.05, 0}); - movePoints({0.05, 0}); - movePoints({0.05, 0}); - QCOMPARE(g_inputBackend->handleEvent(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{10, 0}})), true); - QCOMPARE(m_activatingTriggerSpy->count(), 1); - - QCOMPARE(g_inputBackend->handleEvent(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 0}})), false); - QCOMPARE(m_endingTriggersSpy->count(), 1); - QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::SinglePointMotion); - - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + addPoints(1); + movePoints({0.05, 0}); + QCOMPARE(g_inputBackend->handleEvent(MotionEvent(m_touchpad.get(), InputEventType::PointerMotion, {{10, 0}})), true); + QCOMPARE(m_activatingTriggerSpy->count(), 1); -void TestTouchpadTriggerHandler::tap1() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Tap)); + removePoints(); + QCOMPARE(m_endingTriggersSpy->count(), 1); + QVERIFY(m_endingTriggersSpy->at(0).at(0).value() & TriggerType::SinglePointMotion); - addPoint(); - removePoints(); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - // should not activate without libinput click - QCOMPARE(m_activatingTriggersSpy->count(), 0); + void swipe2() + { + auto trigger = std::make_unique(TriggerType::Swipe); + trigger->setActivationCondition(std::make_shared("fingers", InputActions::Value(2), ComparisonOperator::EqualTo)); + m_handler->addTrigger(std::move(trigger)); - // libinput click - QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, true)), true); - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); - QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, false)), true); - QCOMPARE(m_endingTriggersSpy->count(), 1); - QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); + addPoints(2); + movePoints({0.05, 0}); + movePoints({0.05, 0}); + movePoints({0.05, 0}); + QCOMPARE(g_inputBackend->handleEvent(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{10, 0}})), true); + QCOMPARE(m_activatingTriggerSpy->count(), 1); - QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, true)), false); - QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, false)), false); + QCOMPARE(g_inputBackend->handleEvent(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 0}})), false); + QCOMPARE(m_endingTriggersSpy->count(), 1); + QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::SinglePointMotion); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } -void TestTouchpadTriggerHandler::tap1_noPointerButtonEvent_stateReset() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Tap)); + void tap1() + { + m_handler->addTrigger(std::make_unique(TriggerType::Tap)); - addPoint(); - removePoints(); + addPoint(); + removePoints(); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::LibinputTapBegin); - QTest::qWait(500); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + // should not activate without libinput click + QCOMPARE(m_activatingTriggersSpy->count(), 0); -void TestTouchpadTriggerHandler::tap1_tappedAgainBeforeLibinputButtonReleased() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Tap)); + // libinput click + QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, true)), true); + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); + QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, false)), true); + QCOMPARE(m_endingTriggersSpy->count(), 1); + QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); - addPoint(); - removePoints(); + QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, true)), false); + QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, false)), false); - QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, true)), true); - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - addPoint(); - removePoints(); + void tap1_noPointerButtonEvent_stateReset() + { + m_handler->addTrigger(std::make_unique(TriggerType::Tap)); - QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, false)), true); - QCOMPARE(m_endingTriggersSpy->count(), 1); - QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); + addPoint(); + removePoints(); - QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, true)), true); - QCOMPARE(m_activatingTriggersSpy->count(), 2); - QCOMPARE(m_activatingTriggersSpy->at(1).at(0).value(), TriggerType::Tap); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::LibinputTapBegin); + QTest::qWait(500); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, false)), true); - QCOMPARE(m_endingTriggersSpy->count(), 2); - QCOMPARE(m_endingTriggersSpy->at(1).at(0).value(), TriggerType::Tap); + void tap1_tappedAgainBeforeLibinputButtonReleased() + { + m_handler->addTrigger(std::make_unique(TriggerType::Tap)); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + addPoint(); + removePoints(); -void TestTouchpadTriggerHandler::tap2_variablesSetDuringActivation() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Tap)); + QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, true)), true); + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); - const QPointF first(10, 10); - const QPointF second(20, 20); - addPoint(first); - addPoint(second); + addPoint(); + removePoints(); - const auto finger1Position = g_variableManager->getVariable("finger_1_position_percentage"); - const auto finger2Position = g_variableManager->getVariable("finger_2_position_percentage"); - QCOMPARE(finger1Position->get(), QPointF(0.1, 0.1)); - QCOMPARE(finger2Position->get(), QPointF(0.2, 0.2)); + QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, false)), true); + QCOMPARE(m_endingTriggersSpy->count(), 1); + QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); - removePoints(1); - QCOMPARE(finger1Position->get(), QPointF(0.1, 0.1)); - QCOMPARE(finger2Position->get(), QPointF(0.2, 0.2)); + QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, true)), true); + QCOMPARE(m_activatingTriggersSpy->count(), 2); + QCOMPARE(m_activatingTriggersSpy->at(1).at(0).value(), TriggerType::Tap); - removePoints(1); - QCOMPARE(finger1Position->get(), QPointF(0.1, 0.1)); - QCOMPARE(finger2Position->get(), QPointF(0.2, 0.2)); + QCOMPARE(g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, false)), true); + QCOMPARE(m_endingTriggersSpy->count(), 2); + QCOMPARE(m_endingTriggersSpy->at(1).at(0).value(), TriggerType::Tap); - g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, true)); - g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, false)); - QVERIFY(!finger1Position->get().has_value()); - QVERIFY(!finger2Position->get().has_value()); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + void tap2_variablesSetDuringActivation() + { + m_handler->addTrigger(std::make_unique(TriggerType::Tap)); -void TestTouchpadTriggerHandler::tap4() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Tap)); + const QPointF first(10, 10); + const QPointF second(20, 20); + addPoint(first); + addPoint(second); - addPoints(4); - removePoints(); + const auto finger1Position = g_variableManager->getVariable("finger_1_position_percentage"); + const auto finger2Position = g_variableManager->getVariable("finger_2_position_percentage"); + QCOMPARE(finger1Position->get(), QPointF(0.1, 0.1)); + QCOMPARE(finger2Position->get(), QPointF(0.2, 0.2)); - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); - QCOMPARE(m_endingTriggersSpy->count(), 1); - QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); + removePoints(1); + QCOMPARE(finger1Position->get(), QPointF(0.1, 0.1)); + QCOMPARE(finger2Position->get(), QPointF(0.2, 0.2)); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + removePoints(1); + QCOMPARE(finger1Position->get(), QPointF(0.1, 0.1)); + QCOMPARE(finger2Position->get(), QPointF(0.2, 0.2)); -void TestTouchpadTriggerHandler::tap4_moved() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Tap)); + g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, true)); + g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), BTN_LEFT, false)); + QVERIFY(!finger1Position->get().has_value()); + QVERIFY(!finger2Position->get().has_value()); + + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - addPoints(4); - movePoints({10, 10}); - removePoints(); + void tap4() + { + m_handler->addTrigger(std::make_unique(TriggerType::Tap)); - QCOMPARE(m_activatingTriggersSpy->count(), 0); + addPoints(4); + removePoints(); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); + QCOMPARE(m_endingTriggersSpy->count(), 1); + QCOMPARE(m_endingTriggersSpy->at(0).at(0).value(), TriggerType::Tap); -void TestTouchpadTriggerHandler::tap4_slow() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Tap)); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - addPoints(4); - QTest::qWait(500); - removePoints(); + void tap4_moved() + { + m_handler->addTrigger(std::make_unique(TriggerType::Tap)); - QCOMPARE(m_activatingTriggersSpy->count(), 0); + addPoints(4); + movePoints({10, 10}); + removePoints(); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + QCOMPARE(m_activatingTriggersSpy->count(), 0); -void TestTouchpadTriggerHandler::tap4_clicked() -{ - m_handler->addTrigger(std::make_unique(TriggerType::Click)); - m_handler->addTrigger(std::make_unique(TriggerType::Tap)); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - addPoints(4); - g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), true)); - g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), false)); - removePoints(); + void tap4_slow() + { + m_handler->addTrigger(std::make_unique(TriggerType::Tap)); - QCOMPARE(m_activatingTriggersSpy->count(), 1); - QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Click); + addPoints(4); + QTest::qWait(500); + removePoints(); - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + QCOMPARE(m_activatingTriggersSpy->count(), 0); -void TestTouchpadTriggerHandler::tap_fingerCount_data() -{ - QTest::addColumn("triggerFingers"); - QTest::addColumn("fingers"); - QTest::addColumn("button"); - QTest::addColumn("lmrTapButtonMap"); - QTest::addColumn("activated"); - - QTest::addRow("1") << 1 << 1 << BTN_LEFT << false << true; - QTest::addRow("2") << 2 << 2 << BTN_RIGHT << false << true; - QTest::addRow("3") << 3 << 3 << BTN_MIDDLE << false << true; - QTest::addRow("4") << 4 << 4 << 0 << false << true; - QTest::addRow("5") << 5 << 5 << 0 << false << true; - QTest::addRow("wrong") << 2 << 1 << BTN_LEFT << false << false; - QTest::addRow("1 lmr") << 1 << 1 << BTN_LEFT << true << true; - QTest::addRow("2 lmr") << 2 << 2 << BTN_MIDDLE << true << true; - QTest::addRow("3 lmr") << 3 << 3 << BTN_RIGHT << true << true; - QTest::addRow("4 lmr") << 4 << 4 << 0 << true << true; - QTest::addRow("5 lmr") << 5 << 5 << 0 << true << true; -} + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } -void TestTouchpadTriggerHandler::tap_fingerCount() -{ - QFETCH(int, triggerFingers); - QFETCH(int, fingers); - QFETCH(int, button); - QFETCH(bool, lmrTapButtonMap); - QFETCH(bool, activated); + void tap4_clicked() + { + m_handler->addTrigger(std::make_unique(TriggerType::Click)); + m_handler->addTrigger(std::make_unique(TriggerType::Tap)); - auto trigger = std::make_unique(TriggerType::Tap); - trigger->setActivationCondition(std::make_shared("fingers", InputActions::Value(triggerFingers), ComparisonOperator::EqualTo)); - m_handler->addTrigger(std::move(trigger)); - m_touchpad->properties().setTouchpadLmrTapButtonMap(lmrTapButtonMap); + addPoints(4); + g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), true)); + g_inputBackend->handleEvent(TouchpadClickEvent(m_touchpad.get(), false)); + removePoints(); - addPoints(fingers); - removePoints(); - if (button) { - g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), button, true)); - g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), button, false)); + QCOMPARE(m_activatingTriggersSpy->count(), 1); + QCOMPARE(m_activatingTriggersSpy->at(0).at(0).value(), TriggerType::Click); + + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); } - QCOMPARE(m_activatingTriggerSpy->count(), activated); + void tap_fingerCount_data() + { + QTest::addColumn("triggerFingers"); + QTest::addColumn("fingers"); + QTest::addColumn("button"); + QTest::addColumn("lmrTapButtonMap"); + QTest::addColumn("activated"); + + QTest::addRow("1") << 1 << 1 << BTN_LEFT << false << true; + QTest::addRow("2") << 2 << 2 << BTN_RIGHT << false << true; + QTest::addRow("3") << 3 << 3 << BTN_MIDDLE << false << true; + QTest::addRow("4") << 4 << 4 << 0 << false << true; + QTest::addRow("5") << 5 << 5 << 0 << false << true; + QTest::addRow("wrong") << 2 << 1 << BTN_LEFT << false << false; + QTest::addRow("1 lmr") << 1 << 1 << BTN_LEFT << true << true; + QTest::addRow("2 lmr") << 2 << 2 << BTN_MIDDLE << true << true; + QTest::addRow("3 lmr") << 3 << 3 << BTN_RIGHT << true << true; + QTest::addRow("4 lmr") << 4 << 4 << 0 << true << true; + QTest::addRow("5 lmr") << 5 << 5 << 0 << true << true; + } - QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); -} + void tap_fingerCount() + { + QFETCH(int, triggerFingers); + QFETCH(int, fingers); + QFETCH(int, button); + QFETCH(bool, lmrTapButtonMap); + QFETCH(bool, activated); + + auto trigger = std::make_unique(TriggerType::Tap); + trigger->setActivationCondition(std::make_shared("fingers", + InputActions::Value(triggerFingers), + ComparisonOperator::EqualTo)); + m_handler->addTrigger(std::move(trigger)); + m_touchpad->properties().setTouchpadLmrTapButtonMap(lmrTapButtonMap); + + addPoints(fingers); + removePoints(); + if (button) { + g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), button, true)); + g_inputBackend->handleEvent(PointerButtonEvent(m_touchpad.get(), button, false)); + } -void TestTouchpadTriggerHandler::pointerAxis_oneAxisPerEvent_firstEventPassedThrough() -{ - EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), PointDelta({1, 1}))).Times(1); + QCOMPARE(m_activatingTriggerSpy->count(), activated); - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true)); + QCOMPARE(m_handler->m_state, TouchpadTriggerHandler::State::None); + } - QVERIFY(Mock::VerifyAndClearExpectations(m_handler)); -} + void pointerAxis_oneAxisPerEvent_firstEventPassedThrough() + { + EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), PointDelta({1, 1}))).Times(1); -void TestTouchpadTriggerHandler::pointerAxis_oneAxisPerEvent_eventsBlocked() -{ - EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), _)).WillRepeatedly(Return(true)); + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true)); - // First is passed through - QVERIFY(m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true))); + QVERIFY(Mock::VerifyAndClearExpectations(m_handler)); + } - QVERIFY(m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true))); - QVERIFY(m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true))); -} + void pointerAxis_oneAxisPerEvent_eventsBlocked() + { + EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), _)).WillRepeatedly(Return(true)); -void TestTouchpadTriggerHandler::pointerAxis_oneAxisPerEvent_eventsNotBlocked() -{ - EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), _)).WillRepeatedly(Return(false)); + // First is passed through + QVERIFY(m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true))); - // First is passed through - QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true))); + QVERIFY(m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true))); + QVERIFY(m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true))); + } - QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true))); - QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true))); -} + void pointerAxis_oneAxisPerEvent_eventsNotBlocked() + { + EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), _)).WillRepeatedly(Return(false)); -void TestTouchpadTriggerHandler::pointerAxis_oneAxisPerEvent_eventBlockingStops() -{ - auto block = true; - EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), _)).WillRepeatedly([&block]() { - return block; - }); + // First is passed through + QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true))); - // First is passed through - QVERIFY(m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true))); + QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true))); + QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true))); + } - QVERIFY(m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true))); - block = false; - QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true))); + void pointerAxis_oneAxisPerEvent_eventBlockingStops() + { + auto block = true; + EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), _)).WillRepeatedly([&block]() { + return block; + }); - QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true))); - QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true))); -} + // First is passed through + QVERIFY(m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true))); -void TestTouchpadTriggerHandler::pointerAxis_oneAxisPerEvent_differentAxisEventsMerged() -{ - // First is passed through - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true)); + QVERIFY(m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true))); + block = false; + QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true))); - EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), PointDelta({1, 1}))).Times(1); + QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true))); + QVERIFY(!m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true))); + } - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true)); - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true)); + void pointerAxis_oneAxisPerEvent_differentAxisEventsMerged() + { + // First is passed through + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true)); - QVERIFY(Mock::VerifyAndClearExpectations(m_handler)); -} + EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), PointDelta({1, 1}))).Times(1); -void TestTouchpadTriggerHandler::pointerAxis_oneAxisPerEvent_sameAxisEventsNotMerged() -{ - // First is passed through - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true)); - - EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), PointDelta({1, 0}))).Times(2); - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true)); - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true)); - QVERIFY(Mock::VerifyAndClearExpectations(m_handler)); - - EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), PointDelta({0, 1}))).Times(2); - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true)); - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true)); - QVERIFY(Mock::VerifyAndClearExpectations(m_handler)); -} + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true)); + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true)); -void TestTouchpadTriggerHandler::pointerAxis_notOneAxisPerEvent_notMerged() -{ - // First would be passed through - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, false)); + QVERIFY(Mock::VerifyAndClearExpectations(m_handler)); + } - EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), PointDelta({1, 0}))).Times(1); - m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, false)); - QVERIFY(Mock::VerifyAndClearExpectations(m_handler)); -} + void pointerAxis_oneAxisPerEvent_sameAxisEventsNotMerged() + { + // First is passed through + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, true)); -void TestTouchpadTriggerHandler::addPoint(const QPointF &position) -{ - m_touchId++; - g_inputBackend->handleEvent(TouchDownEvent(m_touchpad.get(), m_touchId, position, position)); -} + EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), PointDelta({1, 0}))).Times(2); + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true)); + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, true)); + QVERIFY(Mock::VerifyAndClearExpectations(m_handler)); -void TestTouchpadTriggerHandler::addPoints(uint8_t count, const QPointF &position) -{ - for (auto i = 0; i < count; i++) { - addPoint(position); + EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), PointDelta({0, 1}))).Times(2); + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true)); + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{0, 1}}, true)); + QVERIFY(Mock::VerifyAndClearExpectations(m_handler)); } -} -void TestTouchpadTriggerHandler::movePoints(const QPointF &delta) -{ - for (auto *point : m_touchpad->physicalState().validTouchPoints()) { - g_inputBackend->handleEvent(TouchMotionEvent(m_touchpad.get(), point->id, point->position + delta, point->rawPosition + delta)); + void pointerAxis_notOneAxisPerEvent_notMerged() + { + // First would be passed through + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 1}}, false)); + + EXPECT_CALL(*m_handler, handleMotion(m_touchpad.get(), PointDelta({1, 0}))).Times(1); + m_handler->pointerAxis(MotionEvent(m_touchpad.get(), InputEventType::PointerAxis, {{1, 0}}, false)); + QVERIFY(Mock::VerifyAndClearExpectations(m_handler)); } -} -void TestTouchpadTriggerHandler::removePoints(int16_t count) -{ - uint8_t removed{}; - for (auto *point : std::ranges::reverse_view(m_touchpad->physicalState().validTouchPoints())) { - g_inputBackend->handleEvent(TouchUpEvent(m_touchpad.get(), point->id)); - if (++removed == count) { - break; +private: + void addPoint(const QPointF &position = {0.5, 0.5}) + { + m_touchId++; + g_inputBackend->handleEvent(TouchDownEvent(m_touchpad.get(), m_touchId, position, position)); + } + + void addPoints(uint8_t count, const QPointF &position = {0.5, 0.5}) + { + for (auto i = 0; i < count; i++) { + addPoint(position); + } + } + + void movePoints(const QPointF &delta) + { + for (auto *point : m_touchpad->physicalState().validTouchPoints()) { + g_inputBackend->handleEvent(TouchMotionEvent(m_touchpad.get(), point->id, point->position + delta, point->rawPosition + delta)); } } -} + void removePoints(int16_t count = -1) + { + uint8_t removed{}; + for (auto *point : std::ranges::reverse_view(m_touchpad->physicalState().validTouchPoints())) { + g_inputBackend->handleEvent(TouchUpEvent(m_touchpad.get(), point->id)); + if (++removed == count) { + break; + } + } + } + + int32_t m_touchId{}; + MockTouchpadTriggerHandler *m_handler; + std::unique_ptr m_activatingTriggerSpy; + std::unique_ptr m_activatingTriggersSpy; + std::unique_ptr m_cancellingTriggersSpy; + std::unique_ptr m_endingTriggersSpy; + + std::unique_ptr m_touchpad; }; -QTEST_MAIN(InputActions::TestTouchpadTriggerHandler) \ No newline at end of file +} + +QTEST_MAIN(InputActions::TestTouchpadTriggerHandler) +#include "TestTouchpadTriggerHandler.moc" \ No newline at end of file diff --git a/tests/libinputactions/handlers/TestTouchpadTriggerHandler.h b/tests/libinputactions/handlers/TestTouchpadTriggerHandler.h deleted file mode 100644 index 8ebe31c..0000000 --- a/tests/libinputactions/handlers/TestTouchpadTriggerHandler.h +++ /dev/null @@ -1,67 +0,0 @@ -#include "Test.h" -#include "mocks/MockTouchpadTriggerHandler.h" -#include -#include - -namespace InputActions -{ - -class TestTouchpadTriggerHandler : public Test -{ - Q_OBJECT - -private slots: - void init(); - - void click_withoutLibinputButton(); - void click_withLibinputButton_data(); - void click_withLibinputButton(); - - void press1_notDelayedOrBlocked(); - void press1_hasClickTrigger_delayed(); - void press1_hasTapTrigger_delayed(); - void press1_clickedDuringPress_pressCancelledAndClickActivated(); - void press2_notDelayedOrBlocked(); - void press3_blocked(); - - void swipe1(); - void swipe2(); - - void tap1(); - void tap1_noPointerButtonEvent_stateReset(); - void tap1_tappedAgainBeforeLibinputButtonReleased(); - void tap2_variablesSetDuringActivation(); - void tap4(); - void tap4_moved(); - void tap4_slow(); - void tap4_clicked(); - - void tap_fingerCount_data(); - void tap_fingerCount(); - - void pointerAxis_oneAxisPerEvent_firstEventPassedThrough(); - void pointerAxis_oneAxisPerEvent_eventsBlocked(); - void pointerAxis_oneAxisPerEvent_eventsNotBlocked(); - void pointerAxis_oneAxisPerEvent_eventBlockingStops(); - void pointerAxis_oneAxisPerEvent_differentAxisEventsMerged(); - void pointerAxis_oneAxisPerEvent_sameAxisEventsNotMerged(); - - void pointerAxis_notOneAxisPerEvent_notMerged(); - -private: - void addPoint(const QPointF &position = {0.5, 0.5}); - void addPoints(uint8_t count, const QPointF &position = {0.5, 0.5}); - void movePoints(const QPointF &delta); - void removePoints(int16_t count = -1); - - int32_t m_touchId{}; - MockTouchpadTriggerHandler *m_handler; - std::unique_ptr m_activatingTriggerSpy; - std::unique_ptr m_activatingTriggersSpy; - std::unique_ptr m_cancellingTriggersSpy; - std::unique_ptr m_endingTriggersSpy; - - std::unique_ptr m_touchpad; -}; - -}; \ No newline at end of file diff --git a/tests/libinputactions/handlers/TestTriggerHandler.cpp b/tests/libinputactions/handlers/TestTriggerHandler.cpp index be37cdf..a9386fc 100644 --- a/tests/libinputactions/handlers/TestTriggerHandler.cpp +++ b/tests/libinputactions/handlers/TestTriggerHandler.cpp @@ -1,69 +1,78 @@ -#include "TestTriggerHandler.h" +#include "Test.h" +#include "mocks/MockTrigger.h" #include +#include using namespace ::testing; namespace InputActions { -void TestTriggerHandler::init() +class TestTriggerHandler : public Test { - m_handler = std::unique_ptr(new TriggerHandler); -} + Q_OBJECT -void TestTriggerHandler::triggers_data() -{ - QTest::addColumn("type"); - QTest::addColumn>("triggers"); - QTest::addColumn("size"); - - QTest::newRow("not activatable") << TriggerType::Press << std::vector({makeTrigger(TriggerType::Press, false)}) << 0; - QTest::newRow("activatable") << TriggerType::Press << std::vector({makeTrigger(TriggerType::Press, true)}) << 1; - QTest::newRow("activatable, wrong type") << TriggerType::Swipe << std::vector({makeTrigger(TriggerType::Press, true)}) << 0; - QTest::newRow("activatable, all") << TriggerType::All - << std::vector({makeTrigger(TriggerType::Press, true), makeTrigger(TriggerType::Swipe, true)}) << 2; -} +private slots: + void init() { m_handler = std::unique_ptr(new TriggerHandler); } -void TestTriggerHandler::triggers() -{ - QFETCH(TriggerType, type); - QFETCH(std::vector, triggers); - QFETCH(int, size); + void triggers_data() + { + QTest::addColumn("type"); + QTest::addColumn>("triggers"); + QTest::addColumn("size"); - for (auto trigger : triggers) { - m_handler->addTrigger(std::unique_ptr(trigger)); + QTest::newRow("not activatable") << TriggerType::Press << std::vector({makeTrigger(TriggerType::Press, false)}) << 0; + QTest::newRow("activatable") << TriggerType::Press << std::vector({makeTrigger(TriggerType::Press, true)}) << 1; + QTest::newRow("activatable, wrong type") << TriggerType::Swipe << std::vector({makeTrigger(TriggerType::Press, true)}) << 0; + QTest::newRow("activatable, all") << TriggerType::All + << std::vector({makeTrigger(TriggerType::Press, true), makeTrigger(TriggerType::Swipe, true)}) << 2; } - TriggerActivationEvent event; - QCOMPARE(m_handler->triggers(type, event).size(), size); - QCOMPARE(m_handler->activateTriggers(type, event).success, size != 0); - QCOMPARE(m_handler->activeTriggers(type).size(), size); -} + void triggers() + { + QFETCH(TriggerType, type); + QFETCH(std::vector, triggers); + QFETCH(int, size); -void TestTriggerHandler::activateTriggers_cancelsAllTriggers() -{ - QSignalSpy spy(m_handler.get(), &TriggerHandler::cancellingTriggers); - - m_handler->addTrigger(std::make_unique(TriggerType::Press)); - m_handler->activateTriggers(TriggerType::Swipe); - QCOMPARE(spy.count(), 0); - m_handler->activateTriggers(TriggerType::Swipe | TriggerType::Press); - QCOMPARE(spy.count(), 0); - m_handler->activateTriggers(TriggerType::All); - QCOMPARE(spy.count(), 1); - - for (const auto &args : spy) { - QCOMPARE(args.at(0).value(), TriggerType::All); + for (auto trigger : triggers) { + m_handler->addTrigger(std::unique_ptr(trigger)); + } + TriggerActivationEvent event; + + QCOMPARE(m_handler->triggers(type, event).size(), size); + QCOMPARE(m_handler->activateTriggers(type, event).success, size != 0); + QCOMPARE(m_handler->activeTriggers(type).size(), size); } -} -MockTrigger *TestTriggerHandler::makeTrigger(TriggerType type, bool activatable) -{ - auto *trigger = new MockTrigger(type); - ON_CALL(*trigger, canActivate(_)).WillByDefault(Return(activatable)); - return trigger; -} + void activateTriggers_cancelsAllTriggers() + { + QSignalSpy spy(m_handler.get(), &TriggerHandler::cancellingTriggers); + + m_handler->addTrigger(std::make_unique(TriggerType::Press)); + m_handler->activateTriggers(TriggerType::Swipe); + QCOMPARE(spy.count(), 0); + m_handler->activateTriggers(TriggerType::Swipe | TriggerType::Press); + QCOMPARE(spy.count(), 0); + m_handler->activateTriggers(TriggerType::All); + QCOMPARE(spy.count(), 1); + + for (const auto &args : spy) { + QCOMPARE(args.at(0).value(), TriggerType::All); + } + } + +private: + MockTrigger *makeTrigger(TriggerType type, bool activatable) + { + auto *trigger = new MockTrigger(type); + ON_CALL(*trigger, canActivate(_)).WillByDefault(Return(activatable)); + return trigger; + } + + std::unique_ptr m_handler; +}; } -QTEST_MAIN(InputActions::TestTriggerHandler) \ No newline at end of file +QTEST_MAIN(InputActions::TestTriggerHandler) +#include "TestTriggerHandler.moc" \ No newline at end of file diff --git a/tests/libinputactions/handlers/TestTriggerHandler.h b/tests/libinputactions/handlers/TestTriggerHandler.h deleted file mode 100644 index 4687751..0000000 --- a/tests/libinputactions/handlers/TestTriggerHandler.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "Test.h" -#include "mocks/MockTrigger.h" -#include - -namespace InputActions -{ - -class TestTriggerHandler : public Test -{ - Q_OBJECT - -private slots: - void init(); - - void triggers_data(); - void triggers(); - - void activateTriggers_cancelsAllTriggers(); - -private: - MockTrigger *makeTrigger(TriggerType type, bool activatable); - - std::unique_ptr m_handler; -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/triggers/TestDirectionalMotionTrigger.cpp b/tests/libinputactions/triggers/TestDirectionalMotionTrigger.cpp index f9089fc..beb0dae 100644 --- a/tests/libinputactions/triggers/TestDirectionalMotionTrigger.cpp +++ b/tests/libinputactions/triggers/TestDirectionalMotionTrigger.cpp @@ -1,78 +1,88 @@ -#include "TestDirectionalMotionTrigger.h" +#include "Test.h" #include namespace InputActions { -void TestDirectionalMotionTrigger::canUpdate_data() +class TestDirectionalMotionTrigger : public Test { - QTest::addColumn("direction"); - QTest::addColumn>("valid"); - QTest::addColumn>("invalid"); + Q_OBJECT - QTest::addRow("pinch any") << static_cast(PinchDirection::Any) - << std::vector({static_cast(PinchDirection::In), static_cast(PinchDirection::Out)}) - << std::vector(); - QTest::addRow("pinch in") << static_cast(PinchDirection::In) << std::vector({static_cast(PinchDirection::In)}) - << std::vector({static_cast(PinchDirection::Out)}); - QTest::addRow("pinch out") << static_cast(PinchDirection::Out) - << std::vector({static_cast(PinchDirection::Out)}) - << std::vector({static_cast(PinchDirection::In)}); - // Rotate is same as pinch - QTest::addRow("swipe left") << static_cast(SwipeDirection::Left) - << std::vector({static_cast(SwipeDirection::Left)}) - << std::vector({static_cast(SwipeDirection::Right), - static_cast(SwipeDirection::Up), - static_cast(SwipeDirection::Down)}); - QTest::addRow("swipe right") << static_cast(SwipeDirection::Right) - << std::vector({static_cast(SwipeDirection::Right)}) - << std::vector({static_cast(SwipeDirection::Left), - static_cast(SwipeDirection::Up), - static_cast(SwipeDirection::Down)}); - QTest::addRow("swipe left/right") - << static_cast(SwipeDirection::LeftRight) - << std::vector({static_cast(SwipeDirection::Left), static_cast(SwipeDirection::Right)}) - << std::vector({static_cast(SwipeDirection::Up), static_cast(SwipeDirection::Down)}); - QTest::addRow("swipe up") << static_cast(SwipeDirection::Up) << std::vector({static_cast(SwipeDirection::Up)}) - << std::vector({static_cast(SwipeDirection::Right), - static_cast(SwipeDirection::Left), - static_cast(SwipeDirection::Down)}); - QTest::addRow("swipe down") << static_cast(SwipeDirection::Down) - << std::vector({static_cast(SwipeDirection::Down)}) - << std::vector({static_cast(SwipeDirection::Right), - static_cast(SwipeDirection::Up), - static_cast(SwipeDirection::Left)}); - QTest::addRow("swipe up/down") - << static_cast(SwipeDirection::UpDown) - << std::vector({static_cast(SwipeDirection::Up), static_cast(SwipeDirection::Down)}) - << std::vector({static_cast(SwipeDirection::Left), static_cast(SwipeDirection::Right)}); - QTest::addRow("swipe any") << static_cast(SwipeDirection::Any) - << std::vector({static_cast(SwipeDirection::Up), - static_cast(SwipeDirection::Down), - static_cast(SwipeDirection::Left), - static_cast(SwipeDirection::Right)}) - << std::vector({}); -} - -void TestDirectionalMotionTrigger::canUpdate() -{ - QFETCH(uint32_t, direction); - QFETCH(std::vector, valid); - QFETCH(std::vector, invalid); +private slots: + void canUpdate_data() + { + QTest::addColumn("direction"); + QTest::addColumn>("valid"); + QTest::addColumn>("invalid"); - auto trigger = std::make_unique(TriggerType::None, direction); - for (const auto &validDirection : valid) { - DirectionalMotionTriggerUpdateEvent event; - event.setDirection(validDirection); - QVERIFY(trigger->canUpdate(event)); + QTest::addRow("pinch any") << static_cast(PinchDirection::Any) + << std::vector({static_cast(PinchDirection::In), + static_cast(PinchDirection::Out)}) + << std::vector(); + QTest::addRow("pinch in") << static_cast(PinchDirection::In) + << std::vector({static_cast(PinchDirection::In)}) + << std::vector({static_cast(PinchDirection::Out)}); + QTest::addRow("pinch out") << static_cast(PinchDirection::Out) + << std::vector({static_cast(PinchDirection::Out)}) + << std::vector({static_cast(PinchDirection::In)}); + // Rotate is same as pinch + QTest::addRow("swipe left") << static_cast(SwipeDirection::Left) + << std::vector({static_cast(SwipeDirection::Left)}) + << std::vector({static_cast(SwipeDirection::Right), + static_cast(SwipeDirection::Up), + static_cast(SwipeDirection::Down)}); + QTest::addRow("swipe right") << static_cast(SwipeDirection::Right) + << std::vector({static_cast(SwipeDirection::Right)}) + << std::vector({static_cast(SwipeDirection::Left), + static_cast(SwipeDirection::Up), + static_cast(SwipeDirection::Down)}); + QTest::addRow("swipe left/right") + << static_cast(SwipeDirection::LeftRight) + << std::vector({static_cast(SwipeDirection::Left), static_cast(SwipeDirection::Right)}) + << std::vector({static_cast(SwipeDirection::Up), static_cast(SwipeDirection::Down)}); + QTest::addRow("swipe up") << static_cast(SwipeDirection::Up) + << std::vector({static_cast(SwipeDirection::Up)}) + << std::vector({static_cast(SwipeDirection::Right), + static_cast(SwipeDirection::Left), + static_cast(SwipeDirection::Down)}); + QTest::addRow("swipe down") << static_cast(SwipeDirection::Down) + << std::vector({static_cast(SwipeDirection::Down)}) + << std::vector({static_cast(SwipeDirection::Right), + static_cast(SwipeDirection::Up), + static_cast(SwipeDirection::Left)}); + QTest::addRow("swipe up/down") + << static_cast(SwipeDirection::UpDown) + << std::vector({static_cast(SwipeDirection::Up), static_cast(SwipeDirection::Down)}) + << std::vector({static_cast(SwipeDirection::Left), static_cast(SwipeDirection::Right)}); + QTest::addRow("swipe any") << static_cast(SwipeDirection::Any) + << std::vector({static_cast(SwipeDirection::Up), + static_cast(SwipeDirection::Down), + static_cast(SwipeDirection::Left), + static_cast(SwipeDirection::Right)}) + << std::vector({}); } - for (const auto &invalidDirection : invalid) { - DirectionalMotionTriggerUpdateEvent event; - event.setDirection(invalidDirection); - QVERIFY(!trigger->canUpdate(event)); + + void canUpdate() + { + QFETCH(uint32_t, direction); + QFETCH(std::vector, valid); + QFETCH(std::vector, invalid); + + auto trigger = std::make_unique(TriggerType::None, direction); + for (const auto &validDirection : valid) { + DirectionalMotionTriggerUpdateEvent event; + event.setDirection(validDirection); + QVERIFY(trigger->canUpdate(event)); + } + for (const auto &invalidDirection : invalid) { + DirectionalMotionTriggerUpdateEvent event; + event.setDirection(invalidDirection); + QVERIFY(!trigger->canUpdate(event)); + } } -} +}; } -QTEST_MAIN(InputActions::TestDirectionalMotionTrigger) \ No newline at end of file +QTEST_MAIN(InputActions::TestDirectionalMotionTrigger) +#include "TestDirectionalMotionTrigger.moc" \ No newline at end of file diff --git a/tests/libinputactions/triggers/TestDirectionalMotionTrigger.h b/tests/libinputactions/triggers/TestDirectionalMotionTrigger.h deleted file mode 100644 index ea94c6c..0000000 --- a/tests/libinputactions/triggers/TestDirectionalMotionTrigger.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestDirectionalMotionTrigger : public Test -{ - Q_OBJECT - -private slots: - void canUpdate_data(); - void canUpdate(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/triggers/TestMotionTrigger.cpp b/tests/libinputactions/triggers/TestMotionTrigger.cpp index 4bbda5f..fda1696 100644 --- a/tests/libinputactions/triggers/TestMotionTrigger.cpp +++ b/tests/libinputactions/triggers/TestMotionTrigger.cpp @@ -1,40 +1,47 @@ -#include "TestMotionTrigger.h" +#include "Test.h" #include namespace InputActions { -void TestMotionTrigger::canUpdate_speed_data() +class TestMotionTrigger : public Test { - QTest::addColumn("triggerSpeed"); - QTest::addColumn("eventSpeed"); - QTest::addColumn("result"); - - QTest::addRow("any, any") << TriggerSpeed::Any << TriggerSpeed::Any << true; - QTest::addRow("any, fast") << TriggerSpeed::Any << TriggerSpeed::Fast << true; - QTest::addRow("any, slow") << TriggerSpeed::Any << TriggerSpeed::Slow << true; - QTest::addRow("fast, any") << TriggerSpeed::Fast << TriggerSpeed::Any << false; - QTest::addRow("fast, fast") << TriggerSpeed::Fast << TriggerSpeed::Fast << true; - QTest::addRow("fast, slow") << TriggerSpeed::Fast << TriggerSpeed::Slow << false; - QTest::addRow("slow, any") << TriggerSpeed::Slow << TriggerSpeed::Any << false; - QTest::addRow("slow, fast") << TriggerSpeed::Slow << TriggerSpeed::Fast << false; - QTest::addRow("slow, slow") << TriggerSpeed::Slow << TriggerSpeed::Slow << true; -} - -void TestMotionTrigger::canUpdate_speed() -{ - QFETCH(TriggerSpeed, triggerSpeed); - QFETCH(TriggerSpeed, eventSpeed); - QFETCH(bool, result); - - auto trigger = std::make_unique(); - trigger->setSpeed(triggerSpeed); - MotionTriggerUpdateEvent event; - event.setSpeed(eventSpeed); - - QCOMPARE(trigger->canUpdate(event), result); -} + Q_OBJECT + +private slots: + void canUpdate_speed_data() + { + QTest::addColumn("triggerSpeed"); + QTest::addColumn("eventSpeed"); + QTest::addColumn("result"); + + QTest::addRow("any, any") << TriggerSpeed::Any << TriggerSpeed::Any << true; + QTest::addRow("any, fast") << TriggerSpeed::Any << TriggerSpeed::Fast << true; + QTest::addRow("any, slow") << TriggerSpeed::Any << TriggerSpeed::Slow << true; + QTest::addRow("fast, any") << TriggerSpeed::Fast << TriggerSpeed::Any << false; + QTest::addRow("fast, fast") << TriggerSpeed::Fast << TriggerSpeed::Fast << true; + QTest::addRow("fast, slow") << TriggerSpeed::Fast << TriggerSpeed::Slow << false; + QTest::addRow("slow, any") << TriggerSpeed::Slow << TriggerSpeed::Any << false; + QTest::addRow("slow, fast") << TriggerSpeed::Slow << TriggerSpeed::Fast << false; + QTest::addRow("slow, slow") << TriggerSpeed::Slow << TriggerSpeed::Slow << true; + } + + void canUpdate_speed() + { + QFETCH(TriggerSpeed, triggerSpeed); + QFETCH(TriggerSpeed, eventSpeed); + QFETCH(bool, result); + + auto trigger = std::make_unique(); + trigger->setSpeed(triggerSpeed); + MotionTriggerUpdateEvent event; + event.setSpeed(eventSpeed); + + QCOMPARE(trigger->canUpdate(event), result); + } +}; } -QTEST_MAIN(InputActions::TestMotionTrigger) \ No newline at end of file +QTEST_MAIN(InputActions::TestMotionTrigger) +#include "TestMotionTrigger.moc" \ No newline at end of file diff --git a/tests/libinputactions/triggers/TestMotionTrigger.h b/tests/libinputactions/triggers/TestMotionTrigger.h deleted file mode 100644 index 72ff5ee..0000000 --- a/tests/libinputactions/triggers/TestMotionTrigger.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestMotionTrigger : public Test -{ - Q_OBJECT - -private slots: - void canUpdate_speed_data(); - void canUpdate_speed(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/triggers/TestSwipeTrigger.cpp b/tests/libinputactions/triggers/TestSwipeTrigger.cpp index 7a09a05..27d0be7 100644 --- a/tests/libinputactions/triggers/TestSwipeTrigger.cpp +++ b/tests/libinputactions/triggers/TestSwipeTrigger.cpp @@ -1,4 +1,4 @@ -#include "TestSwipeTrigger.h" +#include "Test.h" #include "mocks/MockSwipeTrigger.h" using namespace ::testing; @@ -6,176 +6,183 @@ using namespace ::testing; namespace InputActions { -void TestSwipeTrigger::canUpdate_currentAngleDoesNotMatchRange_averageAngleMatchesRange__returnsTrue() +class TestSwipeTrigger : public Test { - SwipeTrigger trigger(30, 60); - - SwipeTriggerUpdateEvent event; - event.setAngle(0); - event.setAverageAngle(45); - - QCOMPARE(trigger.canUpdate(event), true); -} - -void TestSwipeTrigger::canUpdate_currentAngleMatchesRange_averageAngleDoesNotMatchRange__returnsFalse() -{ - SwipeTrigger trigger(30, 60); - - SwipeTriggerUpdateEvent event; - event.setAngle(45); - event.setAverageAngle(0); - - QCOMPARE(trigger.canUpdate(event), false); -} - -void TestSwipeTrigger::canUpdate_data() -{ - QTest::addColumn("min"); - QTest::addColumn("max"); - QTest::addColumn("bidirectional"); - QTest::addColumn("angle"); - QTest::addColumn("returnValue"); - - QTest::addRow("normalAngle__returnsTrue") << 30.0 << 60.0 << false << 45.0 << true; - QTest::addRow("oppositeAngle__returnsFalse") << 30.0 << 60.0 << false << 225.0 << false; - QTest::addRow("normalAngle_bidirectional__returnsTrue") << 30.0 << 60.0 << true << 45.0 << true; - QTest::addRow("oppositeAngle_bidirectional__returnsFalse") << 30.0 << 60.0 << true << 225.0 << true; -} - -void TestSwipeTrigger::canUpdate() -{ - QFETCH(qreal, min); - QFETCH(qreal, max); - QFETCH(bool, bidirectional); - QFETCH(qreal, angle); - QFETCH(bool, returnValue); - - SwipeTrigger trigger(min, max); - trigger.setBidirectional(bidirectional); - - SwipeTriggerUpdateEvent event; - event.setAverageAngle(angle); - - QCOMPARE(trigger.canUpdate(event), returnValue); -} - -void TestSwipeTrigger::updateActions_bidirectional_normalAngle__updatesActionsWithPositiveDelta() -{ - MockSwipeTrigger trigger(0, 0); - trigger.setBidirectional(true); - EXPECT_CALL(trigger, doUpdateActions(Property(&TriggerUpdateEvent::delta, Property(&Delta::unaccelerated, Eq(10))))).Times(1); - - SwipeTriggerUpdateEvent event; - event.setAngle(0); - event.setDelta(10); - - trigger.updateActions(event); - - QVERIFY(Mock::VerifyAndClearExpectations(&trigger)); -} - -void TestSwipeTrigger::updateActions_bidirectional_oppositeAngle__updatesActionsWithNegativeDelta() -{ - MockSwipeTrigger trigger(0, 0); - trigger.setBidirectional(true); - EXPECT_CALL(trigger, doUpdateActions(Property(&TriggerUpdateEvent::delta, Property(&Delta::unaccelerated, Eq(-10))))).Times(1); - - SwipeTriggerUpdateEvent event; - event.setAngle(180); - event.setDelta(10); - - trigger.updateActions(event); - - QVERIFY(Mock::VerifyAndClearExpectations(&trigger)); -} - -void TestSwipeTrigger::updateActions_bidirectional_overlappingAngleRanges__normalRangeHasHigherPriority() -{ - MockSwipeTrigger trigger(0, 270); - trigger.setBidirectional(true); - EXPECT_CALL(trigger, doUpdateActions(Property(&TriggerUpdateEvent::delta, Property(&Delta::unaccelerated, Gt(-10))))).Times(2); - - SwipeTriggerUpdateEvent event; - event.setAngle(30); - event.setDelta(10); - trigger.updateActions(event); - - event.setAngle(260); - trigger.updateActions(event); - - QVERIFY(Mock::VerifyAndClearExpectations(&trigger)); -} - -void TestSwipeTrigger::matchesAngleRange_data() -{ - QTest::addColumn("a"); - QTest::addColumn("b"); - QTest::addColumn("angle"); - QTest::addColumn("result"); - - QTest::addRow("a true") << 90.0 << 270.0 << 180.0 << true; - QTest::addRow("a true") << 90.0 << 270.0 << 90.0 << true; - QTest::addRow("a true") << 90.0 << 270.0 << 270.0 << true; - QTest::addRow("a false") << 90.0 << 270.0 << 89.0 << false; - QTest::addRow("a false") << 90.0 << 270.0 << 271.0 << false; - QTest::addRow("a false") << 90.0 << 270.0 << 0.0 << false; - - QTest::addRow("a>b, middle => true") << 270.0 << 90.0 << 0.0 << true; - QTest::addRow("a>b, min => true") << 270.0 << 90.0 << 270.0 << true; - QTest::addRow("a>b, max => true") << 270.0 << 90.0 << 90.0 << true; - QTest::addRow("a>b, min-1 => false") << 270.0 << 90.0 << 269.0 << false; - QTest::addRow("a>b, max+1 => false") << 270.0 << 90.0 << 91.0 << false; - QTest::addRow("a>b, middle opposite => false") << 270.0 << 90.0 << 180.0 << false; - - QTest::addRow("a=b => true") << 0.0 << 0.0 << 0.0 << true; - QTest::addRow("a=b, opposite => false") << 0.0 << 0.0 << 180.0 << false; -} - -void TestSwipeTrigger::matchesAngleRange() -{ - QFETCH(qreal, a); - QFETCH(qreal, b); - QFETCH(qreal, angle); - QFETCH(bool, result); - - QCOMPARE(SwipeTrigger::matchesAngleRange(angle, a, b), result); -} - -void TestSwipeTrigger::matchesOppositeAngleRange_data() -{ - QTest::addColumn("a"); - QTest::addColumn("b"); - QTest::addColumn("angle"); - QTest::addColumn("result"); - - QTest::addRow("a true") << 90.0 << 270.0 << 0.0 << true; - QTest::addRow("a true") << 90.0 << 270.0 << 270.0 << true; - QTest::addRow("a true") << 90.0 << 270.0 << 90.0 << true; - QTest::addRow("a false") << 90.0 << 270.0 << 269.0 << false; - QTest::addRow("a false") << 90.0 << 270.0 << 91.0 << false; - QTest::addRow("a false") << 90.0 << 270.0 << 180.0 << false; - - QTest::addRow("a>b, middle opposite => true") << 270.0 << 90.0 << 180.0 << true; - QTest::addRow("a>b, min opposite => true") << 270.0 << 90.0 << 90.0 << true; - QTest::addRow("a>b, max opposite => true") << 270.0 << 90.0 << 270.0 << true; - QTest::addRow("a>b, min-1 opposite => false") << 270.0 << 90.0 << 89.0 << false; - QTest::addRow("a>b, max+1 opposite => false") << 270.0 << 90.0 << 271.0 << false; - QTest::addRow("a>b, middle normal => false") << 270.0 << 90.0 << 0.0 << false; - - QTest::addRow("a=b, opposite => true") << 0.0 << 0.0 << 180.0 << true; - QTest::addRow("a=b, normal => false") << 0.0 << 0.0 << 0.0 << false; -} - -void TestSwipeTrigger::matchesOppositeAngleRange() -{ - QFETCH(qreal, a); - QFETCH(qreal, b); - QFETCH(qreal, angle); - QFETCH(bool, result); - - QCOMPARE(SwipeTrigger::matchesOppositeAngleRange(angle, a, b), result); -} + Q_OBJECT + +private slots: + void canUpdate_currentAngleDoesNotMatchRange_averageAngleMatchesRange__returnsTrue() + { + SwipeTrigger trigger(30, 60); + + SwipeTriggerUpdateEvent event; + event.setAngle(0); + event.setAverageAngle(45); + + QCOMPARE(trigger.canUpdate(event), true); + } + + void canUpdate_currentAngleMatchesRange_averageAngleDoesNotMatchRange__returnsFalse() + { + SwipeTrigger trigger(30, 60); + + SwipeTriggerUpdateEvent event; + event.setAngle(45); + event.setAverageAngle(0); + + QCOMPARE(trigger.canUpdate(event), false); + } + + void canUpdate_data() + { + QTest::addColumn("min"); + QTest::addColumn("max"); + QTest::addColumn("bidirectional"); + QTest::addColumn("angle"); + QTest::addColumn("returnValue"); + + QTest::addRow("normalAngle__returnsTrue") << 30.0 << 60.0 << false << 45.0 << true; + QTest::addRow("oppositeAngle__returnsFalse") << 30.0 << 60.0 << false << 225.0 << false; + QTest::addRow("normalAngle_bidirectional__returnsTrue") << 30.0 << 60.0 << true << 45.0 << true; + QTest::addRow("oppositeAngle_bidirectional__returnsFalse") << 30.0 << 60.0 << true << 225.0 << true; + } + + void canUpdate() + { + QFETCH(qreal, min); + QFETCH(qreal, max); + QFETCH(bool, bidirectional); + QFETCH(qreal, angle); + QFETCH(bool, returnValue); + + SwipeTrigger trigger(min, max); + trigger.setBidirectional(bidirectional); + + SwipeTriggerUpdateEvent event; + event.setAverageAngle(angle); + + QCOMPARE(trigger.canUpdate(event), returnValue); + } + + void updateActions_bidirectional_normalAngle__updatesActionsWithPositiveDelta() + { + MockSwipeTrigger trigger(0, 0); + trigger.setBidirectional(true); + EXPECT_CALL(trigger, doUpdateActions(Property(&TriggerUpdateEvent::delta, Property(&Delta::unaccelerated, Eq(10))))).Times(1); + + SwipeTriggerUpdateEvent event; + event.setAngle(0); + event.setDelta(10); + + trigger.updateActions(event); + + QVERIFY(Mock::VerifyAndClearExpectations(&trigger)); + } + + void updateActions_bidirectional_oppositeAngle__updatesActionsWithNegativeDelta() + { + MockSwipeTrigger trigger(0, 0); + trigger.setBidirectional(true); + EXPECT_CALL(trigger, doUpdateActions(Property(&TriggerUpdateEvent::delta, Property(&Delta::unaccelerated, Eq(-10))))).Times(1); + + SwipeTriggerUpdateEvent event; + event.setAngle(180); + event.setDelta(10); + + trigger.updateActions(event); + + QVERIFY(Mock::VerifyAndClearExpectations(&trigger)); + } + + void updateActions_bidirectional_overlappingAngleRanges__normalRangeHasHigherPriority() + { + MockSwipeTrigger trigger(0, 270); + trigger.setBidirectional(true); + EXPECT_CALL(trigger, doUpdateActions(Property(&TriggerUpdateEvent::delta, Property(&Delta::unaccelerated, Gt(-10))))).Times(2); + + SwipeTriggerUpdateEvent event; + event.setAngle(30); + event.setDelta(10); + trigger.updateActions(event); + + event.setAngle(260); + trigger.updateActions(event); + + QVERIFY(Mock::VerifyAndClearExpectations(&trigger)); + } + + void matchesAngleRange_data() + { + QTest::addColumn("a"); + QTest::addColumn("b"); + QTest::addColumn("angle"); + QTest::addColumn("result"); + + QTest::addRow("a true") << 90.0 << 270.0 << 180.0 << true; + QTest::addRow("a true") << 90.0 << 270.0 << 90.0 << true; + QTest::addRow("a true") << 90.0 << 270.0 << 270.0 << true; + QTest::addRow("a false") << 90.0 << 270.0 << 89.0 << false; + QTest::addRow("a false") << 90.0 << 270.0 << 271.0 << false; + QTest::addRow("a false") << 90.0 << 270.0 << 0.0 << false; + + QTest::addRow("a>b, middle => true") << 270.0 << 90.0 << 0.0 << true; + QTest::addRow("a>b, min => true") << 270.0 << 90.0 << 270.0 << true; + QTest::addRow("a>b, max => true") << 270.0 << 90.0 << 90.0 << true; + QTest::addRow("a>b, min-1 => false") << 270.0 << 90.0 << 269.0 << false; + QTest::addRow("a>b, max+1 => false") << 270.0 << 90.0 << 91.0 << false; + QTest::addRow("a>b, middle opposite => false") << 270.0 << 90.0 << 180.0 << false; + + QTest::addRow("a=b => true") << 0.0 << 0.0 << 0.0 << true; + QTest::addRow("a=b, opposite => false") << 0.0 << 0.0 << 180.0 << false; + } + + void matchesAngleRange() + { + QFETCH(qreal, a); + QFETCH(qreal, b); + QFETCH(qreal, angle); + QFETCH(bool, result); + + QCOMPARE(SwipeTrigger::matchesAngleRange(angle, a, b), result); + } + + void matchesOppositeAngleRange_data() + { + QTest::addColumn("a"); + QTest::addColumn("b"); + QTest::addColumn("angle"); + QTest::addColumn("result"); + + QTest::addRow("a true") << 90.0 << 270.0 << 0.0 << true; + QTest::addRow("a true") << 90.0 << 270.0 << 270.0 << true; + QTest::addRow("a true") << 90.0 << 270.0 << 90.0 << true; + QTest::addRow("a false") << 90.0 << 270.0 << 269.0 << false; + QTest::addRow("a false") << 90.0 << 270.0 << 91.0 << false; + QTest::addRow("a false") << 90.0 << 270.0 << 180.0 << false; + + QTest::addRow("a>b, middle opposite => true") << 270.0 << 90.0 << 180.0 << true; + QTest::addRow("a>b, min opposite => true") << 270.0 << 90.0 << 90.0 << true; + QTest::addRow("a>b, max opposite => true") << 270.0 << 90.0 << 270.0 << true; + QTest::addRow("a>b, min-1 opposite => false") << 270.0 << 90.0 << 89.0 << false; + QTest::addRow("a>b, max+1 opposite => false") << 270.0 << 90.0 << 271.0 << false; + QTest::addRow("a>b, middle normal => false") << 270.0 << 90.0 << 0.0 << false; + + QTest::addRow("a=b, opposite => true") << 0.0 << 0.0 << 180.0 << true; + QTest::addRow("a=b, normal => false") << 0.0 << 0.0 << 0.0 << false; + } + + void matchesOppositeAngleRange() + { + QFETCH(qreal, a); + QFETCH(qreal, b); + QFETCH(qreal, angle); + QFETCH(bool, result); + + QCOMPARE(SwipeTrigger::matchesOppositeAngleRange(angle, a, b), result); + } +}; } -QTEST_MAIN(InputActions::TestSwipeTrigger) \ No newline at end of file +QTEST_MAIN(InputActions::TestSwipeTrigger) +#include "TestSwipeTrigger.moc" \ No newline at end of file diff --git a/tests/libinputactions/triggers/TestSwipeTrigger.h b/tests/libinputactions/triggers/TestSwipeTrigger.h deleted file mode 100644 index 5319425..0000000 --- a/tests/libinputactions/triggers/TestSwipeTrigger.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include "Test.h" - -namespace InputActions -{ - -class TestSwipeTrigger : public Test -{ - Q_OBJECT - -private slots: - void canUpdate_currentAngleDoesNotMatchRange_averageAngleMatchesRange__returnsTrue(); - void canUpdate_currentAngleMatchesRange_averageAngleDoesNotMatchRange__returnsFalse(); - - void canUpdate_data(); - void canUpdate(); - - void updateActions_bidirectional_normalAngle__updatesActionsWithPositiveDelta(); - void updateActions_bidirectional_oppositeAngle__updatesActionsWithNegativeDelta(); - void updateActions_bidirectional_overlappingAngleRanges__normalRangeHasHigherPriority(); - - void matchesAngleRange_data(); - void matchesAngleRange(); - - void matchesOppositeAngleRange_data(); - void matchesOppositeAngleRange(); -}; - -} \ No newline at end of file diff --git a/tests/libinputactions/triggers/TestTrigger.cpp b/tests/libinputactions/triggers/TestTrigger.cpp index 37504b8..306b983 100644 --- a/tests/libinputactions/triggers/TestTrigger.cpp +++ b/tests/libinputactions/triggers/TestTrigger.cpp @@ -1,106 +1,114 @@ -#include "TestTrigger.h" +#include "Test.h" #include #include +#include namespace InputActions { -void TestTrigger::init() +class TestTrigger : public Test { - m_trigger = std::make_unique(); -} - -void TestTrigger::canActivate_mouseButtons_data() -{ - QTest::addColumn>>("triggerButtons"); - QTest::addColumn>>("eventButtons"); - QTest::addColumn("orderMatters"); - QTest::addColumn("result"); - - const auto unset = std::optional>(); - const auto none = std::optional>(std::vector()); - const auto left = std::optional>{{BTN_LEFT}}; - const auto right = std::optional>{{BTN_RIGHT}}; - const auto leftRight = std::optional>{{BTN_LEFT, BTN_RIGHT}}; - const auto rightLeft = std::optional>{{BTN_RIGHT, BTN_LEFT}}; - - QTest::newRow("1") << left << unset << false << true; - QTest::newRow("3") << left << left << false << true; - QTest::newRow("4") << right << left << false << false; - QTest::newRow("5") << left << right << false << false; - QTest::newRow("6") << leftRight << left << false << false; - QTest::newRow("7") << left << leftRight << false << false; - - QTest::newRow("8") << left << unset << true << true; - QTest::newRow("9") << left << left << true << true; - QTest::newRow("10") << right << left << true << false; - QTest::newRow("11") << left << right << true << false; - QTest::newRow("12") << leftRight << left << true << false; - QTest::newRow("13") << left << leftRight << true << false; - - QTest::newRow("14") << leftRight << leftRight << false << true; - QTest::newRow("15") << leftRight << rightLeft << false << true; - QTest::newRow("16") << rightLeft << leftRight << false << true; - - QTest::newRow("17") << leftRight << rightLeft << true << false; - QTest::newRow("18") << rightLeft << leftRight << true << false; - - QTest::newRow("19") << none << unset << false << true; - QTest::newRow("20") << none << left << false << true; - QTest::newRow("21") << none << unset << true << true; - QTest::newRow("22") << none << left << true << true; -} - -void TestTrigger::canActivate_mouseButtons() -{ - QFETCH(std::optional>, triggerButtons); - QFETCH(std::optional>, eventButtons); - QFETCH(bool, orderMatters); - QFETCH(bool, result); - - TriggerActivationEvent event; - m_trigger->setMouseButtons(triggerButtons.value()); - m_trigger->setMouseButtonsExactOrder(orderMatters); - event.setMouseButtons(eventButtons); - QCOMPARE(m_trigger->canActivate(event), result); -} + Q_OBJECT + +private slots: + void init() { m_trigger = std::make_unique(); } + + void canActivate_mouseButtons_data() + { + QTest::addColumn>>("triggerButtons"); + QTest::addColumn>>("eventButtons"); + QTest::addColumn("orderMatters"); + QTest::addColumn("result"); + + const auto unset = std::optional>(); + const auto none = std::optional>(std::vector()); + const auto left = std::optional>{{BTN_LEFT}}; + const auto right = std::optional>{{BTN_RIGHT}}; + const auto leftRight = std::optional>{{BTN_LEFT, BTN_RIGHT}}; + const auto rightLeft = std::optional>{{BTN_RIGHT, BTN_LEFT}}; + + QTest::newRow("1") << left << unset << false << true; + QTest::newRow("3") << left << left << false << true; + QTest::newRow("4") << right << left << false << false; + QTest::newRow("5") << left << right << false << false; + QTest::newRow("6") << leftRight << left << false << false; + QTest::newRow("7") << left << leftRight << false << false; + + QTest::newRow("8") << left << unset << true << true; + QTest::newRow("9") << left << left << true << true; + QTest::newRow("10") << right << left << true << false; + QTest::newRow("11") << left << right << true << false; + QTest::newRow("12") << leftRight << left << true << false; + QTest::newRow("13") << left << leftRight << true << false; + + QTest::newRow("14") << leftRight << leftRight << false << true; + QTest::newRow("15") << leftRight << rightLeft << false << true; + QTest::newRow("16") << rightLeft << leftRight << false << true; + + QTest::newRow("17") << leftRight << rightLeft << true << false; + QTest::newRow("18") << rightLeft << leftRight << true << false; + + QTest::newRow("19") << none << unset << false << true; + QTest::newRow("20") << none << left << false << true; + QTest::newRow("21") << none << unset << true << true; + QTest::newRow("22") << none << left << true << true; + } -void TestTrigger::update_threshold_data() -{ - QTest::addColumn>>("threshold"); - QTest::addColumn>("deltas"); - QTest::addColumn("actionExecuted"); - - // total delta > threshold is tested to ensure the begin action only executes once - QTest::newRow("no threshold, 0 delta") << std::optional>() << std::vector{0} << true; - QTest::newRow("total delta < min_threshold") << std::optional>(Range(3, {})) << std::vector{1, 1} << false; - QTest::newRow("total delta > min_threshold") << std::optional>(Range(3, {})) << std::vector{2, 2} << true; - QTest::newRow("delta1, delta2 > max_threshold") << std::optional>(Range({}, 3)) << std::vector{4, 4} << false; - QTest::newRow("total delta > max_threshold") << std::optional>(Range({}, 3)) << std::vector{2, 2} << true; -} + void canActivate_mouseButtons() + { + QFETCH(std::optional>, triggerButtons); + QFETCH(std::optional>, eventButtons); + QFETCH(bool, orderMatters); + QFETCH(bool, result); + + TriggerActivationEvent event; + m_trigger->setMouseButtons(triggerButtons.value()); + m_trigger->setMouseButtonsExactOrder(orderMatters); + event.setMouseButtons(eventButtons); + QCOMPARE(m_trigger->canActivate(event), result); + } -void TestTrigger::update_threshold() -{ - QFETCH(std::optional>, threshold); - QFETCH(std::vector, deltas); - QFETCH(bool, actionExecuted); - - auto action = std::make_unique(); - const auto *actionRaw = action.get(); - action->setOn(On::Begin); - m_trigger->addAction(std::move(action)); - if (threshold) { - m_trigger->setThreshold(threshold.value()); + void update_threshold_data() + { + QTest::addColumn>>("threshold"); + QTest::addColumn>("deltas"); + QTest::addColumn("actionExecuted"); + + // total delta > threshold is tested to ensure the begin action only executes once + QTest::newRow("no threshold, 0 delta") << std::optional>() << std::vector{0} << true; + QTest::newRow("total delta < min_threshold") << std::optional>(Range(3, {})) << std::vector{1, 1} << false; + QTest::newRow("total delta > min_threshold") << std::optional>(Range(3, {})) << std::vector{2, 2} << true; + QTest::newRow("delta1, delta2 > max_threshold") << std::optional>(Range({}, 3)) << std::vector{4, 4} << false; + QTest::newRow("total delta > max_threshold") << std::optional>(Range({}, 3)) << std::vector{2, 2} << true; } - TriggerUpdateEvent event; - for (const auto &delta : deltas) { - event.setDelta(delta); - m_trigger->update(event); + void update_threshold() + { + QFETCH(std::optional>, threshold); + QFETCH(std::vector, deltas); + QFETCH(bool, actionExecuted); + + auto action = std::make_unique(); + const auto *actionRaw = action.get(); + action->setOn(On::Begin); + m_trigger->addAction(std::move(action)); + if (threshold) { + m_trigger->setThreshold(threshold.value()); + } + + TriggerUpdateEvent event; + for (const auto &delta : deltas) { + event.setDelta(delta); + m_trigger->update(event); + } + QCOMPARE(actionRaw->action()->executions(), actionExecuted); } - QCOMPARE(actionRaw->action()->executions(), actionExecuted); -} + +private: + std::unique_ptr m_trigger; +}; } -QTEST_MAIN(InputActions::TestTrigger) \ No newline at end of file +QTEST_MAIN(InputActions::TestTrigger) +#include "TestTrigger.moc" \ No newline at end of file diff --git a/tests/libinputactions/triggers/TestTrigger.h b/tests/libinputactions/triggers/TestTrigger.h deleted file mode 100644 index b5afed6..0000000 --- a/tests/libinputactions/triggers/TestTrigger.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "Test.h" -#include - -namespace InputActions -{ - -class TestTrigger : public Test -{ - Q_OBJECT - -private slots: - void init(); - - void canActivate_mouseButtons_data(); - void canActivate_mouseButtons(); - - void update_threshold_data(); - void update_threshold(); - -private: - std::unique_ptr m_trigger; -}; - -} \ No newline at end of file