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