API
 
Loading...
Searching...
No Matches
pwrOnOffNode_test.cpp
Go to the documentation of this file.
1/** \file pwrOnOffNode_test.cpp
2 * \brief Catch2 tests for the xInstGraph `pwrOnOffNode` 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 "../../../../libMagAOX/libMagAOX.hpp"
13
14#define XWC_XIGNODE_TEST
15#include "../pwrOnOffNode.hpp"
16
17namespace libXWCTest
18{
19
20/** \addtogroup xInstGraph_unit_test
21 * \brief Additional unit tests for the xInstGraph application.
22 *
23 * \ingroup application_unit_test
24 */
25
26/// Namespace for `xInstGraph` node unit tests.
27/** \ingroup xInstGraph_unit_test
28 */
29namespace xInstGraphTest
30{
31
32void writeXML()
33{
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";
38 fout << " <root>\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";
43 fout << " </root>\n";
44 fout << " </mxGraphModel>\n";
45 fout << " </diagram>\n";
46 fout << "</mxfile>\n";
47 fout.close();
48}
49
50TEST_CASE( "Creating and configuring an pwrOnOffNode", "[instGraph::pwrOnOffNode]" )
51{
52 // clang-format off
53 #ifdef XINSTGRAPH_TEST_DOXYGEN_REF
54 pwrOnOffNode::loadConfig( *(mx::app::appConfigurator *)nullptr );
56 #endif
57 // clang-format on
58
59 SECTION( "node is in file, setting pwr key" )
60 {
61 ingr::instGraphXML parentGraph;
62 writeXML();
63 mx::app::writeConfigFile( "/tmp/pwrOnOffNode_test.conf",
64 { "ttmpupil", "ttmpupil" },
65 { "type", "pwrKey" },
66 { "pwrOnOff", "test.pwr" } );
67 mx::app::appConfigurator config;
68 config.readConfig( "/tmp/pwrOnOffNode_test.conf" );
69
70 std::string emsg;
71
72 int rv = parentGraph.loadXMLFile( emsg, "/tmp/xigNode_test.xml" );
73
74 REQUIRE( rv == 0 );
75 REQUIRE( emsg == "" );
76
77 pwrOnOffNode *tsn = nullptr;
78 bool pass = false;
79 try
80 {
81 tsn = new pwrOnOffNode( "ttmpupil", &parentGraph );
82 pass = true;
83 }
84 catch( const std::exception &e )
85 {
86 std::cerr << e.what() << "\n";
87 }
88
89 REQUIRE( pass == true );
90 REQUIRE( tsn != nullptr );
91
92 REQUIRE( tsn->name() == "ttmpupil" );
93 REQUIRE( tsn->node()->name() == "ttmpupil" );
94
95 pass = false;
96 try
97 {
98 tsn->loadConfig( config );
99 pass = true;
100 }
101 catch( const std::exception &e )
102 {
103 std::cerr << e.what() << "\n";
104 }
105
106 REQUIRE( pass == true );
107
108 // check config-ed values
109 REQUIRE( tsn->pwrKey() == "test.pwr" );
110 }
111
112 SECTION( "node is in file, error: not setting pwr key" )
113 {
114 ingr::instGraphXML parentGraph;
115 writeXML();
116 mx::app::writeConfigFile( "/tmp/pwrOnOffNode_test.conf", { "ttmpupil" }, { "type" }, { "pwrOnOff" } );
117 mx::app::appConfigurator config;
118 config.readConfig( "/tmp/pwrOnOffNode_test.conf" );
119
120 std::string emsg;
121
122 int rv = parentGraph.loadXMLFile( emsg, "/tmp/xigNode_test.xml" );
123
124 REQUIRE( rv == 0 );
125 REQUIRE( emsg == "" );
126
127 pwrOnOffNode *tsn = nullptr;
128 bool pass = false;
129 try
130 {
131 tsn = new pwrOnOffNode( "ttmpupil", &parentGraph );
132 pass = true;
133 }
134 catch( const std::exception &e )
135 {
136 std::cerr << e.what() << "\n";
137 }
138
139 REQUIRE( pass == true );
140 REQUIRE( tsn != nullptr );
141
142 REQUIRE( tsn->name() == "ttmpupil" );
143 REQUIRE( tsn->node()->name() == "ttmpupil" );
144
145 pass = false;
146 try
147 {
148 tsn->loadConfig( config );
149 pass = true;
150 }
151 catch( const std::exception &e )
152 {
153 std::cerr << e.what() << "\n";
154 }
155
156 REQUIRE( pass == false );
157 }
158}
159
160} // namespace xInstGraphTest
161
162} // namespace libXWCTest
void loadConfig(mx::app::appConfigurator &config)
void pwrKey(const std::string &pk)
const std::string & pwrKey() const
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
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.