50SCENARIO(
"Creating and configuring an indiPropNode",
"[instGraph::indiPropNode]" )
53 #ifdef XINSTGRAPH_TEST_DOXYGEN_REF
59 GIVEN(
"a valid XML file, a valid config file" )
61 WHEN(
"node is in file, default config" )
63 ingr::instGraphXML parentGraph;
65 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
66 {
"telescope",
"telescope",
"telescope",
"telescope" },
67 {
"type",
"propKey",
"propEl",
"propVal" },
68 {
"indiProp",
"tel.dome",
"status",
"on" } );
69 mx::app::appConfigurator config;
70 config.readConfig(
"/tmp/indiPropNode_test.conf" );
74 int rv = parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
77 REQUIRE( emsg ==
"" );
86 catch(
const std::exception &e )
88 std::cerr << e.what() <<
"\n";
91 REQUIRE( pass ==
true );
92 REQUIRE( tsn !=
nullptr );
94 REQUIRE( tsn->
name() ==
"telescope" );
95 REQUIRE( tsn->
node()->name() ==
"telescope" );
103 catch(
const std::exception &e )
105 std::cerr << e.what() <<
"\n";
108 REQUIRE( pass ==
true );
111 REQUIRE( tsn->
propKey() ==
"tel.dome" );
112 REQUIRE( tsn->
propEl() ==
"status" );
114 REQUIRE( tsn->
propValNum() == std::numeric_limits<double>::lowest() );
115 REQUIRE( tsn->
propValSw() == pcf::IndiElement::SwitchStateType::UnknownSwitchState );
116 REQUIRE( tsn->
type() == pcf::IndiProperty::Type::Unknown );
117 REQUIRE( tsn->
tol() == 1e-7 );
118 REQUIRE( tsn->
state() ==
false );
120 WHEN(
"node is in file, config setting tol" )
122 ingr::instGraphXML parentGraph;
124 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
125 {
"telescope",
"telescope",
"telescope",
"telescope",
"telescope" },
126 {
"type",
"propKey",
"propEl",
"propVal",
"tol" },
127 {
"indiProp",
"tel.dome",
"status",
"on",
"1e-8" } );
128 mx::app::appConfigurator config;
129 config.readConfig(
"/tmp/indiPropNode_test.conf" );
133 int rv = parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
136 REQUIRE( emsg ==
"" );
145 catch(
const std::exception &e )
147 std::cerr << e.what() <<
"\n";
150 REQUIRE( pass ==
true );
151 REQUIRE( tsn !=
nullptr );
153 REQUIRE( tsn->
name() ==
"telescope" );
154 REQUIRE( tsn->
node()->name() ==
"telescope" );
162 catch(
const std::exception &e )
164 std::cerr << e.what() <<
"\n";
167 REQUIRE( pass ==
true );
170 REQUIRE( tsn->
propKey() ==
"tel.dome" );
171 REQUIRE( tsn->
propEl() ==
"status" );
173 REQUIRE( tsn->
propValNum() == std::numeric_limits<double>::lowest() );
174 REQUIRE( tsn->
propValSw() == pcf::IndiElement::SwitchStateType::UnknownSwitchState );
175 REQUIRE( tsn->
type() == pcf::IndiProperty::Type::Unknown );
176 REQUIRE( tsn->
tol() == 1e-8 );
177 REQUIRE( tsn->
state() ==
false );
180 WHEN(
"node is in file, handling a text property" )
182 ingr::instGraphXML parentGraph;
184 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
185 {
"telescope",
"telescope",
"telescope",
"telescope" },
186 {
"type",
"propKey",
"propEl",
"propVal" },
187 {
"indiProp",
"tel.dome",
"status",
"on" } );
188 mx::app::appConfigurator config;
189 config.readConfig(
"/tmp/indiPropNode_test.conf" );
193 parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
198 pcf::IndiProperty ip( pcf::IndiProperty::Text );
199 ip.setDevice(
"tel" );
200 ip.setName(
"dome" );
201 ip.add( pcf::IndiElement(
"status" ) );
205 REQUIRE( tsn->
type() == pcf::IndiProperty::Text );
206 REQUIRE( tsn->
state() ==
true );
208 ip[
"status"] =
"off";
210 REQUIRE( tsn->
state() ==
false );
213 WHEN(
"node is in file, handling a number property" )
215 ingr::instGraphXML parentGraph;
217 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
218 {
"telescope",
"telescope",
"telescope",
"telescope" },
219 {
"type",
"propKey",
"propEl",
"propVal" },
220 {
"indiProp",
"tel.dome",
"status",
"1.5" } );
221 mx::app::appConfigurator config;
222 config.readConfig(
"/tmp/indiPropNode_test.conf" );
226 parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
231 pcf::IndiProperty ip( pcf::IndiProperty::Number );
232 ip.setDevice(
"tel" );
233 ip.setName(
"dome" );
234 ip.add( pcf::IndiElement(
"status" ) );
235 ip[
"status"] =
"1.5";
238 REQUIRE( tsn->
type() == pcf::IndiProperty::Number );
240 REQUIRE( tsn->
state() ==
true );
242 ip[
"status"] =
"1.6";
244 REQUIRE( tsn->
state() ==
false );
247 WHEN(
"node is in file, handling a switch property" )
249 ingr::instGraphXML parentGraph;
251 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
252 {
"telescope",
"telescope",
"telescope",
"telescope" },
253 {
"type",
"propKey",
"propEl",
"propVal" },
254 {
"indiProp",
"tel.dome",
"status",
"on" } );
255 mx::app::appConfigurator config;
256 config.readConfig(
"/tmp/indiPropNode_test.conf" );
260 parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
265 pcf::IndiProperty ip( pcf::IndiProperty::Switch );
266 ip.setDevice(
"tel" );
267 ip.setName(
"dome" );
268 ip.add( pcf::IndiElement(
"status" ) );
269 ip[
"status"].setSwitchState( pcf::IndiElement::SwitchStateType::On );
272 REQUIRE( tsn->
type() == pcf::IndiProperty::Switch );
273 REQUIRE( tsn->
propValSw() == pcf::IndiElement::SwitchStateType::On );
274 REQUIRE( tsn->
state() ==
true );
276 ip[
"status"].setSwitchState( pcf::IndiElement::SwitchStateType::Off );
278 REQUIRE( tsn->
state() ==
false );
282 GIVEN(
"invalid configs" )
284 WHEN(
"parent graph is null, default config" )
293 catch(
const std::exception &e )
295 std::cerr << e.what() <<
"\n";
298 REQUIRE( pass ==
false );
299 REQUIRE( tsn ==
nullptr );
301 WHEN(
"node not in file, default config" )
303 ingr::instGraphXML parentGraph;
305 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
306 {
"telescope",
"telescope",
"telescope",
"telescope" },
307 {
"type",
"propKey",
"propEl",
"propVal" },
308 {
"indiProp",
"tel.dome",
"status",
"on" } );
309 mx::app::appConfigurator config;
310 config.readConfig(
"/tmp/indiPropNode_test.conf" );
314 int rv = parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
317 REQUIRE( emsg ==
"" );
326 catch(
const std::exception &e )
328 std::cerr << e.what() <<
"\n";
331 REQUIRE( pass ==
false );
332 REQUIRE( tsn ==
nullptr );
335 WHEN(
"node is in file, default config, wrong node type" )
337 ingr::instGraphXML parentGraph;
339 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
340 {
"telescope",
"telescope",
"telescope",
"telescope" },
341 {
"type",
"propKey",
"propEl",
"propVal" },
342 {
"fakeProp",
"tel.dome",
"status",
"on" } );
343 mx::app::appConfigurator config;
344 config.readConfig(
"/tmp/indiPropNode_test.conf" );
348 int rv = parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
351 REQUIRE( emsg ==
"" );
360 catch(
const std::exception &e )
362 std::cerr << e.what() <<
"\n";
365 REQUIRE( pass ==
true );
366 REQUIRE( tsn !=
nullptr );
368 REQUIRE( tsn->
name() ==
"telescope" );
369 REQUIRE( tsn->
node()->name() ==
"telescope" );
377 catch(
const std::exception &e )
379 std::cerr << e.what() <<
"\n";
382 REQUIRE( pass ==
false );
384 WHEN(
"node is in file, default config, propKey empty" )
386 ingr::instGraphXML parentGraph;
388 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
389 {
"telescope",
"telescope",
"telescope",
"telescope" },
390 {
"type",
"propKey",
"propEl",
"propVal" },
391 {
"indiProp",
"",
"status",
"on" } );
392 mx::app::appConfigurator config;
393 config.readConfig(
"/tmp/indiPropNode_test.conf" );
397 int rv = parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
400 REQUIRE( emsg ==
"" );
409 catch(
const std::exception &e )
411 std::cerr << e.what() <<
"\n";
414 REQUIRE( pass ==
true );
415 REQUIRE( tsn !=
nullptr );
417 REQUIRE( tsn->
name() ==
"telescope" );
418 REQUIRE( tsn->
node()->name() ==
"telescope" );
426 catch(
const std::exception &e )
428 std::cerr << e.what() <<
"\n";
431 REQUIRE( pass ==
false );
433 WHEN(
"node is in file, default config, propEl empty" )
435 ingr::instGraphXML parentGraph;
437 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
438 {
"telescope",
"telescope",
"telescope",
"telescope" },
439 {
"type",
"propKey",
"propEl",
"propVal" },
440 {
"indiProp",
"tel.dome",
"",
"on" } );
441 mx::app::appConfigurator config;
442 config.readConfig(
"/tmp/indiPropNode_test.conf" );
446 int rv = parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
449 REQUIRE( emsg ==
"" );
458 catch(
const std::exception &e )
460 std::cerr << e.what() <<
"\n";
463 REQUIRE( pass ==
true );
464 REQUIRE( tsn !=
nullptr );
466 REQUIRE( tsn->
name() ==
"telescope" );
467 REQUIRE( tsn->
node()->name() ==
"telescope" );
475 catch(
const std::exception &e )
477 std::cerr << e.what() <<
"\n";
480 REQUIRE( pass ==
false );
482 WHEN(
"node is in file, default config, propVal empty" )
484 ingr::instGraphXML parentGraph;
486 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
487 {
"telescope",
"telescope",
"telescope",
"telescope" },
488 {
"type",
"propKey",
"propEl",
"propVal" },
489 {
"indiProp",
"tel.come",
"status",
"" } );
490 mx::app::appConfigurator config;
491 config.readConfig(
"/tmp/indiPropNode_test.conf" );
495 int rv = parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
498 REQUIRE( emsg ==
"" );
507 catch(
const std::exception &e )
509 std::cerr << e.what() <<
"\n";
512 REQUIRE( pass ==
true );
513 REQUIRE( tsn !=
nullptr );
515 REQUIRE( tsn->
name() ==
"telescope" );
516 REQUIRE( tsn->
node()->name() ==
"telescope" );
524 catch(
const std::exception &e )
526 std::cerr << e.what() <<
"\n";
529 REQUIRE( pass ==
false );
531 WHEN(
"a number property with invalid propVal" )
533 ingr::instGraphXML parentGraph;
535 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
536 {
"telescope",
"telescope",
"telescope",
"telescope" },
537 {
"type",
"propKey",
"propEl",
"propVal" },
538 {
"indiProp",
"tel.dome",
"status",
"abcde" } );
539 mx::app::appConfigurator config;
540 config.readConfig(
"/tmp/indiPropNode_test.conf" );
544 parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
549 pcf::IndiProperty ip( pcf::IndiProperty::Number );
550 ip.setDevice(
"tel" );
551 ip.setName(
"dome" );
552 ip.add( pcf::IndiElement(
"status" ) );
553 ip[
"status"] =
"1.5";
561 catch(
const std::exception &e )
563 std::cerr << e.what() <<
'\n';
566 REQUIRE( pass ==
false );
568 WHEN(
"invalid switch property" )
570 ingr::instGraphXML parentGraph;
572 mx::app::writeConfigFile(
"/tmp/indiPropNode_test.conf",
573 {
"telescope",
"telescope",
"telescope",
"telescope" },
574 {
"type",
"propKey",
"propEl",
"propVal" },
575 {
"indiProp",
"tel.dome",
"status",
"qq" } );
576 mx::app::appConfigurator config;
577 config.readConfig(
"/tmp/indiPropNode_test.conf" );
581 parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
586 pcf::IndiProperty ip( pcf::IndiProperty::Switch );
587 ip.setDevice(
"tel" );
588 ip.setName(
"dome" );
589 ip.add( pcf::IndiElement(
"status" ) );
590 ip[
"status"].setSwitchState( pcf::IndiElement::SwitchStateType::On );
598 catch(
const std::exception &e )
600 std::cerr << e.what() <<
'\n';
603 REQUIRE( pass ==
false );