1 #if(__cplusplus == 201703L)
3 #include "../../../tests/catch2/catch.hpp"
5 #include "../indiCompRules.hpp"
8 SCENARIO(
"basic INDI Property Element-value rules",
"[stateRuleEngine::rules]" )
10 GIVEN(
"string comparison")
12 pcf::IndiProperty prop1(pcf::IndiProperty::Text);
13 prop1.setDevice(
"ruleTest");
14 prop1.setName(
"prop1");
15 prop1.setPerm(pcf::IndiProperty::ReadWrite);
16 prop1.setState(pcf::IndiProperty::Idle);
17 prop1.add(pcf::IndiElement(
"current"));
18 prop1[
"current"] =
"test";
19 prop1.add(pcf::IndiElement(
"target"));
20 prop1[
"target"] =
"tset";
27 WHEN(
"string should be equal and is")
35 WHEN(
"string should be equal and is not")
43 WHEN(
"string should be not equal and is not equal")
51 WHEN(
"string should be not equal and is equal")
60 GIVEN(
"float comparison")
62 pcf::IndiProperty prop1(pcf::IndiProperty::Number);
63 prop1.setDevice(
"ruleTest");
64 prop1.setName(
"prop1");
65 prop1.setPerm(pcf::IndiProperty::ReadWrite);
66 prop1.setState(pcf::IndiProperty::Idle);
67 prop1.add(pcf::IndiElement(
"current"));
68 prop1[
"current"].setValue(2.314159);
69 prop1.add(pcf::IndiElement(
"target"));
70 prop1[
"target"].setValue(1.567202);
77 WHEN(
"float should be equal and is")
84 WHEN(
"float should be equal and aren't")
91 WHEN(
"float should be equal and aren't within tol")
99 WHEN(
"float should be equal and are within tol")
108 WHEN(
"float should be less than and is")
115 WHEN(
"float should be less than but is not")
122 WHEN(
"float should be greater than and is")
129 WHEN(
"float should be greater than but is not")
136 WHEN(
"float should be less-or-equal than and is less than")
143 WHEN(
"float should be less-or-equal than and is equal")
150 WHEN(
"float should be less-or-equal than but is not")
157 WHEN(
"float should be greater-or-equal than and is greater than")
164 WHEN(
"float should be greater-or-equal than and is equal")
171 WHEN(
"float should be greater-or-equal than but is not")
179 GIVEN(
"switch comparison")
181 pcf::IndiProperty prop1(pcf::IndiProperty::Switch);
182 prop1.setDevice(
"ruleTest");
183 prop1.setName(
"prop1");
184 prop1.setPerm(pcf::IndiProperty::ReadWrite);
185 prop1.setState(pcf::IndiProperty::Idle);
186 prop1.add(pcf::IndiElement(
"toggle"));
193 WHEN(
"switch is on and should be equal and is")
195 prop1[
"toggle"].setSwitchState(pcf::IndiElement::On);
201 WHEN(
"switch is on and should be equal but isn't")
203 prop1[
"toggle"].setSwitchState(pcf::IndiElement::On);
209 WHEN(
"switch is on and should be not equal and is not")
211 prop1[
"toggle"].setSwitchState(pcf::IndiElement::On);
217 WHEN(
"switch is on and should be not equal but is")
219 prop1[
"toggle"].setSwitchState(pcf::IndiElement::On);
225 WHEN(
"switch is off and should be equal and is")
227 prop1[
"toggle"].setSwitchState(pcf::IndiElement::Off);
233 WHEN(
"switch is off and should be equal but isn't")
235 prop1[
"toggle"].setSwitchState(pcf::IndiElement::Off);
241 WHEN(
"switch is off and should be not equal and is not")
243 prop1[
"toggle"].setSwitchState(pcf::IndiElement::Off);
249 WHEN(
"switch is off and should be not equal but is")
251 prop1[
"toggle"].setSwitchState(pcf::IndiElement::Off);
259 SCENARIO(
"INDI element comparison",
"[stateRuleEngine::rules]" )
261 GIVEN(
"string comparison within same property")
263 pcf::IndiProperty prop1(pcf::IndiProperty::Text);
264 prop1.setDevice(
"ruleTest");
265 prop1.setName(
"prop1");
266 prop1.setPerm(pcf::IndiProperty::ReadWrite);
267 prop1.setState(pcf::IndiProperty::Idle);
268 prop1.add(pcf::IndiElement(
"current"));
269 prop1.add(pcf::IndiElement(
"target"));
277 WHEN(
"string elements wihtin same property should be equal and are")
279 prop1[
"current"] =
"test";
280 prop1[
"target"] =
"test";
286 WHEN(
"string elements within same property should be equal and are not")
288 prop1[
"current"] =
"test";
289 prop1[
"target"] =
"tset";
295 WHEN(
"string elements within same property should not be equal and are not")
297 prop1[
"current"] =
"test";
298 prop1[
"target"] =
"tset";
304 WHEN(
"string elements within same property should not be equal and are")
306 prop1[
"current"] =
"test";
307 prop1[
"target"] =
"test";
314 GIVEN(
"switch comparison")
316 pcf::IndiProperty prop1(pcf::IndiProperty::Switch);
317 prop1.setDevice(
"ruleTest1");
318 prop1.setName(
"prop1");
319 prop1.setPerm(pcf::IndiProperty::ReadWrite);
320 prop1.setState(pcf::IndiProperty::Idle);
321 prop1.add(pcf::IndiElement(
"nameTest"));
323 pcf::IndiProperty prop2(pcf::IndiProperty::Switch);
324 prop2.setDevice(
"ruleTest2");
325 prop2.setName(
"prop2");
326 prop2.setPerm(pcf::IndiProperty::ReadWrite);
327 prop2.setState(pcf::IndiProperty::Idle);
328 prop2.add(pcf::IndiElement(
"badgeTest"));
336 WHEN(
"switches should be On and equal and are")
338 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::On);
339 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::On);
345 WHEN(
"switches should be On and equal but are not")
347 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::On);
348 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::Off);
354 WHEN(
"switches should be On and not equal and are not")
356 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::On);
357 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::Off);
363 WHEN(
"switches should be On and not equal but are")
365 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::On);
366 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::On);
372 WHEN(
"switches should be Off and equal and are")
374 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::Off);
375 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::Off);
381 WHEN(
"switches should be Off and equal but are not")
383 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::Off);
384 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::On);
390 WHEN(
"switches should be Off and not equal and are not")
392 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::Off);
393 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::On);
399 WHEN(
"switches should be Off and not equal but are")
401 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::Off);
402 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::Off);
408 GIVEN(
"numeric comparison")
410 pcf::IndiProperty prop1(pcf::IndiProperty::Number);
411 prop1.setDevice(
"ruleTest1");
412 prop1.setName(
"prop1");
413 prop1.setPerm(pcf::IndiProperty::ReadWrite);
414 prop1.setState(pcf::IndiProperty::Idle);
415 prop1.add(pcf::IndiElement(
"nameTest"));
417 pcf::IndiProperty prop2(pcf::IndiProperty::Number);
418 prop2.setDevice(
"ruleTest2");
419 prop2.setName(
"prop2");
420 prop2.setPerm(pcf::IndiProperty::ReadWrite);
421 prop2.setState(pcf::IndiProperty::Idle);
422 prop2.add(pcf::IndiElement(
"badgeTest"));
430 WHEN(
"numbers should be equal and are")
432 prop1[
"nameTest"].set(2.5);
433 prop2[
"badgeTest"].set(2.5);
439 WHEN(
"numbers should be equal but are not")
441 prop1[
"nameTest"].set(2.5);
442 prop2[
"badgeTest"].set(2.6);
451 SCENARIO(
"basic rule comparisons",
"[stateRuleEngine::rules]" )
453 GIVEN(
"INDI Property rule comparison")
455 WHEN(
"two strings should be equal and are")
457 pcf::IndiProperty prop1(pcf::IndiProperty::Text);
458 prop1.setDevice(
"ruleTest");
459 prop1.setName(
"prop1");
460 prop1.setPerm(pcf::IndiProperty::ReadWrite);
461 prop1.setState(pcf::IndiProperty::Idle);
462 prop1.add(pcf::IndiElement(
"current"));
463 prop1[
"current"] =
"test";
464 prop1.add(pcf::IndiElement(
"target"));
465 prop1[
"target"] =
"tset";
475 pcf::IndiProperty prop2(pcf::IndiProperty::Text);
476 prop2.setDevice(
"ruleTest2");
477 prop2.setName(
"prop2");
478 prop2.setPerm(pcf::IndiProperty::ReadWrite);
479 prop2.setState(pcf::IndiProperty::Idle);
480 prop2.add(pcf::IndiElement(
"current"));
481 prop2[
"current"] =
"fail";
482 prop2.add(pcf::IndiElement(
"target"));
483 prop2[
"target"] =
"liaf";
504 SCENARIO(
"compound rule compariaons",
"[stateRuleEngine::rules]" )
506 GIVEN(
"(A && B) || C")
508 pcf::IndiProperty prop1(pcf::IndiProperty::Text);
509 prop1.setDevice(
"ruleTest");
510 prop1.setName(
"prop1");
511 prop1.setPerm(pcf::IndiProperty::ReadWrite);
512 prop1.setState(pcf::IndiProperty::Idle);
513 prop1.add(pcf::IndiElement(
"current"));
514 prop1[
"current"] =
"test";
515 prop1.add(pcf::IndiElement(
"target"));
516 prop1[
"target"] =
"tset";
524 pcf::IndiProperty prop2(pcf::IndiProperty::Text);
525 prop2.setDevice(
"ruleTest2");
526 prop2.setName(
"prop2");
527 prop2.setPerm(pcf::IndiProperty::ReadWrite);
528 prop2.setState(pcf::IndiProperty::Idle);
529 prop2.add(pcf::IndiElement(
"current"));
530 prop2[
"current"] =
"fail";
531 prop2.add(pcf::IndiElement(
"target"));
532 prop2[
"target"] =
"liaf";
545 pcf::IndiProperty prop3(pcf::IndiProperty::Text);
546 prop3.setDevice(
"ruleTest3");
547 prop3.setName(
"prop3");
548 prop3.setPerm(pcf::IndiProperty::ReadWrite);
549 prop3.setState(pcf::IndiProperty::Idle);
550 prop3.add(pcf::IndiElement(
"current"));
551 prop3[
"current"] =
"pass";
552 prop3.add(pcf::IndiElement(
"target"));
553 prop3[
"target"] =
"ssap";
566 WHEN(
"A==1, B==0, C==1")
577 WHEN(
"A==0, B==0, C==1")
587 WHEN(
"A==1, B==0, C==0")
597 WHEN(
"A==1, B==1, C==0")
@ LtEq
Less than or equal to.
@ GtEq
Greater than or equal to.
Compare two elements based on their numeric values.
virtual bool value()
Get the value of this rule.
Compare two elements based on their switch values.
virtual bool value()
Get the value of this rule.
Compare two elements based on their text values.
virtual bool value()
Get the value of this rule.
void comparison(const ruleComparison &c)
Set the comparison for this rule.
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.
virtual bool value()
Get the value of this rule.
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.
virtual bool value()
Get the value of this rule.
Compare the value of a switch to a target value.
virtual bool value()
Get the value of this rule.
void target(const pcf::IndiElement::SwitchStateType &ss)
Set the target for the comparison.
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.
virtual bool value()
Get the value of this rule.