API
 
Loading...
Searching...
No Matches
stdMotionNode_test.cpp
Go to the documentation of this file.
1//#define CATCH_CONFIG_MAIN
2#include "../../../../tests/catch2/catch.hpp"
3
4#include <fstream>
5
6#include "../../../../libMagAOX/libMagAOX.hpp"
7
8#define XWC_XIGNODE_TEST
9#include "../stdMotionNode.hpp"
10
12{
13 std::ofstream fout("/tmp/xigNode_test.xml");
14 fout << "<mxfile host=\"test\">\n";
15 fout << " <diagram id=\"test\" name=\"test\">\n";
16 fout << " <mxGraphModel>\n";
17 fout << " <root>\n";
18 fout << " <mxCell id=\"0\"/>\n";
19 fout << " <mxCell id=\"1\" parent=\"0\"/>\n";
20 fout << " <mxCell id=\"node:fwtelsim\">\n";
21 fout << "</mxCell>\n";
22 fout << " </root>\n";
23 fout << " </mxGraphModel>\n";
24 fout << " </diagram>\n";
25 fout << "</mxfile>\n";
26 fout.close();
27}
28
29SCENARIO( "Creating and configuring a stdMotionNode", "[instGraph::stdMotionNode]" )
30{
31 GIVEN("a valid XML file, a valid config file")
32 {
33 WHEN("node is in file, default config")
34 {
35 ingr::instGraphXML parentGraph;
36 writeXML();
37 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim"},
38 {"type"},
39 {"stdMotion"} );
40 mx::app::appConfigurator config;
41 config.readConfig("/tmp/stdMotionNode_test.conf");
42
43 std::string emsg;
44
45 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
46
47 REQUIRE(rv == 0);
48 REQUIRE(emsg == "");
49
50 stdMotionNode * tsn = nullptr;
51 bool pass = false;
52 try
53 {
54 tsn = new stdMotionNode("fwtelsim", &parentGraph);
55 pass = true;
56 }
57 catch(const std::exception & e)
58 {
59 std::cerr << e.what() << "\n";
60 }
61
62 REQUIRE(pass == true);
63 REQUIRE(tsn != nullptr);
64
65 REQUIRE( tsn->name() == "fwtelsim");
66 REQUIRE( tsn->node()->name() == "fwtelsim");
67
68 pass = false;
69 try
70 {
71 tsn->loadConfig(config);
72 pass = true;
73 }
74 catch(const std::exception & e)
75 {
76 std::cerr << e.what() << "\n";
77 }
78
79 REQUIRE(pass == true);
80
81 //check defaults
82 REQUIRE(tsn->device() == "fwtelsim");
83 REQUIRE(tsn->presetPrefix() == "preset");
84 REQUIRE(tsn->presetDir() == ingr::ioDir::output);
85 REQUIRE(tsn->presetPutName().size() == 1);
86 REQUIRE(tsn->presetPutName()[0] == "out");
87 REQUIRE(tsn->trackingReqKey() == "");
88 REQUIRE(tsn->trackingReqElement() == "");
89 REQUIRE(tsn->trackerKey() == "");
90 REQUIRE(tsn->trackerElement() == "");
91 }
92
93 WHEN("node is in file, full config")
94 {
95 ingr::instGraphXML parentGraph;
96 writeXML();
97 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim", "fwtelsim", "fwtelsim", "fwtelsim", "fwtelsim", "fwtelsim", "fwtelsim", "fwtelsim",},
98 {"type", "device", "presetPrefix", "presetDir", "presetPutName", "trackingReqKey", "trackingReqElement", "trackerKey", "trackerElement"},
99 {"stdMotion", "devtelsim", "filter", "input", "filt1,filt2", "labrules.info", "trackreq", "adc.track", "toggle"} );
100 mx::app::appConfigurator config;
101 config.readConfig("/tmp/stdMotionNode_test.conf");
102
103 std::string emsg;
104
105 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
106
107 REQUIRE(rv == 0);
108 REQUIRE(emsg == "");
109
110 stdMotionNode * tsn = nullptr;
111 bool pass = false;
112 try
113 {
114 tsn = new stdMotionNode("fwtelsim", &parentGraph);
115 pass = true;
116 }
117 catch(const std::exception & e)
118 {
119 std::cerr << e.what() << "\n";
120 }
121
122 REQUIRE(pass == true);
123 REQUIRE(tsn != nullptr);
124
125 REQUIRE( tsn->name() == "fwtelsim");
126 REQUIRE( tsn->node()->name() == "fwtelsim");
127
128 pass = false;
129 try
130 {
131 tsn->loadConfig(config);
132 pass = true;
133 }
134 catch(const std::exception & e)
135 {
136 std::cerr << e.what() << "\n";
137 }
138
139 REQUIRE(pass == true);
140 REQUIRE(tsn->device() == "devtelsim");
141 REQUIRE(tsn->presetPrefix() == "filter");
142 REQUIRE(tsn->presetDir() == ingr::ioDir::input);
143 REQUIRE(tsn->presetPutName().size() == 2);
144 REQUIRE(tsn->presetPutName()[0] == "filt1");
145 REQUIRE(tsn->presetPutName()[1] == "filt2");
146 REQUIRE(tsn->trackerKey() == "adc.track");
147 REQUIRE(tsn->trackerElement() == "toggle");
148 }
149 }
150 GIVEN("an invalid parent graph")
151 {
152 WHEN("parent graph is null on construction")
153 {
154 ingr::instGraphXML * parentGraph = nullptr;
155
156 stdMotionNode * tsn = nullptr;
157 bool pass = false;
158 try
159 {
160 tsn = new stdMotionNode("fwtelsim", parentGraph);
161 pass = true;
162 }
163 catch(const std::exception & e)
164 {
165 std::cerr << e.what() << "\n";
166 }
167
168 // pass should be false b/c parentGraph being nullptr causes and exception
169 REQUIRE(pass == false);
170 REQUIRE(tsn == nullptr);
171 }
172
173 WHEN("valid xml, parent graph becomes null somehow")
174 {
175 ingr::instGraphXML parentGraph;
176 writeXML();
177 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim"},
178 {"type"},
179 {"stdMotion"} );
180 mx::app::appConfigurator config;
181 config.readConfig("/tmp/stdMotionNode_test.conf");
182
183 std::string emsg;
184
185 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
186
187 REQUIRE(rv == 0);
188 REQUIRE(emsg == "");
189
190 stdMotionNode * tsn = nullptr;
191 bool pass = false;
192 try
193 {
194 tsn = new stdMotionNode("fwtelsim", &parentGraph);
195 pass = true;
196 }
197 catch(const std::exception & e)
198 {
199 std::cerr << e.what() << "\n";
200 }
201
202 REQUIRE(pass == true);
203 REQUIRE(tsn != nullptr);
204
205 REQUIRE( tsn->name() == "fwtelsim");
206 REQUIRE( tsn->node()->name() == "fwtelsim");
207
208 //Set it to null for testing
209 tsn->setParentGraphNull();
210
211 pass = false;
212 try
213 {
214 tsn->loadConfig(config);
215 pass = true;
216 }
217 catch(const std::exception & e)
218 {
219 std::cerr << e.what() << "\n";
220 }
221
222 REQUIRE(pass == false);
223 }
224 }
225
226 GIVEN("an invalid config file")
227 {
228 WHEN("node is in xml file, does not have type set in config")
229 {
230 ingr::instGraphXML parentGraph;
231 writeXML();
232 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim"},
233 {""},
234 {""} );
235 mx::app::appConfigurator config;
236 config.readConfig("/tmp/stdMotionNode_test.conf");
237
238 std::string emsg;
239
240 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
241
242 REQUIRE(rv == 0);
243 REQUIRE(emsg == "");
244
245 // First we load the XML file which has fwtelsim
246 stdMotionNode * tsn = nullptr;
247 bool pass = false;
248 try
249 {
250 tsn = new stdMotionNode("fwtelsim", &parentGraph);
251 pass = true;
252 }
253 catch(const std::exception & e)
254 {
255 std::cerr << e.what() << "\n";
256 }
257
258 REQUIRE(pass == true);
259 REQUIRE(tsn != nullptr);
260
261 REQUIRE( tsn->name() == "fwtelsim");
262 REQUIRE( tsn->node()->name() == "fwtelsim");
263
264 //Now we load the config, which should fail b/c type isn't set, so pass should stay false
265 pass = false;
266 try
267 {
268 tsn->loadConfig(config);
269 pass = true;
270 }
271 catch(const std::exception & e)
272 {
273 std::cerr << e.what() << "\n";
274 }
275
276 REQUIRE(pass == false);
277
278 }
279
280 WHEN("node is in xml file, has wrong type in config")
281 {
282 ingr::instGraphXML parentGraph;
283 writeXML();
284 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim"},
285 {"type"},
286 {"xigNode"} );
287 mx::app::appConfigurator config;
288 config.readConfig("/tmp/stdMotionNode_test.conf");
289
290 std::string emsg;
291
292 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
293
294 REQUIRE(rv == 0);
295 REQUIRE(emsg == "");
296
297 // First we load the XML file which has fwtelsim
298 stdMotionNode * tsn = nullptr;
299 bool pass = false;
300 try
301 {
302 tsn = new stdMotionNode("fwtelsim", &parentGraph);
303 pass = true;
304 }
305 catch(const std::exception & e)
306 {
307 std::cerr << e.what() << "\n";
308 }
309
310 REQUIRE(pass == true);
311 REQUIRE(tsn != nullptr);
312
313 REQUIRE( tsn->name() == "fwtelsim");
314 REQUIRE( tsn->node()->name() == "fwtelsim");
315
316 //Now we load the config, which should fail b/c type is wrong, so pass should stay false
317 pass = false;
318 try
319 {
320 tsn->loadConfig(config);
321 pass = true;
322 }
323 catch(const std::exception & e)
324 {
325 std::cerr << e.what() << "\n";
326 }
327
328 REQUIRE(pass == false);
329
330 }
331
332 WHEN("node is in xml file, is not in config")
333 {
334 ingr::instGraphXML parentGraph;
335 writeXML();
336 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"nonode"},
337 {"type"},
338 {"stdMotion"} );
339 mx::app::appConfigurator config;
340 config.readConfig("/tmp/stdMotionNode_test.conf");
341
342 std::string emsg;
343
344 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
345
346 REQUIRE(rv == 0);
347 REQUIRE(emsg == "");
348
349 // First we load the XML file which has fwtelsim
350 stdMotionNode * tsn = nullptr;
351 bool pass = false;
352 try
353 {
354 tsn = new stdMotionNode("fwtelsim", &parentGraph);
355 pass = true;
356 }
357 catch(const std::exception & e)
358 {
359 std::cerr << e.what() << "\n";
360 }
361
362 REQUIRE(pass == true);
363 REQUIRE(tsn != nullptr);
364
365 REQUIRE( tsn->name() == "fwtelsim");
366 REQUIRE( tsn->node()->name() == "fwtelsim");
367
368 //Now we load the config, which should fail b/c it doesn't have fwtelsim, so pass should stay false
369 pass = false;
370 try
371 {
372 tsn->loadConfig(config);
373 pass = true;
374 }
375 catch(const std::exception & e)
376 {
377 std::cerr << e.what() << "\n";
378 }
379
380 REQUIRE(pass == false);
381
382 }
383
384 WHEN("config invalid: changing device")
385 {
386 ingr::instGraphXML parentGraph;
387 writeXML();
388 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim"},
389 {"type", "device"},
390 {"stdMotion", "device2"} );
391 mx::app::appConfigurator config;
392 config.readConfig("/tmp/stdMotionNode_test.conf");
393
394 std::string emsg;
395
396 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
397
398 REQUIRE(rv == 0);
399 REQUIRE(emsg == "");
400
401 // First we load the XML file which has fwtelsim
402 stdMotionNode * tsn = nullptr;
403 bool pass = false;
404 try
405 {
406 tsn = new stdMotionNode("fwtelsim", &parentGraph);
407 pass = true;
408 }
409 catch(const std::exception & e)
410 {
411 std::cerr << e.what() << "\n";
412 }
413
414 REQUIRE(pass == true);
415 REQUIRE(tsn != nullptr);
416
417 REQUIRE( tsn->name() == "fwtelsim");
418 REQUIRE( tsn->node()->name() == "fwtelsim");
419
420 tsn->device("device1");
421
422 //Now we load the config, which should fail b/c device is already set, so pass should stay false
423 pass = false;
424 try
425 {
426 tsn->loadConfig(config);
427 pass = true;
428 }
429 catch(const std::exception & e)
430 {
431 std::cerr << e.what() << "\n";
432 }
433
434 REQUIRE(pass == false);
435
436 }
437
438 WHEN("config invalid: changing presetName")
439 {
440 ingr::instGraphXML parentGraph;
441 writeXML();
442 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim"},
443 {"type", "presetPrefix"},
444 {"stdMotion", "preset2"} );
445 mx::app::appConfigurator config;
446 config.readConfig("/tmp/stdMotionNode_test.conf");
447
448 std::string emsg;
449
450 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
451
452 REQUIRE(rv == 0);
453 REQUIRE(emsg == "");
454
455 // First we load the XML file which has fwtelsim
456 stdMotionNode * tsn = nullptr;
457 bool pass = false;
458 try
459 {
460 tsn = new stdMotionNode("fwtelsim", &parentGraph);
461 pass = true;
462 }
463 catch(const std::exception & e)
464 {
465 std::cerr << e.what() << "\n";
466 }
467
468 REQUIRE(pass == true);
469 REQUIRE(tsn != nullptr);
470
471 REQUIRE( tsn->name() == "fwtelsim");
472 REQUIRE( tsn->node()->name() == "fwtelsim");
473
474 tsn->presetPrefix("preset1");
475
476 //Now we load the config, which should fail b/c presetName is already set, so pass should stay false
477 pass = false;
478 try
479 {
480 tsn->loadConfig(config);
481 pass = true;
482 }
483 catch(const std::exception & e)
484 {
485 std::cerr << e.what() << "\n";
486 }
487
488 REQUIRE(pass == false);
489
490 }
491
492 WHEN("config invalid: invalid presetDir")
493 {
494 ingr::instGraphXML parentGraph;
495 writeXML();
496 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim"},
497 {"type", "presetDir"},
498 {"stdMotion", "wrongput"} );
499 mx::app::appConfigurator config;
500 config.readConfig("/tmp/stdMotionNode_test.conf");
501
502 std::string emsg;
503
504 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
505
506 REQUIRE(rv == 0);
507 REQUIRE(emsg == "");
508
509 // First we load the XML file which has fwtelsim
510 stdMotionNode * tsn = nullptr;
511 bool pass = false;
512 try
513 {
514 tsn = new stdMotionNode("fwtelsim", &parentGraph);
515 pass = true;
516 }
517 catch(const std::exception & e)
518 {
519 std::cerr << e.what() << "\n";
520 }
521
522 REQUIRE(pass == true);
523 REQUIRE(tsn != nullptr);
524
525 REQUIRE( tsn->name() == "fwtelsim");
526 REQUIRE( tsn->node()->name() == "fwtelsim");
527
528 //Now we load the config, which should fail b/c presetDir is neither input nor output, so pass should stay false
529 pass = false;
530 try
531 {
532 tsn->loadConfig(config);
533 pass = true;
534 }
535 catch(const std::exception & e)
536 {
537 std::cerr << e.what() << "\n";
538 }
539
540 REQUIRE(pass == false);
541
542 }
543
544 WHEN("config invalid: presetPutName empty")
545 {
546 ingr::instGraphXML parentGraph;
547 writeXML();
548 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim"},
549 {"type", "presetPutName"},
550 {"stdMotion", ""} );
551 mx::app::appConfigurator config;
552 config.readConfig("/tmp/stdMotionNode_test.conf");
553
554 std::string emsg;
555
556 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
557
558 REQUIRE(rv == 0);
559 REQUIRE(emsg == "");
560
561 // First we load the XML file which has fwtelsim
562 stdMotionNode * tsn = nullptr;
563 bool pass = false;
564 try
565 {
566 tsn = new stdMotionNode("fwtelsim", &parentGraph);
567 pass = true;
568 }
569 catch(const std::exception & e)
570 {
571 std::cerr << e.what() << "\n";
572 }
573
574 REQUIRE(pass == true);
575 REQUIRE(tsn != nullptr);
576
577 REQUIRE( tsn->name() == "fwtelsim");
578 REQUIRE( tsn->node()->name() == "fwtelsim");
579
580 //Now we load the config, which should fail b/c presetPutName is empty, so pass should stay false
581 pass = false;
582 try
583 {
584 tsn->loadConfig(config);
585 pass = true;
586 }
587 catch(const std::exception & e)
588 {
589 std::cerr << e.what() << "\n";
590 }
591
592 REQUIRE(pass == false);
593
594 }
595
596 WHEN("config invalid: only trackingReqKey provided")
597 {
598 ingr::instGraphXML parentGraph;
599 writeXML();
600 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim"},
601 {"type", "trackingReqKey"},
602 {"stdMotion", "labrules.info"} );
603 mx::app::appConfigurator config;
604 config.readConfig("/tmp/stdMotionNode_test.conf");
605
606 std::string emsg;
607
608 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
609
610 REQUIRE(rv == 0);
611 REQUIRE(emsg == "");
612
613 // First we load the XML file which has fwtelsim
614 stdMotionNode * tsn = nullptr;
615 bool pass = false;
616 try
617 {
618 tsn = new stdMotionNode("fwtelsim", &parentGraph);
619 pass = true;
620 }
621 catch(const std::exception & e)
622 {
623 std::cerr << e.what() << "\n";
624 }
625
626 REQUIRE(pass == true);
627 REQUIRE(tsn != nullptr);
628
629 REQUIRE( tsn->name() == "fwtelsim");
630 REQUIRE( tsn->node()->name() == "fwtelsim");
631
632 //Now we load the config, which should fail b/c trackerElement is empty, so pass should stay false
633 pass = false;
634 try
635 {
636 tsn->loadConfig(config);
637 pass = true;
638 }
639 catch(const std::exception & e)
640 {
641 std::cerr << e.what() << "\n";
642 }
643
644 REQUIRE(pass == false);
645
646 }
647
648 WHEN("config invalid: only trackingReqElement provided")
649 {
650 ingr::instGraphXML parentGraph;
651 writeXML();
652 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim"},
653 {"type", "trackingReqElement"},
654 {"stdMotion", "toggle"} );
655 mx::app::appConfigurator config;
656 config.readConfig("/tmp/stdMotionNode_test.conf");
657
658 std::string emsg;
659
660 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
661
662 REQUIRE(rv == 0);
663 REQUIRE(emsg == "");
664
665 // First we load the XML file which has fwtelsim
666 stdMotionNode * tsn = nullptr;
667 bool pass = false;
668 try
669 {
670 tsn = new stdMotionNode("fwtelsim", &parentGraph);
671 pass = true;
672 }
673 catch(const std::exception & e)
674 {
675 std::cerr << e.what() << "\n";
676 }
677
678 REQUIRE(pass == true);
679 REQUIRE(tsn != nullptr);
680
681 REQUIRE( tsn->name() == "fwtelsim");
682 REQUIRE( tsn->node()->name() == "fwtelsim");
683
684 //Now we load the config, which should fail b/c trackerKey is empty, so pass should stay false
685 pass = false;
686 try
687 {
688 tsn->loadConfig(config);
689 pass = true;
690 }
691 catch(const std::exception & e)
692 {
693 std::cerr << e.what() << "\n";
694 }
695
696 REQUIRE(pass == false);
697
698 }
699
700 WHEN("config invalid: only trackerKey provided")
701 {
702 ingr::instGraphXML parentGraph;
703 writeXML();
704 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim"},
705 {"type", "trackerKey"},
706 {"stdMotion", "adctrack.tracking"} );
707 mx::app::appConfigurator config;
708 config.readConfig("/tmp/stdMotionNode_test.conf");
709
710 std::string emsg;
711
712 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
713
714 REQUIRE(rv == 0);
715 REQUIRE(emsg == "");
716
717 // First we load the XML file which has fwtelsim
718 stdMotionNode * tsn = nullptr;
719 bool pass = false;
720 try
721 {
722 tsn = new stdMotionNode("fwtelsim", &parentGraph);
723 pass = true;
724 }
725 catch(const std::exception & e)
726 {
727 std::cerr << e.what() << "\n";
728 }
729
730 REQUIRE(pass == true);
731 REQUIRE(tsn != nullptr);
732
733 REQUIRE( tsn->name() == "fwtelsim");
734 REQUIRE( tsn->node()->name() == "fwtelsim");
735
736 //Now we load the config, which should fail b/c trackerElement is empty, so pass should stay false
737 pass = false;
738 try
739 {
740 tsn->loadConfig(config);
741 pass = true;
742 }
743 catch(const std::exception & e)
744 {
745 std::cerr << e.what() << "\n";
746 }
747
748 REQUIRE(pass == false);
749
750 }
751
752 WHEN("config invalid: only trackerElement provided")
753 {
754 ingr::instGraphXML parentGraph;
755 writeXML();
756 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim"},
757 {"type", "trackerElement"},
758 {"stdMotion", "toggle"} );
759 mx::app::appConfigurator config;
760 config.readConfig("/tmp/stdMotionNode_test.conf");
761
762 std::string emsg;
763
764 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
765
766 REQUIRE(rv == 0);
767 REQUIRE(emsg == "");
768
769 // First we load the XML file which has fwtelsim
770 stdMotionNode * tsn = nullptr;
771 bool pass = false;
772 try
773 {
774 tsn = new stdMotionNode("fwtelsim", &parentGraph);
775 pass = true;
776 }
777 catch(const std::exception & e)
778 {
779 std::cerr << e.what() << "\n";
780 }
781
782 REQUIRE(pass == true);
783 REQUIRE(tsn != nullptr);
784
785 REQUIRE( tsn->name() == "fwtelsim");
786 REQUIRE( tsn->node()->name() == "fwtelsim");
787
788 //Now we load the config, which should fail b/c trackerKey is empty, so pass should stay false
789 pass = false;
790 try
791 {
792 tsn->loadConfig(config);
793 pass = true;
794 }
795 catch(const std::exception & e)
796 {
797 std::cerr << e.what() << "\n";
798 }
799
800 REQUIRE(pass == false);
801
802 }
803
804 WHEN("config invalid: only trackingReqKey and trackingReqElement provided")
805 {
806 ingr::instGraphXML parentGraph;
807 writeXML();
808 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim", "fwtelsim"},
809 {"type", "trackingReqKey", "trackingReqElement"},
810 {"stdMotion", "labrules.info", "adcTrackingReq"} );
811 mx::app::appConfigurator config;
812 config.readConfig("/tmp/stdMotionNode_test.conf");
813
814 std::string emsg;
815
816 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
817
818 REQUIRE(rv == 0);
819 REQUIRE(emsg == "");
820
821 // First we load the XML file which has fwtelsim
822 stdMotionNode * tsn = nullptr;
823 bool pass = false;
824 try
825 {
826 tsn = new stdMotionNode("fwtelsim", &parentGraph);
827 pass = true;
828 }
829 catch(const std::exception & e)
830 {
831 std::cerr << e.what() << "\n";
832 }
833
834 REQUIRE(pass == true);
835 REQUIRE(tsn != nullptr);
836
837 REQUIRE( tsn->name() == "fwtelsim");
838 REQUIRE( tsn->node()->name() == "fwtelsim");
839
840 //Now we load the config, which should fail b/c trackerElement is empty, so pass should stay false
841 pass = false;
842 try
843 {
844 tsn->loadConfig(config);
845 pass = true;
846 }
847 catch(const std::exception & e)
848 {
849 std::cerr << e.what() << "\n";
850 }
851
852 REQUIRE(pass == false);
853
854 }
855
856 WHEN("config invalid: only trackerKey and trackerElement provided")
857 {
858 ingr::instGraphXML parentGraph;
859 writeXML();
860 mx::app::writeConfigFile( "/tmp/stdMotionNode_test.conf", {"fwtelsim", "fwtelsim", "fwtelsim"},
861 {"type", "trackerKey", "trackerElement"},
862 {"stdMotion", "adctrack.tracking", "toggle"} );
863 mx::app::appConfigurator config;
864 config.readConfig("/tmp/stdMotionNode_test.conf");
865
866 std::string emsg;
867
868 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
869
870 REQUIRE(rv == 0);
871 REQUIRE(emsg == "");
872
873 // First we load the XML file which has fwtelsim
874 stdMotionNode * tsn = nullptr;
875 bool pass = false;
876 try
877 {
878 tsn = new stdMotionNode("fwtelsim", &parentGraph);
879 pass = true;
880 }
881 catch(const std::exception & e)
882 {
883 std::cerr << e.what() << "\n";
884 }
885
886 REQUIRE(pass == true);
887 REQUIRE(tsn != nullptr);
888
889 REQUIRE( tsn->name() == "fwtelsim");
890 REQUIRE( tsn->node()->name() == "fwtelsim");
891
892 //Now we load the config, which should fail b/c trackerElement is empty, so pass should stay false
893 pass = false;
894 try
895 {
896 tsn->loadConfig(config);
897 pass = true;
898 }
899 catch(const std::exception & e)
900 {
901 std::cerr << e.what() << "\n";
902 }
903
904 REQUIRE(pass == false);
905
906 }
907 }
908}
909
910SCENARIO( "Sending Properties to a stdMotionNode", "[instGraph::stdMotionNode]" )
911{
912 GIVEN("a configured stdMotionNode with tracking")
913 {
914 //First configure the node
915 ingr::instGraphXML parentGraph;
916 writeXML();
917
918 std::string emsg;
919 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
920
921 REQUIRE(rv == 0);
922 REQUIRE(emsg == "");
923
924 stdMotionNode * tsn = nullptr;
925 bool pass = false;
926 try
927 {
928 tsn = new stdMotionNode("fwtelsim", &parentGraph);
929 pass = true;
930 }
931 catch(const std::exception & e)
932 {
933 std::cerr << e.what() << "\n";
934 }
935
936 REQUIRE(pass == true);
937 REQUIRE(tsn != nullptr);
938
939 REQUIRE( tsn->name() == "fwtelsim");
940 REQUIRE( tsn->node()->name() == "fwtelsim");
941
942 tsn->device("fwtelsim");
943 tsn->presetPrefix("filter");
944 tsn->trackingReqKey("labrules.info");
945 tsn->trackingReqElement("adcTrackReq");
946 tsn->trackerKey("adctrack.tracking");
947 tsn->trackerElement("toggle");
948
949 WHEN("tracking off, tracking not rquired")
950 {
951 pcf::IndiProperty ipSend;
952 ipSend.setDevice("adctrack");
953 ipSend.setName("tracking");
954 ipSend.add(pcf::IndiElement("toggle"));
955 ipSend["toggle"].setSwitchState(pcf::IndiElement::Off);
956
957 tsn->handleSetProperty(ipSend);
958
959 pcf::IndiProperty ipSend2;
960 ipSend2.setDevice("labrules");
961 ipSend2.setName("info");
962 ipSend2.add(pcf::IndiElement("adcTrackReq"));
963 ipSend2["adcTrackReq"].setSwitchState(pcf::IndiElement::Off);
964
965 tsn->handleSetProperty(ipSend2);
966
967 pcf::IndiProperty ipSend3;
968 ipSend3.setDevice("fwtelsim");
969 ipSend3.setName("filterName");
970 ipSend3.add(pcf::IndiElement("filt1"));
971 ipSend3["filt1"].setSwitchState(pcf::IndiElement::On);
972 ipSend3.add(pcf::IndiElement("none"));
973 ipSend3["none"].setSwitchState(pcf::IndiElement::Off);
974
975 tsn->handleSetProperty(ipSend3);
976
977 REQUIRE(tsn->curLabel() == "off");
978
979 pcf::IndiProperty ipSend4;
980 ipSend4.setDevice("fwtelsim");
981 ipSend4.setName("fsm");
982 ipSend4.add(pcf::IndiElement("state"));
983 ipSend4["state"].set("READY");
984
985 tsn->handleSetProperty(ipSend4);
986
987 REQUIRE(tsn->curLabel() == "filt1");
988
989 ipSend2["adcTrackReq"].setSwitchState(pcf::IndiElement::On);
990 tsn->handleSetProperty(ipSend2);
991
992 REQUIRE(tsn->curLabel() == "not tracking");
993
994 ipSend["toggle"].setSwitchState(pcf::IndiElement::On);
995 tsn->handleSetProperty(ipSend);
996
997 REQUIRE(tsn->curLabel() == "tracking");
998
999 ipSend4["state"].set("OPERATING");
1000 tsn->handleSetProperty(ipSend4);
1001
1002 REQUIRE(tsn->curLabel() == "tracking");
1003
1004 ipSend2["adcTrackReq"].setSwitchState(pcf::IndiElement::Off);
1005 tsn->handleSetProperty(ipSend2);
1006
1007 //Now we're still tracking and OPERATING, but shouldn't be
1008 REQUIRE(tsn->curLabel() == "tracking");
1009
1010 ipSend["toggle"].setSwitchState(pcf::IndiElement::Off);
1011 tsn->handleSetProperty(ipSend);
1012
1013 //Now we're not tracking, but still OPERATING and in filt1
1014 REQUIRE(tsn->curLabel() == "off");
1015
1016 ipSend3["filt1"].setSwitchState(pcf::IndiElement::Off);
1017 tsn->handleSetProperty(ipSend3);
1018
1019 ipSend4["state"].set("READY");
1020 tsn->handleSetProperty(ipSend4);
1021
1022 //Now we're in READY but nothing is on
1023 REQUIRE(tsn->curLabel() == "off");
1024
1025 ipSend3["filt1"].setSwitchState(pcf::IndiElement::On);
1026 tsn->handleSetProperty(ipSend3);
1027
1028 //Now filt1 is on
1029 REQUIRE(tsn->curLabel() == "filt1");
1030
1031 ipSend3["filt1"].setSwitchState(pcf::IndiElement::Off);
1032 ipSend3["none"].setSwitchState(pcf::IndiElement::On);
1033
1034 tsn->handleSetProperty(ipSend3);
1035
1036 //Now none is on
1037 REQUIRE(tsn->curLabel() == "off");
1038
1039 ipSend3["filt1"].setSwitchState(pcf::IndiElement::On);
1040 ipSend3["none"].setSwitchState(pcf::IndiElement::Off);
1041
1042 tsn->handleSetProperty(ipSend3);
1043
1044 //Now filt1 is back on
1045 REQUIRE(tsn->curLabel() == "filt1");
1046 }
1047 }
1048}
void trackerKey(const std::string &tk)
void trackingReqElement(const std::string &te)
void trackingReqKey(const std::string &tk)
void trackerElement(const std::string &te)
virtual void device(const std::string &dev)
Set the device name. This can only be done once.
virtual int handleSetProperty(const pcf::IndiProperty &ipRecv)
INDI SetProperty callback.
void loadConfig(mx::app::appConfigurator &config)
void presetDir(const ingr::ioDir &dir)
const std::string & curLabel()
Get the current label text.
virtual void presetPrefix(const std::string &pp)
void presetPutName(const std::vector< std::string > &ppp)
ingr::instNode * node()
Get the pointer to the underlying node.
Definition xigNode.hpp:121
std::string name()
Get the name of this node.
Definition xigNode.hpp:106
void writeXML()
SCENARIO("Creating and configuring a stdMotionNode", "[instGraph::stdMotionNode]")