22 #include <boost/property_tree/ptree.hpp>
23 #include <gtest/gtest.h>
30 static std::string gl_data_path;
41 boost::property_tree::ptree empty_cfg;
42 empty_cfg.add<std::string>(
"instance_name",
"OoOoO");
43 cfg0 = std::make_shared<ConfigManager>(empty_cfg);
47 cfg1 = std::make_shared<ConfigManager>(cfg_tree.get_child(
"kernel"));
51 cfg2 = std::make_shared<ConfigManager>(cfg_tree.get_child(
"kernel"));
55 cfg3 = std::make_shared<ConfigManager>(cfg_tree.get_child(
"kernel"));
59 cfg4 = std::make_shared<ConfigManager>(cfg_tree.get_child(
"kernel"));
63 cfg5 = std::make_shared<ConfigManager>(cfg_tree.get_child(
"kernel"));
67 cfg6 = std::make_shared<ConfigManager>(cfg_tree.get_child(
"kernel"));
71 cfg7 = std::make_shared<ConfigManager>(cfg_tree.get_child(
"kernel"));
75 cfg8 = std::make_shared<ConfigManager>(cfg_tree.get_child(
"kernel"));
79 std::shared_ptr<ConfigManager>
cfg0;
80 std::shared_ptr<ConfigManager>
cfg1;
81 std::shared_ptr<ConfigManager>
cfg2;
82 std::shared_ptr<ConfigManager>
cfg3;
83 std::shared_ptr<ConfigManager>
cfg4;
84 std::shared_ptr<ConfigManager>
cfg5;
85 std::shared_ptr<ConfigManager>
cfg6;
86 std::shared_ptr<ConfigManager>
cfg7;
87 std::shared_ptr<ConfigManager>
cfg8;
93 boost::property_tree::ptree my_module_cfg;
95 ASSERT_FALSE(cfg0->store_config(
"my", my_module_cfg));
97 ASSERT_TRUE(cfg0->store_config(
"my", my_module_cfg));
99 auto cfg = cfg0->load_config(
"my");
100 ASSERT_EQ(my_module_cfg, cfg);
105 auto network_cfg = cfg1->kconfig().get_child(
"network");
107 bool enabled = network_cfg.get<
bool>(
"enabled");
108 ASSERT_EQ(
false, enabled);
113 auto cfg = cfg1->get_general_config();
115 auto c1 = cfg.get_child(
"plugin_directories");
116 auto c2 = cfg.get_child(
"log");
117 auto c3 = cfg.get_child(
"network");
126 auto cfg = cfg1->get_exportable_general_config();
128 auto c1 = cfg.get_child_optional(
"plugin_directories");
129 auto c2 = cfg.get_child_optional(
"log");
130 auto c3 = cfg.get_child_optional(
"network");
144 auto cfg = cfg2->get_exportable_general_config();
146 auto c1 = cfg.get_child_optional(
"plugin_directories");
147 auto c2 = cfg.get_child_optional(
"log");
148 auto c3 = cfg.get_child_optional(
"network");
157 auto cfg = cfg3->get_exportable_general_config();
159 auto c1 = cfg.get_child_optional(
"plugin_directories");
160 auto c2 = cfg.get_child_optional(
"log");
161 auto c3 = cfg.get_child_optional(
"network");
176 auto cfg = cfg4->get_exportable_general_config();
179 cfg5->set_kconfig(cfg);
182 auto merged_cfg = cfg5->get_general_config();
184 auto c1 = merged_cfg.get_child_optional(
"log");
185 auto c2 = merged_cfg.get_child_optional(
"remote");
186 auto c3 = merged_cfg.get_child_optional(
"plugin_directories");
201 auto cfg = cfg6->get_exportable_general_config();
203 auto port_before = cfg.get<
int>(
"remote.port");
205 ASSERT_EQ(12345, port_before);
207 cfg7->set_kconfig(cfg);
210 auto merged_cfg = cfg7->get_general_config();
212 auto c1 = merged_cfg.get_child_optional(
"log");
213 auto c2 = merged_cfg.get_child_optional(
"remote");
214 auto c3 = merged_cfg.get_child_optional(
"plugin_directories");
220 auto port = (*c2).get<
int>(
"port");
221 ASSERT_EQ(12347, port);
229 auto cfg = cfg8->get_non_importable_modules();
230 ASSERT_EQ(cfg, std::list<std::string>({
"WIEGAND_READER",
"TEST_AND_RESET"}));
231 ASSERT_FALSE(cfg8->is_module_importable(
"WIEGAND_READER"));
232 ASSERT_FALSE(cfg8->is_module_importable(
"TEST_AND_RESET"));
237 int main(
int argc,
char **argv)
239 ::testing::InitGoogleTest(&argc, argv);
244 gl_data_path = std::string(argv[1]) +
'/';
245 return RUN_ALL_TESTS();