Newer
Older
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
#include "catch.hpp"
#include <ftl/configurable.hpp>
using ftl::Configurable;
using std::string;
SCENARIO( "Configurable::get()" ) {
GIVEN( "a non-existent property" ) {
nlohmann::json json = {{"test",5}};
Configurable cfg(json);
auto r = cfg.get<int>("test2");
REQUIRE( !r );
}
GIVEN( "a valid property" ) {
nlohmann::json json = {{"test",5}};
Configurable cfg(json);
auto r = cfg.get<int>("test");
REQUIRE( r );
REQUIRE( *r == 5 );
}
}
SCENARIO( "Configurable::on()" ) {
GIVEN( "a changed property with no handlers" ) {
nlohmann::json json = {{"test",5}};
Configurable cfg(json);
cfg.set("test", 55);
REQUIRE( *(cfg.get<int>("test")) == 55 );
}
GIVEN( "a changed property one handler" ) {
nlohmann::json json = {{"test",5}};
Configurable cfg(json);
bool trig = false;
trig = true;
});
cfg.set("test", 55);
REQUIRE( trig );
}
GIVEN( "a changed property two handlers" ) {
nlohmann::json json = {{"test",5}};
Configurable cfg(json);
bool trig1 = false;
bool trig2 = false;
trig2 = true;
});
cfg.set("test", 55);
REQUIRE( (trig1 && trig2) );
}
}