API
 
Loading...
Searching...
No Matches
pwrOnOffNode_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 "../../../../libMagAOX/libMagAOX.hpp"
7
8#define XWC_XIGNODE_TEST
9#include "../pwrOnOffNode.hpp"
10
12{
13 std::ofstream fout( "/tmp/xigNode_test.xml" );
14 fout << "<mxfile host=\"test\">\n";
15 fout << " <diagram id=\"test\" name=\"test\">\n";
16 fout << " <mxGraphModel>\n";
17 fout << " <root>\n";
18 fout << " <mxCell id=\"0\"/>\n";
19 fout << " <mxCell id=\"1\" parent=\"0\"/>\n";
20 fout << " <mxCell id=\"node:ttmpupil\">\n";
21 fout << "</mxCell>\n";
22 fout << " </root>\n";
23 fout << " </mxGraphModel>\n";
24 fout << " </diagram>\n";
25 fout << "</mxfile>\n";
26 fout.close();
27}
28
29TEST_CASE( "Creating and configuring an pwrOnOffNode", "[instGraph::pwrOnOffNode]" )
30{
31 SECTION( "node is in file, setting pwr key" )
32 {
33 ingr::instGraphXML parentGraph;
34 writeXML();
35 mx::app::writeConfigFile( "/tmp/pwrOnOffNode_test.conf",
36 { "ttmpupil", "ttmpupil" },
37 { "type", "pwrKey" },
38 { "pwrOnOff", "test.pwr" } );
39 mx::app::appConfigurator config;
40 config.readConfig( "/tmp/pwrOnOffNode_test.conf" );
41
42 std::string emsg;
43
44 int rv = parentGraph.loadXMLFile( emsg, "/tmp/xigNode_test.xml" );
45
46 REQUIRE( rv == 0 );
47 REQUIRE( emsg == "" );
48
49 pwrOnOffNode *tsn = nullptr;
50 bool pass = false;
51 try
52 {
53 tsn = new pwrOnOffNode( "ttmpupil", &parentGraph );
54 pass = true;
55 }
56 catch( const std::exception &e )
57 {
58 std::cerr << e.what() << "\n";
59 }
60
61 REQUIRE( pass == true );
62 REQUIRE( tsn != nullptr );
63
64 REQUIRE( tsn->name() == "ttmpupil" );
65 REQUIRE( tsn->node()->name() == "ttmpupil" );
66
67 pass = false;
68 try
69 {
70 tsn->loadConfig( config );
71 pass = true;
72 }
73 catch( const std::exception &e )
74 {
75 std::cerr << e.what() << "\n";
76 }
77
78 REQUIRE( pass == true );
79
80 // check config-ed values
81 REQUIRE( tsn->pwrKey() == "test.pwr" );
82 }
83
84 SECTION( "node is in file, error: not setting pwr key" )
85 {
86 ingr::instGraphXML parentGraph;
87 writeXML();
88 mx::app::writeConfigFile( "/tmp/pwrOnOffNode_test.conf",
89 { "ttmpupil" },
90 { "type" },
91 { "pwrOnOff" } );
92 mx::app::appConfigurator config;
93 config.readConfig( "/tmp/pwrOnOffNode_test.conf" );
94
95 std::string emsg;
96
97 int rv = parentGraph.loadXMLFile( emsg, "/tmp/xigNode_test.xml" );
98
99 REQUIRE( rv == 0 );
100 REQUIRE( emsg == "" );
101
102 pwrOnOffNode *tsn = nullptr;
103 bool pass = false;
104 try
105 {
106 tsn = new pwrOnOffNode( "ttmpupil", &parentGraph );
107 pass = true;
108 }
109 catch( const std::exception &e )
110 {
111 std::cerr << e.what() << "\n";
112 }
113
114 REQUIRE( pass == true );
115 REQUIRE( tsn != nullptr );
116
117 REQUIRE( tsn->name() == "ttmpupil" );
118 REQUIRE( tsn->node()->name() == "ttmpupil" );
119
120 pass = false;
121 try
122 {
123 tsn->loadConfig( config );
124 pass = true;
125 }
126 catch( const std::exception &e )
127 {
128 std::cerr << e.what() << "\n";
129 }
130
131 REQUIRE( pass == false );
132
133 }
134}
void loadConfig(mx::app::appConfigurator &config)
void pwrKey(const std::string &pk)
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
void writeXML()
TEST_CASE("Creating and configuring an pwrOnOffNode", "[instGraph::pwrOnOffNode]")