1#if(__cplusplus == 201703L)
3#include "../../../tests/catch2/catch.hpp"
5#include "../indiCompRuleConfig.hpp"
7SCENARIO(
"configuring basic rules",
"[stateRuleEngine::ruleConfig]" )
9 GIVEN(
"single rules in a config file")
11 WHEN(
"a numValRule using defaults")
13 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1" },
14 {
"ruleType",
"property",
"element",
"target" },
15 {
"numVal",
"dev.prop",
"elem",
"1.234" } );
16 mx::app::appConfigurator config;
17 config.readConfig(
"/tmp/ruleConfig_test.conf");
20 std::map<std::string, ruleRuleKeys> rrkMap;
32 WHEN(
"a numValRule changing defaults")
34 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
35 {
"ruleType",
"priority",
"comp",
"property",
"element",
"target",
"tol" },
36 {
"numVal",
"warning",
"GtEq",
"dev.prop",
"elem",
"1.234",
"1e-8" } );
37 mx::app::appConfigurator config;
38 config.readConfig(
"/tmp/ruleConfig_test.conf");
41 std::map<std::string, ruleRuleKeys> rrkMap;
53 WHEN(
"a txtValRule using defaults")
55 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1" },
56 {
"ruleType",
"property",
"element",
"target" },
57 {
"txtVal",
"dev.prop",
"elem",
"xxx" } );
58 mx::app::appConfigurator config;
59 config.readConfig(
"/tmp/ruleConfig_test.conf");
62 std::map<std::string, ruleRuleKeys> rrkMap;
73 WHEN(
"a txtValRule changing defaults")
75 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
76 {
"ruleType",
"priority",
"comp",
"property",
"element",
"target" },
77 {
"txtVal",
"alert",
"Neq",
"dev.prop",
"elem",
"xxx" } );
78 mx::app::appConfigurator config;
79 config.readConfig(
"/tmp/ruleConfig_test.conf");
82 std::map<std::string, ruleRuleKeys> rrkMap;
94 WHEN(
"a swValRule using defaults")
96 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1" },
97 {
"ruleType",
"property",
"element" },
98 {
"swVal",
"dev.prop",
"elem"} );
99 mx::app::appConfigurator config;
100 config.readConfig(
"/tmp/ruleConfig_test.conf");
103 std::map<std::string, ruleRuleKeys> rrkMap;
114 WHEN(
"a swValRule changing defaults")
116 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
117 {
"ruleType",
"priority",
"comp",
"property",
"element",
"target" },
118 {
"swVal",
"info",
"Neq",
"dev.prop",
"elem",
"Off" } );
119 mx::app::appConfigurator config;
120 config.readConfig(
"/tmp/ruleConfig_test.conf");
123 std::map<std::string, ruleRuleKeys> rrkMap;
135 WHEN(
"an elCompNumRule using defaults")
137 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
138 {
"ruleType",
"property1",
"element1",
"property2",
"element2" },
139 {
"elCompNum",
"dev1.prop1",
"elem1",
"dev2.prop2",
"elem2" } );
140 mx::app::appConfigurator config;
141 config.readConfig(
"/tmp/ruleConfig_test.conf");
144 std::map<std::string, ruleRuleKeys> rrkMap;
157 WHEN(
"an elCompTxtRule using defaults")
159 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
160 {
"ruleType",
"property1",
"element1",
"property2",
"element2" },
161 {
"elCompTxt",
"dev1.prop1",
"elem1",
"dev2.prop2",
"elem2" } );
162 mx::app::appConfigurator config;
163 config.readConfig(
"/tmp/ruleConfig_test.conf");
166 std::map<std::string, ruleRuleKeys> rrkMap;
179 WHEN(
"an elCompSwRule using defaults")
181 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
182 {
"ruleType",
"property1",
"element1",
"property2",
"element2" },
183 {
"elCompSw",
"dev1.prop1",
"elem1",
"dev2.prop2",
"elem2" } );
184 mx::app::appConfigurator config;
185 config.readConfig(
"/tmp/ruleConfig_test.conf");
188 std::map<std::string, ruleRuleKeys> rrkMap;
201 WHEN(
"a ruleCompRule using defaults")
204 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf",
205 {
"ruleA",
"ruleA",
"ruleA",
"rule3",
"rule3",
"rule3",
"rule3",
"rule4",
"rule4",
"rule4",
"rule4" },
206 {
"ruleType",
"rule1",
"rule2",
"ruleType",
"property",
"element",
"target",
"ruleType",
"property",
"element",
"target" },
207 {
"ruleComp",
"rule3",
"rule4",
"txtVal",
"dev3.propQ",
"elem",
"xxx",
"txtVal",
"dev4.propR",
"mele",
"yyy" }
209 mx::app::appConfigurator config;
210 config.readConfig(
"/tmp/ruleConfig_test.conf");
213 std::map<std::string, ruleRuleKeys> rrkMap;
227SCENARIO(
"configuring the demo",
"[stateRuleEngine::ruleConfig]" )
231 WHEN(
"the demo as writen")
234 fout.open(
"/tmp/ruleConfig_test.conf");
235 fout <<
"[fwfpm-fpm]\n";
236 fout <<
"ruleType=swVal\n";
237 fout <<
"priority=none\n";
239 fout <<
"property=fwfpm.filterName\n";
240 fout <<
"element=fpm\n";
241 fout <<
"target=On\n";
243 fout <<
"[fwfpm-READY]\n";
244 fout <<
"ruleType=txtVal\n";
245 fout <<
"property=fwfpm.fsm_state\n";
246 fout <<
"element=state\n";
247 fout <<
"target=READY\n";
249 fout <<
"[fwfpm-fpm-READY]\n";
250 fout <<
"ruleType=ruleComp\n";
251 fout <<
"comp=And\n";
252 fout <<
"rule1=fwfpm-READY\n";
253 fout <<
"rule2=fwfpm-fpm\n";
255 fout <<
"[fwfpm-stagesci1-neq]\n";
256 fout <<
"ruleType=elCompSw\n";
257 fout <<
"property1=fwfpm.filterName\n";
258 fout <<
"element1=fpm\n";
259 fout <<
"property2=stagesci1.presetName\n";
260 fout <<
"element2=fpm\n";
261 fout <<
"comp=Neq\n";
263 fout <<
"[fwfpm-fpm-stagesci-fpm]\n";
264 fout <<
"ruleType=ruleComp\n";
265 fout <<
"priority=caution\n";
266 fout <<
"rule1=fwfpm-fpm-READY\n";
267 fout <<
"rule2=fwfpm-stagesci1-neq\n";
268 fout <<
"comp=And\n";
271 mx::app::appConfigurator config;
272 config.readConfig(
"/tmp/ruleConfig_test.conf");
275 std::map<std::string, ruleRuleKeys> rrkMap;
291SCENARIO(
"rule configurations with errors",
"[stateRuleEngine::ruleConfig]" )
293 GIVEN(
"single rules in a config file")
295 WHEN(
"no rule sections given")
297 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1" },
300 mx::app::appConfigurator config;
302 config.add(
"rule1.prop",
"",
"", argType::Required,
"rule1",
"property",
false,
"string",
"");
303 config.readConfig(
"/tmp/ruleConfig_test.conf");
306 std::map<std::string, ruleRuleKeys> rrkMap;
313 catch(
const mx::err::invalidconfig & e)
324 WHEN(
"an invalid rule")
326 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1" },
327 {
"ruleType",
"property",
"element",
"target" },
328 {
"badRule",
"dev.prop",
"elem",
"1.234" } );
329 mx::app::appConfigurator config;
330 config.readConfig(
"/tmp/ruleConfig_test.conf");
333 std::map<std::string, ruleRuleKeys> rrkMap;
340 catch(
const mx::err::notimpl & e)
351 GIVEN(
"ruleComp rules with errors")
353 WHEN(
"a ruleCompRule with rule1 not found")
356 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf",
357 {
"ruleA",
"ruleA",
"ruleA",
"rule3",
"rule3",
"rule3",
"rule3",
"rule4",
"rule4",
"rule4",
"rule4" },
358 {
"ruleType",
"rule1",
"rule2",
"ruleType",
"property",
"element",
"target",
"ruleType",
"property",
"element",
"target" },
359 {
"ruleComp",
"rule6",
"rule4",
"txtVal",
"dev3.propQ",
"elem",
"xxx",
"txtVal",
"dev4.propR",
"mele",
"yyy" }
361 mx::app::appConfigurator config;
362 config.readConfig(
"/tmp/ruleConfig_test.conf");
365 std::map<std::string, ruleRuleKeys> rrkMap;
381 WHEN(
"a ruleCompRule with rule1 self-referencing")
384 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf",
385 {
"ruleA",
"ruleA",
"ruleA",
"rule3",
"rule3",
"rule3",
"rule3",
"rule4",
"rule4",
"rule4",
"rule4" },
386 {
"ruleType",
"rule1",
"rule2",
"ruleType",
"property",
"element",
"target",
"ruleType",
"property",
"element",
"target" },
387 {
"ruleComp",
"ruleA",
"rule4",
"txtVal",
"dev3.propQ",
"elem",
"xxx",
"txtVal",
"dev4.propR",
"mele",
"yyy" }
389 mx::app::appConfigurator config;
390 config.readConfig(
"/tmp/ruleConfig_test.conf");
393 std::map<std::string, ruleRuleKeys> rrkMap;
408 WHEN(
"a ruleCompRule with rule2 not found")
411 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf",
412 {
"ruleA",
"ruleA",
"ruleA",
"rule3",
"rule3",
"rule3",
"rule3",
"rule4",
"rule4",
"rule4",
"rule4" },
413 {
"ruleType",
"rule1",
"rule2",
"ruleType",
"property",
"element",
"target",
"ruleType",
"property",
"element",
"target" },
414 {
"ruleComp",
"rule3",
"rule5",
"txtVal",
"dev3.propQ",
"elem",
"xxx",
"txtVal",
"dev4.propR",
"mele",
"yyy" }
416 mx::app::appConfigurator config;
417 config.readConfig(
"/tmp/ruleConfig_test.conf");
420 std::map<std::string, ruleRuleKeys> rrkMap;
436 WHEN(
"a ruleCompRule with rule2 self-referencing")
439 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf",
440 {
"ruleA",
"ruleA",
"ruleA",
"rule3",
"rule3",
"rule3",
"rule3",
"rule4",
"rule4",
"rule4",
"rule4" },
441 {
"ruleType",
"rule1",
"rule2",
"ruleType",
"property",
"element",
"target",
"ruleType",
"property",
"element",
"target" },
442 {
"ruleComp",
"rule3",
"ruleA",
"txtVal",
"dev3.propQ",
"elem",
"xxx",
"txtVal",
"dev4.propR",
"mele",
"yyy" }
444 mx::app::appConfigurator config;
445 config.readConfig(
"/tmp/ruleConfig_test.conf");
448 std::map<std::string, ruleRuleKeys> rrkMap;
void loadRuleConfig(indiRuleMaps &maps, std::map< std::string, ruleRuleKeys > &rrkMap, mx::app::appConfigurator &config)
Load the rule and properties maps for a rule engine from a configuration file.
@ GtEq
Greater than or equal to.
@ warning
Warning – something is probably wrong, you should check.
@ alert
Alert – something is definitely wrong, you should take action.
@ info
For information only.
Virtual base-class for all rules.
Structure to provide management of the rule and property maps.
Compare the value of a number element to a target.
void target(const double &tgt)
Set the target for the comparison.
void tol(const double &t)
Set the tolerance.
A rule base class for testing an element in one property.
void property(pcf::IndiProperty *property)
Set the property pointer.
void element(const std::string &el)
Set the element name.
A rule to compare two rules.
void rule2(indiCompRule *r)
Set the pointer to the second rule.
void rule1(indiCompRule *r)
Set the pointer to the first rule.
Compare the value of a switch to a target value.
void target(const pcf::IndiElement::SwitchStateType &ss)
Set the target for the comparison.
A rule base class for testing elements in two properties.
void property1(pcf::IndiProperty *property)
Set the first property pointer.
void element2(const std::string &el)
Set the second element name.
void element1(const std::string &el)
Set the first element name.
void property2(pcf::IndiProperty *property)
Set the second property pointer.
Compare the value of a text element to a target value.
void target(const std::string &target)
Set the target for the comparison.