aboutsummaryrefslogtreecommitdiff
path: root/lib/configuration/test/qt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/configuration/test/qt.cpp')
-rw-r--r--lib/configuration/test/qt.cpp71
1 files changed, 71 insertions, 0 deletions
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;
+}