// 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; }