ChimeraTK-ControlSystemAdapter-OPCUAAdapter  04.00.01
test_opcua_mapping.cpp
Go to the documentation of this file.
1 #include <csa_opcua_adapter.h>
2 #include <test_sample_data.h>
3 #include <ua_adapter.h>
4 #include <xml_file_handler.h>
5 
6 #include <boost/test/included/unit_test.hpp>
7 
8 using namespace boost::unit_test_framework;
9 using namespace std;
10 
12  public:
13  static void testExampleSet();
14 };
15 
16 void 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?
28  csaOPCUA.start();
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 
75 class UAMappingTestSuite : public test_suite {
76  public:
77  UAMappingTestSuite() : test_suite("PV mapping Test Suite") { add(BOOST_TEST_CASE(&UAMappingTest::testExampleSet)); }
78 };
79 
80 test_suite* init_unit_test_suite(int /*argc*/, char** /*argv[]*/) {
81  framework::master_test_suite().add(new UAMappingTestSuite);
82  return 0;
83 }
ChimeraTK::csa_opcua_adapter
This class provide the two parts of the OPCUA Adapter. First of all the OPCUA server starts with a po...
Definition: csa_opcua_adapter.h:44
csa_opcua_adapter.h
checkNode
void checkNode(const std::string &node, std::shared_ptr< ua_uaadapter > uaadapter)
Definition: test_opcua_mapping.cpp:16
ChimeraTK::csa_opcua_adapter::stop
void stop()
Stop all objects in single threads for this case only the opc ua server.
Definition: csa_opcua_adapter.cpp:216
UAMappingTestSuite::UAMappingTestSuite
UAMappingTestSuite()
Definition: test_opcua_mapping.cpp:77
UAMappingTestSuite
Definition: test_opcua_mapping.cpp:75
ChimeraTK::csa_opcua_adapter::isRunning
bool isRunning()
Checks if the opcua server is still running and return the suitable bool value.
Definition: csa_opcua_adapter.cpp:226
xml_file_handler.h
TestFixturePVSet
Definition: test_sample_data.h:33
ua_adapter.h
TestFixturePVSet::csManager
boost::shared_ptr< ControlSystemPVManager > csManager
Definition: test_sample_data.h:35
ChimeraTK::csa_opcua_adapter::getUAAdapter
std::shared_ptr< ua_uaadapter > getUAAdapter()
Return the uaadapter, hence the OPC UA server.
Definition: csa_opcua_adapter.cpp:176
csaOPCUA
csa_opcua_adapter * csaOPCUA
Definition: csa_opcua_adapter_example.cpp:43
ChimeraTK::csa_opcua_adapter::start
void start()
Start all objects in single threads for this case only the opc ua server.
Definition: csa_opcua_adapter.cpp:180
test_sample_data.h
UAMappingTest
Definition: test_opcua_mapping.cpp:11
ChimeraTK::ua_uaadapter::getMappedServer
UA_Server * getMappedServer()
Return the OPC UA Server instance.
Definition: ua_adapter.cpp:1690
init_unit_test_suite
test_suite * init_unit_test_suite(int, char **)
Definition: test_opcua_mapping.cpp:80
UAMappingTest::testExampleSet
static void testExampleSet()
Definition: test_opcua_mapping.cpp:23
ChimeraTK::csa_opcua_adapter::getControlSystemManager
boost::shared_ptr< ControlSystemPVManager > const & getControlSystemManager() const
Return the ControlsystemPVManager of the class.
Definition: csa_opcua_adapter.cpp:172