API
 
Loading...
Searching...
No Matches
fsmNode_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 "../fsmNode.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:ttmpupil\">\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 an fsmNode", "[instGraph::fsmNode]" )
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/fsmNode_test.conf", {"ttmpupil"},
38 {"type"},
39 {"fsm"} );
40 mx::app::appConfigurator config;
41 config.readConfig("/tmp/fsmNode_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 fsmNode * tsn = nullptr;
51 bool pass = false;
52 try
53 {
54 tsn = new fsmNode("ttmpupil", &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() == "ttmpupil");
66 REQUIRE( tsn->node()->name() == "ttmpupil");
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 config-ed values
82 REQUIRE(tsn->device() == "ttmpupil");
83 REQUIRE(tsn->fsmKey() == "ttmpupil.fsm");
84 REQUIRE(tsn->fsmAction() == fsmNodeActionT::passive);
85 REQUIRE(tsn->targetStates().size() == 0);
86 }
87 WHEN("node is in file, setting action to threshOff for two states")
88 {
89 ingr::instGraphXML parentGraph;
90 writeXML();
91 mx::app::writeConfigFile( "/tmp/fsmNode_test.conf", {"ttmpupil","ttmpupil","ttmpupil"},
92 {"type", "fsmAction", "targetStates"},
93 {"fsm", "threshOff", "READY,OPERATING"} );
94 mx::app::appConfigurator config;
95 config.readConfig("/tmp/fsmNode_test.conf");
96
97 std::string emsg;
98
99 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
100
101 REQUIRE(rv == 0);
102 REQUIRE(emsg == "");
103
104 fsmNode * tsn = nullptr;
105 bool pass = false;
106 try
107 {
108 tsn = new fsmNode("ttmpupil", &parentGraph);
109 pass = true;
110 }
111 catch(const std::exception & e)
112 {
113 std::cerr << e.what() << "\n";
114 }
115
116 REQUIRE(pass == true);
117 REQUIRE(tsn != nullptr);
118
119 REQUIRE( tsn->name() == "ttmpupil");
120 REQUIRE( tsn->node()->name() == "ttmpupil");
121
122 pass = false;
123 try
124 {
125 tsn->loadConfig(config);
126 pass = true;
127 }
128 catch(const std::exception & e)
129 {
130 std::cerr << e.what() << "\n";
131 }
132
133 REQUIRE(pass == true);
134
135 //check config-ed values
136 REQUIRE(tsn->device() == "ttmpupil");
137 REQUIRE(tsn->fsmKey() == "ttmpupil.fsm");
138 REQUIRE(tsn->fsmAction() == fsmNodeActionT::threshOff);
139 REQUIRE(tsn->targetStates().size() == 2);
140 REQUIRE(tsn->targetStates()[0] == MagAOX::app::stateCodes::READY);
142 }
143 WHEN("node is in file, setting action to active for one state")
144 {
145 ingr::instGraphXML parentGraph;
146 writeXML();
147 mx::app::writeConfigFile( "/tmp/fsmNode_test.conf", {"ttmpupil","ttmpupil","ttmpupil"},
148 {"type", "fsmAction", "targetStates"},
149 {"fsm", "active", "OPERATING"} );
150 mx::app::appConfigurator config;
151 config.readConfig("/tmp/fsmNode_test.conf");
152
153 std::string emsg;
154
155 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
156
157 REQUIRE(rv == 0);
158 REQUIRE(emsg == "");
159
160 fsmNode * tsn = nullptr;
161 bool pass = false;
162 try
163 {
164 tsn = new fsmNode("ttmpupil", &parentGraph);
165 pass = true;
166 }
167 catch(const std::exception & e)
168 {
169 std::cerr << e.what() << "\n";
170 }
171
172 REQUIRE(pass == true);
173 REQUIRE(tsn != nullptr);
174
175 REQUIRE( tsn->name() == "ttmpupil");
176 REQUIRE( tsn->node()->name() == "ttmpupil");
177
178 pass = false;
179 try
180 {
181 tsn->loadConfig(config);
182 pass = true;
183 }
184 catch(const std::exception & e)
185 {
186 std::cerr << e.what() << "\n";
187 }
188
189 REQUIRE(pass == true);
190
191 //check config-ed values
192 REQUIRE(tsn->device() == "ttmpupil");
193 REQUIRE(tsn->fsmKey() == "ttmpupil.fsm");
194 REQUIRE(tsn->fsmAction() == fsmNodeActionT::active);
195 REQUIRE(tsn->targetStates().size() == 1);
197 }
198 }
199}
Implementation of an instGraph node interface for a MagAO-X Finite State Machine (FSM)
Definition fsmNode.hpp:69
const std::vector< stateCodeT > & targetStates() const
Get the target states.
Definition fsmNode.hpp:305
virtual void device(const std::string &dev)
Set the device name.
Definition fsmNode.hpp:201
fsmNodeActionT fsmAction() const
Get the action.
Definition fsmNode.hpp:295
void loadConfig(mx::app::appConfigurator &config)
Load this specific node's settings from an application configuration.
Definition fsmNode.hpp:310
const std::string & fsmKey() const
Get the FSM unique key.
Definition fsmNode.hpp:290
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()
@ OPERATING
The device is operating, other than homing.
@ READY
The device is ready for operation, but is not operating.