ChimeraTK-ControlSystemAdapter-OPCUAAdapter  04.00.01
test_opcua_uaadapter.cpp
Go to the documentation of this file.
1 #include "ChimeraTK/ControlSystemAdapter/ControlSystemPVManager.h"
2 #include "ChimeraTK/ControlSystemAdapter/DevicePVManager.h"
3 #include "ChimeraTK/ControlSystemAdapter/PVManager.h"
4 #include <test_sample_data.h>
5 #include <ua_adapter.h>
6 #include <xml_file_handler.h>
7 
8 #include <boost/test/included/unit_test.hpp>
9 
10 using namespace boost::unit_test_framework;
11 using namespace std;
12 
14  public:
15  static void testExampleSet();
16 };
17 
19  cout << "UAAdapterTest with ExampleSet started." << endl;
20  TestFixturePVSet tfExampleSet;
21  // Test config handling
22  BOOST_CHECK_THROW(ua_uaadapter("uamapping_test_twoconfigs.xml"), std::runtime_error);
23  BOOST_CHECK_THROW(ua_uaadapter("uamapping_test_notwellformed.xml"), std::logic_error);
24 
25  ua_uaadapter* ad1 = new ua_uaadapter("uamapping_test_applicationismissing.xml");
26  delete ad1;
27  ad1 = new ua_uaadapter("uamapping_test_configismissing.xml");
28  delete ad1;
29  ad1 = new ua_uaadapter("uamapping_test_portismissing.xml");
30  delete ad1;
31 
32  // Create the managers
33  ua_uaadapter* adapter = new ua_uaadapter("uamapping_test_2.xml");
34  xml_file_handler* xmlHandler = new xml_file_handler("uamapping_test_2.xml");
35 
36  // is Server running?
37  UA_NodeId ownNodeId = adapter->getOwnNodeId();
38  BOOST_CHECK(!UA_NodeId_isNull(&ownNodeId));
39 
40  // Check folder functions
41  vector<string> pathVector = xmlHandler->parseVariablePath("/test/test/");
42  // Check if path exist
43  UA_NodeId folderNodeId = adapter->existFolderPath(ownNodeId, pathVector);
44  BOOST_CHECK(UA_NodeId_isNull(&folderNodeId));
45 
46  // create path
47  folderNodeId = adapter->createFolderPath(ownNodeId, pathVector);
48  BOOST_CHECK(!UA_NodeId_isNull(&folderNodeId));
49  // cheack if path exist now
50  folderNodeId = adapter->existFolderPath(ownNodeId, pathVector);
51  BOOST_CHECK(!UA_NodeId_isNull(&folderNodeId));
52 
53  // Check if path partly exist and create it
54  pathVector = xmlHandler->parseVariablePath("/test/test1/");
55  folderNodeId = adapter->createFolderPath(UA_NODEID_NULL, pathVector);
56  BOOST_CHECK(UA_NodeId_isNull(&folderNodeId));
57 
58  folderNodeId = adapter->createFolderPath(ownNodeId, pathVector);
59  BOOST_CHECK(!UA_NodeId_isNull(&folderNodeId));
60 
61  folderNodeId = adapter->existFolderPath(ownNodeId, pathVector);
62  BOOST_CHECK(!UA_NodeId_isNull(&folderNodeId));
63 
64  // Double creation of folder, should be the same folder nodeid
65  UA_NodeId existingFolderNodeId = adapter->createFolderPath(ownNodeId, pathVector);
66  BOOST_CHECK(UA_NodeId_equal(&existingFolderNodeId, &folderNodeId));
67 
68  folderNodeId = adapter->existFolderPath(UA_NODEID_NULL, pathVector);
69  BOOST_CHECK(UA_NodeId_isNull(&folderNodeId));
70 
71  for(auto processVar : tfExampleSet.csManager.get()->getAllProcessVariables()) {
72  adapter->implicitVarMapping(processVar.get()->getName(), tfExampleSet.csManager);
73  }
74 
75  BOOST_CHECK(adapter->getVariables().size() > 0);
76 
77  /* Check if both var are not mapped */
78  cout << "Größe von: " << adapter->getAllNotMappableVariablesNames().size() << endl;
79  BOOST_CHECK(adapter->getAllNotMappableVariablesNames().size() == 7);
80  // Check if timestamp is not enmpty
81  string dateTime = "";
82  BOOST_CHECK(adapter->getSourceTimeStamp() != 0);
83 
84  delete adapter;
85  delete xmlHandler;
86 }
87 
88 class UAAdapterTestSuite : public test_suite {
89  public:
90  UAAdapterTestSuite() : test_suite("ua_uaadapter Test Suite") { add(BOOST_TEST_CASE(&UAAdapterTest::testExampleSet)); }
91 };
92 
93 test_suite* init_unit_test_suite(int /*argc*/, char** /*argv[]*/) {
94  framework::master_test_suite().add(new UAAdapterTestSuite);
95  return 0;
96 }
ChimeraTK::ua_uaadapter
This class provide the opcua server and manage the variable mapping.
Definition: ua_adapter.h:100
UAAdapterTest
Definition: test_opcua_uaadapter.cpp:13
init_unit_test_suite
test_suite * init_unit_test_suite(int, char **)
Definition: test_opcua_uaadapter.cpp:93
UAAdapterTestSuite::UAAdapterTestSuite
UAAdapterTestSuite()
Definition: test_opcua_uaadapter.cpp:90
ChimeraTK::xml_file_handler
This class support any file interaction with a xml file.
Definition: xml_file_handler.h:44
xml_file_handler.h
ChimeraTK::ua_uaadapter::existFolderPath
UA_NodeId existFolderPath(UA_NodeId basenodeid, const vector< string > &folderPath)
Check if a folder path exist in opcua server.
Definition: ua_adapter.cpp:1565
ChimeraTK::ua_uaadapter::implicitVarMapping
void implicitVarMapping(const std::string &varName, const boost::shared_ptr< ControlSystemPVManager > &csManager)
Start implicit mapping process.
Definition: ua_adapter.cpp:713
TestFixturePVSet
Definition: test_sample_data.h:33
ua_adapter.h
ChimeraTK::xml_file_handler::parseVariablePath
static std::vector< std::string > parseVariablePath(const std::string &variablePath, const std::string &seperator="/")
This methode splitt a given string bey the given seperators.
Definition: xml_file_handler.cpp:110
TestFixturePVSet::csManager
boost::shared_ptr< ControlSystemPVManager > csManager
Definition: test_sample_data.h:35
ChimeraTK::ua_uaadapter::getSourceTimeStamp
UA_DateTime getSourceTimeStamp()
Return the timestamp of the node.
Definition: ua_adapter.cpp:1686
ChimeraTK::ua_uaadapter::getOwnNodeId
UA_NodeId getOwnNodeId()
Methode that returns the node id of the instanced class.
Definition: ua_adapter.cpp:1561
ChimeraTK::ua_uaadapter::getAllNotMappableVariablesNames
vector< string > getAllNotMappableVariablesNames()
Methode to get all names from all potential VarableNodes from XML-Mappingfile which could not allocat...
Definition: ua_adapter.cpp:1660
UAAdapterTestSuite
Definition: test_opcua_uaadapter.cpp:88
test_sample_data.h
ChimeraTK::ua_uaadapter::getVariables
vector< ua_processvariable * > getVariables()
Methode that returns all <ua_processvariable> of the class.
Definition: ua_adapter.cpp:1426
ChimeraTK::ua_uaadapter::createFolderPath
UA_NodeId createFolderPath(UA_NodeId basenodeid, vector< string > folderPathVector)
Create a path of folders in the given parent node.
Definition: ua_adapter.cpp:1586
UAAdapterTest::testExampleSet
static void testExampleSet()
Definition: test_opcua_uaadapter.cpp:18