diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-12-07 12:22:15 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-12-07 12:22:15 +0200 |
commit | 92b3c2dcff3e85ad3d455f6ab845d9a97d3b525b (patch) | |
tree | a850643f7b86e6cebfddbeec98d7c372478d379c /lib/configuration/test | |
parent | Hostlist filter plugin can rewrite hostnames (diff) | |
download | smolbote-92b3c2dcff3e85ad3d455f6ab845d9a97d3b525b.tar.xz |
Rewrite meson build scripts into cmakelists
Diffstat (limited to 'lib/configuration/test')
-rw-r--r-- | lib/configuration/test/main.cpp | 39 | ||||
-rw-r--r-- | lib/configuration/test/qt.cpp | 71 |
2 files changed, 74 insertions, 36 deletions
diff --git a/lib/configuration/test/main.cpp b/lib/configuration/test/main.cpp index d83f7af..9c83f8b 100644 --- a/lib/configuration/test/main.cpp +++ b/lib/configuration/test/main.cpp @@ -1,9 +1,7 @@ -#define CATCH_CONFIG_RUNNER - // clazy:excludeall=non-pod-global-static +#define CATCH_CONFIG_MAIN #include "configuration.h" -#include <QApplication> #include <catch2/catch.hpp> SCENARIO("Configuration") @@ -32,7 +30,7 @@ SCENARIO("Configuration") WHEN("reading default values") { REQUIRE(conf.value<std::string>("name")); - REQUIRE(conf.value<std::string>("name").value() == std::string()); + REQUIRE(conf.value<std::string>("name").value().empty()); REQUIRE(conf.value<int>("number")); REQUIRE(conf.value<int>("number").value() == 0); REQUIRE(conf.value<bool>("toggle")); @@ -43,7 +41,7 @@ SCENARIO("Configuration") REQUIRE(!conf.value<std::string>("nullopt")); REQUIRE(conf.value<std::string>("main/name")); - REQUIRE(conf.value<std::string>("main/name").value() == std::string()); + REQUIRE(conf.value<std::string>("main/name").value().empty()); REQUIRE(conf.value<int>("main/number")); REQUIRE(conf.value<int>("main/number").value() == 0); REQUIRE(conf.value<bool>("main/toggle")); @@ -101,30 +99,6 @@ SCENARIO("Configuration") REQUIRE(conf.value<std::string>("toggle").value() == "true"); REQUIRE(conf.value<std::string>("main/toggle").value() == "false"); } - - THEN("Qt cast specialization") - { - REQUIRE(conf.value<QString>("name").value() == "Top level"); - REQUIRE(conf.value<QString>("number").value() == "12"); - REQUIRE(conf.value<QString>("toggle").value() == "true"); - REQUIRE(conf.value<QString>("main/toggle").value() == "false"); - REQUIRE(!conf.value<QString>("nullopt")); - - REQUIRE(conf.value<QStringList>("list").value() == QStringList({ "one", "two", "three", "for four" })); - REQUIRE(!conf.value<QStringList>("nullopt")); - } - - THEN("Qt shortcut") - { - REQUIRE(conf.value<std::string>("qt/shortcut") == "Ctrl+Q"); - QAction action; - REQUIRE(conf.shortcut<QAction>(action, "qt/shortcut").shortcut().toString() == "Ctrl+Q"); - REQUIRE(conf.shortcut<QAction>(action, "qt/nil").shortcut().toString() == "Ctrl+Q"); - - QKeySequence sequence; - REQUIRE(conf.shortcut<QKeySequence>(sequence, "qt/shortcut").toString() == "Ctrl+Q"); - REQUIRE(conf.shortcut<QKeySequence>(sequence, "qt/nil").toString() == "Ctrl+Q"); - } } } @@ -167,10 +141,3 @@ SCENARIO("Configuration") } } } - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - int result = Catch::Session().run(argc, argv); - return result; -} diff --git a/lib/configuration/test/qt.cpp b/lib/configuration/test/qt.cpp new file mode 100644 index 0000000..44114df --- /dev/null +++ b/lib/configuration/test/qt.cpp @@ -0,0 +1,71 @@ +// clazy:excludeall=non-pod-global-static +#define CATCH_CONFIG_RUNNER + +#include "configuration.h" +#include <QApplication> +#include <catch2/catch.hpp> + +SCENARIO("Configuration") +{ + GIVEN("a Configuration object with some initial values") + { + Configuration conf{ + { "name", std::string() }, + { "over", std::string() }, + // this entry is not in the conf file + { "other", std::string("not in cfg") }, + // commented out entry in the conf file + { "comment", std::string("123.456") }, + { "number", 0 }, + { "toggle", false }, + + { "main/name", std::string() }, + { "main/number", 0 }, + { "main/toggle", true }, + + { "extra/name", std::string() }, + { "extra/number", 0 }, + { "extra/toggle", false }, + }; + + WHEN("reading default values") + { + } + + WHEN("reading configuration file") + { + conf.read_file(std::getenv("CONFIGFILE")); + + THEN("Qt cast specialization") + { + REQUIRE(conf.value<QString>("name").value() == "Top level"); + REQUIRE(conf.value<QString>("number").value() == "12"); + REQUIRE(conf.value<QString>("toggle").value() == "true"); + REQUIRE(conf.value<QString>("main/toggle").value() == "false"); + REQUIRE(!conf.value<QString>("nullopt")); + + REQUIRE(conf.value<QStringList>("list").value() == QStringList({ "one", "two", "three", "for four" })); + REQUIRE(!conf.value<QStringList>("nullopt")); + } + + THEN("Qt shortcut") + { + REQUIRE(conf.value<std::string>("qt/shortcut") == "Ctrl+Q"); + QAction action; + REQUIRE(conf.shortcut<QAction>(action, "qt/shortcut").shortcut().toString() == "Ctrl+Q"); + REQUIRE(conf.shortcut<QAction>(action, "qt/nil").shortcut().toString() == "Ctrl+Q"); + + QKeySequence sequence; + REQUIRE(conf.shortcut<QKeySequence>(sequence, "qt/shortcut").toString() == "Ctrl+Q"); + REQUIRE(conf.shortcut<QKeySequence>(sequence, "qt/nil").toString() == "Ctrl+Q"); + } + } + } +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + int result = Catch::Session().run(argc, argv); + return result; +} |