API
 
Loading...
Searching...
No Matches
xigNode_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 "../xigNode.hpp"
7
8void writeXML()
9{
10 std::ofstream fout("/tmp/xigNode_test.xml");
11 fout << "<mxfile host=\"test\">\n";
12 fout << " <diagram id=\"test\" name=\"test\">\n";
13 fout << " <mxGraphModel>\n";
14 fout << " <root>\n";
15 fout << " <mxCell id=\"0\"/>\n";
16 fout << " <mxCell id=\"1\" parent=\"0\"/>\n";
17 fout << " <mxCell id=\"node:telescope\">\n";
18 fout << "</mxCell>\n";
19 fout << " </root>\n";
20 fout << " </mxGraphModel>\n";
21 fout << " </diagram>\n";
22 fout << "</mxfile>\n";
23 fout.close();
24}
25
26class test_xigNode : public xigNode
27{
28public:
29 test_xigNode( const std::string &name, ingr::instGraphXML *parentGraph ) : xigNode(name,parentGraph)
30 {}
31
32 int handleSetProperty( const pcf::IndiProperty &ipRecv )
33 {
34 static_cast<void>(ipRecv);
35 return 0;
36 }
37};
38
39SCENARIO( "Creating an xigNode", "[instGraph::xigNode]" )
40{
41 GIVEN("a valid XML file")
42 {
43 WHEN("node is in file")
44 {
45 ingr::instGraphXML parentGraph;
46 writeXML();
47
48 std::string emsg;
49
50 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
51
52 REQUIRE(rv == 0);
53 REQUIRE(emsg == "");
54
55 test_xigNode * txn = nullptr;
56 bool pass = false;
57 try
58 {
59 txn = new test_xigNode("telescope", &parentGraph);
60 pass = true;
61 }
62 catch(...)
63 {
64 }
65
66 REQUIRE(pass == true);
67 REQUIRE(txn != nullptr);
68
69
70 REQUIRE( txn->name() == "telescope");
71 REQUIRE( txn->node()->name() == "telescope");
72 REQUIRE( pass == true );
73
74 txn->key("tkey");
75 REQUIRE( txn->keys().count("tkey") == 1);
76
77 }
78
79 WHEN("node is not in file")
80 {
81 ingr::instGraphXML parentGraph;
82 writeXML();
83
84 std::string emsg;
85
86 int rv = parentGraph.loadXMLFile(emsg, "/tmp/xigNode_test.xml");
87
88 REQUIRE(rv == 0);
89 REQUIRE(emsg == "");
90
91 test_xigNode * txn = nullptr;
92
93 bool pass = false;
94 try
95 {
96 txn = new test_xigNode("epocselet", &parentGraph);
97 pass = true;
98 }
99 catch(...)
100 {
101 }
102
103 REQUIRE(pass == false);
104 REQUIRE(txn == nullptr);
105 }
106 }
107
108 GIVEN("an invalid XML file")
109 {
110 WHEN("parent graph is null on construction")
111 {
112 ingr::instGraphXML * parentGraph = nullptr;
113
114 test_xigNode * txn = nullptr;
115 bool pass = false;
116 try
117 {
118 txn = new test_xigNode("telescope", parentGraph);
119 pass = true;
120 }
121 catch(...)
122 {
123 }
124
125 REQUIRE(pass == false);
126 REQUIRE(txn == nullptr);
127 }
128 }
129}
130
131
test_xigNode(const std::string &name, ingr::instGraphXML *parentGraph)
int handleSetProperty(const pcf::IndiProperty &ipRecv)
INDI SetProperty callback.
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
void writeXML()
SCENARIO("Creating an xigNode", "[instGraph::xigNode]")