29SCENARIO(
"Creating and configuring an indiPropNode",
"[instGraph::indiPropNode]" )
31 GIVEN(
"a valid XML file, a valid config file")
33 WHEN(
"node is in file, default config")
35 ingr::instGraphXML parentGraph;
37 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
38 {
"type",
"propKey",
"propEl",
"propVal"},
39 {
"indiProp",
"tel.dome",
"status",
"on"} );
40 mx::app::appConfigurator config;
41 config.readConfig(
"/tmp/indiPropNode_test.conf");
45 int rv = parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
57 catch(
const std::exception & e)
59 std::cerr << e.what() <<
"\n";
62 REQUIRE(pass ==
true);
63 REQUIRE(tsn !=
nullptr);
65 REQUIRE( tsn->
name() ==
"telescope");
66 REQUIRE( tsn->
node()->name() ==
"telescope");
74 catch(
const std::exception & e)
76 std::cerr << e.what() <<
"\n";
79 REQUIRE(pass ==
true);
82 REQUIRE(tsn->
propKey() ==
"tel.dome");
83 REQUIRE(tsn->
propEl() ==
"status");
85 REQUIRE(tsn->
propValNum() == std::numeric_limits<double>::lowest());
86 REQUIRE(tsn->
propValSw() == pcf::IndiElement::SwitchStateType::UnknownSwitchState);
87 REQUIRE(tsn->
type() == pcf::IndiProperty::Type::Unknown);
88 REQUIRE(tsn->
tol() == 1e-7);
89 REQUIRE(tsn->
state() ==
false);
92 WHEN(
"node is in file, config setting tol")
94 ingr::instGraphXML parentGraph;
96 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope",
"telescope"},
97 {
"type",
"propKey",
"propEl",
"propVal",
"tol"},
98 {
"indiProp",
"tel.dome",
"status",
"on",
"1e-8"} );
99 mx::app::appConfigurator config;
100 config.readConfig(
"/tmp/indiPropNode_test.conf");
104 int rv = parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
116 catch(
const std::exception & e)
118 std::cerr << e.what() <<
"\n";
121 REQUIRE(pass ==
true);
122 REQUIRE(tsn !=
nullptr);
124 REQUIRE( tsn->
name() ==
"telescope");
125 REQUIRE( tsn->
node()->name() ==
"telescope");
133 catch(
const std::exception & e)
135 std::cerr << e.what() <<
"\n";
138 REQUIRE(pass ==
true);
141 REQUIRE(tsn->
propKey() ==
"tel.dome");
142 REQUIRE(tsn->
propEl() ==
"status");
144 REQUIRE(tsn->
propValNum() == std::numeric_limits<double>::lowest());
145 REQUIRE(tsn->
propValSw() == pcf::IndiElement::SwitchStateType::UnknownSwitchState);
146 REQUIRE(tsn->
type() == pcf::IndiProperty::Type::Unknown);
147 REQUIRE(tsn->
tol() == 1e-8);
148 REQUIRE(tsn->
state() ==
false);
152 WHEN(
"node is in file, handling a text property")
154 ingr::instGraphXML parentGraph;
156 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
157 {
"type",
"propKey",
"propEl",
"propVal"},
158 {
"indiProp",
"tel.dome",
"status",
"on"} );
159 mx::app::appConfigurator config;
160 config.readConfig(
"/tmp/indiPropNode_test.conf");
164 parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
169 pcf::IndiProperty ip(pcf::IndiProperty::Text);
172 ip.add(pcf::IndiElement(
"status"));
176 REQUIRE(tsn->
type() == pcf::IndiProperty::Text);
177 REQUIRE(tsn->
state() ==
true);
181 REQUIRE(tsn->
state() ==
false);
184 WHEN(
"node is in file, handling a number property")
186 ingr::instGraphXML parentGraph;
188 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
189 {
"type",
"propKey",
"propEl",
"propVal"},
190 {
"indiProp",
"tel.dome",
"status",
"1.5"} );
191 mx::app::appConfigurator config;
192 config.readConfig(
"/tmp/indiPropNode_test.conf");
196 parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
201 pcf::IndiProperty ip(pcf::IndiProperty::Number);
204 ip.add(pcf::IndiElement(
"status"));
208 REQUIRE(tsn->
type() == pcf::IndiProperty::Number);
210 REQUIRE(tsn->
state() ==
true);
215 REQUIRE(tsn->
state() ==
false);
218 WHEN(
"node is in file, handling a switch property")
220 ingr::instGraphXML parentGraph;
222 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
223 {
"type",
"propKey",
"propEl",
"propVal"},
224 {
"indiProp",
"tel.dome",
"status",
"on"} );
225 mx::app::appConfigurator config;
226 config.readConfig(
"/tmp/indiPropNode_test.conf");
230 parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
235 pcf::IndiProperty ip(pcf::IndiProperty::Switch);
238 ip.add(pcf::IndiElement(
"status"));
239 ip[
"status"].setSwitchState(pcf::IndiElement::SwitchStateType::On);
242 REQUIRE(tsn->
type() == pcf::IndiProperty::Switch);
243 REQUIRE(tsn->
propValSw() == pcf::IndiElement::SwitchStateType::On);
244 REQUIRE(tsn->
state() ==
true);
247 ip[
"status"].setSwitchState(pcf::IndiElement::SwitchStateType::Off);
249 REQUIRE(tsn->
state() ==
false);
253 GIVEN(
"invalid configs")
255 WHEN(
"parent graph is null, default config")
264 catch(
const std::exception & e)
266 std::cerr << e.what() <<
"\n";
269 REQUIRE(pass ==
false);
270 REQUIRE(tsn ==
nullptr);
272 WHEN(
"node not in file, default config")
274 ingr::instGraphXML parentGraph;
276 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
277 {
"type",
"propKey",
"propEl",
"propVal"},
278 {
"indiProp",
"tel.dome",
"status",
"on"} );
279 mx::app::appConfigurator config;
280 config.readConfig(
"/tmp/indiPropNode_test.conf");
284 int rv = parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
296 catch(
const std::exception & e)
298 std::cerr << e.what() <<
"\n";
301 REQUIRE(pass ==
false);
302 REQUIRE(tsn ==
nullptr);
305 WHEN(
"node is in file, default config, wrong node type")
307 ingr::instGraphXML parentGraph;
309 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
310 {
"type",
"propKey",
"propEl",
"propVal"},
311 {
"fakeProp",
"tel.dome",
"status",
"on"} );
312 mx::app::appConfigurator config;
313 config.readConfig(
"/tmp/indiPropNode_test.conf");
317 int rv = parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
329 catch(
const std::exception & e)
331 std::cerr << e.what() <<
"\n";
334 REQUIRE(pass ==
true);
335 REQUIRE(tsn !=
nullptr);
337 REQUIRE( tsn->
name() ==
"telescope");
338 REQUIRE( tsn->
node()->name() ==
"telescope");
346 catch(
const std::exception & e)
348 std::cerr << e.what() <<
"\n";
351 REQUIRE(pass ==
false);
354 WHEN(
"node is in file, default config, propKey empty")
356 ingr::instGraphXML parentGraph;
358 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
359 {
"type",
"propKey",
"propEl",
"propVal"},
360 {
"indiProp",
"",
"status",
"on"} );
361 mx::app::appConfigurator config;
362 config.readConfig(
"/tmp/indiPropNode_test.conf");
366 int rv = parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
378 catch(
const std::exception & e)
380 std::cerr << e.what() <<
"\n";
383 REQUIRE(pass ==
true);
384 REQUIRE(tsn !=
nullptr);
386 REQUIRE( tsn->
name() ==
"telescope");
387 REQUIRE( tsn->
node()->name() ==
"telescope");
395 catch(
const std::exception & e)
397 std::cerr << e.what() <<
"\n";
400 REQUIRE(pass ==
false);
403 WHEN(
"node is in file, default config, propEl empty")
405 ingr::instGraphXML parentGraph;
407 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
408 {
"type",
"propKey",
"propEl",
"propVal"},
409 {
"indiProp",
"tel.dome",
"",
"on"} );
410 mx::app::appConfigurator config;
411 config.readConfig(
"/tmp/indiPropNode_test.conf");
415 int rv = parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
427 catch(
const std::exception & e)
429 std::cerr << e.what() <<
"\n";
432 REQUIRE(pass ==
true);
433 REQUIRE(tsn !=
nullptr);
435 REQUIRE( tsn->
name() ==
"telescope");
436 REQUIRE( tsn->
node()->name() ==
"telescope");
444 catch(
const std::exception & e)
446 std::cerr << e.what() <<
"\n";
449 REQUIRE(pass ==
false);
452 WHEN(
"node is in file, default config, propVal empty")
454 ingr::instGraphXML parentGraph;
456 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
457 {
"type",
"propKey",
"propEl",
"propVal"},
458 {
"indiProp",
"tel.come",
"status",
""} );
459 mx::app::appConfigurator config;
460 config.readConfig(
"/tmp/indiPropNode_test.conf");
464 int rv = parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
476 catch(
const std::exception & e)
478 std::cerr << e.what() <<
"\n";
481 REQUIRE(pass ==
true);
482 REQUIRE(tsn !=
nullptr);
484 REQUIRE( tsn->
name() ==
"telescope");
485 REQUIRE( tsn->
node()->name() ==
"telescope");
493 catch(
const std::exception & e)
495 std::cerr << e.what() <<
"\n";
498 REQUIRE(pass ==
false);
501 WHEN(
"a number property with invalid propVal")
503 ingr::instGraphXML parentGraph;
505 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
506 {
"type",
"propKey",
"propEl",
"propVal"},
507 {
"indiProp",
"tel.dome",
"status",
"abcde"} );
508 mx::app::appConfigurator config;
509 config.readConfig(
"/tmp/indiPropNode_test.conf");
513 parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
518 pcf::IndiProperty ip(pcf::IndiProperty::Number);
521 ip.add(pcf::IndiElement(
"status"));
530 catch(
const std::exception& e)
532 std::cerr << e.what() <<
'\n';
535 REQUIRE(pass ==
false);
537 WHEN(
"invalid switch property")
539 ingr::instGraphXML parentGraph;
541 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf", {
"telescope",
"telescope",
"telescope",
"telescope"},
542 {
"type",
"propKey",
"propEl",
"propVal"},
543 {
"indiProp",
"tel.dome",
"status",
"qq"} );
544 mx::app::appConfigurator config;
545 config.readConfig(
"/tmp/indiPropNode_test.conf");
549 parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
554 pcf::IndiProperty ip(pcf::IndiProperty::Switch);
557 ip.add(pcf::IndiElement(
"status"));
558 ip[
"status"].setSwitchState(pcf::IndiElement::SwitchStateType::On);
566 catch(
const std::exception& e)
568 std::cerr << e.what() <<
'\n';
571 REQUIRE(pass ==
false);