check_client_highlevel.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "ua_server.h"
  7. #include "ua_client.h"
  8. #include "ua_config_default.h"
  9. #include "ua_client_highlevel.h"
  10. #include "ua_network_tcp.h"
  11. #include "check.h"
  12. #include "thread_wrapper.h"
  13. UA_Server *server;
  14. UA_ServerConfig *config;
  15. UA_Boolean running;
  16. UA_ServerNetworkLayer nl;
  17. THREAD_HANDLE server_thread;
  18. UA_Client *client;
  19. #define CUSTOM_NS "http://open62541.org/ns/test"
  20. #define CUSTOM_NS_UPPER "http://open62541.org/ns/Test"
  21. THREAD_CALLBACK(serverloop) {
  22. while (running)
  23. UA_Server_run_iterate(server, true);
  24. return 0;
  25. }
  26. static void setup(void) {
  27. running = true;
  28. config = UA_ServerConfig_new_default();
  29. server = UA_Server_new(config);
  30. ck_assert_uint_eq(2, UA_Server_addNamespace(server, CUSTOM_NS));
  31. UA_Server_run_startup(server);
  32. THREAD_CREATE(server_thread, serverloop);
  33. client = UA_Client_new(UA_ClientConfig_default);
  34. UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
  35. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  36. }
  37. static void teardown(void) {
  38. UA_Client_disconnect(client);
  39. UA_Client_delete(client);
  40. running = false;
  41. THREAD_JOIN(server_thread);
  42. UA_Server_run_shutdown(server);
  43. UA_Server_delete(server);
  44. UA_ServerConfig_delete(config);
  45. }
  46. START_TEST(Misc_State) {
  47. UA_ClientState state = UA_Client_getState(client);
  48. ck_assert_uint_eq(state, UA_CLIENTSTATE_SESSION);
  49. }
  50. END_TEST
  51. START_TEST(Misc_NamespaceGetIndex) {
  52. UA_UInt16 idx;
  53. UA_String ns = UA_STRING(CUSTOM_NS);
  54. UA_StatusCode retval = UA_Client_NamespaceGetIndex(client, &ns, &idx);
  55. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  56. ck_assert_uint_eq(idx, 2);
  57. // namespace uri is case sensitive
  58. ns = UA_STRING(CUSTOM_NS_UPPER);
  59. retval = UA_Client_NamespaceGetIndex(client, &ns, &idx);
  60. ck_assert_uint_eq(retval, UA_STATUSCODE_BADNOTFOUND);
  61. } END_TEST
  62. UA_NodeId newReferenceTypeId;
  63. UA_NodeId newObjectTypeId;
  64. UA_NodeId newDataTypeId;
  65. UA_NodeId newVariableTypeId;
  66. UA_NodeId newObjectId;
  67. UA_NodeId newVariableId;
  68. UA_NodeId newMethodId;
  69. UA_NodeId newViewId;
  70. #ifdef UA_ENABLE_NODEMANAGEMENT
  71. START_TEST(Node_Add) {
  72. UA_StatusCode retval;
  73. // Create custom reference type 'HasSubSubType' as child of HasSubtype
  74. {
  75. UA_ReferenceTypeAttributes attr = UA_ReferenceTypeAttributes_default;
  76. attr.description = UA_LOCALIZEDTEXT("en-US", "Some HasSubSubType");
  77. attr.displayName = UA_LOCALIZEDTEXT("en-US", "HasSubSubType");
  78. retval = UA_Client_addReferenceTypeNode(client, UA_NODEID_NULL,
  79. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  80. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  81. UA_QUALIFIEDNAME(1, "HasSubSubType"), attr,
  82. &newReferenceTypeId);
  83. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  84. }
  85. // Create TestObjectType SubType within BaseObjectType
  86. {
  87. UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;
  88. attr.description = UA_LOCALIZEDTEXT("en-US", "Some TestObjectType");
  89. attr.displayName = UA_LOCALIZEDTEXT("en-US", "TestObjectType");
  90. retval = UA_Client_addObjectTypeNode(client, UA_NODEID_NULL,
  91. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
  92. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  93. UA_QUALIFIEDNAME(1, "TestObjectType"), attr, &newObjectTypeId);
  94. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  95. }
  96. // Create Int128 DataType within Integer Datatype
  97. {
  98. UA_DataTypeAttributes attr = UA_DataTypeAttributes_default;
  99. attr.description = UA_LOCALIZEDTEXT("en-US", "Some Int128");
  100. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Int128");
  101. retval = UA_Client_addDataTypeNode(client, UA_NODEID_NULL,
  102. UA_NODEID_NUMERIC(0, UA_NS0ID_INTEGER),
  103. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  104. UA_QUALIFIEDNAME(1, "Int128"), attr, &newDataTypeId);
  105. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  106. }
  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 = 1; /* array with 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 = 1; /* array with 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), attr, &nodeReadWriteUnitTest);
  312. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  313. }
  314. // create Variable 'Top' within UnitTest Object
  315. {
  316. UA_VariableAttributes attr = UA_VariableAttributes_default;
  317. attr.description = UA_LOCALIZEDTEXT("en-US", "Array");
  318. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Array");
  319. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  320. attr.writeMask = UA_WRITEMASK_ARRRAYDIMENSIONS;
  321. UA_Int32 values[2];
  322. values[0] = 10;
  323. values[1] = 20;
  324. UA_Variant_setArray(&attr.value, values, 2, &UA_TYPES[UA_TYPES_INT32]);
  325. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  326. attr.valueRank = 1; /* array with one dimension */
  327. UA_UInt32 arrayDims[1] = {2};
  328. attr.arrayDimensions = arrayDims;
  329. attr.arrayDimensionsSize = 1;
  330. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  331. nodeReadWriteUnitTest,
  332. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  333. UA_QUALIFIEDNAME(1, "Array"),
  334. UA_NODEID_NULL, attr, &nodeReadWriteArray);
  335. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  336. }
  337. // create Variable 'Int' within UnitTest Object
  338. {
  339. UA_VariableAttributes attr = UA_VariableAttributes_default;
  340. attr.description = UA_LOCALIZEDTEXT("en-US", "Int");
  341. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Int");
  342. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  343. attr.writeMask = 0xFFFFFFFF;
  344. UA_Int32 int_value = 5678;
  345. UA_Variant_setScalar(&attr.value, &int_value, &UA_TYPES[UA_TYPES_INT32]);
  346. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  347. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  348. nodeReadWriteUnitTest,
  349. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  350. UA_QUALIFIEDNAME(1, "Int"),
  351. UA_NODEID_NULL, attr, &nodeReadWriteInt);
  352. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  353. }
  354. // create Variable 'Generic' within UnitTest Object
  355. {
  356. UA_VariableAttributes attr = UA_VariableAttributes_default;
  357. attr.description = UA_LOCALIZEDTEXT("en-US", "Generic");
  358. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Generic");
  359. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  360. attr.writeMask = 0xFFFFFFFF;
  361. // generic datatype
  362. attr.dataType = UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATATYPE);
  363. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  364. nodeReadWriteUnitTest,
  365. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  366. UA_QUALIFIEDNAME(1, "Generic"),
  367. UA_NODEID_NULL, attr, &nodeReadWriteGeneric);
  368. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  369. }
  370. // create Method 'Dummy' within Coordinates Object.
  371. {
  372. UA_MethodAttributes attr = UA_MethodAttributes_default;
  373. attr.description = UA_LOCALIZEDTEXT("en-US", "Dummy method");
  374. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Dummy");
  375. attr.executable = true;
  376. attr.userExecutable = true;
  377. attr.writeMask = 0xFFFFFFFF;
  378. retval = UA_Client_addMethodNode(client, UA_NODEID_NULL,
  379. nodeReadWriteUnitTest,
  380. UA_NODEID_NUMERIC(0, UA_NS0ID_HASORDEREDCOMPONENT),
  381. UA_QUALIFIEDNAME(1, "Dummy"),
  382. attr, &nodeReadWriteMethod);
  383. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  384. }
  385. // Create TestObjectType SubType within BaseObjectType
  386. {
  387. UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;
  388. attr.description = UA_LOCALIZEDTEXT("en-US", "Some TestObjectType");
  389. attr.displayName = UA_LOCALIZEDTEXT("en-US", "TestObjectType");
  390. attr.writeMask = 0xFFFFFFFF;
  391. retval = UA_Client_addObjectTypeNode(client, UA_NODEID_NULL,
  392. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
  393. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  394. UA_QUALIFIEDNAME(1, "TestObjectType"), attr, &nodeReadWriteTestObjectType);
  395. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  396. }
  397. // Create custom reference type 'HasSubSubType' as child of HasSubtype
  398. {
  399. UA_ReferenceTypeAttributes attr = UA_ReferenceTypeAttributes_default;
  400. attr.description = UA_LOCALIZEDTEXT("en-US", "Some HasSubSubType");
  401. attr.displayName = UA_LOCALIZEDTEXT("en-US", "HasSubSubType");
  402. attr.inverseName = UA_LOCALIZEDTEXT("en-US", "HasParentParentType");
  403. attr.writeMask = 0xFFFFFFFF;
  404. retval = UA_Client_addReferenceTypeNode(client, UA_NODEID_NULL,
  405. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  406. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  407. UA_QUALIFIEDNAME(1, "HasSubSubType"), attr,
  408. &nodeReadWriteTestHasSubSubType);
  409. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  410. }
  411. // create View 'AllTopCoordinates' whithin Views Folder
  412. {
  413. UA_ViewAttributes attr = UA_ViewAttributes_default;
  414. attr.description = UA_LOCALIZEDTEXT("en-US", "List of all top coordinates");
  415. attr.displayName = UA_LOCALIZEDTEXT("en-US", "AllTopCoordinates");
  416. attr.writeMask = 0xFFFFFFFF;
  417. retval = UA_Client_addViewNode(client, UA_NODEID_NULL,
  418. UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
  419. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  420. UA_QUALIFIEDNAME(1, "AllTopCoordinates"),
  421. attr, &nodeReadWriteView);
  422. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  423. }
  424. // iterate over children
  425. retval = UA_Client_forEachChildNodeCall(client, nodeReadWriteUnitTest, nodeIter, NULL);
  426. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  427. ck_assert(UA_NodeId_equal(&nodeReadWriteArray, &iteratedNodes[0]));
  428. ck_assert(UA_NodeId_equal(&nodeReadWriteInt, &iteratedNodes[1]));
  429. }
  430. END_TEST
  431. START_TEST(Node_ReadWrite_Id) {
  432. UA_NodeId newNodeId;
  433. // read to check if node id was changed
  434. UA_StatusCode retval = UA_Client_readNodeIdAttribute(client, nodeReadWriteInt, &newNodeId);
  435. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  436. ck_assert(UA_NodeId_equal(&newNodeId, &nodeReadWriteInt));
  437. newNodeId.identifier.numeric = 900;
  438. retval = UA_Client_writeNodeIdAttribute(client, nodeReadWriteInt, &newNodeId);
  439. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  440. }
  441. END_TEST
  442. static void checkNodeClass(UA_Client *clientNc, const UA_NodeId nodeId, const UA_NodeClass expectedClass) {
  443. UA_NodeClass nodeClass = UA_NODECLASS_UNSPECIFIED;
  444. UA_StatusCode retval = UA_Client_readNodeClassAttribute(clientNc, nodeId, &nodeClass);
  445. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  446. ck_assert_int_eq(nodeClass, expectedClass);
  447. }
  448. START_TEST(Node_ReadWrite_Class) {
  449. checkNodeClass(client, nodeReadWriteInt, UA_NODECLASS_VARIABLE);
  450. checkNodeClass(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER), UA_NODECLASS_OBJECT);
  451. checkNodeClass(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_GETMONITOREDITEMS), UA_NODECLASS_METHOD);
  452. UA_NodeClass newClass = UA_NODECLASS_METHOD;
  453. UA_StatusCode retval = UA_Client_writeNodeClassAttribute(client, nodeReadWriteInt, &newClass);
  454. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  455. }
  456. END_TEST
  457. START_TEST(Node_ReadWrite_BrowseName) {
  458. UA_QualifiedName browseName;
  459. UA_StatusCode retval = UA_Client_readBrowseNameAttribute(client, nodeReadWriteInt, &browseName);
  460. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  461. UA_QualifiedName orig = UA_QUALIFIEDNAME(1, "Int");
  462. ck_assert_int_eq(browseName.namespaceIndex, orig.namespaceIndex);
  463. ck_assert(UA_String_equal(&browseName.name, &orig.name));
  464. UA_QualifiedName_deleteMembers(&browseName);
  465. browseName = UA_QUALIFIEDNAME(1,"Int-Changed");
  466. retval = UA_Client_writeBrowseNameAttribute(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER), &browseName);
  467. ck_assert_uint_eq(retval, UA_STATUSCODE_BADUSERACCESSDENIED);
  468. retval = UA_Client_writeBrowseNameAttribute(client, nodeReadWriteInt, &browseName);
  469. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  470. UA_QualifiedName browseNameChangedRead;
  471. retval = UA_Client_readBrowseNameAttribute(client, nodeReadWriteInt, &browseNameChangedRead);
  472. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  473. ck_assert_int_eq(browseName.namespaceIndex, browseNameChangedRead.namespaceIndex);
  474. ck_assert(UA_String_equal(&browseName.name, &browseNameChangedRead.name));
  475. UA_QualifiedName_deleteMembers(&browseNameChangedRead);
  476. }
  477. END_TEST
  478. START_TEST(Node_ReadWrite_DisplayName) {
  479. UA_LocalizedText displayName;
  480. UA_StatusCode retval = UA_Client_readDisplayNameAttribute(client, nodeReadWriteInt, &displayName);
  481. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  482. UA_LocalizedText orig = UA_LOCALIZEDTEXT("en-US", "Int");
  483. ck_assert(UA_String_equal(&displayName.locale, &orig.locale));
  484. ck_assert(UA_String_equal(&displayName.text, &orig.text));
  485. UA_LocalizedText_deleteMembers(&displayName);
  486. UA_LocalizedText newLocale = UA_LOCALIZEDTEXT("en-US", "Int-Changed");
  487. retval = UA_Client_writeDisplayNameAttribute(client, nodeReadWriteInt, &newLocale);
  488. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  489. UA_LocalizedText displayNameChangedRead;
  490. retval = UA_Client_readDisplayNameAttribute(client, nodeReadWriteInt, &displayNameChangedRead);
  491. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  492. ck_assert(UA_String_equal(&newLocale.locale, &displayNameChangedRead.locale));
  493. ck_assert(UA_String_equal(&newLocale.text, &displayNameChangedRead.text));
  494. UA_LocalizedText_deleteMembers(&displayNameChangedRead);
  495. }
  496. END_TEST
  497. START_TEST(Node_ReadWrite_Description) {
  498. UA_LocalizedText description;
  499. UA_StatusCode retval = UA_Client_readDescriptionAttribute(client, nodeReadWriteInt, &description);
  500. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  501. UA_LocalizedText orig = UA_LOCALIZEDTEXT("en-US", "Int");
  502. ck_assert(UA_String_equal(&description.locale, &orig.locale));
  503. ck_assert(UA_String_equal(&description.text, &orig.text));
  504. UA_LocalizedText_deleteMembers(&description);
  505. UA_LocalizedText newLocale = UA_LOCALIZEDTEXT("en-US", "Int-Changed");
  506. retval = UA_Client_writeDescriptionAttribute(client, nodeReadWriteInt, &newLocale);
  507. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  508. UA_LocalizedText descriptionChangedRead;
  509. retval = UA_Client_readDescriptionAttribute(client, nodeReadWriteInt, &descriptionChangedRead);
  510. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  511. ck_assert(UA_String_equal(&newLocale.locale, &descriptionChangedRead.locale));
  512. ck_assert(UA_String_equal(&newLocale.text, &descriptionChangedRead.text));
  513. UA_LocalizedText_deleteMembers(&descriptionChangedRead);
  514. }
  515. END_TEST
  516. START_TEST(Node_ReadWrite_WriteMask) {
  517. UA_UInt32 writeMask;
  518. UA_StatusCode retval = UA_Client_readWriteMaskAttribute(client, nodeReadWriteInt, &writeMask);
  519. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  520. ck_assert_int_eq(writeMask, 0xFFFFFFFF);
  521. // Disable a random write mask bit
  522. UA_UInt32 newMask = 0xFFFFFFFF & ~UA_WRITEMASK_BROWSENAME;
  523. retval = UA_Client_writeWriteMaskAttribute(client, nodeReadWriteInt, &newMask);
  524. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  525. UA_UInt32 writeMaskChangedRead;
  526. retval = UA_Client_readWriteMaskAttribute(client, nodeReadWriteInt, &writeMaskChangedRead);
  527. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  528. ck_assert_int_eq(writeMaskChangedRead, newMask);
  529. }
  530. END_TEST
  531. START_TEST(Node_ReadWrite_UserWriteMask) {
  532. UA_UInt32 userWriteMask;
  533. UA_StatusCode retval = UA_Client_readUserWriteMaskAttribute(client, nodeReadWriteInt, &userWriteMask);
  534. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  535. ck_assert_int_eq(userWriteMask, 0xFFFFFFFF & ~UA_WRITEMASK_BROWSENAME);
  536. // Disable a random write mask bit
  537. UA_UInt32 newMask = 0xFFFFFFFF & ~UA_WRITEMASK_DISPLAYNAME;
  538. retval = UA_Client_writeUserWriteMaskAttribute(client, nodeReadWriteInt, &newMask);
  539. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  540. }
  541. END_TEST
  542. START_TEST(Node_ReadWrite_IsAbstract) {
  543. UA_Boolean isAbstract;
  544. UA_StatusCode retval = UA_Client_readIsAbstractAttribute(client, nodeReadWriteInt, &isAbstract);
  545. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  546. retval = UA_Client_readIsAbstractAttribute(client, nodeReadWriteTestObjectType, &isAbstract);
  547. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  548. ck_assert_int_eq(isAbstract, UA_FALSE);
  549. UA_Boolean newIsAbstract = UA_TRUE;
  550. retval = UA_Client_writeIsAbstractAttribute(client, nodeReadWriteTestObjectType, &newIsAbstract);
  551. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  552. retval = UA_Client_readIsAbstractAttribute(client, nodeReadWriteTestObjectType, &isAbstract);
  553. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  554. ck_assert_int_eq(isAbstract, newIsAbstract);
  555. }
  556. END_TEST
  557. START_TEST(Node_ReadWrite_Symmetric) {
  558. UA_Boolean symmetric;
  559. UA_StatusCode retval = UA_Client_readSymmetricAttribute(client, nodeReadWriteInt, &symmetric);
  560. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  561. retval = UA_Client_readSymmetricAttribute(client, nodeReadWriteTestHasSubSubType, &symmetric);
  562. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  563. ck_assert_int_eq(symmetric, UA_FALSE);
  564. UA_Boolean newSymmetric = UA_TRUE;
  565. retval = UA_Client_writeSymmetricAttribute(client, nodeReadWriteTestHasSubSubType, &newSymmetric);
  566. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  567. retval = UA_Client_readSymmetricAttribute(client, nodeReadWriteTestHasSubSubType, &symmetric);
  568. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  569. ck_assert_int_eq(symmetric, newSymmetric);
  570. }
  571. END_TEST
  572. START_TEST(Node_ReadWrite_InverseName) {
  573. UA_LocalizedText inverseName;
  574. UA_StatusCode retval = UA_Client_readInverseNameAttribute(client, nodeReadWriteTestHasSubSubType, &inverseName);
  575. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  576. UA_LocalizedText orig = UA_LOCALIZEDTEXT("en-US", "HasParentParentType");
  577. ck_assert(UA_String_equal(&inverseName.locale, &orig.locale));
  578. ck_assert(UA_String_equal(&inverseName.text, &orig.text));
  579. UA_LocalizedText_deleteMembers(&inverseName);
  580. UA_LocalizedText newLocale = UA_LOCALIZEDTEXT("en-US", "HasParentParentType-Changed");
  581. retval = UA_Client_writeInverseNameAttribute(client, nodeReadWriteTestHasSubSubType, &newLocale);
  582. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  583. UA_LocalizedText inverseNameChangedRead;
  584. retval = UA_Client_readInverseNameAttribute(client, nodeReadWriteTestHasSubSubType, &inverseNameChangedRead);
  585. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  586. ck_assert(UA_String_equal(&newLocale.locale, &inverseNameChangedRead.locale));
  587. ck_assert(UA_String_equal(&newLocale.text, &inverseNameChangedRead.text));
  588. UA_LocalizedText_deleteMembers(&inverseNameChangedRead);
  589. }
  590. END_TEST
  591. START_TEST(Node_ReadWrite_ContainsNoLoops) {
  592. UA_Boolean containsNoLoops;
  593. UA_StatusCode retval = UA_Client_readContainsNoLoopsAttribute(client, nodeReadWriteTestHasSubSubType, &containsNoLoops);
  594. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  595. retval = UA_Client_readContainsNoLoopsAttribute(client, nodeReadWriteView, &containsNoLoops);
  596. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  597. ck_assert_int_eq(containsNoLoops, UA_FALSE);
  598. UA_Boolean newContainsNoLoops = UA_TRUE;
  599. retval = UA_Client_writeContainsNoLoopsAttribute(client, nodeReadWriteView, &newContainsNoLoops);
  600. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  601. retval = UA_Client_readContainsNoLoopsAttribute(client, nodeReadWriteView, &containsNoLoops);
  602. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  603. ck_assert_int_eq(containsNoLoops, newContainsNoLoops);
  604. }
  605. END_TEST
  606. START_TEST(Node_ReadWrite_EventNotifier) {
  607. UA_Byte eventNotifier = 0;
  608. UA_StatusCode retval = UA_Client_readEventNotifierAttribute(client, nodeReadWriteTestHasSubSubType, &eventNotifier);
  609. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  610. retval = UA_Client_readEventNotifierAttribute(client, nodeReadWriteView, &eventNotifier);
  611. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  612. ck_assert_int_eq(eventNotifier, 0);
  613. UA_Byte newEventNotifier = 1;
  614. retval = UA_Client_writeEventNotifierAttribute(client, nodeReadWriteView, &newEventNotifier);
  615. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  616. retval = UA_Client_readEventNotifierAttribute(client, nodeReadWriteView, &eventNotifier);
  617. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  618. ck_assert_int_eq(eventNotifier, newEventNotifier);
  619. }
  620. END_TEST
  621. START_TEST(Node_ReadWrite_Value) {
  622. UA_Int32 value = 0;
  623. UA_Variant *val = UA_Variant_new();
  624. UA_StatusCode retval = UA_Client_readValueAttribute(client, nodeReadWriteInt, val);
  625. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  626. ck_assert(UA_Variant_isScalar(val) && val->type == &UA_TYPES[UA_TYPES_INT32]);
  627. value = *(UA_Int32*)val->data;
  628. ck_assert_int_eq(value, 5678);
  629. UA_Variant_delete(val);
  630. /* Write attribute */
  631. value++;
  632. val = UA_Variant_new();
  633. UA_Variant_setScalarCopy(val, &value, &UA_TYPES[UA_TYPES_INT32]);
  634. retval = UA_Client_writeValueAttribute(client, nodeReadWriteInt, val);
  635. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  636. UA_Variant_delete(val);
  637. /* Read again to check value */
  638. val = UA_Variant_new();
  639. retval = UA_Client_readValueAttribute(client, nodeReadWriteInt, val);
  640. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  641. ck_assert(UA_Variant_isScalar(val) && val->type == &UA_TYPES[UA_TYPES_INT32]);
  642. value = *(UA_Int32*)val->data;
  643. ck_assert_int_eq(value, 5679);
  644. UA_Variant_delete(val);
  645. }
  646. END_TEST
  647. START_TEST(Node_ReadWrite_DataType) {
  648. UA_NodeId dataType;
  649. // read to check if node id was changed
  650. UA_StatusCode retval = UA_Client_readDataTypeAttribute(client, nodeReadWriteInt, &dataType);
  651. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  652. ck_assert(UA_NodeId_equal(&dataType, &UA_TYPES[UA_TYPES_INT32].typeId));
  653. UA_NodeId newDataType = UA_TYPES[UA_TYPES_VARIANT].typeId;
  654. retval = UA_Client_writeDataTypeAttribute(client, nodeReadWriteGeneric, &newDataType);
  655. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  656. retval = UA_Client_readDataTypeAttribute(client, nodeReadWriteGeneric, &dataType);
  657. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  658. ck_assert(UA_NodeId_equal(&dataType, &newDataType));
  659. }
  660. END_TEST
  661. START_TEST(Node_ReadWrite_ValueRank) {
  662. UA_Int32 valueRank = 0;
  663. UA_StatusCode retval = UA_Client_readValueRankAttribute(client, nodeReadWriteGeneric, &valueRank);
  664. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  665. ck_assert_int_eq(valueRank, -2);
  666. // set the value to a scalar
  667. UA_Double val = 0.0;
  668. UA_Variant value;
  669. UA_Variant_setScalar(&value, &val, &UA_TYPES[UA_TYPES_DOUBLE]);
  670. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  671. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  672. // we want an array
  673. UA_Int32 newValueRank = 1;
  674. // shall fail when the value is not compatible
  675. retval = UA_Client_writeValueRankAttribute(client, nodeReadWriteGeneric, &newValueRank);
  676. ck_assert(retval != UA_STATUSCODE_GOOD);
  677. // set the value to an array
  678. UA_Double vec[3] = {0.0, 0.0, 0.0};
  679. UA_Variant_setArray(&value, vec, 3, &UA_TYPES[UA_TYPES_DOUBLE]);
  680. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  681. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  682. // try again
  683. retval = UA_Client_writeValueRankAttribute(client, nodeReadWriteGeneric, &newValueRank);
  684. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  685. retval = UA_Client_readValueRankAttribute(client, nodeReadWriteGeneric, &valueRank);
  686. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  687. ck_assert_int_eq(valueRank, newValueRank);
  688. // set the value to no array
  689. UA_Variant_init(&value);
  690. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  691. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  692. }
  693. END_TEST
  694. START_TEST(Node_ReadWrite_ArrayDimensions) {
  695. UA_UInt32 *arrayDimsRead;
  696. size_t arrayDimsReadSize;
  697. UA_StatusCode retval = UA_Client_readArrayDimensionsAttribute(client, nodeReadWriteGeneric,
  698. &arrayDimsReadSize, &arrayDimsRead);
  699. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  700. ck_assert_int_eq(arrayDimsReadSize, 0);
  701. // writing the array dimensions shall fail at first
  702. UA_UInt32 arrayDimsNew[] = {3};
  703. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeReadWriteGeneric, 1, arrayDimsNew);
  704. ck_assert(retval != UA_STATUSCODE_GOOD);
  705. // Set a vector of size 3 as the value
  706. UA_Double vec[3] = {0.0, 0.0, 0.0};
  707. UA_Variant value;
  708. UA_Variant_setArray(&value, vec, 3, &UA_TYPES[UA_TYPES_DOUBLE]);
  709. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  710. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  711. // Now we can set matching array-dimensions
  712. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeReadWriteGeneric, 1, arrayDimsNew);
  713. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  714. retval = UA_Client_readArrayDimensionsAttribute(client, nodeReadWriteGeneric,
  715. &arrayDimsReadSize, &arrayDimsRead);
  716. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  717. ck_assert_int_eq(arrayDimsReadSize, 1);
  718. ck_assert_int_eq(arrayDimsRead[0], 3);
  719. UA_Array_delete(arrayDimsRead, arrayDimsReadSize, &UA_TYPES[UA_TYPES_UINT32]);
  720. }
  721. END_TEST
  722. START_TEST(Node_ReadWrite_AccessLevel) {
  723. UA_Byte accessLevel;
  724. UA_StatusCode retval = UA_Client_readAccessLevelAttribute(client, nodeReadWriteInt, &accessLevel);
  725. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  726. ck_assert_int_eq(accessLevel, UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE);
  727. UA_Byte newMask = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
  728. retval = UA_Client_writeAccessLevelAttribute(client, nodeReadWriteInt, &newMask);
  729. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  730. UA_Byte accessLevelChangedRead;
  731. retval = UA_Client_readAccessLevelAttribute(client, nodeReadWriteInt, &accessLevelChangedRead);
  732. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  733. ck_assert_int_eq(accessLevelChangedRead, newMask);
  734. }
  735. END_TEST
  736. START_TEST(Node_ReadWrite_UserAccessLevel) {
  737. UA_Byte userAccessLevel;
  738. UA_StatusCode retval = UA_Client_readUserAccessLevelAttribute(client, nodeReadWriteInt, &userAccessLevel);
  739. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  740. ck_assert_int_eq(userAccessLevel, UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD);
  741. UA_Byte newMask = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
  742. retval = UA_Client_writeUserAccessLevelAttribute(client, nodeReadWriteInt, &newMask);
  743. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  744. }
  745. END_TEST
  746. START_TEST(Node_ReadWrite_MinimumSamplingInterval) {
  747. UA_Double minimumSamplingInterval = 0;
  748. UA_StatusCode retval = UA_Client_readMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &minimumSamplingInterval);
  749. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  750. ck_assert(minimumSamplingInterval == 0);
  751. // we want an array
  752. UA_Double newMinimumSamplingInterval = 1;
  753. retval = UA_Client_writeMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &newMinimumSamplingInterval);
  754. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  755. retval = UA_Client_readMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &minimumSamplingInterval);
  756. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  757. ck_assert(minimumSamplingInterval == newMinimumSamplingInterval);
  758. }
  759. END_TEST
  760. START_TEST(Node_ReadWrite_Historizing) {
  761. UA_Boolean historizing;
  762. UA_StatusCode retval = UA_Client_readHistorizingAttribute(client, nodeReadWriteInt, &historizing);
  763. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  764. ck_assert_int_eq(historizing, UA_FALSE);
  765. UA_Boolean newHistorizing = UA_TRUE;
  766. retval = UA_Client_writeHistorizingAttribute(client, nodeReadWriteInt, &newHistorizing);
  767. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  768. retval = UA_Client_readHistorizingAttribute(client, nodeReadWriteInt, &historizing);
  769. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  770. ck_assert_int_eq(historizing, newHistorizing);
  771. }
  772. END_TEST
  773. START_TEST(Node_ReadWrite_Executable) {
  774. UA_Boolean executable;
  775. UA_StatusCode retval = UA_Client_readExecutableAttribute(client, nodeReadWriteMethod, &executable);
  776. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  777. ck_assert_int_eq(executable, UA_TRUE);
  778. UA_Boolean newExecutable = UA_FALSE;
  779. retval = UA_Client_writeExecutableAttribute(client, nodeReadWriteMethod, &newExecutable);
  780. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  781. retval = UA_Client_readExecutableAttribute(client, nodeReadWriteMethod, &executable);
  782. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  783. ck_assert_int_eq(executable, newExecutable);
  784. }
  785. END_TEST
  786. START_TEST(Node_ReadWrite_UserExecutable) {
  787. UA_Boolean userExecutable;
  788. UA_StatusCode retval = UA_Client_readUserExecutableAttribute(client, nodeReadWriteMethod, &userExecutable);
  789. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  790. ck_assert_int_eq(userExecutable, UA_FALSE);
  791. UA_Boolean newUserExecutable = UA_TRUE;
  792. retval = UA_Client_writeUserExecutableAttribute(client, nodeReadWriteMethod, &newUserExecutable);
  793. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  794. }
  795. END_TEST
  796. #endif
  797. static Suite *testSuite_Client(void) {
  798. Suite *s = suite_create("Client Highlevel");
  799. TCase *tc_misc = tcase_create("Client Highlevel Misc");
  800. tcase_add_checked_fixture(tc_misc, setup, teardown);
  801. tcase_add_test(tc_misc, Misc_State);
  802. tcase_add_test(tc_misc, Misc_NamespaceGetIndex);
  803. suite_add_tcase(s, tc_misc);
  804. TCase *tc_nodes = tcase_create("Client Highlevel Node Management");
  805. tcase_add_checked_fixture(tc_nodes, setup, teardown);
  806. #ifdef UA_ENABLE_NODEMANAGEMENT
  807. tcase_add_test(tc_nodes, Node_Add);
  808. #endif
  809. tcase_add_test(tc_nodes, Node_Browse);
  810. tcase_add_test(tc_nodes, Node_Register);
  811. suite_add_tcase(s, tc_nodes);
  812. #ifdef UA_ENABLE_NODEMANAGEMENT
  813. TCase *tc_readwrite = tcase_create("Client Highlevel Read/Write");
  814. tcase_add_unchecked_fixture(tc_readwrite, setup, teardown);
  815. // first add some nodes where we test on
  816. tcase_add_test(tc_readwrite, Node_AddReadWriteNodes);
  817. // Now run all the read write tests
  818. tcase_add_test(tc_readwrite, Node_ReadWrite_Id);
  819. tcase_add_test(tc_readwrite, Node_ReadWrite_Class);
  820. tcase_add_test(tc_readwrite, Node_ReadWrite_BrowseName);
  821. tcase_add_test(tc_readwrite, Node_ReadWrite_DisplayName);
  822. tcase_add_test(tc_readwrite, Node_ReadWrite_Description);
  823. tcase_add_test(tc_readwrite, Node_ReadWrite_WriteMask);
  824. tcase_add_test(tc_readwrite, Node_ReadWrite_UserWriteMask);
  825. tcase_add_test(tc_readwrite, Node_ReadWrite_IsAbstract);
  826. tcase_add_test(tc_readwrite, Node_ReadWrite_Symmetric);
  827. tcase_add_test(tc_readwrite, Node_ReadWrite_InverseName);
  828. tcase_add_test(tc_readwrite, Node_ReadWrite_ContainsNoLoops);
  829. tcase_add_test(tc_readwrite, Node_ReadWrite_EventNotifier);
  830. tcase_add_test(tc_readwrite, Node_ReadWrite_Value);
  831. tcase_add_test(tc_readwrite, Node_ReadWrite_DataType);
  832. tcase_add_test(tc_readwrite, Node_ReadWrite_ValueRank);
  833. tcase_add_test(tc_readwrite, Node_ReadWrite_ArrayDimensions);
  834. tcase_add_test(tc_readwrite, Node_ReadWrite_AccessLevel);
  835. tcase_add_test(tc_readwrite, Node_ReadWrite_UserAccessLevel);
  836. tcase_add_test(tc_readwrite, Node_ReadWrite_MinimumSamplingInterval);
  837. tcase_add_test(tc_readwrite, Node_ReadWrite_Historizing);
  838. tcase_add_test(tc_readwrite, Node_ReadWrite_Executable);
  839. tcase_add_test(tc_readwrite, Node_ReadWrite_UserExecutable);
  840. suite_add_tcase(s, tc_readwrite);
  841. #endif
  842. return s;
  843. }
  844. int main(void) {
  845. Suite *s = testSuite_Client();
  846. SRunner *sr = srunner_create(s);
  847. srunner_set_fork_status(sr, CK_NOFORK);
  848. srunner_run_all(sr, CK_NORMAL);
  849. int number_failed = srunner_ntests_failed(sr);
  850. srunner_free(sr);
  851. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  852. }