8#include "../../../../tests/testXWC.hpp"
12#include "../../../../libMagAOX/libMagAOX.hpp"
14#define XWC_XIGNODE_TEST
15#include "../fsmNode.hpp"
29namespace xInstGraphTest
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";
39 fout <<
" <mxCell id=\"0\"/>\n";
40 fout <<
" <mxCell id=\"1\" parent=\"0\"/>\n";
41 fout <<
" <mxCell id=\"node:ttmpupil\">\n";
42 fout <<
"</mxCell>\n";
44 fout <<
" </mxGraphModel>\n";
45 fout <<
" </diagram>\n";
46 fout <<
"</mxfile>\n";
50SCENARIO(
"Creating and configuring an fsmNode",
"[instGraph::fsmNode]" )
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/fsmNode_test.conf", {
"ttmpupil" }, {
"type" }, {
"fsm" } );
66 mx::app::appConfigurator config;
67 config.readConfig(
"/tmp/fsmNode_test.conf" );
71 int rv = parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
74 REQUIRE( emsg ==
"" );
80 tsn =
new fsmNode(
"ttmpupil", &parentGraph );
83 catch(
const std::exception &e )
85 std::cerr << e.what() <<
"\n";
88 REQUIRE( pass ==
true );
89 REQUIRE( tsn !=
nullptr );
91 REQUIRE( tsn->
name() ==
"ttmpupil" );
92 REQUIRE( tsn->
node()->name() ==
"ttmpupil" );
100 catch(
const std::exception &e )
102 std::cerr << e.what() <<
"\n";
105 REQUIRE( pass ==
true );
108 REQUIRE( tsn->
device() ==
"ttmpupil" );
109 REQUIRE( tsn->
fsmKey() ==
"ttmpupil.fsm" );
113 WHEN(
"node is in file, setting action to threshOff for two states" )
115 ingr::instGraphXML parentGraph;
117 mx::app::writeConfigFile(
"/tmp/fsmNode_test.conf",
118 {
"ttmpupil",
"ttmpupil",
"ttmpupil" },
119 {
"type",
"fsmAction",
"targetStates" },
120 {
"fsm",
"threshOff",
"READY,OPERATING" } );
121 mx::app::appConfigurator config;
122 config.readConfig(
"/tmp/fsmNode_test.conf" );
126 int rv = parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
129 REQUIRE( emsg ==
"" );
135 tsn =
new fsmNode(
"ttmpupil", &parentGraph );
138 catch(
const std::exception &e )
140 std::cerr << e.what() <<
"\n";
143 REQUIRE( pass ==
true );
144 REQUIRE( tsn !=
nullptr );
146 REQUIRE( tsn->
name() ==
"ttmpupil" );
147 REQUIRE( tsn->
node()->name() ==
"ttmpupil" );
155 catch(
const std::exception &e )
157 std::cerr << e.what() <<
"\n";
160 REQUIRE( pass ==
true );
163 REQUIRE( tsn->
device() ==
"ttmpupil" );
164 REQUIRE( tsn->
fsmKey() ==
"ttmpupil.fsm" );
170 WHEN(
"node is in file, setting action to active for one state" )
172 ingr::instGraphXML parentGraph;
174 mx::app::writeConfigFile(
"/tmp/fsmNode_test.conf",
175 {
"ttmpupil",
"ttmpupil",
"ttmpupil" },
176 {
"type",
"fsmAction",
"targetStates" },
177 {
"fsm",
"active",
"OPERATING" } );
178 mx::app::appConfigurator config;
179 config.readConfig(
"/tmp/fsmNode_test.conf" );
183 int rv = parentGraph.loadXMLFile( emsg,
"/tmp/xigNode_test.xml" );
186 REQUIRE( emsg ==
"" );
192 tsn =
new fsmNode(
"ttmpupil", &parentGraph );
195 catch(
const std::exception &e )
197 std::cerr << e.what() <<
"\n";
200 REQUIRE( pass ==
true );
201 REQUIRE( tsn !=
nullptr );
203 REQUIRE( tsn->
name() ==
"ttmpupil" );
204 REQUIRE( tsn->
node()->name() ==
"ttmpupil" );
212 catch(
const std::exception &e )
214 std::cerr << e.what() <<
"\n";
217 REQUIRE( pass ==
true );
220 REQUIRE( tsn->
device() ==
"ttmpupil" );
221 REQUIRE( tsn->
fsmKey() ==
"ttmpupil.fsm" );
Implementation of an instGraph node interface for a MagAO-X Finite State Machine (FSM)
const std::vector< stateCodeT > & targetStates() const
Get the target states.
virtual void device(const std::string &dev)
Set the device name.
fsmNodeActionT fsmAction() const
Get the action.
void loadConfig(mx::app::appConfigurator &config)
Load this specific node's settings from an application configuration.
const std::string & fsmKey() const
Get the FSM unique key.
ingr::instNode * node()
Get the pointer to the underlying node.
std::string name()
Get the name of this node.
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.
@ OPERATING
The device is operating, other than homing.
@ READY
The device is ready for operation, but is not operating.