1 #if(__cplusplus == 201703L)
3 #include "../../../tests/catch2/catch.hpp"
5 #include "../indiCompRuleConfig.hpp"
7 SCENARIO(
"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");
31 WHEN(
"a numValRule changing defaults")
33 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
34 {
"ruleType",
"priority",
"comp",
"property",
"element",
"target",
"tol" },
35 {
"numVal",
"warning",
"GtEq",
"dev.prop",
"elem",
"1.234",
"1e-8" } );
36 mx::app::appConfigurator config;
37 config.readConfig(
"/tmp/ruleConfig_test.conf");
51 WHEN(
"a txtValRule using defaults")
53 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1" },
54 {
"ruleType",
"property",
"element",
"target" },
55 {
"txtVal",
"dev.prop",
"elem",
"xxx" } );
56 mx::app::appConfigurator config;
57 config.readConfig(
"/tmp/ruleConfig_test.conf");
70 WHEN(
"a txtValRule changing defaults")
72 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
73 {
"ruleType",
"priority",
"comp",
"property",
"element",
"target" },
74 {
"txtVal",
"alert",
"Neq",
"dev.prop",
"elem",
"xxx" } );
75 mx::app::appConfigurator config;
76 config.readConfig(
"/tmp/ruleConfig_test.conf");
90 WHEN(
"a swValRule using defaults")
92 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1" },
93 {
"ruleType",
"property",
"element" },
94 {
"swVal",
"dev.prop",
"elem"} );
95 mx::app::appConfigurator config;
96 config.readConfig(
"/tmp/ruleConfig_test.conf");
109 WHEN(
"a swValRule changing defaults")
111 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
112 {
"ruleType",
"priority",
"comp",
"property",
"element",
"target" },
113 {
"swVal",
"info",
"Neq",
"dev.prop",
"elem",
"Off" } );
114 mx::app::appConfigurator config;
115 config.readConfig(
"/tmp/ruleConfig_test.conf");
129 WHEN(
"an elCompNumRule using defaults")
131 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
132 {
"ruleType",
"property1",
"element1",
"property2",
"element2" },
133 {
"elCompNum",
"dev1.prop1",
"elem1",
"dev2.prop2",
"elem2" } );
134 mx::app::appConfigurator config;
135 config.readConfig(
"/tmp/ruleConfig_test.conf");
150 WHEN(
"an elCompTxtRule using defaults")
152 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
153 {
"ruleType",
"property1",
"element1",
"property2",
"element2" },
154 {
"elCompTxt",
"dev1.prop1",
"elem1",
"dev2.prop2",
"elem2" } );
155 mx::app::appConfigurator config;
156 config.readConfig(
"/tmp/ruleConfig_test.conf");
171 WHEN(
"an elCompSwRule using defaults")
173 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1",
"rule1" },
174 {
"ruleType",
"property1",
"element1",
"property2",
"element2" },
175 {
"elCompSw",
"dev1.prop1",
"elem1",
"dev2.prop2",
"elem2" } );
176 mx::app::appConfigurator config;
177 config.readConfig(
"/tmp/ruleConfig_test.conf");
192 WHEN(
"a ruleCompRule using defaults")
195 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf",
196 {
"ruleA",
"ruleA",
"ruleA",
"rule3",
"rule3",
"rule3",
"rule3",
"rule4",
"rule4",
"rule4",
"rule4" },
197 {
"ruleType",
"rule1",
"rule2",
"ruleType",
"property",
"element",
"target",
"ruleType",
"property",
"element",
"target" },
198 {
"ruleComp",
"rule3",
"rule4",
"txtVal",
"dev3.propQ",
"elem",
"xxx",
"txtVal",
"dev4.propR",
"mele",
"yyy" }
200 mx::app::appConfigurator config;
201 config.readConfig(
"/tmp/ruleConfig_test.conf");
217 SCENARIO(
"configuring the demo",
"[stateRuleEngine::ruleConfig]" )
221 WHEN(
"the demo as writen")
224 fout.open(
"/tmp/ruleConfig_test.conf");
225 fout <<
"[fwfpm-fpm]\n";
226 fout <<
"ruleType=swVal\n";
227 fout <<
"priority=none\n";
229 fout <<
"property=fwfpm.filterName\n";
230 fout <<
"element=fpm\n";
231 fout <<
"target=On\n";
233 fout <<
"[fwfpm-READY]\n";
234 fout <<
"ruleType=txtVal\n";
235 fout <<
"property=fwfpm.fsm_state\n";
236 fout <<
"element=state\n";
237 fout <<
"target=READY\n";
239 fout <<
"[fwfpm-fpm-READY]\n";
240 fout <<
"ruleType=ruleComp\n";
241 fout <<
"comp=And\n";
242 fout <<
"rule1=fwfpm-READY\n";
243 fout <<
"rule2=fwfpm-fpm\n";
245 fout <<
"[fwfpm-stagesci1-neq]\n";
246 fout <<
"ruleType=elCompSw\n";
247 fout <<
"property1=fwfpm.filterName\n";
248 fout <<
"element1=fpm\n";
249 fout <<
"property2=stagesci1.presetName\n";
250 fout <<
"element2=fpm\n";
251 fout <<
"comp=Neq\n";
253 fout <<
"[fwfpm-fpm-stagesci-fpm]\n";
254 fout <<
"ruleType=ruleComp\n";
255 fout <<
"priority=caution\n";
256 fout <<
"rule1=fwfpm-fpm-READY\n";
257 fout <<
"rule2=fwfpm-stagesci1-neq\n";
258 fout <<
"comp=And\n";
261 mx::app::appConfigurator config;
262 config.readConfig(
"/tmp/ruleConfig_test.conf");
280 SCENARIO(
"rule configurations with errors",
"[stateRuleEngine::ruleConfig]" )
282 GIVEN(
"single rules in a config file")
284 WHEN(
"no rule sections given")
286 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1" },
289 mx::app::appConfigurator config;
291 config.add(
"rule1.prop",
"",
"", argType::Required,
"rule1",
"property",
false,
"string",
"");
292 config.readConfig(
"/tmp/ruleConfig_test.conf");
301 catch(
const mx::err::invalidconfig & e)
312 WHEN(
"an invalid rule")
314 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf", {
"rule1",
"rule1",
"rule1",
"rule1" },
315 {
"ruleType",
"property",
"element",
"target" },
316 {
"badRule",
"dev.prop",
"elem",
"1.234" } );
317 mx::app::appConfigurator config;
318 config.readConfig(
"/tmp/ruleConfig_test.conf");
327 catch(
const mx::err::notimpl & e)
338 GIVEN(
"ruleComp rules with errors")
340 WHEN(
"a ruleCompRule with rule1 not found")
343 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf",
344 {
"ruleA",
"ruleA",
"ruleA",
"rule3",
"rule3",
"rule3",
"rule3",
"rule4",
"rule4",
"rule4",
"rule4" },
345 {
"ruleType",
"rule1",
"rule2",
"ruleType",
"property",
"element",
"target",
"ruleType",
"property",
"element",
"target" },
346 {
"ruleComp",
"rule6",
"rule4",
"txtVal",
"dev3.propQ",
"elem",
"xxx",
"txtVal",
"dev4.propR",
"mele",
"yyy" }
348 mx::app::appConfigurator config;
349 config.readConfig(
"/tmp/ruleConfig_test.conf");
367 WHEN(
"a ruleCompRule with rule1 self-referencing")
370 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf",
371 {
"ruleA",
"ruleA",
"ruleA",
"rule3",
"rule3",
"rule3",
"rule3",
"rule4",
"rule4",
"rule4",
"rule4" },
372 {
"ruleType",
"rule1",
"rule2",
"ruleType",
"property",
"element",
"target",
"ruleType",
"property",
"element",
"target" },
373 {
"ruleComp",
"ruleA",
"rule4",
"txtVal",
"dev3.propQ",
"elem",
"xxx",
"txtVal",
"dev4.propR",
"mele",
"yyy" }
375 mx::app::appConfigurator config;
376 config.readConfig(
"/tmp/ruleConfig_test.conf");
393 WHEN(
"a ruleCompRule with rule2 not found")
396 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf",
397 {
"ruleA",
"ruleA",
"ruleA",
"rule3",
"rule3",
"rule3",
"rule3",
"rule4",
"rule4",
"rule4",
"rule4" },
398 {
"ruleType",
"rule1",
"rule2",
"ruleType",
"property",
"element",
"target",
"ruleType",
"property",
"element",
"target" },
399 {
"ruleComp",
"rule3",
"rule5",
"txtVal",
"dev3.propQ",
"elem",
"xxx",
"txtVal",
"dev4.propR",
"mele",
"yyy" }
401 mx::app::appConfigurator config;
402 config.readConfig(
"/tmp/ruleConfig_test.conf");
420 WHEN(
"a ruleCompRule with rule2 self-referencing")
423 mx::app::writeConfigFile(
"/tmp/ruleConfig_test.conf",
424 {
"ruleA",
"ruleA",
"ruleA",
"rule3",
"rule3",
"rule3",
"rule3",
"rule4",
"rule4",
"rule4",
"rule4" },
425 {
"ruleType",
"rule1",
"rule2",
"ruleType",
"property",
"element",
"target",
"ruleType",
"property",
"element",
"target" },
426 {
"ruleComp",
"rule3",
"ruleA",
"txtVal",
"dev3.propQ",
"elem",
"xxx",
"txtVal",
"dev4.propR",
"mele",
"yyy" }
428 mx::app::appConfigurator config;
429 config.readConfig(
"/tmp/ruleConfig_test.conf");
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.