ChimeraTK-ControlSystemAdapter-OPCUAAdapter 04.00.05
Loading...
Searching...
No Matches
test_opcua_mapping.cpp
Go to the documentation of this file.
1#include <boost/test/included/unit_test.hpp>
2
3#include <csa_opcua_adapter.h>
4#include <test_sample_data.h>
5#include <ua_adapter.h>
6#include <xml_file_handler.h>
7
8using namespace boost::unit_test_framework;
9using namespace std;
10
12 public:
13 static void testExampleSet();
14};
15
16void checkNode(const std::string& node, std::shared_ptr<ua_uaadapter> uaadapter) {
17 UA_NodeId result = UA_NODEID_NULL;
18 UA_Server_readNodeId(uaadapter->getMappedServer(), UA_NODEID_STRING(1, const_cast<char*>(node.c_str())), &result);
19 BOOST_CHECK(UA_NodeId_isNull(&result) == UA_FALSE);
20 UA_NodeId_clear(&result);
21}
22
24 cout << "General PV mapping test." << endl;
25 TestFixturePVSet tfExampleSet;
26 csa_opcua_adapter csaOPCUA(tfExampleSet.csManager, "uamapping_test_general.xml");
27 // is Server running?
29 BOOST_CHECK(csaOPCUA.isRunning());
30 while(!csaOPCUA.getUAAdapter()->running) {
31 };
32 BOOST_CHECK(csaOPCUA.getUAAdapter()->running);
33 // is csManager init
34 BOOST_CHECK(csaOPCUA.getControlSystemManager()->getAllProcessVariables().size() == 21);
35
36 std::shared_ptr<ua_uaadapter> uaadapter = csaOPCUA.getUAAdapter();
37
38 checkNode("llrfCtrl_hzdr/1/FOLDERDir", uaadapter);
39 checkNode("llrfCtrl_hzdr/copyWithSourceTestDir", uaadapter);
40 checkNode("llrfCtrl_hzdr/copyWithSourceTest/defaultSepDir", uaadapter);
41 checkNode("llrfCtrl_hzdr/copyWithSourceTest/defaultSep/stringScalar", uaadapter);
42 checkNode("llrfCtrl_hzdr/linkWithSourceTestDir", uaadapter);
43 UA_BrowseDescription bd;
44 bd.includeSubtypes = false;
45 bd.nodeId = UA_NODEID_STRING(1, (char*)"llrfCtrl_hzdr/linkWithSourceTestDir");
46 bd.referenceTypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
47 bd.resultMask = UA_BROWSERESULTMASK_BROWSENAME;
48 bd.nodeClassMask = UA_NODECLASS_OBJECT;
49 bd.browseDirection = UA_BROWSEDIRECTION_FORWARD;
50 UA_BrowseResult br = UA_Server_browse(uaadapter->getMappedServer(), 1000, &bd);
51 BOOST_CHECK(br.referencesSize > 0);
52 for(size_t j = 0; j < br.referencesSize; ++j) {
53 UA_String compareString = UA_STRING((char*)"defaultSep");
54 BOOST_CHECK(UA_String_equal(&br.references[j].browseName.name, &compareString) == UA_TRUE);
55 }
56 UA_BrowseResult_clear(&br);
57
58 bd.nodeId = UA_NODEID_STRING(1, (char*)"llrfCtrl_hzdr/2/FOLDERDir");
59 bd.referenceTypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT);
60 bd.resultMask = UA_BROWSERESULTMASK_BROWSENAME;
61 bd.nodeClassMask = UA_NODECLASS_VARIABLE;
62 bd.browseDirection = UA_BROWSEDIRECTION_BOTH;
63 br = UA_Server_browse(uaadapter->getMappedServer(), 1000, &bd);
64 BOOST_CHECK(br.referencesSize > 0);
65 for(size_t j = 0; j < br.referencesSize; ++j) {
66 UA_String compareString = UA_STRING((char*)"stringScalar");
67 BOOST_CHECK(UA_String_equal(&br.references[j].browseName.name, &compareString) == UA_TRUE);
68 }
69 UA_BrowseResult_clear(&br);
70
71 csaOPCUA.stop();
72 BOOST_CHECK(csaOPCUA.isRunning() != true);
73}
74
75class UAMappingTestSuite : public test_suite {
76 public:
77 UAMappingTestSuite() : test_suite("PV mapping Test Suite") { add(BOOST_TEST_CASE(&UAMappingTest::testExampleSet)); }
78};
79
80test_suite* init_unit_test_suite(int /*argc*/, char** /*argv[]*/) {
81 framework::master_test_suite().add(new UAMappingTestSuite);
82 return 0;
83}
This class provide the two parts of the OPCUA Adapter.
bool isRunning()
Checks if the opcua server is still running and return the suitable bool value.
void start()
Start all objects in single threads for this case only the opc ua server.
std::shared_ptr< ua_uaadapter > getUAAdapter()
Return the uaadapter, hence the OPC UA server.
void stop()
Stop all objects in single threads for this case only the opc ua server.
boost::shared_ptr< ControlSystemPVManager > const & getControlSystemManager() const
Return the ControlsystemPVManager of the class.
static void testExampleSet()
csa_opcua_adapter * csaOPCUA
boost::shared_ptr< ControlSystemPVManager > csManager
test_suite * init_unit_test_suite(int, char **)
void checkNode(const std::string &node, std::shared_ptr< ua_uaadapter > uaadapter)