~singpolyma/biboumi

ref: 46ff73662cc94220c5ee962b591c8ee327de6f85 biboumi/tests/config.cpp -rw-r--r-- 1.2 KiB
46ff7366 — louiz’ Clean the Config module, use static things instead of a stupid singleton 6 years ago
                                                                                
3c1889fb Florent Le Coz
46ff7366 louiz’
3c1889fb Florent Le Coz
46ff7366 louiz’
3c1889fb Florent Le Coz
46ff7366 louiz’
3c1889fb Florent Le Coz
46ff7366 louiz’
3c1889fb Florent Le Coz
66887c22 Florent Le Coz
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);
}