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 * History:
6 */
7
8#include "../../../tests/catch2/catch.hpp"
9#include "../../tests/testMacrosINDI.hpp"
10
11#include "../xInstGraph.hpp"
12
13
15{
16
18{
19 public:
20
21 void configDir(const std::string & cp)
22 {
24 }
25
26 mx::app::appConfigurator & config()
27 {
28 return MagAOX::app::xInstGraph::config;
29 }
30
31};
32
34{
35 std::ofstream fout("/tmp/xInstGraph_test/config/instgraph_test.drawio");
36 fout << "<mxfile host=\"test\">\n";
37 fout << " <diagram id=\"test\" name=\"test\">\n";
38 fout << " <mxGraphModel>\n";
39 fout << " <root>\n";
40 fout << " <mxCell id=\"0\"/>\n";
41 fout << " <mxCell id=\"1\" parent=\"0\"/>\n";
42 fout << " <mxCell id=\"node:fsmNode\">\n";
43 fout << "</mxCell>\n";
44 fout << " <mxCell id=\"node:indiPropNode\">\n";
45 fout << "</mxCell>\n";
46 fout << " <mxCell id=\"node:pwrOnOffNode\">\n";
47 fout << "</mxCell>\n";
48 fout << " <mxCell id=\"node:stdMotionNode\">\n";
49 fout << "</mxCell>\n";
50 fout << " <mxCell id=\"node:staticNode\">\n";
51 fout << "</mxCell>\n";
52 fout << " </root>\n";
53 fout << " </mxGraphModel>\n";
54 fout << " </diagram>\n";
55 fout << "</mxfile>\n";
56 fout.close();
57}
58
59TEST_CASE( "Configuring xInstGraph with no errors", "[xInstGraph]" )
60{
61 mx::ioutils::createDirectories("/tmp/xInstGraph_test/config");
62
63 writeXML();
64
65 SECTION( "A valid configuration with each node type" )
66 {
67 std::vector<std::string> sections;
68 std::vector<std::string> keys;
69 std::vector<std::string> values;
70
71 sections.insert(sections.end(), {"graph", "graph"});
72 keys.insert(keys.end(), {"file", "outputPath"});
73 values.insert(values.end(), {"instgraph_test.drawio", "/tmp/xInstGraph_test/instgraph_test_out.drawio"});
74
75 sections.insert(sections.end(), {"indiPropNode","indiPropNode","indiPropNode","indiPropNode"});
76 keys.insert(keys.end(), {"type", "propKey", "propEl", "propVal"});
77 values.insert(values.end(), {"indiProp", "test.test", "test", "test"});
78
79 sections.insert(sections.end(), {"pwrOnOffNode", "pwrOnOffNode"});
80 keys.insert(keys.end(), {"type", "pwrKey"});
81 values.insert(values.end(), {"pwrOnOff", "testpwr.test"});
82
83 sections.insert(sections.end(), {"fsmNode"});
84 keys.insert(keys.end(), {"type"});
85 values.insert(values.end(), {"fsm"});
86
87 sections.insert(sections.end(), {"stdMotionNode"});
88 keys.insert(keys.end(), {"type"});
89 values.insert(values.end(), {"stdMotion"});
90
91 sections.insert(sections.end(), {"staticNode"});
92 keys.insert(keys.end(), {"type"});
93 values.insert(values.end(), {"static"});
94
95 mx::app::writeConfigFile( "/tmp/xInstGraph_test/config/instgraph_test.conf", sections, keys, values);
96
97 xInstGraph xig;
98 xig.configDir("/tmp/xInstGraph_test/config");
99
100 REQUIRE(xig.shutdown() == 0);
101
102 xig.setupConfig();
103
104 REQUIRE(xig.shutdown() == 0);
105
106 //mx::app::appConfigurator config;
107 xig.config().readConfig("/tmp/xInstGraph_test/config/instgraph_test.conf");
108
109
110 xig.loadConfig();
111 REQUIRE(xig.shutdown() == 0);
112
113 REQUIRE(xig.appStartup() == 0);
114
115 pcf::IndiProperty ip;
116 ip.setDevice("testpwr");
117 ip.setName("test");
118 ip.add(pcf::IndiElement("state"));
119 ip["state"] = "On";
120
122
123 //file should be written now
124 bool ex = std::filesystem::exists("/tmp/xInstGraph_test/instgraph_test_out.drawio");
125 REQUIRE(ex == true);
126
127 REQUIRE(xig.appLogic() == 0);
128
129 REQUIRE(xig.appShutdown() == 0);
130
131 //file should be removed
132 ex = std::filesystem::exists("/tmp/xInstGraph_test/instgraph_test_out.drawio");
133 REQUIRE(ex == false);
134 }
135}
136
137} // namespace xInstGraph_test
int shutdown()
Get the value of the shutdown flag.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
std::string m_configDir
The path to configuration files for MagAOX.
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.
void configDir(const std::string &cp)
mx::app::appConfigurator & config()
TEST_CASE("Configuring xInstGraph with no errors", "[xInstGraph]")