From 92b3c2dcff3e85ad3d455f6ab845d9a97d3b525b Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 7 Dec 2020 12:22:15 +0200 Subject: Rewrite meson build scripts into cmakelists --- lib/configuration/test/main.cpp | 39 ++-------------------- lib/configuration/test/qt.cpp | 71 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 36 deletions(-) create mode 100644 lib/configuration/test/qt.cpp (limited to 'lib/configuration/test') 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 #include SCENARIO("Configuration") @@ -32,7 +30,7 @@ SCENARIO("Configuration") WHEN("reading default values") { REQUIRE(conf.value("name")); - REQUIRE(conf.value("name").value() == std::string()); + REQUIRE(conf.value("name").value().empty()); REQUIRE(conf.value("number")); REQUIRE(conf.value("number").value() == 0); REQUIRE(conf.value("toggle")); @@ -43,7 +41,7 @@ SCENARIO("Configuration") REQUIRE(!conf.value("nullopt")); REQUIRE(conf.value("main/name")); - REQUIRE(conf.value("main/name").value() == std::string()); + REQUIRE(conf.value("main/name").value().empty()); REQUIRE(conf.value("main/number")); REQUIRE(conf.value("main/number").value() == 0); REQUIRE(conf.value("main/toggle")); @@ -101,30 +99,6 @@ SCENARIO("Configuration") REQUIRE(conf.value("toggle").value() == "true"); REQUIRE(conf.value("main/toggle").value() == "false"); } - - THEN("Qt cast specialization") - { - REQUIRE(conf.value("name").value() == "Top level"); - REQUIRE(conf.value("number").value() == "12"); - REQUIRE(conf.value("toggle").value() == "true"); - REQUIRE(conf.value("main/toggle").value() == "false"); - REQUIRE(!conf.value("nullopt")); - - REQUIRE(conf.value("list").value() == QStringList({ "one", "two", "three", "for four" })); - REQUIRE(!conf.value("nullopt")); - } - - THEN("Qt shortcut") - { - REQUIRE(conf.value("qt/shortcut") == "Ctrl+Q"); - QAction action; - REQUIRE(conf.shortcut(action, "qt/shortcut").shortcut().toString() == "Ctrl+Q"); - REQUIRE(conf.shortcut(action, "qt/nil").shortcut().toString() == "Ctrl+Q"); - - QKeySequence sequence; - REQUIRE(conf.shortcut(sequence, "qt/shortcut").toString() == "Ctrl+Q"); - REQUIRE(conf.shortcut(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 +#include + +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("name").value() == "Top level"); + REQUIRE(conf.value("number").value() == "12"); + REQUIRE(conf.value("toggle").value() == "true"); + REQUIRE(conf.value("main/toggle").value() == "false"); + REQUIRE(!conf.value("nullopt")); + + REQUIRE(conf.value("list").value() == QStringList({ "one", "two", "three", "for four" })); + REQUIRE(!conf.value("nullopt")); + } + + THEN("Qt shortcut") + { + REQUIRE(conf.value("qt/shortcut") == "Ctrl+Q"); + QAction action; + REQUIRE(conf.shortcut(action, "qt/shortcut").shortcut().toString() == "Ctrl+Q"); + REQUIRE(conf.shortcut(action, "qt/nil").shortcut().toString() == "Ctrl+Q"); + + QKeySequence sequence; + REQUIRE(conf.shortcut(sequence, "qt/shortcut").toString() == "Ctrl+Q"); + REQUIRE(conf.shortcut(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; +} -- cgit v1.2.1