1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
}
|