~singpolyma/biboumi

ref: 0bb4f144fcded6b5753b5de7493b7b10474c9a1f biboumi/tests/config.cpp -rw-r--r-- 1.3 KiB
0bb4f144 — Félix Baylac-Jacqué CLI: Add a test config flag 2 years ago
                                                                                
3c1889fb Florent Le Coz
34bd8b93 louiz’
3c1889fb Florent Le Coz
34bd8b93 louiz’
4cc3dc03 louiz’
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
55
56
57
58
59
#include "catch.hpp"
#include "io_tester.hpp"

#include <iostream>

#include <config/config.hpp>

TEST_CASE("Config basic")
{
  // Disable all output for this test
  IoTester<std::ostream> out(std::cerr);
  // 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);
}