API
 
Loading...
Searching...
No Matches
xInstGraph_test.cpp
Go to the documentation of this file.
1/** \file xInstGraph_test.cpp
2 * \brief Catch2 tests for the xInstGraph app.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup xInstGraph_files
6 */
7
8#include "../../../tests/testXWC.hpp"
9#include "../../tests/testMacrosINDI.hpp"
10
11#include "../xInstGraph.hpp"
12
13using namespace MagAOX::app;
14
15namespace libXWCTest
16{
17
18/** \defgroup xInstGraph_unit_test xInstGraph Unit Tests
19 * \brief Unit tests for the xInstGraph application.
20 *
21 * \ingroup application_unit_test
22 */
23
24/// Namespace for `xInstGraph` unit tests.
25/** \ingroup xInstGraph_unit_test
26 */
27namespace xInstGraphTest
28{
29
30/// \cond DOXYGEN_SUPPRESS_TEST_HARNESS
32{
33 public:
34 void configDir( const std::string &cp )
35 {
36 m_configDir = cp;
37 }
38
39 mx::app::appConfigurator &config()
40 {
41 return MagAOX::app::xInstGraph::config;
42 }
43};
44/// \endcond
45
46/// Write a minimal draw.io graph containing one of each supported node type.
48{
49 std::ofstream fout( "/tmp/xInstGraph_test/config/instgraph_test.drawio" );
50 fout << "<mxfile host=\"test\">\n";
51 fout << " <diagram id=\"test\" name=\"test\">\n";
52 fout << " <mxGraphModel>\n";
53 fout << " <root>\n";
54 fout << " <mxCell id=\"0\"/>\n";
55 fout << " <mxCell id=\"1\" parent=\"0\"/>\n";
56 fout << " <mxCell id=\"node:fsmNode\">\n";
57 fout << "</mxCell>\n";
58 fout << " <mxCell id=\"node:indiPropNode\">\n";
59 fout << "</mxCell>\n";
60 fout << " <mxCell id=\"node:pwrOnOffNode\">\n";
61 fout << "</mxCell>\n";
62 fout << " <mxCell id=\"node:stdMotionNode\">\n";
63 fout << "</mxCell>\n";
64 fout << " <mxCell id=\"node:staticNode\">\n";
65 fout << "</mxCell>\n";
66 fout << " </root>\n";
67 fout << " </mxGraphModel>\n";
68 fout << " </diagram>\n";
69 fout << "</mxfile>\n";
70 fout.close();
71}
72
73/// Verify xInstGraph configures and runs when given a minimal graph with all supported node types.
74/**
75 * \ingroup xInstGraph_unit_test
76 */
77TEST_CASE( "Configuring xInstGraph with no errors", "[xInstGraph]" )
78{
79 // clang-format off
80 #ifdef XINSTGRAPH_TEST_DOXYGEN_REF
86 xInstGraph::st_igHandleSetProperty( nullptr, pcf::IndiProperty() );
87 #endif
88 // clang-format on
89
90 mx::ioutils::createDirectories( "/tmp/xInstGraph_test/config" );
91
92 writeXML();
93
94 SECTION( "A valid configuration with each node type" )
95 {
96 std::vector<std::string> sections;
97 std::vector<std::string> keys;
98 std::vector<std::string> values;
99
100 sections.insert( sections.end(), { "graph", "graph" } );
101 keys.insert( keys.end(), { "file", "outputPath" } );
102 values.insert( values.end(), { "instgraph_test.drawio", "/tmp/xInstGraph_test/instgraph_test_out.drawio" } );
103
104 sections.insert( sections.end(), { "indiPropNode", "indiPropNode", "indiPropNode", "indiPropNode" } );
105 keys.insert( keys.end(), { "type", "propKey", "propEl", "propVal" } );
106 values.insert( values.end(), { "indiProp", "test.test", "test", "test" } );
107
108 sections.insert( sections.end(), { "pwrOnOffNode", "pwrOnOffNode" } );
109 keys.insert( keys.end(), { "type", "pwrKey" } );
110 values.insert( values.end(), { "pwrOnOff", "testpwr.test" } );
111
112 sections.insert( sections.end(), { "fsmNode" } );
113 keys.insert( keys.end(), { "type" } );
114 values.insert( values.end(), { "fsm" } );
115
116 sections.insert( sections.end(), { "stdMotionNode" } );
117 keys.insert( keys.end(), { "type" } );
118 values.insert( values.end(), { "stdMotion" } );
119
120 sections.insert( sections.end(), { "staticNode" } );
121 keys.insert( keys.end(), { "type" } );
122 values.insert( values.end(), { "static" } );
123
124 mx::app::writeConfigFile( "/tmp/xInstGraph_test/config/instgraph_test.conf", sections, keys, values );
125
126 xInstGraph xig;
127 xig.configDir( "/tmp/xInstGraph_test/config" );
128
129 REQUIRE( xig.shutdown() == 0 );
130
131 xig.setupConfig();
132
133 REQUIRE( xig.shutdown() == 0 );
134
135 xig.config().readConfig( "/tmp/xInstGraph_test/config/instgraph_test.conf" );
136
137 xig.loadConfig();
138 REQUIRE( xig.shutdown() == 0 );
139
140 REQUIRE( xig.appStartup() == 0 );
141
142 pcf::IndiProperty ip;
143 ip.setDevice( "testpwr" );
144 ip.setName( "test" );
145 ip.add( pcf::IndiElement( "state" ) );
146 ip["state"] = "On";
147
149
150 bool ex = std::filesystem::exists( "/tmp/xInstGraph_test/instgraph_test_out.drawio" );
151 REQUIRE( ex == true );
152
153 REQUIRE( xig.appLogic() == 0 );
154
155 REQUIRE( xig.appShutdown() == 0 );
156
157 ex = std::filesystem::exists( "/tmp/xInstGraph_test/instgraph_test_out.drawio" );
158 REQUIRE( ex == false );
159 }
160}
161
162} // namespace xInstGraphTest
163
164} // namespace libXWCTest
int shutdown()
Get the value of the shutdown flag.
std::string configDir()
Get the config directory.
The MagAO-X xxxxxxxx.
virtual int appStartup()
Startup function.
virtual void setupConfig()
static int st_igHandleSetProperty(void *igapp, const pcf::IndiProperty &ipRecv)
virtual int appShutdown()
Shutdown the app.
virtual void loadConfig()
virtual int appLogic()
Implementation of the FSM for xInstGraph.
TEST_CASE("Configuring xInstGraph with no errors", "[xInstGraph]")
Verify xInstGraph configures and runs when given a minimal graph with all supported node types.
void writeXML()
Write a minimal draw.io graph containing one of each supported node type.
Namespace for all libXWC tests.