diff options
author | Vasudev Kamath <vasudev@copyninja.info> | 2016-10-23 21:09:40 +0530 |
---|---|---|
committer | Vasudev Kamath <vasudev@copyninja.info> | 2016-10-23 21:09:40 +0530 |
commit | eda4b75b1cff83336e87da90efca9fd6b4ced2c7 (patch) | |
tree | 491317ce50b5d19bc434ccc4b448d1bc70520177 /tests/config.cpp | |
parent | 716c40e4ec45f8d538695225f4f06d541d959084 (diff) | |
parent | 0f14fe83ef53b08bd8fa09670c82f4996c329bdc (diff) | |
download | biboumi-upstream/3.0.tar.gz biboumi-upstream/3.0.tar.bz2 biboumi-upstream/3.0.tar.xz biboumi-upstream/3.0.zip |
New upstream version 3.0upstream/3.0
Diffstat (limited to 'tests/config.cpp')
-rw-r--r-- | tests/config.cpp | 54 |
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); +} |