API
 
Loading...
Searching...
No Matches
staticNode_test.cpp
Go to the documentation of this file.
1/** \file staticNode_test.cpp
2 * \brief Catch2 tests for the xInstGraph `staticNode` 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 "../staticNode.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 id=\"input:ttmpupil:in1\" parent=\"node:ttmpupil\" style=\"fontSize=17;\" />\n";
43 fout << " <mxCell id=\"input:ttmpupil:in2\" parent=\"node:ttmpupil\" style=\"fontSize=17;\" />\n";
44 fout << " <mxCell id=\"input:ttmpupil:in3\" parent=\"node:ttmpupil\" style=\"fontSize=17;\" />\n";
45 fout << " <mxCell id=\"input:ttmpupil:in4\" parent=\"node:ttmpupil\" style=\"fontSize=17;\" />\n";
46 fout << " <mxCell id=\"output:ttmpupil:out1\" parent=\"node:ttmpupil\" style=\"fontSize=17;\" "
47 "/>\n";
48 fout << " <mxCell id=\"output:ttmpupil:out2\" parent=\"node:ttmpupil\" style=\"fontSize=17;\" "
49 "/>\n";
50 fout << " <mxCell id=\"output:ttmpupil:out3\" parent=\"node:ttmpupil\" style=\"fontSize=17;\" "
51 "/>\n";
52 fout << " <mxCell id=\"output:ttmpupil:out4\" parent=\"node:ttmpupil\" style=\"fontSize=17;\" "
53 "/>\n";
54 fout << " </root>\n";
55 fout << " </mxGraphModel>\n";
56 fout << " </diagram>\n";
57 fout << "</mxfile>\n";
58 fout.close();
59}
60
61TEST_CASE( "Creating and configuring an staticNode", "[instGraph::staticNode]" )
62{
63 // clang-format off
64 #ifdef XINSTGRAPH_TEST_DOXYGEN_REF
65 staticNode::loadConfig( *(mx::app::appConfigurator *)nullptr );
67 #endif
68 // clang-format on
69
70 SECTION( "node is in file, setting pwr key" )
71 {
72 ingr::instGraphXML parentGraph;
73 writeXML();
74 mx::app::writeConfigFile( "/tmp/staticNode_test.conf",
75 { "ttmpupil", "ttmpupil", "ttmpupil", "ttmpupil", "ttmpupil" },
76 { "type", "inputsOn", "inputsOff", "outputsOn", "outputsOff" },
77 { "static", "in1,in2", "in3,in4", "out1,out2", "out3,out4" } );
78 mx::app::appConfigurator config;
79 config.readConfig( "/tmp/staticNode_test.conf" );
80
81 std::string emsg;
82
83 int rv = parentGraph.loadXMLFile( emsg, "/tmp/xigNode_test.xml" );
84
85 REQUIRE( rv == 0 );
86 REQUIRE( emsg == "" );
87
88 staticNode *tsn = nullptr;
89 bool pass = false;
90 try
91 {
92 tsn = new staticNode( "ttmpupil", &parentGraph );
93 pass = true;
94 }
95 catch( const std::exception &e )
96 {
97 std::cerr << e.what() << "\n";
98 }
99
100 REQUIRE( pass == true );
101 REQUIRE( tsn != nullptr );
102
103 REQUIRE( tsn->name() == "ttmpupil" );
104 REQUIRE( tsn->node()->name() == "ttmpupil" );
105
106 pass = false;
107 try
108 {
109 tsn->loadConfig( config );
110 pass = true;
111 }
112 catch( const std::exception &e )
113 {
114 std::cerr << e.what() << "\n";
115 }
116
117 REQUIRE( pass == true );
118
119 // check config-ed values
120 REQUIRE( tsn->inputsOn().size() == 2 );
121 REQUIRE( tsn->inputsOn().count( "in1" ) == 1 );
122 REQUIRE( tsn->inputsOn().count( "in2" ) == 1 );
123 REQUIRE( tsn->inputsOff().size() == 2 );
124 REQUIRE( tsn->inputsOff().count( "in3" ) == 1 );
125 REQUIRE( tsn->inputsOff().count( "in4" ) == 1 );
126 REQUIRE( tsn->outputsOn().size() == 2 );
127 REQUIRE( tsn->outputsOn().count( "out1" ) == 1 );
128 REQUIRE( tsn->outputsOn().count( "out2" ) == 1 );
129 REQUIRE( tsn->outputsOff().size() == 2 );
130 REQUIRE( tsn->outputsOff().count( "out3" ) == 1 );
131 REQUIRE( tsn->outputsOff().count( "out4" ) == 1 );
132 }
133}
134
135} // namespace xInstGraphTest
136
137} // namespace libXWCTest
An instGraph node which is static, with status set at config time and not changing.
const std::set< std::string > & inputsOff() const
Get the always off inputs.
const std::set< std::string > & inputsOn() const
Get the always on inputs.
const std::set< std::string > & outputsOn() const
Get the always on outputs.
const std::set< std::string > & outputsOff() const
Get the always off outputs.
void loadConfig(mx::app::appConfigurator &config)
Configure this node form an appConfigurator.
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.