Commit c5a68ad8 authored by Dominik Charousset's avatar Dominik Charousset

Add tests for synchronizing config members

parent 595a8e30
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "caf/test/dsl.hpp" #include "caf/test/dsl.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/config_option_set.hpp" #include "caf/config_option_set.hpp"
#include "caf/config_value_object_access.hpp" #include "caf/config_value_object_access.hpp"
...@@ -254,4 +255,65 @@ CAF_TEST(object access from CLI arguments - foobar_foobar) { ...@@ -254,4 +255,65 @@ CAF_TEST(object access from CLI arguments - foobar_foobar) {
fbfb({123, "hello"}, {1, "world!"})); fbfb({123, "hello"}, {1, "world!"}));
} }
namespace {
constexpr const char* config_text = R"__(
arg1 = {
foo = 42
bar = "Don't panic!"
}
arg2 = {
x = {
foo = 1
bar = "hello"
}
y = {
foo = 2
bar = "world"
}
}
)__";
struct test_config : actor_system_config {
test_config() {
opt_group{custom_options_, "global"}
.add(fb, "arg1,1", "some foobar")
.add(fbfb, "arg2,2", "somme foobar-foobar");
}
foobar fb;
foobar_foobar fbfb;
};
} // namespace
CAF_TEST(object access from actor system config - file input) {
test_config cfg;
std::istringstream in{config_text};
if (auto err = cfg.parse(0, nullptr, in))
CAF_FAIL("cfg.parse failed: " << cfg.render(err));
CAF_CHECK_EQUAL(cfg.fb.foo, 42);
CAF_CHECK_EQUAL(cfg.fb.bar, "Don't panic!");
CAF_CHECK_EQUAL(cfg.fbfb.x.foo, 1);
CAF_CHECK_EQUAL(cfg.fbfb.y.foo, 2);
CAF_CHECK_EQUAL(cfg.fbfb.x.bar, "hello");
CAF_CHECK_EQUAL(cfg.fbfb.y.bar, "world");
}
CAF_TEST(object access from actor system config - file input and arguments) {
std::vector<std::string> args{
"-2",
"{y = {bar = CAF, foo = 20}, x = {foo = 10, bar = hello}}",
};
test_config cfg;
std::istringstream in{config_text};
if (auto err = cfg.parse(std::move(args), in))
CAF_FAIL("cfg.parse failed: " << cfg.render(err));
CAF_CHECK_EQUAL(cfg.fb.foo, 42);
CAF_CHECK_EQUAL(cfg.fb.bar, "Don't panic!");
CAF_CHECK_EQUAL(cfg.fbfb.x.foo, 10);
CAF_CHECK_EQUAL(cfg.fbfb.y.foo, 20);
CAF_CHECK_EQUAL(cfg.fbfb.x.bar, "hello");
CAF_CHECK_EQUAL(cfg.fbfb.y.bar, "CAF");
}
CAF_TEST_FIXTURE_SCOPE_END() CAF_TEST_FIXTURE_SCOPE_END()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment