check_client_highlevel.c 45 KB

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