check_client_highlevel.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <pthread.h>
  7. #include <ua_types.h>
  8. #include "ua_server.h"
  9. #include "ua_client.h"
  10. #include "ua_config_default.h"
  11. #include "ua_client_highlevel.h"
  12. #include "ua_network_tcp.h"
  13. #include "check.h"
  14. UA_Server *server;
  15. UA_ServerConfig *config;
  16. UA_Boolean running;
  17. UA_ServerNetworkLayer nl;
  18. pthread_t server_thread;
  19. UA_Client *client;
  20. #define CUSTOM_NS "http://open62541.org/ns/test"
  21. #define CUSTOM_NS_UPPER "http://open62541.org/ns/Test"
  22. static void *serverloop(void *_) {
  23. while (running)
  24. UA_Server_run_iterate(server, true);
  25. return NULL;
  26. }
  27. static void setup(void) {
  28. running = true;
  29. config = UA_ServerConfig_new_default();
  30. server = UA_Server_new(config);
  31. ck_assert_uint_eq(2, UA_Server_addNamespace(server, CUSTOM_NS));
  32. UA_Server_run_startup(server);
  33. pthread_create(&server_thread, NULL, serverloop, NULL);
  34. client = UA_Client_new(UA_ClientConfig_default);
  35. UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
  36. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  37. }
  38. static void teardown(void) {
  39. UA_Client_disconnect(client);
  40. UA_Client_delete(client);
  41. running = false;
  42. pthread_join(server_thread, NULL);
  43. UA_Server_run_shutdown(server);
  44. UA_Server_delete(server);
  45. UA_ServerConfig_delete(config);
  46. }
  47. START_TEST(Misc_State) {
  48. UA_ClientState state = UA_Client_getState(client);
  49. ck_assert_uint_eq(state, UA_CLIENTSTATE_SESSION);
  50. }
  51. END_TEST
  52. START_TEST(Misc_NamespaceGetIndex) {
  53. UA_UInt16 idx;
  54. UA_String ns = UA_STRING(CUSTOM_NS);
  55. UA_StatusCode retval = UA_Client_NamespaceGetIndex(client, &ns, &idx);
  56. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  57. ck_assert_uint_eq(idx, 2);
  58. // namespace uri is case sensitive
  59. ns = UA_STRING(CUSTOM_NS_UPPER);
  60. retval = UA_Client_NamespaceGetIndex(client, &ns, &idx);
  61. ck_assert_uint_eq(retval, UA_STATUSCODE_BADNOTFOUND);
  62. } END_TEST
  63. UA_NodeId newReferenceTypeId;
  64. UA_NodeId newObjectTypeId;
  65. UA_NodeId newDataTypeId;
  66. UA_NodeId newVariableTypeId;
  67. UA_NodeId newObjectId;
  68. UA_NodeId newVariableId;
  69. UA_NodeId newMethodId;
  70. UA_NodeId newViewId;
  71. #ifdef UA_ENABLE_NODEMANAGEMENT
  72. START_TEST(Node_Add) {
  73. UA_StatusCode retval;
  74. // Create custom reference type 'HasSubSubType' as child of HasSubtype
  75. {
  76. UA_ReferenceTypeAttributes attr = UA_ReferenceTypeAttributes_default;
  77. attr.description = UA_LOCALIZEDTEXT("en-US", "Some HasSubSubType");
  78. attr.displayName = UA_LOCALIZEDTEXT("en-US", "HasSubSubType");
  79. retval = UA_Client_addReferenceTypeNode(client, UA_NODEID_NULL,
  80. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  81. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  82. UA_QUALIFIEDNAME(1, "HasSubSubType"), attr,
  83. &newReferenceTypeId);
  84. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  85. }
  86. // Create TestObjectType SubType within BaseObjectType
  87. {
  88. UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;
  89. attr.description = UA_LOCALIZEDTEXT("en-US", "Some TestObjectType");
  90. attr.displayName = UA_LOCALIZEDTEXT("en-US", "TestObjectType");
  91. retval = UA_Client_addObjectTypeNode(client, UA_NODEID_NULL,
  92. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
  93. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  94. UA_QUALIFIEDNAME(1, "TestObjectType"), attr, &newObjectTypeId);
  95. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  96. }
  97. // Create Int128 DataType within Integer Datatype
  98. {
  99. UA_DataTypeAttributes attr = UA_DataTypeAttributes_default;
  100. attr.description = UA_LOCALIZEDTEXT("en-US", "Some Int128");
  101. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Int128");
  102. retval = UA_Client_addDataTypeNode(client, UA_NODEID_NULL,
  103. UA_NODEID_NUMERIC(0, UA_NS0ID_INTEGER),
  104. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  105. UA_QUALIFIEDNAME(1, "Int128"), attr, &newDataTypeId);
  106. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  107. }
  108. // Create PointType VariableType within BaseDataVariableType
  109. {
  110. UA_VariableTypeAttributes attr = UA_VariableTypeAttributes_default;
  111. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  112. attr.valueRank = 1; /* array with one dimension */
  113. UA_UInt32 arrayDims[1] = {2};
  114. attr.arrayDimensions = arrayDims;
  115. attr.arrayDimensionsSize = 1;
  116. attr.displayName = UA_LOCALIZEDTEXT("en-US", "PointType");
  117. /* a matching default value is required */
  118. UA_Double zero[2] = {0.0, 0.0};
  119. UA_Variant_setArray(&attr.value, zero, 2, &UA_TYPES[UA_TYPES_INT32]);
  120. retval = UA_Client_addVariableTypeNode(client, UA_NODEID_NULL,
  121. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEVARIABLETYPE),
  122. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  123. UA_QUALIFIEDNAME(1, "PointType"), attr, &newVariableTypeId);
  124. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  125. }
  126. // create Coordinates Object within ObjectsFolder
  127. {
  128. UA_ObjectAttributes attr = UA_ObjectAttributes_default;
  129. attr.description = UA_LOCALIZEDTEXT("en-US", "Some Coordinates");
  130. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Coordinates");
  131. retval = UA_Client_addObjectNode(client, UA_NODEID_NULL,
  132. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  133. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  134. UA_QUALIFIEDNAME(1, "Coordinates"),
  135. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), attr, &newObjectId);
  136. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  137. }
  138. // create Variable 'Top' within Coordinates Object
  139. {
  140. UA_VariableAttributes attr = UA_VariableAttributes_default;
  141. attr.description = UA_LOCALIZEDTEXT("en-US", "Top Coordinate");
  142. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Top");
  143. UA_Int32 values[2] = {10, 20};
  144. UA_Variant_setArray(&attr.value, values, 2, &UA_TYPES[UA_TYPES_INT32]);
  145. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  146. attr.valueRank = 1; /* array with one dimension */
  147. UA_UInt32 arrayDims[1] = {2};
  148. attr.arrayDimensions = arrayDims;
  149. attr.arrayDimensionsSize = 1;
  150. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  151. newObjectId,
  152. UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY),
  153. UA_QUALIFIEDNAME(1, "Top"),
  154. newVariableTypeId, attr, &newVariableId);
  155. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  156. }
  157. // create Method 'Dummy' within Coordinates Object.
  158. {
  159. UA_MethodAttributes attr = UA_MethodAttributes_default;
  160. attr.description = UA_LOCALIZEDTEXT("en-US", "Dummy method");
  161. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Dummy");
  162. attr.executable = true;
  163. attr.userExecutable = true;
  164. retval = UA_Client_addMethodNode(client, UA_NODEID_NULL,
  165. newObjectId,
  166. UA_NODEID_NUMERIC(0, UA_NS0ID_HASORDEREDCOMPONENT),
  167. UA_QUALIFIEDNAME(1, "Dummy"),
  168. attr, &newMethodId);
  169. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  170. }
  171. // create View 'AllTopCoordinates' whithin Views Folder
  172. {
  173. UA_ViewAttributes attr = UA_ViewAttributes_default;
  174. attr.description = UA_LOCALIZEDTEXT("en-US", "List of all top coordinates");
  175. attr.displayName = UA_LOCALIZEDTEXT("en-US", "AllTopCoordinates");
  176. retval = UA_Client_addViewNode(client, UA_NODEID_NULL,
  177. UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
  178. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  179. UA_QUALIFIEDNAME(1, "AllTopCoordinates"),
  180. attr, &newViewId);
  181. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  182. }
  183. UA_ExpandedNodeId target = UA_EXPANDEDNODEID_NULL;
  184. target.nodeId = newObjectId;
  185. // Add 'Top' to view
  186. retval = UA_Client_addReference(client, newViewId, UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  187. UA_TRUE, UA_STRING_NULL, target, UA_NODECLASS_VARIABLE);
  188. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  189. // Delete 'Top' from view
  190. retval = UA_Client_deleteReference(client, newViewId,
  191. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  192. true, target, true);
  193. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  194. // Delete 'AllTopCoordinates' view
  195. retval = UA_Client_deleteNode(client, newViewId, UA_TRUE);
  196. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  197. }
  198. END_TEST
  199. unsigned int iteratedNodeCount = 0;
  200. UA_NodeId iteratedNodes[4];
  201. static UA_StatusCode
  202. nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, void *handle) {
  203. if (isInverse || (referenceTypeId.identifierType == UA_NODEIDTYPE_NUMERIC &&
  204. referenceTypeId.identifier.numeric == UA_NS0ID_HASTYPEDEFINITION))
  205. return UA_STATUSCODE_GOOD;
  206. if (iteratedNodeCount >= 4)
  207. return UA_STATUSCODE_BADINDEXRANGEINVALID;
  208. UA_NodeId_copy(&childId, &iteratedNodes[iteratedNodeCount]);
  209. iteratedNodeCount++;
  210. return UA_STATUSCODE_GOOD;
  211. }
  212. #endif
  213. START_TEST(Node_Browse) {
  214. // Browse node in server folder
  215. UA_BrowseRequest bReq;
  216. UA_BrowseRequest_init(&bReq);
  217. // normally is set to 0, to get all the nodes, but we want to test browse next
  218. bReq.requestedMaxReferencesPerNode = 1;
  219. bReq.nodesToBrowse = UA_BrowseDescription_new();
  220. bReq.nodesToBrowseSize = 1;
  221. bReq.nodesToBrowse[0].nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER);
  222. bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL;
  223. UA_BrowseResponse bResp = UA_Client_Service_browse(client, bReq);
  224. ck_assert_uint_eq(bResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  225. ck_assert_uint_eq(bResp.resultsSize, 1);
  226. ck_assert_uint_eq(bResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  227. ck_assert_uint_eq(bResp.results[0].referencesSize, 1);
  228. /* References might have a different order in generated nodesets */
  229. /* UA_ReferenceDescription *ref = &(bResp.results[0].references[0]); */
  230. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVERTYPE); */
  231. // browse next
  232. UA_BrowseNextRequest bNextReq;
  233. UA_BrowseNextRequest_init(&bNextReq);
  234. // normally is set to 0, to get all the nodes, but we want to test browse next
  235. bNextReq.releaseContinuationPoints = UA_FALSE;
  236. bNextReq.continuationPoints = &bResp.results[0].continuationPoint;
  237. bNextReq.continuationPointsSize = 1;
  238. UA_BrowseNextResponse bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  239. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  240. ck_assert_uint_eq(bNextResp.resultsSize, 1);
  241. ck_assert_uint_eq(bNextResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  242. ck_assert_uint_eq(bNextResp.results[0].referencesSize, 1);
  243. /* ref = &(bNextResp.results[0].references[0]); */
  244. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVER_NAMESPACEARRAY); */
  245. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  246. bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  247. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  248. ck_assert_uint_eq(bNextResp.resultsSize, 1);
  249. ck_assert_uint_eq(bNextResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  250. ck_assert_uint_eq(bNextResp.results[0].referencesSize, 1);
  251. /* ref = &(bNextResp.results[0].references[0]); */
  252. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVER_SERVERARRAY); */
  253. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  254. // release continuation point. Result is then empty
  255. bNextReq.releaseContinuationPoints = UA_TRUE;
  256. bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  257. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  258. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  259. ck_assert_uint_eq(bNextResp.resultsSize, 0);
  260. UA_BrowseRequest_deleteMembers(&bReq);
  261. UA_BrowseResponse_deleteMembers(&bResp);
  262. // already deleted by browse request
  263. bNextReq.continuationPoints = NULL;
  264. bNextReq.continuationPointsSize = 0;
  265. UA_BrowseNextRequest_deleteMembers(&bNextReq);
  266. }
  267. END_TEST
  268. START_TEST(Node_Register) {
  269. UA_RegisterNodesRequest req;
  270. UA_RegisterNodesRequest_init(&req);
  271. req.nodesToRegister = UA_NodeId_new();
  272. req.nodesToRegister[0] = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
  273. req.nodesToRegisterSize = 1;
  274. UA_RegisterNodesResponse res = UA_Client_Service_registerNodes(client, req);
  275. ck_assert_uint_eq(res.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  276. ck_assert_uint_eq(res.registeredNodeIdsSize, 1);
  277. UA_UnregisterNodesRequest reqUn;
  278. UA_UnregisterNodesRequest_init(&reqUn);
  279. reqUn.nodesToUnregister = UA_NodeId_new();
  280. reqUn.nodesToUnregister[0] = res.registeredNodeIds[0];
  281. reqUn.nodesToUnregisterSize = 1;
  282. UA_UnregisterNodesResponse resUn = UA_Client_Service_unregisterNodes(client, reqUn);
  283. ck_assert_uint_eq(resUn.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  284. UA_UnregisterNodesRequest_deleteMembers(&reqUn);
  285. UA_UnregisterNodesResponse_deleteMembers(&resUn);
  286. UA_RegisterNodesRequest_deleteMembers(&req);
  287. UA_RegisterNodesResponse_deleteMembers(&res);
  288. }
  289. END_TEST
  290. // NodeIds for ReadWrite testing
  291. UA_NodeId nodeReadWriteUnitTest;
  292. UA_NodeId nodeReadWriteArray;
  293. UA_NodeId nodeReadWriteInt;
  294. UA_NodeId nodeReadWriteGeneric;
  295. UA_NodeId nodeReadWriteTestObjectType;
  296. UA_NodeId nodeReadWriteTestHasSubSubType;
  297. UA_NodeId nodeReadWriteView;
  298. UA_NodeId nodeReadWriteMethod;
  299. #ifdef UA_ENABLE_NODEMANAGEMENT
  300. START_TEST(Node_AddReadWriteNodes) {
  301. UA_StatusCode retval;
  302. // Create a folder with two variables for testing
  303. // create Coordinates Object within ObjectsFolder
  304. {
  305. UA_ObjectAttributes attr = UA_ObjectAttributes_default;
  306. attr.description = UA_LOCALIZEDTEXT("en-US", "UnitTest");
  307. attr.displayName = UA_LOCALIZEDTEXT("en-US", "UnitTest");
  308. retval = UA_Client_addObjectNode(client, UA_NODEID_NULL,
  309. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  310. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  311. UA_QUALIFIEDNAME(1, "UnitTest"),
  312. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), attr, &nodeReadWriteUnitTest);
  313. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  314. }
  315. // create Variable 'Top' within UnitTest Object
  316. {
  317. UA_VariableAttributes attr = UA_VariableAttributes_default;
  318. attr.description = UA_LOCALIZEDTEXT("en-US", "Array");
  319. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Array");
  320. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  321. attr.writeMask = UA_WRITEMASK_ARRRAYDIMENSIONS;
  322. UA_Int32 values[2];
  323. values[0] = 10;
  324. values[1] = 20;
  325. UA_Variant_setArray(&attr.value, values, 2, &UA_TYPES[UA_TYPES_INT32]);
  326. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  327. attr.valueRank = 1; /* array with one dimension */
  328. UA_UInt32 arrayDims[1] = {2};
  329. attr.arrayDimensions = arrayDims;
  330. attr.arrayDimensionsSize = 1;
  331. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  332. nodeReadWriteUnitTest,
  333. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  334. UA_QUALIFIEDNAME(1, "Array"),
  335. UA_NODEID_NULL, attr, &nodeReadWriteArray);
  336. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  337. }
  338. // create Variable 'Int' within UnitTest Object
  339. {
  340. UA_VariableAttributes attr = UA_VariableAttributes_default;
  341. attr.description = UA_LOCALIZEDTEXT("en-US", "Int");
  342. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Int");
  343. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  344. attr.writeMask = 0xFFFFFFFF;
  345. UA_Int32 int_value = 5678;
  346. UA_Variant_setScalar(&attr.value, &int_value, &UA_TYPES[UA_TYPES_INT32]);
  347. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  348. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  349. nodeReadWriteUnitTest,
  350. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  351. UA_QUALIFIEDNAME(1, "Int"),
  352. UA_NODEID_NULL, attr, &nodeReadWriteInt);
  353. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  354. }
  355. // create Variable 'Generic' within UnitTest Object
  356. {
  357. UA_VariableAttributes attr = UA_VariableAttributes_default;
  358. attr.description = UA_LOCALIZEDTEXT("en-US", "Generic");
  359. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Generic");
  360. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  361. attr.writeMask = 0xFFFFFFFF;
  362. // generic datatype
  363. attr.dataType = UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATATYPE);
  364. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  365. nodeReadWriteUnitTest,
  366. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  367. UA_QUALIFIEDNAME(1, "Generic"),
  368. UA_NODEID_NULL, attr, &nodeReadWriteGeneric);
  369. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  370. }
  371. // create Method 'Dummy' within Coordinates Object.
  372. {
  373. UA_MethodAttributes attr = UA_MethodAttributes_default;
  374. attr.description = UA_LOCALIZEDTEXT("en-US", "Dummy method");
  375. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Dummy");
  376. attr.executable = true;
  377. attr.userExecutable = true;
  378. attr.writeMask = 0xFFFFFFFF;
  379. retval = UA_Client_addMethodNode(client, UA_NODEID_NULL,
  380. nodeReadWriteUnitTest,
  381. UA_NODEID_NUMERIC(0, UA_NS0ID_HASORDEREDCOMPONENT),
  382. UA_QUALIFIEDNAME(1, "Dummy"),
  383. attr, &nodeReadWriteMethod);
  384. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  385. }
  386. // Create TestObjectType SubType within BaseObjectType
  387. {
  388. UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;
  389. attr.description = UA_LOCALIZEDTEXT("en-US", "Some TestObjectType");
  390. attr.displayName = UA_LOCALIZEDTEXT("en-US", "TestObjectType");
  391. attr.writeMask = 0xFFFFFFFF;
  392. retval = UA_Client_addObjectTypeNode(client, UA_NODEID_NULL,
  393. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
  394. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  395. UA_QUALIFIEDNAME(1, "TestObjectType"), attr, &nodeReadWriteTestObjectType);
  396. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  397. }
  398. // Create custom reference type 'HasSubSubType' as child of HasSubtype
  399. {
  400. UA_ReferenceTypeAttributes attr = UA_ReferenceTypeAttributes_default;
  401. attr.description = UA_LOCALIZEDTEXT("en-US", "Some HasSubSubType");
  402. attr.displayName = UA_LOCALIZEDTEXT("en-US", "HasSubSubType");
  403. attr.inverseName = UA_LOCALIZEDTEXT("en-US", "HasParentParentType");
  404. attr.writeMask = 0xFFFFFFFF;
  405. retval = UA_Client_addReferenceTypeNode(client, UA_NODEID_NULL,
  406. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  407. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  408. UA_QUALIFIEDNAME(1, "HasSubSubType"), attr,
  409. &nodeReadWriteTestHasSubSubType);
  410. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  411. }
  412. // create View 'AllTopCoordinates' whithin Views Folder
  413. {
  414. UA_ViewAttributes attr = UA_ViewAttributes_default;
  415. attr.description = UA_LOCALIZEDTEXT("en-US", "List of all top coordinates");
  416. attr.displayName = UA_LOCALIZEDTEXT("en-US", "AllTopCoordinates");
  417. attr.writeMask = 0xFFFFFFFF;
  418. retval = UA_Client_addViewNode(client, UA_NODEID_NULL,
  419. UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
  420. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  421. UA_QUALIFIEDNAME(1, "AllTopCoordinates"),
  422. attr, &nodeReadWriteView);
  423. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  424. }
  425. // iterate over children
  426. retval = UA_Client_forEachChildNodeCall(client, nodeReadWriteUnitTest, nodeIter, NULL);
  427. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  428. ck_assert(UA_NodeId_equal(&nodeReadWriteArray, &iteratedNodes[0]));
  429. ck_assert(UA_NodeId_equal(&nodeReadWriteInt, &iteratedNodes[1]));
  430. }
  431. END_TEST
  432. START_TEST(Node_ReadWrite_Id) {
  433. UA_NodeId newNodeId;
  434. // read to check if node id was changed
  435. UA_StatusCode retval = UA_Client_readNodeIdAttribute(client, nodeReadWriteInt, &newNodeId);
  436. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  437. ck_assert(UA_NodeId_equal(&newNodeId, &nodeReadWriteInt));
  438. newNodeId.identifier.numeric = 900;
  439. retval = UA_Client_writeNodeIdAttribute(client, nodeReadWriteInt, &newNodeId);
  440. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  441. }
  442. END_TEST
  443. static void checkNodeClass(UA_Client *clientNc, const UA_NodeId nodeId, const UA_NodeClass expectedClass) {
  444. UA_NodeClass nodeClass = UA_NODECLASS_UNSPECIFIED;
  445. UA_StatusCode retval = UA_Client_readNodeClassAttribute(clientNc, nodeId, &nodeClass);
  446. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  447. ck_assert_int_eq(nodeClass, expectedClass);
  448. }
  449. START_TEST(Node_ReadWrite_Class) {
  450. checkNodeClass(client, nodeReadWriteInt, UA_NODECLASS_VARIABLE);
  451. checkNodeClass(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER), UA_NODECLASS_OBJECT);
  452. checkNodeClass(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_GETMONITOREDITEMS), UA_NODECLASS_METHOD);
  453. UA_NodeClass newClass = UA_NODECLASS_METHOD;
  454. UA_StatusCode retval = UA_Client_writeNodeClassAttribute(client, nodeReadWriteInt, &newClass);
  455. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  456. }
  457. END_TEST
  458. START_TEST(Node_ReadWrite_BrowseName) {
  459. UA_QualifiedName browseName;
  460. UA_StatusCode retval = UA_Client_readBrowseNameAttribute(client, nodeReadWriteInt, &browseName);
  461. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  462. UA_QualifiedName orig = UA_QUALIFIEDNAME(1, "Int");
  463. ck_assert_int_eq(browseName.namespaceIndex, orig.namespaceIndex);
  464. ck_assert(UA_String_equal(&browseName.name, &orig.name));
  465. UA_QualifiedName_deleteMembers(&browseName);
  466. browseName = UA_QUALIFIEDNAME(1,"Int-Changed");
  467. retval = UA_Client_writeBrowseNameAttribute(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER), &browseName);
  468. ck_assert_uint_eq(retval, UA_STATUSCODE_BADUSERACCESSDENIED);
  469. retval = UA_Client_writeBrowseNameAttribute(client, nodeReadWriteInt, &browseName);
  470. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  471. UA_QualifiedName browseNameChangedRead;
  472. retval = UA_Client_readBrowseNameAttribute(client, nodeReadWriteInt, &browseNameChangedRead);
  473. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  474. ck_assert_int_eq(browseName.namespaceIndex, browseNameChangedRead.namespaceIndex);
  475. ck_assert(UA_String_equal(&browseName.name, &browseNameChangedRead.name));
  476. UA_QualifiedName_deleteMembers(&browseNameChangedRead);
  477. }
  478. END_TEST
  479. START_TEST(Node_ReadWrite_DisplayName) {
  480. UA_LocalizedText displayName;
  481. UA_StatusCode retval = UA_Client_readDisplayNameAttribute(client, nodeReadWriteInt, &displayName);
  482. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  483. UA_LocalizedText orig = UA_LOCALIZEDTEXT("en-US", "Int");
  484. ck_assert(UA_String_equal(&displayName.locale, &orig.locale));
  485. ck_assert(UA_String_equal(&displayName.text, &orig.text));
  486. UA_LocalizedText_deleteMembers(&displayName);
  487. UA_LocalizedText newLocale = UA_LOCALIZEDTEXT("en-US", "Int-Changed");
  488. retval = UA_Client_writeDisplayNameAttribute(client, nodeReadWriteInt, &newLocale);
  489. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  490. UA_LocalizedText displayNameChangedRead;
  491. retval = UA_Client_readDisplayNameAttribute(client, nodeReadWriteInt, &displayNameChangedRead);
  492. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  493. ck_assert(UA_String_equal(&newLocale.locale, &displayNameChangedRead.locale));
  494. ck_assert(UA_String_equal(&newLocale.text, &displayNameChangedRead.text));
  495. UA_LocalizedText_deleteMembers(&displayNameChangedRead);
  496. }
  497. END_TEST
  498. START_TEST(Node_ReadWrite_Description) {
  499. UA_LocalizedText description;
  500. UA_StatusCode retval = UA_Client_readDescriptionAttribute(client, nodeReadWriteInt, &description);
  501. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  502. UA_LocalizedText orig = UA_LOCALIZEDTEXT("en-US", "Int");
  503. ck_assert(UA_String_equal(&description.locale, &orig.locale));
  504. ck_assert(UA_String_equal(&description.text, &orig.text));
  505. UA_LocalizedText_deleteMembers(&description);
  506. UA_LocalizedText newLocale = UA_LOCALIZEDTEXT("en-US", "Int-Changed");
  507. retval = UA_Client_writeDescriptionAttribute(client, nodeReadWriteInt, &newLocale);
  508. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  509. UA_LocalizedText descriptionChangedRead;
  510. retval = UA_Client_readDescriptionAttribute(client, nodeReadWriteInt, &descriptionChangedRead);
  511. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  512. ck_assert(UA_String_equal(&newLocale.locale, &descriptionChangedRead.locale));
  513. ck_assert(UA_String_equal(&newLocale.text, &descriptionChangedRead.text));
  514. UA_LocalizedText_deleteMembers(&descriptionChangedRead);
  515. }
  516. END_TEST
  517. START_TEST(Node_ReadWrite_WriteMask) {
  518. UA_UInt32 writeMask;
  519. UA_StatusCode retval = UA_Client_readWriteMaskAttribute(client, nodeReadWriteInt, &writeMask);
  520. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  521. ck_assert_int_eq(writeMask, 0xFFFFFFFF);
  522. // Disable a random write mask bit
  523. UA_UInt32 newMask = 0xFFFFFFFF & ~UA_WRITEMASK_BROWSENAME;
  524. retval = UA_Client_writeWriteMaskAttribute(client, nodeReadWriteInt, &newMask);
  525. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  526. UA_UInt32 writeMaskChangedRead;
  527. retval = UA_Client_readWriteMaskAttribute(client, nodeReadWriteInt, &writeMaskChangedRead);
  528. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  529. ck_assert_int_eq(writeMaskChangedRead, newMask);
  530. }
  531. END_TEST
  532. START_TEST(Node_ReadWrite_UserWriteMask) {
  533. UA_UInt32 userWriteMask;
  534. UA_StatusCode retval = UA_Client_readUserWriteMaskAttribute(client, nodeReadWriteInt, &userWriteMask);
  535. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  536. ck_assert_int_eq(userWriteMask, 0xFFFFFFFF & ~UA_WRITEMASK_BROWSENAME);
  537. // Disable a random write mask bit
  538. UA_UInt32 newMask = 0xFFFFFFFF & ~UA_WRITEMASK_DISPLAYNAME;
  539. retval = UA_Client_writeUserWriteMaskAttribute(client, nodeReadWriteInt, &newMask);
  540. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  541. }
  542. END_TEST
  543. START_TEST(Node_ReadWrite_IsAbstract) {
  544. UA_Boolean isAbstract;
  545. UA_StatusCode retval = UA_Client_readIsAbstractAttribute(client, nodeReadWriteInt, &isAbstract);
  546. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  547. retval = UA_Client_readIsAbstractAttribute(client, nodeReadWriteTestObjectType, &isAbstract);
  548. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  549. ck_assert_int_eq(isAbstract, UA_FALSE);
  550. UA_Boolean newIsAbstract = UA_TRUE;
  551. retval = UA_Client_writeIsAbstractAttribute(client, nodeReadWriteTestObjectType, &newIsAbstract);
  552. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  553. retval = UA_Client_readIsAbstractAttribute(client, nodeReadWriteTestObjectType, &isAbstract);
  554. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  555. ck_assert_int_eq(isAbstract, newIsAbstract);
  556. }
  557. END_TEST
  558. START_TEST(Node_ReadWrite_Symmetric) {
  559. UA_Boolean symmetric;
  560. UA_StatusCode retval = UA_Client_readSymmetricAttribute(client, nodeReadWriteInt, &symmetric);
  561. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  562. retval = UA_Client_readSymmetricAttribute(client, nodeReadWriteTestHasSubSubType, &symmetric);
  563. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  564. ck_assert_int_eq(symmetric, UA_FALSE);
  565. UA_Boolean newSymmetric = UA_TRUE;
  566. retval = UA_Client_writeSymmetricAttribute(client, nodeReadWriteTestHasSubSubType, &newSymmetric);
  567. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  568. retval = UA_Client_readSymmetricAttribute(client, nodeReadWriteTestHasSubSubType, &symmetric);
  569. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  570. ck_assert_int_eq(symmetric, newSymmetric);
  571. }
  572. END_TEST
  573. START_TEST(Node_ReadWrite_InverseName) {
  574. UA_LocalizedText inverseName;
  575. UA_StatusCode retval = UA_Client_readInverseNameAttribute(client, nodeReadWriteTestHasSubSubType, &inverseName);
  576. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  577. UA_LocalizedText orig = UA_LOCALIZEDTEXT("en-US", "HasParentParentType");
  578. ck_assert(UA_String_equal(&inverseName.locale, &orig.locale));
  579. ck_assert(UA_String_equal(&inverseName.text, &orig.text));
  580. UA_LocalizedText_deleteMembers(&inverseName);
  581. UA_LocalizedText newLocale = UA_LOCALIZEDTEXT("en-US", "HasParentParentType-Changed");
  582. retval = UA_Client_writeInverseNameAttribute(client, nodeReadWriteTestHasSubSubType, &newLocale);
  583. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  584. UA_LocalizedText inverseNameChangedRead;
  585. retval = UA_Client_readInverseNameAttribute(client, nodeReadWriteTestHasSubSubType, &inverseNameChangedRead);
  586. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  587. ck_assert(UA_String_equal(&newLocale.locale, &inverseNameChangedRead.locale));
  588. ck_assert(UA_String_equal(&newLocale.text, &inverseNameChangedRead.text));
  589. UA_LocalizedText_deleteMembers(&inverseNameChangedRead);
  590. }
  591. END_TEST
  592. START_TEST(Node_ReadWrite_ContainsNoLoops) {
  593. UA_Boolean containsNoLoops;
  594. UA_StatusCode retval = UA_Client_readContainsNoLoopsAttribute(client, nodeReadWriteTestHasSubSubType, &containsNoLoops);
  595. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  596. retval = UA_Client_readContainsNoLoopsAttribute(client, nodeReadWriteView, &containsNoLoops);
  597. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  598. ck_assert_int_eq(containsNoLoops, UA_FALSE);
  599. UA_Boolean newContainsNoLoops = UA_TRUE;
  600. retval = UA_Client_writeContainsNoLoopsAttribute(client, nodeReadWriteView, &newContainsNoLoops);
  601. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  602. retval = UA_Client_readContainsNoLoopsAttribute(client, nodeReadWriteView, &containsNoLoops);
  603. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  604. ck_assert_int_eq(containsNoLoops, newContainsNoLoops);
  605. }
  606. END_TEST
  607. START_TEST(Node_ReadWrite_EventNotifier) {
  608. UA_Byte eventNotifier = 0;
  609. UA_StatusCode retval = UA_Client_readEventNotifierAttribute(client, nodeReadWriteTestHasSubSubType, &eventNotifier);
  610. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  611. retval = UA_Client_readEventNotifierAttribute(client, nodeReadWriteView, &eventNotifier);
  612. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  613. ck_assert_int_eq(eventNotifier, 0);
  614. UA_Byte newEventNotifier = 1;
  615. retval = UA_Client_writeEventNotifierAttribute(client, nodeReadWriteView, &newEventNotifier);
  616. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  617. retval = UA_Client_readEventNotifierAttribute(client, nodeReadWriteView, &eventNotifier);
  618. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  619. ck_assert_int_eq(eventNotifier, newEventNotifier);
  620. }
  621. END_TEST
  622. START_TEST(Node_ReadWrite_Value) {
  623. UA_Int32 value = 0;
  624. UA_Variant *val = UA_Variant_new();
  625. UA_StatusCode retval = UA_Client_readValueAttribute(client, nodeReadWriteInt, val);
  626. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  627. ck_assert(UA_Variant_isScalar(val) && val->type == &UA_TYPES[UA_TYPES_INT32]);
  628. value = *(UA_Int32*)val->data;
  629. ck_assert_int_eq(value, 5678);
  630. UA_Variant_delete(val);
  631. /* Write attribute */
  632. value++;
  633. val = UA_Variant_new();
  634. UA_Variant_setScalarCopy(val, &value, &UA_TYPES[UA_TYPES_INT32]);
  635. retval = UA_Client_writeValueAttribute(client, nodeReadWriteInt, val);
  636. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  637. UA_Variant_delete(val);
  638. /* Read again to check value */
  639. val = UA_Variant_new();
  640. retval = UA_Client_readValueAttribute(client, nodeReadWriteInt, val);
  641. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  642. ck_assert(UA_Variant_isScalar(val) && val->type == &UA_TYPES[UA_TYPES_INT32]);
  643. value = *(UA_Int32*)val->data;
  644. ck_assert_int_eq(value, 5679);
  645. UA_Variant_delete(val);
  646. }
  647. END_TEST
  648. START_TEST(Node_ReadWrite_DataType) {
  649. UA_NodeId dataType;
  650. // read to check if node id was changed
  651. UA_StatusCode retval = UA_Client_readDataTypeAttribute(client, nodeReadWriteInt, &dataType);
  652. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  653. ck_assert(UA_NodeId_equal(&dataType, &UA_TYPES[UA_TYPES_INT32].typeId));
  654. UA_NodeId newDataType = UA_TYPES[UA_TYPES_VARIANT].typeId;
  655. retval = UA_Client_writeDataTypeAttribute(client, nodeReadWriteGeneric, &newDataType);
  656. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  657. retval = UA_Client_readDataTypeAttribute(client, nodeReadWriteGeneric, &dataType);
  658. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  659. ck_assert(UA_NodeId_equal(&dataType, &newDataType));
  660. }
  661. END_TEST
  662. START_TEST(Node_ReadWrite_ValueRank) {
  663. UA_Int32 valueRank = 0;
  664. UA_StatusCode retval = UA_Client_readValueRankAttribute(client, nodeReadWriteGeneric, &valueRank);
  665. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  666. ck_assert_int_eq(valueRank, -2);
  667. // set the value to a scalar
  668. UA_Double val = 0.0;
  669. UA_Variant value;
  670. UA_Variant_setScalar(&value, &val, &UA_TYPES[UA_TYPES_DOUBLE]);
  671. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  672. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  673. // we want an array
  674. UA_Int32 newValueRank = 1;
  675. // shall fail when the value is not compatible
  676. retval = UA_Client_writeValueRankAttribute(client, nodeReadWriteGeneric, &newValueRank);
  677. ck_assert(retval != UA_STATUSCODE_GOOD);
  678. // set the value to an array
  679. UA_Double vec[3] = {0.0, 0.0, 0.0};
  680. UA_Variant_setArray(&value, vec, 3, &UA_TYPES[UA_TYPES_DOUBLE]);
  681. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  682. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  683. // try again
  684. retval = UA_Client_writeValueRankAttribute(client, nodeReadWriteGeneric, &newValueRank);
  685. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  686. retval = UA_Client_readValueRankAttribute(client, nodeReadWriteGeneric, &valueRank);
  687. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  688. ck_assert_int_eq(valueRank, newValueRank);
  689. // set the value to no array
  690. UA_Variant_init(&value);
  691. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  692. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  693. }
  694. END_TEST
  695. START_TEST(Node_ReadWrite_ArrayDimensions) {
  696. UA_UInt32 *arrayDimsRead;
  697. size_t arrayDimsReadSize;
  698. UA_StatusCode retval = UA_Client_readArrayDimensionsAttribute(client, nodeReadWriteGeneric,
  699. &arrayDimsReadSize, &arrayDimsRead);
  700. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  701. ck_assert_int_eq(arrayDimsReadSize, 0);
  702. // writing the array dimensions shall fail at first
  703. UA_UInt32 arrayDimsNew[] = {3};
  704. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeReadWriteGeneric, 1, arrayDimsNew);
  705. ck_assert(retval != UA_STATUSCODE_GOOD);
  706. // Set a vector of size 3 as the value
  707. UA_Double vec[3] = {0.0, 0.0, 0.0};
  708. UA_Variant value;
  709. UA_Variant_setArray(&value, vec, 3, &UA_TYPES[UA_TYPES_DOUBLE]);
  710. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  711. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  712. // Now we can set matching array-dimensions
  713. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeReadWriteGeneric, 1, arrayDimsNew);
  714. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  715. retval = UA_Client_readArrayDimensionsAttribute(client, nodeReadWriteGeneric,
  716. &arrayDimsReadSize, &arrayDimsRead);
  717. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  718. ck_assert_int_eq(arrayDimsReadSize, 1);
  719. ck_assert_int_eq(arrayDimsRead[0], 3);
  720. UA_Array_delete(arrayDimsRead, arrayDimsReadSize, &UA_TYPES[UA_TYPES_UINT32]);
  721. }
  722. END_TEST
  723. START_TEST(Node_ReadWrite_AccessLevel) {
  724. UA_Byte accessLevel;
  725. UA_StatusCode retval = UA_Client_readAccessLevelAttribute(client, nodeReadWriteInt, &accessLevel);
  726. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  727. ck_assert_int_eq(accessLevel, UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE);
  728. UA_Byte newMask = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
  729. retval = UA_Client_writeAccessLevelAttribute(client, nodeReadWriteInt, &newMask);
  730. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  731. UA_Byte accessLevelChangedRead;
  732. retval = UA_Client_readAccessLevelAttribute(client, nodeReadWriteInt, &accessLevelChangedRead);
  733. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  734. ck_assert_int_eq(accessLevelChangedRead, newMask);
  735. }
  736. END_TEST
  737. START_TEST(Node_ReadWrite_UserAccessLevel) {
  738. UA_Byte userAccessLevel;
  739. UA_StatusCode retval = UA_Client_readUserAccessLevelAttribute(client, nodeReadWriteInt, &userAccessLevel);
  740. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  741. ck_assert_int_eq(userAccessLevel, UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD);
  742. UA_Byte newMask = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
  743. retval = UA_Client_writeUserAccessLevelAttribute(client, nodeReadWriteInt, &newMask);
  744. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  745. }
  746. END_TEST
  747. START_TEST(Node_ReadWrite_MinimumSamplingInterval) {
  748. UA_Double minimumSamplingInterval = 0;
  749. UA_StatusCode retval = UA_Client_readMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &minimumSamplingInterval);
  750. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  751. ck_assert(minimumSamplingInterval == 0);
  752. // we want an array
  753. UA_Double newMinimumSamplingInterval = 1;
  754. retval = UA_Client_writeMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &newMinimumSamplingInterval);
  755. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  756. retval = UA_Client_readMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &minimumSamplingInterval);
  757. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  758. ck_assert(minimumSamplingInterval == newMinimumSamplingInterval);
  759. }
  760. END_TEST
  761. START_TEST(Node_ReadWrite_Historizing) {
  762. UA_Boolean historizing;
  763. UA_StatusCode retval = UA_Client_readHistorizingAttribute(client, nodeReadWriteInt, &historizing);
  764. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  765. ck_assert_int_eq(historizing, UA_FALSE);
  766. UA_Boolean newHistorizing = UA_TRUE;
  767. retval = UA_Client_writeHistorizingAttribute(client, nodeReadWriteInt, &newHistorizing);
  768. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  769. retval = UA_Client_readHistorizingAttribute(client, nodeReadWriteInt, &historizing);
  770. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  771. ck_assert_int_eq(historizing, newHistorizing);
  772. }
  773. END_TEST
  774. START_TEST(Node_ReadWrite_Executable) {
  775. UA_Boolean executable;
  776. UA_StatusCode retval = UA_Client_readExecutableAttribute(client, nodeReadWriteMethod, &executable);
  777. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  778. ck_assert_int_eq(executable, UA_TRUE);
  779. UA_Boolean newExecutable = UA_FALSE;
  780. retval = UA_Client_writeExecutableAttribute(client, nodeReadWriteMethod, &newExecutable);
  781. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  782. retval = UA_Client_readExecutableAttribute(client, nodeReadWriteMethod, &executable);
  783. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  784. ck_assert_int_eq(executable, newExecutable);
  785. }
  786. END_TEST
  787. START_TEST(Node_ReadWrite_UserExecutable) {
  788. UA_Boolean userExecutable;
  789. UA_StatusCode retval = UA_Client_readUserExecutableAttribute(client, nodeReadWriteMethod, &userExecutable);
  790. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  791. ck_assert_int_eq(userExecutable, UA_FALSE);
  792. UA_Boolean newUserExecutable = UA_TRUE;
  793. retval = UA_Client_writeUserExecutableAttribute(client, nodeReadWriteMethod, &newUserExecutable);
  794. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  795. }
  796. END_TEST
  797. #endif
  798. static Suite *testSuite_Client(void) {
  799. Suite *s = suite_create("Client Highlevel");
  800. TCase *tc_misc = tcase_create("Client Highlevel Misc");
  801. tcase_add_checked_fixture(tc_misc, setup, teardown);
  802. tcase_add_test(tc_misc, Misc_State);
  803. tcase_add_test(tc_misc, Misc_NamespaceGetIndex);
  804. suite_add_tcase(s, tc_misc);
  805. TCase *tc_nodes = tcase_create("Client Highlevel Node Management");
  806. tcase_add_checked_fixture(tc_nodes, setup, teardown);
  807. #ifdef UA_ENABLE_NODEMANAGEMENT
  808. tcase_add_test(tc_nodes, Node_Add);
  809. #endif
  810. tcase_add_test(tc_nodes, Node_Browse);
  811. tcase_add_test(tc_nodes, Node_Register);
  812. suite_add_tcase(s, tc_nodes);
  813. #ifdef UA_ENABLE_NODEMANAGEMENT
  814. TCase *tc_readwrite = tcase_create("Client Highlevel Read/Write");
  815. tcase_add_unchecked_fixture(tc_readwrite, setup, teardown);
  816. // first add some nodes where we test on
  817. tcase_add_test(tc_readwrite, Node_AddReadWriteNodes);
  818. // Now run all the read write tests
  819. tcase_add_test(tc_readwrite, Node_ReadWrite_Id);
  820. tcase_add_test(tc_readwrite, Node_ReadWrite_Class);
  821. tcase_add_test(tc_readwrite, Node_ReadWrite_BrowseName);
  822. tcase_add_test(tc_readwrite, Node_ReadWrite_DisplayName);
  823. tcase_add_test(tc_readwrite, Node_ReadWrite_Description);
  824. tcase_add_test(tc_readwrite, Node_ReadWrite_WriteMask);
  825. tcase_add_test(tc_readwrite, Node_ReadWrite_UserWriteMask);
  826. tcase_add_test(tc_readwrite, Node_ReadWrite_IsAbstract);
  827. tcase_add_test(tc_readwrite, Node_ReadWrite_Symmetric);
  828. tcase_add_test(tc_readwrite, Node_ReadWrite_InverseName);
  829. tcase_add_test(tc_readwrite, Node_ReadWrite_ContainsNoLoops);
  830. tcase_add_test(tc_readwrite, Node_ReadWrite_EventNotifier);
  831. tcase_add_test(tc_readwrite, Node_ReadWrite_Value);
  832. tcase_add_test(tc_readwrite, Node_ReadWrite_DataType);
  833. tcase_add_test(tc_readwrite, Node_ReadWrite_ValueRank);
  834. tcase_add_test(tc_readwrite, Node_ReadWrite_ArrayDimensions);
  835. tcase_add_test(tc_readwrite, Node_ReadWrite_AccessLevel);
  836. tcase_add_test(tc_readwrite, Node_ReadWrite_UserAccessLevel);
  837. tcase_add_test(tc_readwrite, Node_ReadWrite_MinimumSamplingInterval);
  838. tcase_add_test(tc_readwrite, Node_ReadWrite_Historizing);
  839. tcase_add_test(tc_readwrite, Node_ReadWrite_Executable);
  840. tcase_add_test(tc_readwrite, Node_ReadWrite_UserExecutable);
  841. suite_add_tcase(s, tc_readwrite);
  842. #endif
  843. return s;
  844. }
  845. int main(void) {
  846. Suite *s = testSuite_Client();
  847. SRunner *sr = srunner_create(s);
  848. srunner_set_fork_status(sr, CK_NOFORK);
  849. srunner_run_all(sr, CK_NORMAL);
  850. int number_failed = srunner_ntests_failed(sr);
  851. srunner_free(sr);
  852. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  853. }