6SCENARIO(
"basic INDI Property Element-value rules",
"[stateRuleEngine::rules]" )
8 GIVEN(
"string comparison")
10 pcf::IndiProperty prop1(pcf::IndiProperty::Text);
11 prop1.setDevice(
"ruleTest");
12 prop1.setName(
"prop1");
13 prop1.setPerm(pcf::IndiProperty::ReadWrite);
14 prop1.setState(pcf::IndiProperty::Idle);
15 prop1.add(pcf::IndiElement(
"current"));
16 prop1[
"current"] =
"test";
17 prop1.add(pcf::IndiElement(
"target"));
18 prop1[
"target"] =
"tset";
25 WHEN(
"string should be equal and is")
30 REQUIRE(rule1.
value() ==
true);
33 WHEN(
"string should be equal and is not")
38 REQUIRE(rule1.
value() ==
false);
41 WHEN(
"string should be not equal and is not equal")
46 REQUIRE(rule1.
value() ==
true);
49 WHEN(
"string should be not equal and is equal")
54 REQUIRE(rule1.
value() ==
false);
58 GIVEN(
"float comparison")
60 pcf::IndiProperty prop1(pcf::IndiProperty::Number);
61 prop1.setDevice(
"ruleTest");
62 prop1.setName(
"prop1");
63 prop1.setPerm(pcf::IndiProperty::ReadWrite);
64 prop1.setState(pcf::IndiProperty::Idle);
65 prop1.add(pcf::IndiElement(
"current"));
66 prop1[
"current"].setValue(2.314159);
67 prop1.add(pcf::IndiElement(
"target"));
68 prop1[
"target"].setValue(1.567202);
75 WHEN(
"float should be equal and is")
79 REQUIRE(rule1.
value() ==
true);
82 WHEN(
"float should be equal and aren't")
86 REQUIRE(rule1.
value() ==
false);
89 WHEN(
"float should be equal and aren't within tol")
94 REQUIRE(rule1.
value() ==
false);
97 WHEN(
"float should be equal and are within tol")
103 REQUIRE(rule1.
value() ==
true);
106 WHEN(
"float should be less than and is")
110 REQUIRE(rule1.
value() ==
true);
113 WHEN(
"float should be less than but is not")
117 REQUIRE(rule1.
value() ==
false);
120 WHEN(
"float should be greater than and is")
124 REQUIRE(rule1.
value() ==
true);
127 WHEN(
"float should be greater than but is not")
131 REQUIRE(rule1.
value() ==
false);
134 WHEN(
"float should be less-or-equal than and is less than")
138 REQUIRE(rule1.
value() ==
true);
141 WHEN(
"float should be less-or-equal than and is equal")
145 REQUIRE(rule1.
value() ==
true);
148 WHEN(
"float should be less-or-equal than but is not")
152 REQUIRE(rule1.
value() ==
false);
155 WHEN(
"float should be greater-or-equal than and is greater than")
159 REQUIRE(rule1.
value() ==
true);
162 WHEN(
"float should be greater-or-equal than and is equal")
166 REQUIRE(rule1.
value() ==
true);
169 WHEN(
"float should be greater-or-equal than but is not")
173 REQUIRE(rule1.
value() ==
false);
177 GIVEN(
"switch comparison")
179 pcf::IndiProperty prop1(pcf::IndiProperty::Switch);
180 prop1.setDevice(
"ruleTest");
181 prop1.setName(
"prop1");
182 prop1.setPerm(pcf::IndiProperty::ReadWrite);
183 prop1.setState(pcf::IndiProperty::Idle);
184 prop1.add(pcf::IndiElement(
"toggle"));
191 WHEN(
"switch is on and should be equal and is")
193 prop1[
"toggle"].setSwitchState(pcf::IndiElement::On);
196 REQUIRE(rule1.
value() ==
true);
199 WHEN(
"switch is on and should be equal but isn't")
201 prop1[
"toggle"].setSwitchState(pcf::IndiElement::On);
204 REQUIRE(rule1.
value() ==
false);
207 WHEN(
"switch is on and should be not equal and is not")
209 prop1[
"toggle"].setSwitchState(pcf::IndiElement::On);
212 REQUIRE(rule1.
value() ==
true);
215 WHEN(
"switch is on and should be not equal but is")
217 prop1[
"toggle"].setSwitchState(pcf::IndiElement::On);
220 REQUIRE(rule1.
value() ==
false);
223 WHEN(
"switch is off and should be equal and is")
225 prop1[
"toggle"].setSwitchState(pcf::IndiElement::Off);
228 REQUIRE(rule1.
value() ==
true);
231 WHEN(
"switch is off and should be equal but isn't")
233 prop1[
"toggle"].setSwitchState(pcf::IndiElement::Off);
236 REQUIRE(rule1.
value() ==
false);
239 WHEN(
"switch is off and should be not equal and is not")
241 prop1[
"toggle"].setSwitchState(pcf::IndiElement::Off);
244 REQUIRE(rule1.
value() ==
true);
247 WHEN(
"switch is off and should be not equal but is")
249 prop1[
"toggle"].setSwitchState(pcf::IndiElement::Off);
252 REQUIRE(rule1.
value() ==
false);
257SCENARIO(
"INDI element comparison",
"[stateRuleEngine::rules]" )
259 GIVEN(
"string comparison within same property")
261 pcf::IndiProperty prop1(pcf::IndiProperty::Text);
262 prop1.setDevice(
"ruleTest");
263 prop1.setName(
"prop1");
264 prop1.setPerm(pcf::IndiProperty::ReadWrite);
265 prop1.setState(pcf::IndiProperty::Idle);
266 prop1.add(pcf::IndiElement(
"current"));
267 prop1.add(pcf::IndiElement(
"target"));
275 WHEN(
"string elements wihtin same property should be equal and are")
277 prop1[
"current"] =
"test";
278 prop1[
"target"] =
"test";
281 REQUIRE(rule1.
value() ==
true);
284 WHEN(
"string elements within same property should be equal and are not")
286 prop1[
"current"] =
"test";
287 prop1[
"target"] =
"tset";
290 REQUIRE(rule1.
value() ==
false);
293 WHEN(
"string elements within same property should not be equal and are not")
295 prop1[
"current"] =
"test";
296 prop1[
"target"] =
"tset";
299 REQUIRE(rule1.
value() ==
true);
302 WHEN(
"string elements within same property should not be equal and are")
304 prop1[
"current"] =
"test";
305 prop1[
"target"] =
"test";
308 REQUIRE(rule1.
value() ==
false);
312 GIVEN(
"switch comparison")
314 pcf::IndiProperty prop1(pcf::IndiProperty::Switch);
315 prop1.setDevice(
"ruleTest1");
316 prop1.setName(
"prop1");
317 prop1.setPerm(pcf::IndiProperty::ReadWrite);
318 prop1.setState(pcf::IndiProperty::Idle);
319 prop1.add(pcf::IndiElement(
"nameTest"));
321 pcf::IndiProperty prop2(pcf::IndiProperty::Switch);
322 prop2.setDevice(
"ruleTest2");
323 prop2.setName(
"prop2");
324 prop2.setPerm(pcf::IndiProperty::ReadWrite);
325 prop2.setState(pcf::IndiProperty::Idle);
326 prop2.add(pcf::IndiElement(
"badgeTest"));
334 WHEN(
"switches should be On and equal and are")
336 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::On);
337 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::On);
340 REQUIRE(rule1.
value() ==
true);
343 WHEN(
"switches should be On and equal but are not")
345 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::On);
346 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::Off);
349 REQUIRE(rule1.
value() ==
false);
352 WHEN(
"switches should be On and not equal and are not")
354 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::On);
355 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::Off);
358 REQUIRE(rule1.
value() ==
true);
361 WHEN(
"switches should be On and not equal but are")
363 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::On);
364 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::On);
367 REQUIRE(rule1.
value() ==
false);
370 WHEN(
"switches should be Off and equal and are")
372 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::Off);
373 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::Off);
376 REQUIRE(rule1.
value() ==
true);
379 WHEN(
"switches should be Off and equal but are not")
381 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::Off);
382 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::On);
385 REQUIRE(rule1.
value() ==
false);
388 WHEN(
"switches should be Off and not equal and are not")
390 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::Off);
391 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::On);
394 REQUIRE(rule1.
value() ==
true);
397 WHEN(
"switches should be Off and not equal but are")
399 prop1[
"nameTest"].setSwitchState(pcf::IndiElement::Off);
400 prop2[
"badgeTest"].setSwitchState(pcf::IndiElement::Off);
403 REQUIRE(rule1.
value() ==
false);
406 GIVEN(
"numeric comparison")
408 pcf::IndiProperty prop1(pcf::IndiProperty::Number);
409 prop1.setDevice(
"ruleTest1");
410 prop1.setName(
"prop1");
411 prop1.setPerm(pcf::IndiProperty::ReadWrite);
412 prop1.setState(pcf::IndiProperty::Idle);
413 prop1.add(pcf::IndiElement(
"nameTest"));
415 pcf::IndiProperty prop2(pcf::IndiProperty::Number);
416 prop2.setDevice(
"ruleTest2");
417 prop2.setName(
"prop2");
418 prop2.setPerm(pcf::IndiProperty::ReadWrite);
419 prop2.setState(pcf::IndiProperty::Idle);
420 prop2.add(pcf::IndiElement(
"badgeTest"));
428 WHEN(
"numbers should be equal and are")
430 prop1[
"nameTest"].set(2.5);
431 prop2[
"badgeTest"].set(2.5);
434 REQUIRE(rule1.
value() ==
true);
437 WHEN(
"numbers should be equal but are not")
439 prop1[
"nameTest"].set(2.5);
440 prop2[
"badgeTest"].set(2.6);
443 REQUIRE(rule1.
value() ==
false);
449SCENARIO(
"basic rule comparisons",
"[stateRuleEngine::rules]" )
451 GIVEN(
"INDI Property rule comparison")
453 WHEN(
"two strings should be equal and are")
455 pcf::IndiProperty prop1(pcf::IndiProperty::Text);
456 prop1.setDevice(
"ruleTest");
457 prop1.setName(
"prop1");
458 prop1.setPerm(pcf::IndiProperty::ReadWrite);
459 prop1.setState(pcf::IndiProperty::Idle);
460 prop1.add(pcf::IndiElement(
"current"));
461 prop1[
"current"] =
"test";
462 prop1.add(pcf::IndiElement(
"target"));
463 prop1[
"target"] =
"tset";
473 pcf::IndiProperty prop2(pcf::IndiProperty::Text);
474 prop2.setDevice(
"ruleTest2");
475 prop2.setName(
"prop2");
476 prop2.setPerm(pcf::IndiProperty::ReadWrite);
477 prop2.setState(pcf::IndiProperty::Idle);
478 prop2.add(pcf::IndiElement(
"current"));
479 prop2[
"current"] =
"fail";
480 prop2.add(pcf::IndiElement(
"target"));
481 prop2[
"target"] =
"liaf";
496 REQUIRE(rule3.
value() ==
true);
502SCENARIO(
"compound rule compariaons",
"[stateRuleEngine::rules]" )
504 GIVEN(
"(A && B) || C")
506 pcf::IndiProperty prop1(pcf::IndiProperty::Text);
507 prop1.setDevice(
"ruleTest");
508 prop1.setName(
"prop1");
509 prop1.setPerm(pcf::IndiProperty::ReadWrite);
510 prop1.setState(pcf::IndiProperty::Idle);
511 prop1.add(pcf::IndiElement(
"current"));
512 prop1[
"current"] =
"test";
513 prop1.add(pcf::IndiElement(
"target"));
514 prop1[
"target"] =
"tset";
522 pcf::IndiProperty prop2(pcf::IndiProperty::Text);
523 prop2.setDevice(
"ruleTest2");
524 prop2.setName(
"prop2");
525 prop2.setPerm(pcf::IndiProperty::ReadWrite);
526 prop2.setState(pcf::IndiProperty::Idle);
527 prop2.add(pcf::IndiElement(
"current"));
528 prop2[
"current"] =
"fail";
529 prop2.add(pcf::IndiElement(
"target"));
530 prop2[
"target"] =
"liaf";
543 pcf::IndiProperty prop3(pcf::IndiProperty::Text);
544 prop3.setDevice(
"ruleTest3");
545 prop3.setName(
"prop3");
546 prop3.setPerm(pcf::IndiProperty::ReadWrite);
547 prop3.setState(pcf::IndiProperty::Idle);
548 prop3.add(pcf::IndiElement(
"current"));
549 prop3[
"current"] =
"pass";
550 prop3.add(pcf::IndiElement(
"target"));
551 prop3[
"target"] =
"ssap";
564 WHEN(
"A==1, B==0, C==1")
571 REQUIRE(rule5.
value() ==
true);
575 WHEN(
"A==0, B==0, C==1")
582 REQUIRE(rule5.
value() ==
true);
585 WHEN(
"A==1, B==0, C==0")
592 REQUIRE(rule5.
value() ==
false);
595 WHEN(
"A==1, B==1, C==0")
602 REQUIRE(rule5.
value() ==
true);