summaryrefslogtreecommitdiff
path: root/tests/config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/config.cpp')
-rw-r--r--tests/config.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/config.cpp b/tests/config.cpp
new file mode 100644
index 0000000..ddea151
--- /dev/null
+++ b/tests/config.cpp
@@ -0,0 +1,54 @@
+#include "catch.hpp"
+
+#include <config/config.hpp>
+
+TEST_CASE("Config basic")
+{
+ // Write a value in the config file
+ Config::read_conf("test.cfg");
+ Config::set("coucou", "bonjour", true);
+ Config::clear();
+
+ bool error = false;
+ try
+ {
+ CHECK(Config::read_conf());
+ CHECK(Config::get("coucou", "") == "bonjour");
+ CHECK(Config::get("does not exist", "default") == "default");
+ Config::clear();
+ }
+ catch (const std::ios::failure& e)
+ {
+ error = true;
+ }
+ CHECK_FALSE(error);
+}
+
+TEST_CASE("Config callbacks")
+{
+ bool switched = false;
+ Config::connect([&switched]()
+ {
+ switched = !switched;
+ });
+ CHECK_FALSE(switched);
+ Config::set("un", "deux", true);
+ CHECK(switched);
+ Config::set("un", "trois", true);
+ CHECK_FALSE(switched);
+
+ Config::set("un", "trois", false);
+ CHECK_FALSE(switched);
+}
+
+TEST_CASE("Config get_int")
+{
+ auto res = Config::get_int("number", 0);
+ CHECK(res == 0);
+ Config::set("number", "88");
+ res = Config::get_int("number", 0);
+ CHECK(res == 88);
+ Config::set("number", "pouet");
+ res = Config::get_int("number", -1);
+ CHECK(res == 0);
+}