check_client_highlevel.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  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 "ua_server.h"
  5. #include "ua_client.h"
  6. #include "ua_config_default.h"
  7. #include "ua_client_highlevel.h"
  8. #include "ua_network_tcp.h"
  9. #include "check.h"
  10. #include "thread_wrapper.h"
  11. UA_Server *server;
  12. UA_ServerConfig *config;
  13. UA_Boolean running;
  14. UA_ServerNetworkLayer nl;
  15. THREAD_HANDLE server_thread;
  16. UA_Client *client;
  17. #define CUSTOM_NS "http://open62541.org/ns/test"
  18. #define CUSTOM_NS_UPPER "http://open62541.org/ns/Test"
  19. THREAD_CALLBACK(serverloop) {
  20. while (running)
  21. UA_Server_run_iterate(server, true);
  22. return 0;
  23. }
  24. static void setup(void) {
  25. running = true;
  26. config = UA_ServerConfig_new_default();
  27. server = UA_Server_new(config);
  28. ck_assert_uint_eq(2, UA_Server_addNamespace(server, CUSTOM_NS));
  29. UA_Server_run_startup(server);
  30. THREAD_CREATE(server_thread, serverloop);
  31. client = UA_Client_new(UA_ClientConfig_default);
  32. UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
  33. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  34. }
  35. static void teardown(void) {
  36. UA_Client_disconnect(client);
  37. UA_Client_delete(client);
  38. running = false;
  39. THREAD_JOIN(server_thread);
  40. UA_Server_run_shutdown(server);
  41. UA_Server_delete(server);
  42. UA_ServerConfig_delete(config);
  43. }
  44. START_TEST(Misc_State) {
  45. UA_ClientState state = UA_Client_getState(client);
  46. ck_assert_uint_eq(state, UA_CLIENTSTATE_SESSION);
  47. }
  48. END_TEST
  49. START_TEST(Misc_NamespaceGetIndex) {
  50. UA_UInt16 idx;
  51. UA_String ns = UA_STRING(CUSTOM_NS);
  52. UA_StatusCode retval = UA_Client_NamespaceGetIndex(client, &ns, &idx);
  53. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  54. ck_assert_uint_eq(idx, 2);
  55. // namespace uri is case sensitive
  56. ns = UA_STRING(CUSTOM_NS_UPPER);
  57. retval = UA_Client_NamespaceGetIndex(client, &ns, &idx);
  58. ck_assert_uint_eq(retval, UA_STATUSCODE_BADNOTFOUND);
  59. } END_TEST
  60. UA_NodeId newReferenceTypeId;
  61. UA_NodeId newObjectTypeId;
  62. UA_NodeId newDataTypeId;
  63. UA_NodeId newVariableTypeId;
  64. UA_NodeId newObjectId;
  65. UA_NodeId newVariableId;
  66. UA_NodeId newMethodId;
  67. UA_NodeId newViewId;
  68. #ifdef UA_ENABLE_NODEMANAGEMENT
  69. START_TEST(Node_Add) {
  70. UA_StatusCode retval;
  71. // Create custom reference type 'HasSubSubType' as child of HasSubtype
  72. {
  73. UA_ReferenceTypeAttributes attr = UA_ReferenceTypeAttributes_default;
  74. attr.description = UA_LOCALIZEDTEXT("en-US", "Some HasSubSubType");
  75. attr.displayName = UA_LOCALIZEDTEXT("en-US", "HasSubSubType");
  76. retval = UA_Client_addReferenceTypeNode(client, UA_NODEID_NULL,
  77. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  78. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  79. UA_QUALIFIEDNAME(1, "HasSubSubType"), attr,
  80. &newReferenceTypeId);
  81. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  82. }
  83. // Create TestObjectType SubType within BaseObjectType
  84. {
  85. UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;
  86. attr.description = UA_LOCALIZEDTEXT("en-US", "Some TestObjectType");
  87. attr.displayName = UA_LOCALIZEDTEXT("en-US", "TestObjectType");
  88. retval = UA_Client_addObjectTypeNode(client, UA_NODEID_NULL,
  89. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
  90. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  91. UA_QUALIFIEDNAME(1, "TestObjectType"), attr, &newObjectTypeId);
  92. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  93. }
  94. // Create Int128 DataType within Integer Datatype
  95. {
  96. UA_DataTypeAttributes attr = UA_DataTypeAttributes_default;
  97. attr.description = UA_LOCALIZEDTEXT("en-US", "Some Int128");
  98. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Int128");
  99. retval = UA_Client_addDataTypeNode(client, UA_NODEID_NULL,
  100. UA_NODEID_NUMERIC(0, UA_NS0ID_INTEGER),
  101. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  102. UA_QUALIFIEDNAME(1, "Int128"), attr, &newDataTypeId);
  103. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  104. }
  105. // Create PointType VariableType within BaseDataVariableType
  106. {
  107. UA_VariableTypeAttributes attr = UA_VariableTypeAttributes_default;
  108. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  109. attr.valueRank = UA_VALUERANK_ONE_DIMENSION;
  110. UA_UInt32 arrayDims[1] = {2};
  111. attr.arrayDimensions = arrayDims;
  112. attr.arrayDimensionsSize = 1;
  113. attr.displayName = UA_LOCALIZEDTEXT("en-US", "PointType");
  114. /* a matching default value is required */
  115. UA_Double zero[2] = {0.0, 0.0};
  116. UA_Variant_setArray(&attr.value, zero, 2, &UA_TYPES[UA_TYPES_INT32]);
  117. retval = UA_Client_addVariableTypeNode(client, UA_NODEID_NULL,
  118. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEVARIABLETYPE),
  119. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  120. UA_QUALIFIEDNAME(1, "PointType"), attr, &newVariableTypeId);
  121. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  122. }
  123. // create Coordinates Object within ObjectsFolder
  124. {
  125. UA_ObjectAttributes attr = UA_ObjectAttributes_default;
  126. attr.description = UA_LOCALIZEDTEXT("en-US", "Some Coordinates");
  127. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Coordinates");
  128. retval = UA_Client_addObjectNode(client, UA_NODEID_NULL,
  129. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  130. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  131. UA_QUALIFIEDNAME(1, "Coordinates"),
  132. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), attr, &newObjectId);
  133. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  134. }
  135. // create Variable 'Top' within Coordinates Object
  136. {
  137. UA_VariableAttributes attr = UA_VariableAttributes_default;
  138. attr.description = UA_LOCALIZEDTEXT("en-US", "Top Coordinate");
  139. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Top");
  140. UA_Int32 values[2] = {10, 20};
  141. UA_Variant_setArray(&attr.value, values, 2, &UA_TYPES[UA_TYPES_INT32]);
  142. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  143. attr.valueRank = UA_VALUERANK_ONE_DIMENSION;
  144. UA_UInt32 arrayDims[1] = {2};
  145. attr.arrayDimensions = arrayDims;
  146. attr.arrayDimensionsSize = 1;
  147. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  148. newObjectId,
  149. UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY),
  150. UA_QUALIFIEDNAME(1, "Top"),
  151. newVariableTypeId, attr, &newVariableId);
  152. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  153. }
  154. // create Method 'Dummy' within Coordinates Object.
  155. {
  156. UA_MethodAttributes attr = UA_MethodAttributes_default;
  157. attr.description = UA_LOCALIZEDTEXT("en-US", "Dummy method");
  158. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Dummy");
  159. attr.executable = true;
  160. attr.userExecutable = true;
  161. retval = UA_Client_addMethodNode(client, UA_NODEID_NULL,
  162. newObjectId,
  163. UA_NODEID_NUMERIC(0, UA_NS0ID_HASORDEREDCOMPONENT),
  164. UA_QUALIFIEDNAME(1, "Dummy"),
  165. attr, &newMethodId);
  166. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  167. }
  168. // create View 'AllTopCoordinates' whithin Views Folder
  169. {
  170. UA_ViewAttributes attr = UA_ViewAttributes_default;
  171. attr.description = UA_LOCALIZEDTEXT("en-US", "List of all top coordinates");
  172. attr.displayName = UA_LOCALIZEDTEXT("en-US", "AllTopCoordinates");
  173. retval = UA_Client_addViewNode(client, UA_NODEID_NULL,
  174. UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
  175. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  176. UA_QUALIFIEDNAME(1, "AllTopCoordinates"),
  177. attr, &newViewId);
  178. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  179. }
  180. UA_ExpandedNodeId target = UA_EXPANDEDNODEID_NULL;
  181. target.nodeId = newObjectId;
  182. // Add 'Top' to view
  183. retval = UA_Client_addReference(client, newViewId, UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  184. UA_TRUE, UA_STRING_NULL, target, UA_NODECLASS_VARIABLE);
  185. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  186. // Delete 'Top' from view
  187. retval = UA_Client_deleteReference(client, newViewId,
  188. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  189. true, target, true);
  190. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  191. // Delete 'AllTopCoordinates' view
  192. retval = UA_Client_deleteNode(client, newViewId, UA_TRUE);
  193. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  194. }
  195. END_TEST
  196. unsigned int iteratedNodeCount = 0;
  197. UA_NodeId iteratedNodes[4];
  198. static UA_StatusCode
  199. nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, void *handle) {
  200. if (isInverse || (referenceTypeId.identifierType == UA_NODEIDTYPE_NUMERIC &&
  201. referenceTypeId.identifier.numeric == UA_NS0ID_HASTYPEDEFINITION))
  202. return UA_STATUSCODE_GOOD;
  203. if (iteratedNodeCount >= 4)
  204. return UA_STATUSCODE_BADINDEXRANGEINVALID;
  205. UA_NodeId_copy(&childId, &iteratedNodes[iteratedNodeCount]);
  206. iteratedNodeCount++;
  207. return UA_STATUSCODE_GOOD;
  208. }
  209. #endif
  210. START_TEST(Node_Browse) {
  211. // Browse node in server folder
  212. UA_BrowseRequest bReq;
  213. UA_BrowseRequest_init(&bReq);
  214. // normally is set to 0, to get all the nodes, but we want to test browse next
  215. bReq.requestedMaxReferencesPerNode = 1;
  216. bReq.nodesToBrowse = UA_BrowseDescription_new();
  217. bReq.nodesToBrowseSize = 1;
  218. bReq.nodesToBrowse[0].nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER);
  219. bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL;
  220. UA_BrowseResponse bResp = UA_Client_Service_browse(client, bReq);
  221. ck_assert_uint_eq(bResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  222. ck_assert_uint_eq(bResp.resultsSize, 1);
  223. ck_assert_uint_eq(bResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  224. ck_assert_uint_eq(bResp.results[0].referencesSize, 1);
  225. /* References might have a different order in generated nodesets */
  226. /* UA_ReferenceDescription *ref = &(bResp.results[0].references[0]); */
  227. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVERTYPE); */
  228. // browse next
  229. UA_BrowseNextRequest bNextReq;
  230. UA_BrowseNextRequest_init(&bNextReq);
  231. // normally is set to 0, to get all the nodes, but we want to test browse next
  232. bNextReq.releaseContinuationPoints = UA_FALSE;
  233. bNextReq.continuationPoints = &bResp.results[0].continuationPoint;
  234. bNextReq.continuationPointsSize = 1;
  235. UA_BrowseNextResponse bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  236. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  237. ck_assert_uint_eq(bNextResp.resultsSize, 1);
  238. ck_assert_uint_eq(bNextResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  239. ck_assert_uint_eq(bNextResp.results[0].referencesSize, 1);
  240. /* ref = &(bNextResp.results[0].references[0]); */
  241. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVER_NAMESPACEARRAY); */
  242. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  243. bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  244. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  245. ck_assert_uint_eq(bNextResp.resultsSize, 1);
  246. ck_assert_uint_eq(bNextResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  247. ck_assert_uint_eq(bNextResp.results[0].referencesSize, 1);
  248. /* ref = &(bNextResp.results[0].references[0]); */
  249. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVER_SERVERARRAY); */
  250. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  251. // release continuation point. Result is then empty
  252. bNextReq.releaseContinuationPoints = UA_TRUE;
  253. bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  254. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  255. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  256. ck_assert_uint_eq(bNextResp.resultsSize, 0);
  257. UA_BrowseRequest_deleteMembers(&bReq);
  258. UA_BrowseResponse_deleteMembers(&bResp);
  259. // already deleted by browse request
  260. bNextReq.continuationPoints = NULL;
  261. bNextReq.continuationPointsSize = 0;
  262. UA_BrowseNextRequest_deleteMembers(&bNextReq);
  263. }
  264. END_TEST
  265. START_TEST(Node_Register) {
  266. UA_RegisterNodesRequest req;
  267. UA_RegisterNodesRequest_init(&req);
  268. req.nodesToRegister = UA_NodeId_new();
  269. req.nodesToRegister[0] = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
  270. req.nodesToRegisterSize = 1;
  271. UA_RegisterNodesResponse res = UA_Client_Service_registerNodes(client, req);
  272. ck_assert_uint_eq(res.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  273. ck_assert_uint_eq(res.registeredNodeIdsSize, 1);
  274. UA_UnregisterNodesRequest reqUn;
  275. UA_UnregisterNodesRequest_init(&reqUn);
  276. reqUn.nodesToUnregister = UA_NodeId_new();
  277. reqUn.nodesToUnregister[0] = res.registeredNodeIds[0];
  278. reqUn.nodesToUnregisterSize = 1;
  279. UA_UnregisterNodesResponse resUn = UA_Client_Service_unregisterNodes(client, reqUn);
  280. ck_assert_uint_eq(resUn.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  281. UA_UnregisterNodesRequest_deleteMembers(&reqUn);
  282. UA_UnregisterNodesResponse_deleteMembers(&resUn);
  283. UA_RegisterNodesRequest_deleteMembers(&req);
  284. UA_RegisterNodesResponse_deleteMembers(&res);
  285. }
  286. END_TEST
  287. // NodeIds for ReadWrite testing
  288. UA_NodeId nodeReadWriteUnitTest;
  289. UA_NodeId nodeReadWriteArray;
  290. UA_NodeId nodeReadWriteInt;
  291. UA_NodeId nodeReadWriteGeneric;
  292. UA_NodeId nodeReadWriteTestObjectType;
  293. UA_NodeId nodeReadWriteTestHasSubSubType;
  294. UA_NodeId nodeReadWriteView;
  295. UA_NodeId nodeReadWriteMethod;
  296. #ifdef UA_ENABLE_NODEMANAGEMENT
  297. START_TEST(Node_AddReadWriteNodes) {
  298. UA_StatusCode retval;
  299. // Create a folder with two variables for testing
  300. // create Coordinates Object within ObjectsFolder
  301. {
  302. UA_ObjectAttributes attr = UA_ObjectAttributes_default;
  303. attr.description = UA_LOCALIZEDTEXT("en-US", "UnitTest");
  304. attr.displayName = UA_LOCALIZEDTEXT("en-US", "UnitTest");
  305. retval = UA_Client_addObjectNode(client, UA_NODEID_NULL,
  306. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  307. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  308. UA_QUALIFIEDNAME(1, "UnitTest"),
  309. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE),
  310. attr, &nodeReadWriteUnitTest);
  311. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  312. }
  313. // create Variable 'Top' within UnitTest Object
  314. {
  315. UA_VariableAttributes attr = UA_VariableAttributes_default;
  316. attr.description = UA_LOCALIZEDTEXT("en-US", "Array");
  317. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Array");
  318. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  319. attr.writeMask = UA_WRITEMASK_ARRRAYDIMENSIONS;
  320. UA_Int32 values[2];
  321. values[0] = 10;
  322. values[1] = 20;
  323. UA_Variant_setArray(&attr.value, values, 2, &UA_TYPES[UA_TYPES_INT32]);
  324. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  325. attr.valueRank = UA_VALUERANK_ONE_DIMENSION;
  326. UA_UInt32 arrayDims[1] = {2};
  327. attr.arrayDimensions = arrayDims;
  328. attr.arrayDimensionsSize = 1;
  329. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  330. nodeReadWriteUnitTest,
  331. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  332. UA_QUALIFIEDNAME(1, "Array"),
  333. UA_NODEID_NULL, attr, &nodeReadWriteArray);
  334. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  335. }
  336. // create Variable 'Int' within UnitTest Object
  337. {
  338. UA_VariableAttributes attr = UA_VariableAttributes_default;
  339. attr.description = UA_LOCALIZEDTEXT("en-US", "Int");
  340. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Int");
  341. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  342. attr.writeMask = 0xFFFFFFFF;
  343. UA_Int32 int_value = 5678;
  344. UA_Variant_setScalar(&attr.value, &int_value, &UA_TYPES[UA_TYPES_INT32]);
  345. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  346. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  347. nodeReadWriteUnitTest,
  348. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  349. UA_QUALIFIEDNAME(1, "Int"),
  350. UA_NODEID_NULL, attr, &nodeReadWriteInt);
  351. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  352. }
  353. // create Variable 'Generic' within UnitTest Object
  354. {
  355. UA_VariableAttributes attr = UA_VariableAttributes_default;
  356. attr.description = UA_LOCALIZEDTEXT("en-US", "Generic");
  357. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Generic");
  358. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  359. attr.writeMask = 0xFFFFFFFF;
  360. // generic datatype
  361. attr.dataType = UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATATYPE);
  362. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  363. nodeReadWriteUnitTest,
  364. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  365. UA_QUALIFIEDNAME(1, "Generic"),
  366. UA_NODEID_NULL, attr, &nodeReadWriteGeneric);
  367. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  368. }
  369. // create Method 'Dummy' within Coordinates Object.
  370. {
  371. UA_MethodAttributes attr = UA_MethodAttributes_default;
  372. attr.description = UA_LOCALIZEDTEXT("en-US", "Dummy method");
  373. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Dummy");
  374. attr.executable = true;
  375. attr.userExecutable = true;
  376. attr.writeMask = 0xFFFFFFFF;
  377. retval = UA_Client_addMethodNode(client, UA_NODEID_NULL,
  378. nodeReadWriteUnitTest,
  379. UA_NODEID_NUMERIC(0, UA_NS0ID_HASORDEREDCOMPONENT),
  380. UA_QUALIFIEDNAME(1, "Dummy"),
  381. attr, &nodeReadWriteMethod);
  382. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  383. }
  384. // Create TestObjectType SubType within BaseObjectType
  385. {
  386. UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;
  387. attr.description = UA_LOCALIZEDTEXT("en-US", "Some TestObjectType");
  388. attr.displayName = UA_LOCALIZEDTEXT("en-US", "TestObjectType");
  389. attr.writeMask = 0xFFFFFFFF;
  390. retval = UA_Client_addObjectTypeNode(client, UA_NODEID_NULL,
  391. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
  392. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  393. UA_QUALIFIEDNAME(1, "TestObjectType"), attr, &nodeReadWriteTestObjectType);
  394. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  395. }
  396. // Create custom reference type 'HasSubSubType' as child of HasSubtype
  397. {
  398. UA_ReferenceTypeAttributes attr = UA_ReferenceTypeAttributes_default;
  399. attr.description = UA_LOCALIZEDTEXT("en-US", "Some HasSubSubType");
  400. attr.displayName = UA_LOCALIZEDTEXT("en-US", "HasSubSubType");
  401. attr.inverseName = UA_LOCALIZEDTEXT("en-US", "HasParentParentType");
  402. attr.writeMask = 0xFFFFFFFF;
  403. retval = UA_Client_addReferenceTypeNode(client, UA_NODEID_NULL,
  404. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  405. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  406. UA_QUALIFIEDNAME(1, "HasSubSubType"), attr,
  407. &nodeReadWriteTestHasSubSubType);
  408. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  409. }
  410. // create View 'AllTopCoordinates' whithin Views Folder
  411. {
  412. UA_ViewAttributes attr = UA_ViewAttributes_default;
  413. attr.description = UA_LOCALIZEDTEXT("en-US", "List of all top coordinates");
  414. attr.displayName = UA_LOCALIZEDTEXT("en-US", "AllTopCoordinates");
  415. attr.writeMask = 0xFFFFFFFF;
  416. retval = UA_Client_addViewNode(client, UA_NODEID_NULL,
  417. UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
  418. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  419. UA_QUALIFIEDNAME(1, "AllTopCoordinates"),
  420. attr, &nodeReadWriteView);
  421. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  422. }
  423. // iterate over children
  424. retval = UA_Client_forEachChildNodeCall(client, nodeReadWriteUnitTest, nodeIter, NULL);
  425. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  426. ck_assert(UA_NodeId_equal(&nodeReadWriteArray, &iteratedNodes[0]));
  427. ck_assert(UA_NodeId_equal(&nodeReadWriteInt, &iteratedNodes[1]));
  428. }
  429. END_TEST
  430. START_TEST(Node_ReadWrite_Id) {
  431. UA_NodeId newNodeId;
  432. // read to check if node id was changed
  433. UA_StatusCode retval = UA_Client_readNodeIdAttribute(client, nodeReadWriteInt, &newNodeId);
  434. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  435. ck_assert(UA_NodeId_equal(&newNodeId, &nodeReadWriteInt));
  436. newNodeId.identifier.numeric = 900;
  437. retval = UA_Client_writeNodeIdAttribute(client, nodeReadWriteInt, &newNodeId);
  438. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  439. }
  440. END_TEST
  441. static void checkNodeClass(UA_Client *clientNc, const UA_NodeId nodeId, const UA_NodeClass expectedClass) {
  442. UA_NodeClass nodeClass = UA_NODECLASS_UNSPECIFIED;
  443. UA_StatusCode retval = UA_Client_readNodeClassAttribute(clientNc, nodeId, &nodeClass);
  444. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  445. ck_assert_int_eq(nodeClass, expectedClass);
  446. }
  447. START_TEST(Node_ReadWrite_Class) {
  448. checkNodeClass(client, nodeReadWriteInt, UA_NODECLASS_VARIABLE);
  449. checkNodeClass(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER), UA_NODECLASS_OBJECT);
  450. #ifdef UA_ENABLE_METHODCALLS
  451. checkNodeClass(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_GETMONITOREDITEMS), UA_NODECLASS_METHOD);
  452. #endif
  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 = UA_VALUERANK_ONE_OR_MORE_DIMENSIONS;
  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, UA_VALUERANK_ANY);
  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 = UA_VALUERANK_ONE_DIMENSION;
  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. // Set a vector of size 1 as the value
  703. UA_Double vec2[2] = {0.0, 0.0};
  704. UA_Variant value;
  705. UA_Variant_setArray(&value, vec2, 2, &UA_TYPES[UA_TYPES_DOUBLE]);
  706. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  707. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  708. // writing the array dimensions shall fail at first
  709. // because the current value is not conformant
  710. UA_UInt32 arrayDimsNew[] = {1};
  711. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeReadWriteGeneric, 1, arrayDimsNew);
  712. ck_assert(retval != UA_STATUSCODE_GOOD);
  713. // Set a vector of size 1 as the value
  714. UA_Double vec1[1] = {0.0};
  715. UA_Variant_setArray(&value, vec1, 1, &UA_TYPES[UA_TYPES_DOUBLE]);
  716. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  717. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  718. // Now we can set matching array-dimensions
  719. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeReadWriteGeneric, 1, arrayDimsNew);
  720. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  721. retval = UA_Client_readArrayDimensionsAttribute(client, nodeReadWriteGeneric,
  722. &arrayDimsReadSize, &arrayDimsRead);
  723. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  724. ck_assert_int_eq(arrayDimsReadSize, 1);
  725. ck_assert_int_eq(arrayDimsRead[0], 1);
  726. UA_Array_delete(arrayDimsRead, arrayDimsReadSize, &UA_TYPES[UA_TYPES_UINT32]);
  727. }
  728. END_TEST
  729. START_TEST(Node_ReadWrite_AccessLevel) {
  730. UA_Byte accessLevel;
  731. UA_StatusCode retval = UA_Client_readAccessLevelAttribute(client, nodeReadWriteInt, &accessLevel);
  732. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  733. ck_assert_int_eq(accessLevel, UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE);
  734. UA_Byte newMask = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
  735. retval = UA_Client_writeAccessLevelAttribute(client, nodeReadWriteInt, &newMask);
  736. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  737. UA_Byte accessLevelChangedRead;
  738. retval = UA_Client_readAccessLevelAttribute(client, nodeReadWriteInt, &accessLevelChangedRead);
  739. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  740. ck_assert_int_eq(accessLevelChangedRead, newMask);
  741. }
  742. END_TEST
  743. START_TEST(Node_ReadWrite_UserAccessLevel) {
  744. UA_Byte userAccessLevel;
  745. UA_StatusCode retval = UA_Client_readUserAccessLevelAttribute(client, nodeReadWriteInt, &userAccessLevel);
  746. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  747. ck_assert_int_eq(userAccessLevel, UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD);
  748. UA_Byte newMask = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
  749. retval = UA_Client_writeUserAccessLevelAttribute(client, nodeReadWriteInt, &newMask);
  750. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  751. }
  752. END_TEST
  753. START_TEST(Node_ReadWrite_MinimumSamplingInterval) {
  754. UA_Double minimumSamplingInterval = 0;
  755. UA_StatusCode retval = UA_Client_readMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &minimumSamplingInterval);
  756. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  757. ck_assert(minimumSamplingInterval == 0);
  758. // we want an array
  759. UA_Double newMinimumSamplingInterval = 1;
  760. retval = UA_Client_writeMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &newMinimumSamplingInterval);
  761. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  762. retval = UA_Client_readMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &minimumSamplingInterval);
  763. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  764. ck_assert(minimumSamplingInterval == newMinimumSamplingInterval);
  765. }
  766. END_TEST
  767. START_TEST(Node_ReadWrite_Historizing) {
  768. UA_Boolean historizing;
  769. UA_StatusCode retval = UA_Client_readHistorizingAttribute(client, nodeReadWriteInt, &historizing);
  770. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  771. ck_assert_int_eq(historizing, UA_FALSE);
  772. UA_Boolean newHistorizing = UA_TRUE;
  773. retval = UA_Client_writeHistorizingAttribute(client, nodeReadWriteInt, &newHistorizing);
  774. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  775. retval = UA_Client_readHistorizingAttribute(client, nodeReadWriteInt, &historizing);
  776. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  777. ck_assert_int_eq(historizing, newHistorizing);
  778. }
  779. END_TEST
  780. START_TEST(Node_ReadWrite_Executable) {
  781. UA_Boolean executable;
  782. UA_StatusCode retval = UA_Client_readExecutableAttribute(client, nodeReadWriteMethod, &executable);
  783. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  784. ck_assert_int_eq(executable, UA_TRUE);
  785. UA_Boolean newExecutable = UA_FALSE;
  786. retval = UA_Client_writeExecutableAttribute(client, nodeReadWriteMethod, &newExecutable);
  787. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  788. retval = UA_Client_readExecutableAttribute(client, nodeReadWriteMethod, &executable);
  789. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  790. ck_assert_int_eq(executable, newExecutable);
  791. }
  792. END_TEST
  793. START_TEST(Node_ReadWrite_UserExecutable) {
  794. UA_Boolean userExecutable;
  795. UA_StatusCode retval = UA_Client_readUserExecutableAttribute(client, nodeReadWriteMethod, &userExecutable);
  796. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  797. ck_assert_int_eq(userExecutable, UA_FALSE);
  798. UA_Boolean newUserExecutable = UA_TRUE;
  799. retval = UA_Client_writeUserExecutableAttribute(client, nodeReadWriteMethod, &newUserExecutable);
  800. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  801. }
  802. END_TEST
  803. #endif
  804. static Suite *testSuite_Client(void) {
  805. Suite *s = suite_create("Client Highlevel");
  806. TCase *tc_misc = tcase_create("Client Highlevel Misc");
  807. tcase_add_checked_fixture(tc_misc, setup, teardown);
  808. tcase_add_test(tc_misc, Misc_State);
  809. tcase_add_test(tc_misc, Misc_NamespaceGetIndex);
  810. suite_add_tcase(s, tc_misc);
  811. TCase *tc_nodes = tcase_create("Client Highlevel Node Management");
  812. tcase_add_checked_fixture(tc_nodes, setup, teardown);
  813. #ifdef UA_ENABLE_NODEMANAGEMENT
  814. tcase_add_test(tc_nodes, Node_Add);
  815. #endif
  816. tcase_add_test(tc_nodes, Node_Browse);
  817. tcase_add_test(tc_nodes, Node_Register);
  818. suite_add_tcase(s, tc_nodes);
  819. #ifdef UA_ENABLE_NODEMANAGEMENT
  820. TCase *tc_readwrite = tcase_create("Client Highlevel Read/Write");
  821. tcase_add_unchecked_fixture(tc_readwrite, setup, teardown);
  822. // first add some nodes where we test on
  823. tcase_add_test(tc_readwrite, Node_AddReadWriteNodes);
  824. // Now run all the read write tests
  825. tcase_add_test(tc_readwrite, Node_ReadWrite_Id);
  826. tcase_add_test(tc_readwrite, Node_ReadWrite_Class);
  827. tcase_add_test(tc_readwrite, Node_ReadWrite_BrowseName);
  828. tcase_add_test(tc_readwrite, Node_ReadWrite_DisplayName);
  829. tcase_add_test(tc_readwrite, Node_ReadWrite_Description);
  830. tcase_add_test(tc_readwrite, Node_ReadWrite_WriteMask);
  831. tcase_add_test(tc_readwrite, Node_ReadWrite_UserWriteMask);
  832. tcase_add_test(tc_readwrite, Node_ReadWrite_IsAbstract);
  833. tcase_add_test(tc_readwrite, Node_ReadWrite_Symmetric);
  834. tcase_add_test(tc_readwrite, Node_ReadWrite_InverseName);
  835. tcase_add_test(tc_readwrite, Node_ReadWrite_ContainsNoLoops);
  836. tcase_add_test(tc_readwrite, Node_ReadWrite_EventNotifier);
  837. tcase_add_test(tc_readwrite, Node_ReadWrite_Value);
  838. tcase_add_test(tc_readwrite, Node_ReadWrite_DataType);
  839. tcase_add_test(tc_readwrite, Node_ReadWrite_ValueRank);
  840. tcase_add_test(tc_readwrite, Node_ReadWrite_ArrayDimensions);
  841. tcase_add_test(tc_readwrite, Node_ReadWrite_AccessLevel);
  842. tcase_add_test(tc_readwrite, Node_ReadWrite_UserAccessLevel);
  843. tcase_add_test(tc_readwrite, Node_ReadWrite_MinimumSamplingInterval);
  844. tcase_add_test(tc_readwrite, Node_ReadWrite_Historizing);
  845. tcase_add_test(tc_readwrite, Node_ReadWrite_Executable);
  846. tcase_add_test(tc_readwrite, Node_ReadWrite_UserExecutable);
  847. suite_add_tcase(s, tc_readwrite);
  848. #endif
  849. return s;
  850. }
  851. int main(void) {
  852. Suite *s = testSuite_Client();
  853. SRunner *sr = srunner_create(s);
  854. srunner_set_fork_status(sr, CK_NOFORK);
  855. srunner_run_all(sr, CK_NORMAL);
  856. int number_failed = srunner_ntests_failed(sr);
  857. srunner_free(sr);
  858. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  859. }