1 #include "open62541/plugin/log_stdout.h"
6 #include <boost/fusion/container/map.hpp>
7 #include <boost/test/included/unit_test.hpp>
16 using namespace boost::unit_test_framework;
18 namespace fusion = boost::fusion;
20 typedef fusion::map<fusion::pair<uint8_t, UA_DataType>, fusion::pair<int8_t, UA_DataType>,
21 fusion::pair<uint16_t, UA_DataType>, fusion::pair<int16_t, UA_DataType>, fusion::pair<uint32_t, UA_DataType>,
22 fusion::pair<int32_t, UA_DataType>, fusion::pair<uint64_t, UA_DataType>, fusion::pair<int64_t, UA_DataType>,
23 fusion::pair<float, UA_DataType>, fusion::pair<double, UA_DataType>>
26 static TestTypesMap tMap{fusion::make_pair<uint8_t>(UA_TYPES[UA_TYPES_SBYTE]),
27 fusion::make_pair<int8_t>(UA_TYPES[UA_TYPES_BYTE]), fusion::make_pair<uint16_t>(UA_TYPES[UA_TYPES_UINT16]),
28 fusion::make_pair<int16_t>(UA_TYPES[UA_TYPES_INT16]), fusion::make_pair<uint32_t>(UA_TYPES[UA_TYPES_UINT32]),
29 fusion::make_pair<int32_t>(UA_TYPES[UA_TYPES_INT32]), fusion::make_pair<uint64_t>(UA_TYPES[UA_TYPES_UINT64]),
30 fusion::make_pair<int64_t>(UA_TYPES[UA_TYPES_INT64]), fusion::make_pair<float>(UA_TYPES[UA_TYPES_FLOAT]),
31 fusion::make_pair<double>(UA_TYPES[UA_TYPES_DOUBLE])};
39 static void testClassSide();
41 static void testClientSide();
43 template<
typename CTK_TYPE>
48 template<
typename CTK_TYPE>
51 vector<CTK_TYPE> valueArray =
52 pvSet->
csManager->getProcessArray<CTK_TYPE>(oneProcessVariable->getName())->accessChannel(0);
53 UA_Variant* var = UA_Variant_new();
54 test->
getValue<CTK_TYPE>(var,
nullptr);
55 if(valueArray.size() == 1) {
57 BOOST_CHECK(*(CTK_TYPE*)(var->data) == 0);
59 UA_Variant_clear(var);
60 UA_Variant_setScalarCopy(var, &newValue, &fusion::at_key<CTK_TYPE>(tMap));
63 auto time = oneProcessVariable->getVersionNumber().getTime();
64 auto usecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();
65 BOOST_CHECK(test->
getSourceTimeStamp() == usecs * UA_DATETIME_USEC + UA_DATETIME_UNIX_EPOCH);
68 vector<CTK_TYPE> csValueArray =
69 pvSet->
csManager->getProcessArray<CTK_TYPE>(oneProcessVariable->getName())->accessChannel(0);
70 BOOST_CHECK(csValueArray.size() == 1);
71 BOOST_CHECK(csValueArray.at(0) == 100);
75 std::vector<CTK_TYPE> newVector(var->arrayLength);
76 for(
size_t i = 0; i < var->arrayLength; i++) {
77 BOOST_CHECK(((CTK_TYPE*)(var->data))[i] == 0);
78 newVector.at(i) = (100 - i);
80 UA_Variant_clear(var);
81 UA_Variant_setArrayCopy(var, newVector.data(), newVector.size(), &fusion::at_key<CTK_TYPE>(tMap));
85 vector<CTK_TYPE> valueArray =
86 pvSet->
csManager->getProcessArray<CTK_TYPE>(oneProcessVariable->getName())->accessChannel(0);
88 for(
auto value : valueArray) {
89 BOOST_CHECK(value == (CTK_TYPE)(100 - i));
94 UA_Variant_clear(var);
95 UA_NumericRange range = UA_NUMERICRANGE(
"0:5");
97 test->
getValue<CTK_TYPE>(var, &range);
98 BOOST_CHECK(var->arrayLength == 6);
99 for(
size_t i = 0; i < var->arrayLength; i++) {
100 BOOST_CHECK(((CTK_TYPE*)(var->data))[i] == (CTK_TYPE)(100 - i));
102 UA_free(range.dimensions);
104 UA_Variant_delete(var);
108 std::cout <<
"Enter ProcessVariableTest with ClassSide" << std::endl;
120 for(ProcessVariable::SharedPtr oneProcessVariable : pvSet.
csManager->getAllProcessVariables()) {
124 BOOST_CHECK(test.
getName() == oneProcessVariable->getName());
131 string description =
"";
133 BOOST_CHECK(description == oneProcessVariable->getDescription());
138 std::string valueType = test.
getType();
140 cout <<
"Check Processvariable: " << test.
getName() << endl;
141 if(valueType ==
"int8_t") {
142 BOOST_CHECK(valueType ==
"int8_t");
143 testData<int8_t>(oneProcessVariable, &pvSet, &test);
145 else if(valueType ==
"uint8_t") {
146 BOOST_CHECK(valueType ==
"uint8_t");
147 testData<uint8_t>(oneProcessVariable, &pvSet, &test);
149 else if(valueType ==
"int16_t") {
150 BOOST_CHECK(valueType ==
"int16_t");
151 testData<int16_t>(oneProcessVariable, &pvSet, &test);
153 else if(valueType ==
"uint16_t") {
154 BOOST_CHECK(valueType ==
"uint16_t");
155 testData<uint16_t>(oneProcessVariable, &pvSet, &test);
157 else if(valueType ==
"int32_t") {
158 BOOST_CHECK(valueType ==
"int32_t");
159 testData<int32_t>(oneProcessVariable, &pvSet, &test);
161 else if(valueType ==
"uint32_t") {
162 BOOST_CHECK(valueType ==
"uint32_t");
163 testData<uint32_t>(oneProcessVariable, &pvSet, &test);
165 else if(valueType ==
"int64_t") {
166 BOOST_CHECK(valueType ==
"int64_t");
167 testData<int64_t>(oneProcessVariable, &pvSet, &test);
169 else if(valueType ==
"uint64_t") {
170 BOOST_CHECK(valueType ==
"uint64_t");
171 testData<uint64_t>(oneProcessVariable, &pvSet, &test);
173 else if(valueType ==
"float") {
174 BOOST_CHECK(valueType ==
"float");
175 testData<float>(oneProcessVariable, &pvSet, &test);
177 else if(valueType ==
"double") {
178 BOOST_CHECK(valueType ==
"double");
179 testData<double>(oneProcessVariable, &pvSet, &test);
181 else if(valueType ==
"string") {
187 BOOST_CHECK(!UA_NodeId_isNull(&nodeId));
188 UA_NodeId_clear(&nodeId);
191 newName = oneProcessVariable->getName();
193 BOOST_CHECK(test.
getName() !=
"");
198 if(serverThread->joinable()) {
199 serverThread->join();
207 std::cout <<
"Enter ProcessVariableTest with ExampleSet and ClientSide testing" << std::endl;
219 vector<ua_processvariable*> varList;
220 for(ProcessVariable::SharedPtr oneProcessVariable : pvSet.
csManager->getAllProcessVariables()) {
226 UA_Client* client = UA_Client_new();
227 UA_ClientConfig* cc = UA_Client_getConfig(client);
228 UA_ClientConfig_setDefault(cc);
229 string endpointURL =
"opc.tcp://localhost:" + to_string(serverSet.
opcuaPort);
230 UA_StatusCode retval = UA_Client_connect(client, endpointURL.c_str());
234 while(retval != UA_STATUSCODE_GOOD & k < 10) {
235 retval = UA_Client_connect(client, endpointURL.c_str());
240 if(retval != UA_STATUSCODE_GOOD) {
241 std::cout <<
"Failed to connect to server"
242 <<
"opc.tcp://localhost:" << serverSet.
opcuaPort << std::endl;
246 UA_BrowseRequest bReq;
247 UA_BrowseRequest_init(&bReq);
248 bReq.requestedMaxReferencesPerNode = 0;
249 bReq.nodesToBrowse = UA_BrowseDescription_new();
250 bReq.nodesToBrowseSize = 1;
251 bReq.nodesToBrowse[0].nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
252 bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL;
253 UA_BrowseResponse bResp = UA_Client_Service_browse(client, bReq);
255 for(
size_t i = 0; i < bResp.resultsSize; ++i) {
256 for(
size_t j = 0; j < bResp.results[i].referencesSize; ++j) {
257 UA_ReferenceDescription* ref = &(bResp.results[i].references[j]);
258 if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_NUMERIC) {
259 size_t lenBrowseName = (int)ref->browseName.name.length;
260 std::string browseNameFound(
reinterpret_cast<char const*
>(ref->browseName.name.data), lenBrowseName);
262 UA_BrowseRequest bReq2;
263 UA_BrowseRequest_init(&bReq2);
264 bReq2.requestedMaxReferencesPerNode = 0;
265 bReq2.nodesToBrowse = UA_BrowseDescription_new();
266 bReq2.nodesToBrowseSize = 1;
267 bReq2.nodesToBrowse[0].nodeId = ref->nodeId.nodeId;
268 bReq2.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL;
269 UA_BrowseResponse bResp2 = UA_Client_Service_browse(client, bReq2);
271 UA_NodeId valueNodeId = UA_NODEID_NULL;
272 UA_NodeId typeNodeId = UA_NODEID_NULL;
273 UA_NodeId nameNodeId = UA_NODEID_NULL;
274 UA_NodeId engineeringUnitNodeId = UA_NODEID_NULL;
275 UA_NodeId descriptionNodeId = UA_NODEID_NULL;
278 UA_ReferenceDescription* refe;
279 for(
size_t m = 0; m < bResp2.resultsSize; ++m) {
280 for(
size_t k = 0; k < bResp2.results[m].referencesSize; ++k) {
281 refe = &(bResp2.results[m].references[k]);
282 if(refe->nodeId.nodeId.identifierType == UA_NODEIDTYPE_NUMERIC ||
283 refe->nodeId.nodeId.identifierType == UA_NODEIDTYPE_STRING) {
284 size_t lenBrowseName2 = (int)refe->browseName.name.length;
285 string browseNameFound2(
reinterpret_cast<char const*
>(refe->browseName.name.data), lenBrowseName2);
287 if(browseNameFound2 ==
"Type") {
288 UA_NodeId_copy(&refe->nodeId.nodeId, &typeNodeId);
291 if(browseNameFound2 ==
"Name") {
292 UA_NodeId_copy(&refe->nodeId.nodeId, &nameNodeId);
295 if(browseNameFound2 ==
"Value") {
296 UA_NodeId_copy(&refe->nodeId.nodeId, &valueNodeId);
297 name = browseNameFound;
298 cout <<
"Checking ProcessVariable: " << name << endl;
300 if(browseNameFound2 ==
"EngineeringUnit") {
301 UA_NodeId_copy(&refe->nodeId.nodeId, &engineeringUnitNodeId);
304 if(browseNameFound2 ==
"Description") {
305 UA_NodeId_copy(&refe->nodeId.nodeId, &descriptionNodeId);
310 UA_BrowseRequest_clear(&bReq2);
311 UA_BrowseResponse_clear(&bResp2);
313 if(!UA_NodeId_isNull(&valueNodeId)) {
314 UA_Variant* valueToCheck = UA_Variant_new();
315 UA_Variant_init(valueToCheck);
316 UA_StatusCode retvalValue = UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
317 if(retvalValue != UA_STATUSCODE_GOOD) {
321 UA_Variant* datatypeToCheck = UA_Variant_new();
322 UA_Variant_init(datatypeToCheck);
323 UA_StatusCode retvalValueDatatype = UA_Client_readValueAttribute(client, typeNodeId, datatypeToCheck);
324 if(retvalValueDatatype != UA_STATUSCODE_GOOD) {
328 UA_Variant* nameToCheck = UA_Variant_new();
329 UA_Variant_init(nameToCheck);
330 UA_StatusCode retvalValueName = UA_Client_readValueAttribute(client, nameNodeId, nameToCheck);
331 if(retvalValueName != UA_STATUSCODE_GOOD) {
335 UA_Variant* euToCheck = UA_Variant_new();
336 UA_Variant_init(euToCheck);
337 UA_StatusCode retvalValueEu = UA_Client_readValueAttribute(client, engineeringUnitNodeId, euToCheck);
338 if(retvalValueEu != UA_STATUSCODE_GOOD) {
342 UA_Variant* descToCheck = UA_Variant_new();
343 UA_Variant_init(descToCheck);
344 UA_StatusCode retvalValueDesc = UA_Client_readValueAttribute(client, descriptionNodeId, descToCheck);
345 if(retvalValueDesc != UA_STATUSCODE_GOOD) {
349 UA_NodeId datatypeId;
350 if(retvalValue == UA_STATUSCODE_GOOD) {
351 UA_StatusCode retvalDatatype = UA_Client_readDataTypeAttribute(client, valueNodeId, &datatypeId);
352 if(retvalDatatype != UA_STATUSCODE_GOOD) {
357 if(retvalValue == UA_STATUSCODE_GOOD) {
358 string datatype =
"";
360 string description =
"";
361 string engineeringUnit =
"";
368 if((valName.compare(
"/int8Scalar") == 0) || (valName.compare(
"/Mein/Name_ist#int8Array_s15") == 0) ||
369 (valName.compare(
"/Unser/Name/ist_uint8Array_s10") == 0)) {
370 BOOST_CHECK(engineeringUnit ==
"Einheit");
373 BOOST_CHECK(engineeringUnit ==
"n./a.");
377 string merker =
"mHensel/Iatrou";
378 UA_String newEU = UA_String_fromChars((
char*)merker.c_str());
379 UA_Variant_init(euToCheck);
380 UA_Variant_setScalarCopy(euToCheck, &newEU, &UA_TYPES[UA_TYPES_STRING]);
381 UA_StatusCode retvalNewEU = UA_Client_writeValueAttribute(client, engineeringUnitNodeId, euToCheck);
382 if(retvalNewEU != UA_STATUSCODE_GOOD) {
385 UA_String_clear(&newEU);
387 BOOST_CHECK(engineeringUnit ==
"mHensel/Iatrou");
392 if((valName.compare(
"/int8Scalar") == 0) || (valName.compare(
"/Mein/Name_ist#int8Array_s15") == 0) ||
393 (valName.compare(
"/Unser/Name/ist_uint8Array_s10") == 0)) {
394 BOOST_CHECK(description ==
"Beschreibung der Variable");
397 BOOST_CHECK(description ==
"");
400 merker =
"Beschreibung";
401 UA_String newDesc = UA_String_fromChars((
char*)merker.c_str());
402 UA_Variant_init(descToCheck);
403 UA_Variant_setScalarCopy(descToCheck, &newDesc, &UA_TYPES[UA_TYPES_STRING]);
404 UA_StatusCode retvalNewDesc = UA_Client_writeValueAttribute(client, descriptionNodeId, descToCheck);
405 if(retvalNewDesc != UA_STATUSCODE_GOOD) {
408 UA_String_clear(&newDesc);
410 BOOST_CHECK(valName ==
"Beschreibung");
413 if(valueToCheck->arrayLength < 1) {
414 switch(datatypeId.identifier.numeric - 1) {
415 case UA_TYPES_SBYTE: {
418 BOOST_CHECK(datatype ==
"int8_t");
421 BOOST_CHECK(valName ==
"/int8Scalar");
423 uint8_t value = (uint8_t) * ((uint8_t*)valueToCheck->data);
424 BOOST_CHECK(value == 0);
427 uint8_t newValue = 123;
428 UA_Variant_init(valueToCheck);
429 UA_Variant_setScalarCopy(valueToCheck, &newValue, &UA_TYPES[UA_TYPES_SBYTE]);
430 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
431 if(retvalNewVar == UA_STATUSCODE_GOOD) {
433 UA_Variant_init(valueToCheck);
434 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
435 value = (uint8_t) * ((uint8_t*)valueToCheck->data);
436 BOOST_CHECK(value == newValue);
443 case UA_TYPES_BYTE: {
446 BOOST_CHECK(datatype ==
"uint8_t");
449 BOOST_CHECK(valName ==
"/uint8Scalar");
451 int8_t value = (int8_t) * ((int8_t*)valueToCheck->data);
452 BOOST_CHECK(value == 0);
455 int8_t newValue = 122;
456 UA_Variant_init(valueToCheck);
457 UA_Variant_setScalarCopy(valueToCheck, &newValue, &UA_TYPES[UA_TYPES_BYTE]);
458 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
459 if(retvalNewVar == UA_STATUSCODE_GOOD) {
461 UA_Variant_init(valueToCheck);
462 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
463 value = (int8_t) * ((int8_t*)valueToCheck->data);
464 BOOST_CHECK(value == newValue);
471 case UA_TYPES_INT16: {
474 BOOST_CHECK(datatype ==
"int16_t");
477 BOOST_CHECK(valName ==
"/int16Scalar");
479 int16_t value = (int16_t) * ((int16_t*)valueToCheck->data);
480 BOOST_CHECK(value == 0);
483 int16_t newValue = 123;
484 UA_Variant_init(valueToCheck);
485 UA_Variant_setScalarCopy(valueToCheck, &newValue, &UA_TYPES[UA_TYPES_INT16]);
486 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
487 if(retvalNewVar == UA_STATUSCODE_GOOD) {
489 UA_Variant_init(valueToCheck);
490 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
491 value = (int16_t) * ((int16_t*)valueToCheck->data);
492 BOOST_CHECK(value == newValue);
499 case UA_TYPES_UINT16: {
502 BOOST_CHECK(datatype ==
"uint16_t");
505 BOOST_CHECK(valName ==
"/uint16Scalar");
507 uint16_t value = (uint16_t) * ((uint16_t*)valueToCheck->data);
508 BOOST_CHECK(value == 0);
511 uint16_t newValue = 123;
512 UA_Variant_init(valueToCheck);
513 UA_Variant_setScalarCopy(valueToCheck, &newValue, &UA_TYPES[UA_TYPES_UINT16]);
514 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
515 if(retvalNewVar == UA_STATUSCODE_GOOD) {
517 UA_Variant_init(valueToCheck);
518 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
519 value = (uint16_t) * ((uint16_t*)valueToCheck->data);
520 BOOST_CHECK(value == newValue);
527 case UA_TYPES_INT32: {
530 BOOST_CHECK(datatype ==
"int32_t");
533 BOOST_CHECK(valName ==
"/Dein/Name/ist/int32Scalar");
535 int32_t value = (int32_t) * ((int32_t*)valueToCheck->data);
536 BOOST_CHECK(value == 0);
539 int32_t newValue = 123;
540 UA_Variant_init(valueToCheck);
541 UA_Variant_setScalarCopy(valueToCheck, &newValue, &UA_TYPES[UA_TYPES_INT32]);
542 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
543 if(retvalNewVar == UA_STATUSCODE_GOOD) {
545 UA_Variant_init(valueToCheck);
546 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
547 value = (int32_t) * ((int32_t*)valueToCheck->data);
548 BOOST_CHECK(value == newValue);
555 case UA_TYPES_UINT32: {
558 BOOST_CHECK(datatype ==
"uint32_t");
561 BOOST_CHECK(valName ==
"/Mein/Name/ist/uint32Scalar");
563 uint32_t value = (uint32_t) * ((uint32_t*)valueToCheck->data);
564 BOOST_CHECK(value == 0);
567 uint32_t newValue = 123;
568 UA_Variant_init(valueToCheck);
569 UA_Variant_setScalarCopy(valueToCheck, &newValue, &UA_TYPES[UA_TYPES_UINT32]);
570 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
571 if(retvalNewVar == UA_STATUSCODE_GOOD) {
573 UA_Variant_init(valueToCheck);
574 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
575 value = (uint32_t) * ((uint32_t*)valueToCheck->data);
576 BOOST_CHECK(value == newValue);
583 case UA_TYPES_INT64: {
586 BOOST_CHECK(datatype ==
"int64_t");
589 BOOST_CHECK(valName ==
"/Mein/Name/ist/int64Scalar");
591 int64_t value = (int64_t) * ((int64_t*)valueToCheck->data);
592 BOOST_CHECK(value == 0);
595 int64_t newValue = 123;
596 UA_Variant_init(valueToCheck);
597 UA_Variant_setScalarCopy(valueToCheck, &newValue, &UA_TYPES[UA_TYPES_INT64]);
598 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
599 if(retvalNewVar == UA_STATUSCODE_GOOD) {
601 UA_Variant_init(valueToCheck);
602 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
603 value = (int64_t) * ((int64_t*)valueToCheck->data);
604 BOOST_CHECK(value == newValue);
611 case UA_TYPES_UINT64: {
614 BOOST_CHECK(datatype ==
"uint64_t");
617 BOOST_CHECK(valName ==
"/Mein/Name/ist/uint64Scalar");
619 uint64_t value = (uint64_t) * ((uint64_t*)valueToCheck->data);
620 BOOST_CHECK(value == 0);
623 uint64_t newValue = 123;
624 UA_Variant_init(valueToCheck);
625 UA_Variant_setScalarCopy(valueToCheck, &newValue, &UA_TYPES[UA_TYPES_UINT64]);
626 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
627 if(retvalNewVar == UA_STATUSCODE_GOOD) {
629 UA_Variant_init(valueToCheck);
630 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
631 value = (uint64_t) * ((uint64_t*)valueToCheck->data);
632 BOOST_CHECK(value == newValue);
639 case UA_TYPES_DOUBLE: {
642 BOOST_CHECK(datatype ==
"double");
645 BOOST_CHECK(valName ==
"/Dieser/Name/ist/doubleScalar");
647 double value = (double)*((
double*)valueToCheck->data);
648 BOOST_CHECK(value == 0);
651 double newValue = 123.12;
652 UA_Variant_init(valueToCheck);
653 UA_Variant_setScalarCopy(valueToCheck, &newValue, &UA_TYPES[UA_TYPES_DOUBLE]);
654 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
655 if(retvalNewVar == UA_STATUSCODE_GOOD) {
657 UA_Variant_init(valueToCheck);
658 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
659 value = (double)*((
double*)valueToCheck->data);
660 BOOST_CHECK(((int32_t)value * 100) == ((int32_t)newValue * 100));
667 case UA_TYPES_FLOAT: {
670 BOOST_CHECK(datatype ==
"float");
673 BOOST_CHECK(valName ==
"/floatScalar");
675 float value = (float)*((
float*)valueToCheck->data);
676 BOOST_CHECK(value == 0);
679 float newValue = 123.12;
680 UA_Variant_init(valueToCheck);
681 UA_Variant_setScalarCopy(valueToCheck, &newValue, &UA_TYPES[UA_TYPES_FLOAT]);
682 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
683 if(retvalNewVar == UA_STATUSCODE_GOOD) {
685 UA_Variant_init(valueToCheck);
686 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
687 value = (float)*((
float*)valueToCheck->data);
688 BOOST_CHECK(((int32_t)value * 100) == ((int32_t)newValue * 100));
696 printf(
"Not define: %-16d\n", datatypeId.identifier.numeric);
705 switch(datatypeId.identifier.numeric - 1) {
706 case UA_TYPES_SBYTE: {
709 BOOST_CHECK(datatype ==
"int8_t");
713 BOOST_CHECK(valName ==
"/Mein/Name_ist#int8Array_s15");
715 size_t arrayLength = valueToCheck->arrayLength;
716 int8_t* value = (int8_t*)valueToCheck->data;
717 for(uint32_t i = 0; i < arrayLength; i++) {
718 BOOST_CHECK(value[i] == 0);
721 int8_t varArray[arrayLength];
722 int8_t* newValue = varArray;
723 for(uint32_t i = 0; i < arrayLength; i++) {
727 UA_Variant_init(valueToCheck);
728 UA_Variant_setArrayCopy(valueToCheck, newValue, arrayLength, &UA_TYPES[UA_TYPES_SBYTE]);
729 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
730 if(retvalNewVar == UA_STATUSCODE_GOOD) {
732 UA_Variant_init(valueToCheck);
733 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
734 value = (int8_t*)valueToCheck->data;
735 for(uint32_t i = 0; i < arrayLength; i++) {
736 BOOST_CHECK(value[i] == newValue[i]);
744 case UA_TYPES_BYTE: {
747 BOOST_CHECK(datatype ==
"uint8_t");
751 BOOST_CHECK(valName ==
"/Dein/Name/ist/uint8Array_s10");
753 size_t arrayLength = valueToCheck->arrayLength;
754 uint8_t* value = (uint8_t*)valueToCheck->data;
755 for(uint32_t i = 0; i < arrayLength; i++) {
756 BOOST_CHECK(value[i] == 0);
759 uint8_t varArray[arrayLength];
760 uint8_t* newValue = varArray;
761 for(uint32_t i = 0; i < arrayLength; i++) {
765 UA_Variant_init(valueToCheck);
766 UA_Variant_setArrayCopy(valueToCheck, newValue, arrayLength, &UA_TYPES[UA_TYPES_BYTE]);
767 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
768 if(retvalNewVar == UA_STATUSCODE_GOOD) {
770 UA_Variant_init(valueToCheck);
771 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
772 value = (uint8_t*)valueToCheck->data;
773 for(uint32_t i = 0; i < arrayLength; i++) {
774 BOOST_CHECK(value[i] == newValue[i]);
782 case UA_TYPES_INT16: {
785 BOOST_CHECK(datatype ==
"int16_t");
788 BOOST_CHECK(valName ==
"/Unser/Name/ist_int16Array_s10");
790 size_t arrayLength = valueToCheck->arrayLength;
791 int16_t* value = (int16_t*)valueToCheck->data;
792 for(uint32_t i = 0; i < arrayLength; i++) {
793 BOOST_CHECK(value[i] == 0);
796 value = (int16_t*)valueToCheck->data;
797 for(uint32_t i = 0; i < arrayLength; i++) {
798 BOOST_CHECK(value[i] == 0);
801 int16_t varArray[arrayLength];
802 int16_t* newValue = varArray;
803 for(uint32_t i = 0; i < arrayLength; i++) {
807 UA_Variant_init(valueToCheck);
808 UA_Variant_setArrayCopy(valueToCheck, newValue, arrayLength, &UA_TYPES[UA_TYPES_INT16]);
809 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
810 if(retvalNewVar == UA_STATUSCODE_GOOD) {
812 UA_Variant_init(valueToCheck);
813 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
814 value = (int16_t*)valueToCheck->data;
815 for(uint32_t i = 0; i < arrayLength; i++) {
816 BOOST_CHECK(value[i] == newValue[i]);
824 case UA_TYPES_UINT16: {
827 BOOST_CHECK(datatype ==
"uint16_t");
830 BOOST_CHECK(valName ==
"/Unser/Name/ist_uint8Array_s10");
832 size_t arrayLength = valueToCheck->arrayLength;
833 uint16_t* value = (uint16_t*)valueToCheck->data;
834 for(uint32_t i = 0; i < arrayLength; i++) {
835 BOOST_CHECK(value[i] == 0);
838 value = (uint16_t*)valueToCheck->data;
839 for(uint32_t i = 0; i < arrayLength; i++) {
840 BOOST_CHECK(value[i] == 0);
844 uint16_t varArray[arrayLength];
845 uint16_t* newValue = varArray;
846 for(uint32_t i = 0; i < arrayLength; i++) {
850 UA_Variant_init(valueToCheck);
851 UA_Variant_setArrayCopy(valueToCheck, newValue, arrayLength, &UA_TYPES[UA_TYPES_UINT16]);
852 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
853 if(retvalNewVar == UA_STATUSCODE_GOOD) {
855 UA_Variant_init(valueToCheck);
856 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
857 value = (uint16_t*)valueToCheck->data;
858 for(uint32_t i = 0; i < arrayLength; i++) {
859 BOOST_CHECK(value[i] == newValue[i]);
867 case UA_TYPES_INT32: {
870 BOOST_CHECK(datatype ==
"int32_t");
873 BOOST_CHECK(valName ==
"/int32Array_s15");
875 size_t arrayLength = valueToCheck->arrayLength;
876 int32_t* value = (int32_t*)valueToCheck->data;
877 for(uint32_t i = 0; i < arrayLength; i++) {
878 BOOST_CHECK(value[i] == 0);
881 value = (int32_t*)valueToCheck->data;
882 for(uint32_t i = 0; i < arrayLength; i++) {
883 BOOST_CHECK(value[i] == 0);
887 int32_t varArray[arrayLength];
888 int32_t* newValue = varArray;
889 for(uint32_t i = 0; i < arrayLength; i++) {
893 UA_Variant_init(valueToCheck);
894 UA_Variant_setArrayCopy(valueToCheck, newValue, arrayLength, &UA_TYPES[UA_TYPES_INT32]);
895 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
896 if(retvalNewVar == UA_STATUSCODE_GOOD) {
898 UA_Variant_init(valueToCheck);
899 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
900 value = (int32_t*)valueToCheck->data;
901 for(uint32_t i = 0; i < arrayLength; i++) {
902 BOOST_CHECK(value[i] == newValue[i]);
910 case UA_TYPES_UINT32: {
913 BOOST_CHECK(datatype ==
"uint32_t");
917 BOOST_CHECK(valName ==
"/uint32Array_s10");
919 size_t arrayLength = valueToCheck->arrayLength;
920 uint32_t* value = (uint32_t*)valueToCheck->data;
921 for(uint32_t i = 0; i < arrayLength; i++) {
922 BOOST_CHECK(value[i] == 0);
925 uint32_t varArray[arrayLength];
926 uint32_t* newValue = varArray;
927 for(uint32_t i = 0; i < arrayLength; i++) {
931 UA_Variant_init(valueToCheck);
932 UA_Variant_setArrayCopy(valueToCheck, newValue, arrayLength, &UA_TYPES[UA_TYPES_UINT32]);
933 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
934 if(retvalNewVar == UA_STATUSCODE_GOOD) {
936 UA_Variant_init(valueToCheck);
937 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
938 value = (uint32_t*)valueToCheck->data;
939 for(uint32_t i = 0; i < arrayLength; i++) {
940 BOOST_CHECK(value[i] == newValue[i]);
948 case UA_TYPES_INT64: {
951 BOOST_CHECK(datatype ==
"int64_t");
954 BOOST_CHECK(valName ==
"/int64Array_s15");
956 size_t arrayLength = valueToCheck->arrayLength;
957 int64_t* value = (int64_t*)valueToCheck->data;
958 for(uint32_t i = 0; i < arrayLength; i++) {
959 BOOST_CHECK(value[i] == 0);
962 value = (int64_t*)valueToCheck->data;
963 for(uint32_t i = 0; i < arrayLength; i++) {
964 BOOST_CHECK(value[i] == 0);
968 int64_t varArray[arrayLength];
969 int64_t* newValue = varArray;
970 for(uint32_t i = 0; i < arrayLength; i++) {
974 UA_Variant_init(valueToCheck);
975 UA_Variant_setArrayCopy(valueToCheck, newValue, arrayLength, &UA_TYPES[UA_TYPES_INT64]);
976 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
977 if(retvalNewVar == UA_STATUSCODE_GOOD) {
979 UA_Variant_init(valueToCheck);
980 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
981 value = (int64_t*)valueToCheck->data;
982 for(uint32_t i = 0; i < arrayLength; i++) {
983 BOOST_CHECK(value[i] == newValue[i]);
991 case UA_TYPES_UINT64: {
994 BOOST_CHECK(datatype ==
"uint64_t");
997 BOOST_CHECK(valName ==
"/uint64Array_s10");
999 size_t arrayLength = valueToCheck->arrayLength;
1000 uint64_t* value = (uint64_t*)valueToCheck->data;
1001 for(uint32_t i = 0; i < arrayLength; i++) {
1002 BOOST_CHECK(value[i] == 0);
1005 value = (uint64_t*)valueToCheck->data;
1006 for(uint32_t i = 0; i < arrayLength; i++) {
1007 BOOST_CHECK(value[i] == 0);
1011 uint64_t varArray[arrayLength];
1012 uint64_t* newValue = varArray;
1013 for(uint32_t i = 0; i < arrayLength; i++) {
1017 UA_Variant_init(valueToCheck);
1018 UA_Variant_setArrayCopy(valueToCheck, newValue, arrayLength, &UA_TYPES[UA_TYPES_UINT64]);
1019 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
1020 if(retvalNewVar == UA_STATUSCODE_GOOD) {
1022 UA_Variant_init(valueToCheck);
1023 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
1024 value = (uint64_t*)valueToCheck->data;
1025 for(uint32_t i = 0; i < arrayLength; i++) {
1026 BOOST_CHECK(value[i] == newValue[i]);
1034 case UA_TYPES_DOUBLE: {
1037 BOOST_CHECK(datatype ==
"double");
1041 BOOST_CHECK(valName ==
"/doubleArray_s15");
1043 size_t arrayLength = valueToCheck->arrayLength;
1044 double* value = (
double*)valueToCheck->data;
1045 for(uint32_t i = 0; i < arrayLength; i++) {
1046 BOOST_CHECK(value[i] == 0);
1050 double varArray[arrayLength];
1051 double* newValue = varArray;
1052 for(uint32_t i = 0; i < arrayLength; i++) {
1053 newValue[i] = i * 0.5;
1056 UA_Variant_init(valueToCheck);
1057 UA_Variant_setArrayCopy(valueToCheck, newValue, arrayLength, &UA_TYPES[UA_TYPES_DOUBLE]);
1058 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
1059 if(retvalNewVar == UA_STATUSCODE_GOOD) {
1061 UA_Variant_init(valueToCheck);
1062 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
1063 value = (
double*)valueToCheck->data;
1064 for(uint32_t i = 0; i < arrayLength; i++) {
1065 BOOST_CHECK(((int32_t)(value[i] * 100)) == ((int32_t)(newValue[i] * 100)));
1073 case UA_TYPES_FLOAT: {
1076 BOOST_CHECK(datatype ==
"float");
1079 BOOST_CHECK(valName ==
"/floatArray_s101234");
1081 size_t arrayLength = valueToCheck->arrayLength;
1082 float* value = (
float*)valueToCheck->data;
1083 for(uint32_t i = 0; i < arrayLength; i++) {
1084 BOOST_CHECK(value[i] == 0);
1088 float varArray[arrayLength];
1089 float* newValue = varArray;
1090 for(uint32_t i = 0; i < arrayLength; i++) {
1091 newValue[i] = i * 0.5;
1094 UA_Variant_init(valueToCheck);
1095 UA_Variant_setArrayCopy(valueToCheck, newValue, arrayLength, &UA_TYPES[UA_TYPES_FLOAT]);
1096 UA_StatusCode retvalNewVar = UA_Client_writeValueAttribute(client, valueNodeId, valueToCheck);
1097 if(retvalNewVar == UA_STATUSCODE_GOOD) {
1099 UA_Variant_init(valueToCheck);
1100 UA_Client_readValueAttribute(client, valueNodeId, valueToCheck);
1101 value = (
float*)valueToCheck->data;
1102 for(uint32_t i = 0; i < arrayLength; i++) {
1103 BOOST_CHECK(((int32_t)(value[i] * 100)) == ((int32_t)(newValue[i] * 100)));
1112 printf(
"Not define: %-16d\n", datatypeId.identifier.numeric);
1118 UA_Variant_delete(valueToCheck);
1119 UA_Variant_delete(euToCheck);
1120 UA_Variant_delete(nameToCheck);
1121 UA_Variant_delete(datatypeToCheck);
1122 UA_Variant_delete(descToCheck);
1128 UA_BrowseRequest_clear(&bReq);
1129 UA_BrowseResponse_clear(&bResp);
1130 UA_Client_disconnect(client);
1132 UA_Client_delete(client);
1136 if(serverThread->joinable()) {
1137 serverThread->join();
1140 cout <<
"Delete ServerThread" << endl;
1141 delete serverThread;
1142 serverThread = NULL;
1144 for(
auto& ptr : varList)
delete ptr;