/* This file is part of xdgcfg. */ #include #include #include #include "../src/xdgcfg.hpp" using std::string; SCENARIO ("A config file can be written and then read.") { bool exception = false; WHEN ("Writing config") { xdgcfg config("test.cfg", "xdgcfg"); libconfig::Config &cfg = config.get_cfg(); libconfig::Setting &root = cfg.getRoot(); try { root.add("Hello", libconfig::Setting::TypeString) = "World! 🙂"; config.write(); } catch (const std::exception &e) { exception = true; } THEN ("No exception is thrown") { REQUIRE_FALSE(exception); } WHEN ("Reading config") { string value; try { value = root["Hello"].c_str(); } catch (const std::exception &e) { exception = true; } THEN ("No exception is thrown") AND_THEN ("Value is correct") { REQUIRE_FALSE(exception); REQUIRE(value == "World! 🙂"); } } } }