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