API
 
Loading...
Searching...
No Matches
xigNode_test.cpp
Go to the documentation of this file.
1/** \file xigNode_test.cpp
2 * \brief Catch2 tests for the xInstGraph base `xigNode` 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 "../xigNode.hpp"
13
14namespace libXWCTest
15{
16
17/** \addtogroup xInstGraph_unit_test
18 * \brief Additional unit tests for the xInstGraph application.
19 *
20 * \ingroup application_unit_test
21 */
22
23/// Namespace for `xInstGraph` node unit tests.
24/** \ingroup xInstGraph_unit_test
25 */
26namespace xInstGraphTest
27{
28
29void writeXML()
30{
31 std::ofstream fout( "/tmp/xigNode_test.xml" );
32 fout << "<mxfile host=\"test\">\n";
33 fout << " <diagram id=\"test\" name=\"test\">\n";
34 fout << " <mxGraphModel>\n";
35 fout << " <root>\n";
36 fout << " <mxCell id=\"0\"/>\n";
37 fout << " <mxCell id=\"1\" parent=\"0\"/>\n";
38 fout << " <mxCell id=\"node:telescope\">\n";
39 fout << "</mxCell>\n";
40 fout << " </root>\n";
41 fout << " </mxGraphModel>\n";
42 fout << " </diagram>\n";
43 fout << "</mxfile>\n";
44 fout.close();
45}
46
47class test_xigNode : public xigNode
48{
49 public:
50 test_xigNode( const std::string &name, ingr::instGraphXML *parentGraph ) : xigNode( name, parentGraph )
51 {
52 }
53
54 int handleSetProperty( const pcf::IndiProperty &ipRecv )
55 {
56 static_cast<void>( ipRecv );
57 return 0;
58 }
59};
60
61SCENARIO( "Creating an xigNode", "[instGraph::xigNode]" )
62{
63 // clang-format off
64 #ifdef XINSTGRAPH_TEST_DOXYGEN_REF
65 xigNode::key( "" );
67 #endif
68 // clang-format on
69
70 GIVEN( "a valid XML file" )
71 {
72 WHEN( "node is in file" )
73 {
74 ingr::instGraphXML parentGraph;
75 writeXML();
76
77 std::string emsg;
78
79 int rv = parentGraph.loadXMLFile( emsg, "/tmp/xigNode_test.xml" );
80
81 REQUIRE( rv == 0 );
82 REQUIRE( emsg == "" );
83
84 test_xigNode *txn = nullptr;
85 bool pass = false;
86 try
87 {
88 txn = new test_xigNode( "telescope", &parentGraph );
89 pass = true;
90 }
91 catch( ... )
92 {
93 }
94
95 REQUIRE( pass == true );
96 REQUIRE( txn != nullptr );
97
98 REQUIRE( txn->name() == "telescope" );
99 REQUIRE( txn->node()->name() == "telescope" );
100 REQUIRE( pass == true );
101
102 txn->key( "tkey" );
103 REQUIRE( txn->keys().count( "tkey" ) == 1 );
104 }
105
106 WHEN( "node is not in file" )
107 {
108 ingr::instGraphXML parentGraph;
109 writeXML();
110
111 std::string emsg;
112
113 int rv = parentGraph.loadXMLFile( emsg, "/tmp/xigNode_test.xml" );
114
115 REQUIRE( rv == 0 );
116 REQUIRE( emsg == "" );
117
118 test_xigNode *txn = nullptr;
119
120 bool pass = false;
121 try
122 {
123 txn = new test_xigNode( "epocselet", &parentGraph );
124 pass = true;
125 }
126 catch( ... )
127 {
128 }
129
130 REQUIRE( pass == false );
131 REQUIRE( txn == nullptr );
132 }
133 }
134
135 GIVEN( "an invalid XML file" )
136 {
137 WHEN( "parent graph is null on construction" )
138 {
139 ingr::instGraphXML *parentGraph = nullptr;
140
141 test_xigNode *txn = nullptr;
142 bool pass = false;
143 try
144 {
145 txn = new test_xigNode( "telescope", parentGraph );
146 pass = true;
147 }
148 catch( ... )
149 {
150 }
151
152 REQUIRE( pass == false );
153 REQUIRE( txn == nullptr );
154 }
155 }
156}
157
158} // namespace xInstGraphTest
159
160} // namespace libXWCTest
int handleSetProperty(const pcf::IndiProperty &ipRecv)
INDI SetProperty callback.
test_xigNode(const std::string &name, ingr::instGraphXML *parentGraph)
Implementation of basic instGraph node interface for MagAO-X.
Definition xigNode.hpp:31
void key(const std::string &nkey)
Add a key to the set.
Definition xigNode.hpp:116
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
const std::set< std::string > & keys()
Get the set holding the INDI keys for this node.
Definition xigNode.hpp:111
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.