Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 39 additions & 31 deletions tests/libinputactions/TestRange.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
#include "TestRange.h"
#include "Test.h"
#include <libinputactions/Range.h>

namespace InputActions
{

void TestRange::contains_qreal_data()
class TestRange : public Test
{
QTest::addColumn<std::optional<qreal>>("min");
QTest::addColumn<std::optional<qreal>>("max");
QTest::addColumn<int>("value");
QTest::addColumn<bool>("result");

QTest::addRow("none, 0") << std::optional<qreal>() << std::optional<qreal>() << 0 << true;
QTest::addRow("none, positive") << std::optional<qreal>() << std::optional<qreal>() << 1 << true;
QTest::addRow("none, negative") << std::optional<qreal>() << std::optional<qreal>() << -1 << true;
QTest::addRow("min, below") << std::optional<qreal>{1} << std::optional<qreal>() << -1 << false;
QTest::addRow("min, equal") << std::optional<qreal>{1} << std::optional<qreal>() << 1 << true;
QTest::addRow("min, above") << std::optional<qreal>{1} << std::optional<qreal>() << 2 << true;
QTest::addRow("max, below") << std::optional<qreal>() << std::optional<qreal>{1} << -1 << true;
QTest::addRow("max, equal") << std::optional<qreal>() << std::optional<qreal>{1} << 1 << true;
QTest::addRow("max, above") << std::optional<qreal>() << std::optional<qreal>{1} << 2 << false;
QTest::addRow("minmax, below") << std::optional<qreal>{-1} << std::optional<qreal>{1} << -2 << false;
QTest::addRow("minmax, equal to min") << std::optional<qreal>{-1} << std::optional<qreal>{1} << -1 << true;
QTest::addRow("minmax, between") << std::optional<qreal>{-1} << std::optional<qreal>{1} << 0 << true;
QTest::addRow("minmax, equal to max") << std::optional<qreal>{-1} << std::optional<qreal>{1} << 1 << true;
QTest::addRow("minmax, above") << std::optional<qreal>{-1} << std::optional<qreal>{1} << 2 << false;
}
Q_OBJECT

void TestRange::contains_qreal()
{
QFETCH(std::optional<qreal>, min);
QFETCH(std::optional<qreal>, max);
QFETCH(int, value);
QFETCH(bool, result);
private slots:
void contains_qreal_data()
{
QTest::addColumn<std::optional<qreal>>("min");
QTest::addColumn<std::optional<qreal>>("max");
QTest::addColumn<int>("value");
QTest::addColumn<bool>("result");

QCOMPARE(Range<qreal>(min, max).contains(value), result);
}
QTest::addRow("none, 0") << std::optional<qreal>() << std::optional<qreal>() << 0 << true;
QTest::addRow("none, positive") << std::optional<qreal>() << std::optional<qreal>() << 1 << true;
QTest::addRow("none, negative") << std::optional<qreal>() << std::optional<qreal>() << -1 << true;
QTest::addRow("min, below") << std::optional<qreal>{1} << std::optional<qreal>() << -1 << false;
QTest::addRow("min, equal") << std::optional<qreal>{1} << std::optional<qreal>() << 1 << true;
QTest::addRow("min, above") << std::optional<qreal>{1} << std::optional<qreal>() << 2 << true;
QTest::addRow("max, below") << std::optional<qreal>() << std::optional<qreal>{1} << -1 << true;
QTest::addRow("max, equal") << std::optional<qreal>() << std::optional<qreal>{1} << 1 << true;
QTest::addRow("max, above") << std::optional<qreal>() << std::optional<qreal>{1} << 2 << false;
QTest::addRow("minmax, below") << std::optional<qreal>{-1} << std::optional<qreal>{1} << -2 << false;
QTest::addRow("minmax, equal to min") << std::optional<qreal>{-1} << std::optional<qreal>{1} << -1 << true;
QTest::addRow("minmax, between") << std::optional<qreal>{-1} << std::optional<qreal>{1} << 0 << true;
QTest::addRow("minmax, equal to max") << std::optional<qreal>{-1} << std::optional<qreal>{1} << 1 << true;
QTest::addRow("minmax, above") << std::optional<qreal>{-1} << std::optional<qreal>{1} << 2 << false;
}

void contains_qreal()
{
QFETCH(std::optional<qreal>, min);
QFETCH(std::optional<qreal>, max);
QFETCH(int, value);
QFETCH(bool, result);

QCOMPARE(Range<qreal>(min, max).contains(value), result);
}
};

}

QTEST_MAIN(InputActions::TestRange)
QTEST_MAIN(InputActions::TestRange)
#include "TestRange.moc"
18 changes: 0 additions & 18 deletions tests/libinputactions/TestRange.h

This file was deleted.

94 changes: 49 additions & 45 deletions tests/libinputactions/TestValue.cpp
Original file line number Diff line number Diff line change
@@ -1,62 +1,66 @@
#include "TestValue.h"
#include "Test.h"
#include <libinputactions/Value.h>
#include <libinputactions/variables/VariableManager.h>

namespace InputActions
{

void TestValue::init()
class TestValue : public Test
{
g_variableManager = std::make_shared<VariableManager>();
}
Q_OBJECT

void TestValue::get_defaultConstructor_returnsNullopt()
{
const Value<bool> value;
QVERIFY(!value.get().has_value());
}
private slots:
void init() { g_variableManager = std::make_shared<VariableManager>(); }

void TestValue::get_valueConstructor()
{
const Value<bool> value(true);
QVERIFY(value.get().value());
}
void get_defaultConstructor_returnsNullopt()
{
const Value<bool> value;
QVERIFY(!value.get().has_value());
}

void TestValue::get_command()
{
const auto value = Value<QString>::command(Value<QString>("echo -n a"));
QCOMPARE(value.get().value(), "a");
}
void get_valueConstructor()
{
const Value<bool> value(true);
QVERIFY(value.get().value());
}

void TestValue::get_commandNullValue_returnsNullopt()
{
const auto value = Value<QString>::command({});
QVERIFY(!value.get().has_value());
}
void get_command()
{
const auto value = Value<QString>::command(Value<QString>("echo -n a"));
QCOMPARE(value.get().value(), "a");
}

void TestValue::get_function()
{
const auto value = Value<bool>::function([]() {
return true;
});
QVERIFY(value.get().value());
}
void get_commandNullValue_returnsNullopt()
{
const auto value = Value<QString>::command({});
QVERIFY(!value.get().has_value());
}

void TestValue::get_existentVariable()
{
g_variableManager->registerRemoteVariable<bool>("_test", [](auto &value) {
value = true;
});
const auto value = Value<bool>::variable("_test");
QVERIFY(value.get().value());
}
void get_function()
{
const auto value = Value<bool>::function([]() {
return true;
});
QVERIFY(value.get().value());
}

void TestValue::get_nonExistentVariable_returnsNullopt()
{
const auto value = Value<bool>::variable("_test");
QVERIFY(!value.get().has_value());
}
void get_existentVariable()
{
g_variableManager->registerRemoteVariable<bool>("_test", [](auto &value) {
value = true;
});
const auto value = Value<bool>::variable("_test");
QVERIFY(value.get().value());
}

void get_nonExistentVariable_returnsNullopt()
{
const auto value = Value<bool>::variable("_test");
QVERIFY(!value.get().has_value());
}
};

}

QTEST_MAIN(InputActions::TestValue)
QTEST_MAIN(InputActions::TestValue)
#include "TestValue.moc"
27 changes: 0 additions & 27 deletions tests/libinputactions/TestValue.h

This file was deleted.

55 changes: 31 additions & 24 deletions tests/libinputactions/actions/TestAction.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
#include "TestAction.h"
#include "Test.h"
#include <libinputactions/actions/Action.h>
#include <libinputactions/actions/ActionExecutor.h>

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)
QTEST_MAIN(InputActions::TestAction)
#include "TestAction.moc"
17 changes: 0 additions & 17 deletions tests/libinputactions/actions/TestAction.h

This file was deleted.

Loading