check_client_highlevel.c 45 KB

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