check_client_highlevel.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <pthread.h>
  7. #include <ua_types.h>
  8. #include "ua_server.h"
  9. #include "ua_client.h"
  10. #include "ua_config_standard.h"
  11. #include "ua_network_tcp.h"
  12. #include "check.h"
  13. UA_Server *server;
  14. UA_ServerConfig *config;
  15. UA_Boolean running;
  16. UA_ServerNetworkLayer nl;
  17. pthread_t 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. static void *serverloop(void *_) {
  22. while (running)
  23. UA_Server_run_iterate(server, true);
  24. return NULL;
  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. pthread_create(&server_thread, NULL, serverloop, NULL);
  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. pthread_join(server_thread, NULL);
  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_CONNECTED);
  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. }
  62. END_TEST
  63. UA_NodeId newReferenceTypeId;
  64. UA_NodeId newObjectTypeId;
  65. UA_NodeId newDataTypeId;
  66. UA_NodeId newVariableTypeId;
  67. UA_NodeId newObjectId;
  68. UA_NodeId newVariableId;
  69. UA_NodeId newMethodId;
  70. UA_NodeId newViewId;
  71. 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. // Add 'Top' to view
  183. retval = UA_Client_addReference(client, newViewId, UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  184. UA_TRUE, UA_STRING_NULL,
  185. UA_EXPANDEDNODEID_NUMERIC(1, newObjectId.identifier.numeric),
  186. 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), UA_TRUE,
  191. UA_EXPANDEDNODEID_NUMERIC(1, newObjectId.identifier.numeric), UA_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. START_TEST(Node_Browse) {
  212. // Browse node in server folder
  213. UA_BrowseRequest bReq;
  214. UA_BrowseRequest_init(&bReq);
  215. // normally is set to 0, to get all the nodes, but we want to test browse next
  216. bReq.requestedMaxReferencesPerNode = 1;
  217. bReq.nodesToBrowse = UA_BrowseDescription_new();
  218. bReq.nodesToBrowseSize = 1;
  219. bReq.nodesToBrowse[0].nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER);
  220. bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL;
  221. UA_BrowseResponse bResp = UA_Client_Service_browse(client, bReq);
  222. ck_assert_uint_eq(bResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  223. ck_assert_uint_eq(bResp.resultsSize, 1);
  224. ck_assert_uint_eq(bResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  225. ck_assert_uint_eq(bResp.results[0].referencesSize, 1);
  226. /* References might have a different order in generated nodesets */
  227. /* UA_ReferenceDescription *ref = &(bResp.results[0].references[0]); */
  228. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVERTYPE); */
  229. // browse next
  230. UA_BrowseNextRequest bNextReq;
  231. UA_BrowseNextRequest_init(&bNextReq);
  232. // normally is set to 0, to get all the nodes, but we want to test browse next
  233. bNextReq.releaseContinuationPoints = UA_FALSE;
  234. bNextReq.continuationPoints = &bResp.results[0].continuationPoint;
  235. bNextReq.continuationPointsSize = 1;
  236. UA_BrowseNextResponse bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  237. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  238. ck_assert_uint_eq(bNextResp.resultsSize, 1);
  239. ck_assert_uint_eq(bNextResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  240. ck_assert_uint_eq(bNextResp.results[0].referencesSize, 1);
  241. /* ref = &(bNextResp.results[0].references[0]); */
  242. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVER_NAMESPACEARRAY); */
  243. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  244. bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  245. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  246. ck_assert_uint_eq(bNextResp.resultsSize, 1);
  247. ck_assert_uint_eq(bNextResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  248. ck_assert_uint_eq(bNextResp.results[0].referencesSize, 1);
  249. /* ref = &(bNextResp.results[0].references[0]); */
  250. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVER_SERVERARRAY); */
  251. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  252. // release continuation point. Result is then empty
  253. bNextReq.releaseContinuationPoints = UA_TRUE;
  254. bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  255. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  256. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  257. ck_assert_uint_eq(bNextResp.resultsSize, 0);
  258. UA_BrowseRequest_deleteMembers(&bReq);
  259. UA_BrowseResponse_deleteMembers(&bResp);
  260. // already deleted by browse request
  261. bNextReq.continuationPoints = NULL;
  262. bNextReq.continuationPointsSize = 0;
  263. UA_BrowseNextRequest_deleteMembers(&bNextReq);
  264. }
  265. END_TEST
  266. START_TEST(Node_Register) {
  267. UA_RegisterNodesRequest req;
  268. UA_RegisterNodesRequest_init(&req);
  269. req.nodesToRegister = UA_NodeId_new();
  270. req.nodesToRegister[0] = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
  271. req.nodesToRegisterSize = 1;
  272. UA_RegisterNodesResponse res = UA_Client_Service_registerNodes(client, req);
  273. ck_assert_uint_eq(res.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  274. ck_assert_uint_eq(res.registeredNodeIdsSize, 1);
  275. UA_UnregisterNodesRequest reqUn;
  276. UA_UnregisterNodesRequest_init(&reqUn);
  277. reqUn.nodesToUnregister = UA_NodeId_new();
  278. reqUn.nodesToUnregister[0] = res.registeredNodeIds[0];
  279. reqUn.nodesToUnregisterSize = 1;
  280. UA_UnregisterNodesResponse resUn = UA_Client_Service_unregisterNodes(client, reqUn);
  281. ck_assert_uint_eq(resUn.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  282. UA_UnregisterNodesRequest_deleteMembers(&reqUn);
  283. UA_UnregisterNodesResponse_deleteMembers(&resUn);
  284. UA_RegisterNodesRequest_deleteMembers(&req);
  285. UA_RegisterNodesResponse_deleteMembers(&res);
  286. }
  287. END_TEST
  288. // NodeIds for ReadWrite testing
  289. UA_NodeId nodeReadWriteUnitTest;
  290. UA_NodeId nodeReadWriteArray;
  291. UA_NodeId nodeReadWriteInt;
  292. UA_NodeId nodeReadWriteGeneric;
  293. UA_NodeId nodeReadWriteTestObjectType;
  294. UA_NodeId nodeReadWriteTestHasSubSubType;
  295. UA_NodeId nodeReadWriteView;
  296. UA_NodeId nodeReadWriteMethod;
  297. START_TEST(Node_AddReadWriteNodes) {
  298. UA_StatusCode retval;
  299. // Create a folder with two variables for testing
  300. // create Coordinates Object within ObjectsFolder
  301. {
  302. UA_ObjectAttributes attr = UA_ObjectAttributes_default;
  303. attr.description = UA_LOCALIZEDTEXT("en-US", "UnitTest");
  304. attr.displayName = UA_LOCALIZEDTEXT("en-US", "UnitTest");
  305. retval = UA_Client_addObjectNode(client, UA_NODEID_NULL,
  306. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  307. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  308. UA_QUALIFIEDNAME(1, "UnitTest"),
  309. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), attr, &nodeReadWriteUnitTest);
  310. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  311. }
  312. // create Variable 'Top' within UnitTest Object
  313. {
  314. UA_VariableAttributes attr = UA_VariableAttributes_default;
  315. attr.description = UA_LOCALIZEDTEXT("en-US", "Array");
  316. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Array");
  317. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  318. attr.writeMask = UA_WRITEMASK_ARRRAYDIMENSIONS;
  319. UA_Int32 values[2];
  320. values[0] = 10;
  321. values[1] = 20;
  322. UA_Variant_setArray(&attr.value, values, 2, &UA_TYPES[UA_TYPES_INT32]);
  323. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  324. attr.valueRank = 1; /* array with one dimension */
  325. UA_UInt32 arrayDims[1] = {2};
  326. attr.arrayDimensions = arrayDims;
  327. attr.arrayDimensionsSize = 1;
  328. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  329. nodeReadWriteUnitTest,
  330. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  331. UA_QUALIFIEDNAME(1, "Array"),
  332. UA_NODEID_NULL, attr, &nodeReadWriteArray);
  333. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  334. }
  335. // create Variable 'Int' within UnitTest Object
  336. {
  337. UA_VariableAttributes attr = UA_VariableAttributes_default;
  338. attr.description = UA_LOCALIZEDTEXT("en-US", "Int");
  339. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Int");
  340. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  341. attr.writeMask = 0xFFFFFFFF;
  342. UA_Int32 int_value = 5678;
  343. UA_Variant_setScalar(&attr.value, &int_value, &UA_TYPES[UA_TYPES_INT32]);
  344. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  345. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  346. nodeReadWriteUnitTest,
  347. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  348. UA_QUALIFIEDNAME(1, "Int"),
  349. UA_NODEID_NULL, attr, &nodeReadWriteInt);
  350. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  351. }
  352. // create Variable 'Generic' within UnitTest Object
  353. {
  354. UA_VariableAttributes attr = UA_VariableAttributes_default;
  355. attr.description = UA_LOCALIZEDTEXT("en-US", "Generic");
  356. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Generic");
  357. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  358. attr.writeMask = 0xFFFFFFFF;
  359. // generic datatype
  360. attr.dataType = UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATATYPE);
  361. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  362. nodeReadWriteUnitTest,
  363. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  364. UA_QUALIFIEDNAME(1, "Generic"),
  365. UA_NODEID_NULL, attr, &nodeReadWriteGeneric);
  366. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  367. }
  368. // create Method 'Dummy' within Coordinates Object.
  369. {
  370. UA_MethodAttributes attr = UA_MethodAttributes_default;
  371. attr.description = UA_LOCALIZEDTEXT("en-US", "Dummy method");
  372. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Dummy");
  373. attr.executable = true;
  374. attr.userExecutable = true;
  375. attr.writeMask = 0xFFFFFFFF;
  376. retval = UA_Client_addMethodNode(client, UA_NODEID_NULL,
  377. nodeReadWriteUnitTest,
  378. UA_NODEID_NUMERIC(0, UA_NS0ID_HASORDEREDCOMPONENT),
  379. UA_QUALIFIEDNAME(1, "Dummy"),
  380. attr, &nodeReadWriteMethod);
  381. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  382. }
  383. // Create TestObjectType SubType within BaseObjectType
  384. {
  385. UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;
  386. attr.description = UA_LOCALIZEDTEXT("en-US", "Some TestObjectType");
  387. attr.displayName = UA_LOCALIZEDTEXT("en-US", "TestObjectType");
  388. attr.writeMask = 0xFFFFFFFF;
  389. retval = UA_Client_addObjectTypeNode(client, UA_NODEID_NULL,
  390. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
  391. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  392. UA_QUALIFIEDNAME(1, "TestObjectType"), attr, &nodeReadWriteTestObjectType);
  393. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  394. }
  395. // Create custom reference type 'HasSubSubType' as child of HasSubtype
  396. {
  397. UA_ReferenceTypeAttributes attr = UA_ReferenceTypeAttributes_default;
  398. attr.description = UA_LOCALIZEDTEXT("en-US", "Some HasSubSubType");
  399. attr.displayName = UA_LOCALIZEDTEXT("en-US", "HasSubSubType");
  400. attr.inverseName = UA_LOCALIZEDTEXT("en-US", "HasParentParentType");
  401. attr.writeMask = 0xFFFFFFFF;
  402. retval = UA_Client_addReferenceTypeNode(client, UA_NODEID_NULL,
  403. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  404. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  405. UA_QUALIFIEDNAME(1, "HasSubSubType"), attr,
  406. &nodeReadWriteTestHasSubSubType);
  407. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  408. }
  409. // create View 'AllTopCoordinates' whithin Views Folder
  410. {
  411. UA_ViewAttributes attr = UA_ViewAttributes_default;
  412. attr.description = UA_LOCALIZEDTEXT("en-US", "List of all top coordinates");
  413. attr.displayName = UA_LOCALIZEDTEXT("en-US", "AllTopCoordinates");
  414. attr.writeMask = 0xFFFFFFFF;
  415. retval = UA_Client_addViewNode(client, UA_NODEID_NULL,
  416. UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
  417. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  418. UA_QUALIFIEDNAME(1, "AllTopCoordinates"),
  419. attr, &nodeReadWriteView);
  420. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  421. }
  422. // iterate over children
  423. retval = UA_Client_forEachChildNodeCall(client, nodeReadWriteUnitTest, nodeIter, NULL);
  424. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  425. ck_assert(UA_NodeId_equal(&nodeReadWriteArray, &iteratedNodes[0]));
  426. ck_assert(UA_NodeId_equal(&nodeReadWriteInt, &iteratedNodes[1]));
  427. }
  428. END_TEST
  429. START_TEST(Node_ReadWrite_Id) {
  430. UA_NodeId newNodeId;
  431. // read to check if node id was changed
  432. UA_StatusCode retval = UA_Client_readNodeIdAttribute(client, nodeReadWriteInt, &newNodeId);
  433. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  434. ck_assert(UA_NodeId_equal(&newNodeId, &nodeReadWriteInt));
  435. newNodeId.identifier.numeric = 900;
  436. retval = UA_Client_writeNodeIdAttribute(client, nodeReadWriteInt, &newNodeId);
  437. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  438. }
  439. END_TEST
  440. static void checkNodeClass(UA_Client *clientNc, const UA_NodeId nodeId, const UA_NodeClass expectedClass) {
  441. UA_NodeClass nodeClass = UA_NODECLASS_UNSPECIFIED;
  442. UA_StatusCode retval = UA_Client_readNodeClassAttribute(clientNc, nodeId, &nodeClass);
  443. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  444. ck_assert_int_eq(nodeClass, expectedClass);
  445. }
  446. START_TEST(Node_ReadWrite_Class) {
  447. checkNodeClass(client, nodeReadWriteInt, UA_NODECLASS_VARIABLE);
  448. checkNodeClass(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER), UA_NODECLASS_OBJECT);
  449. checkNodeClass(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_GETMONITOREDITEMS), UA_NODECLASS_METHOD);
  450. UA_NodeClass newClass = UA_NODECLASS_METHOD;
  451. UA_StatusCode retval = UA_Client_writeNodeClassAttribute(client, nodeReadWriteInt, &newClass);
  452. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  453. }
  454. END_TEST
  455. START_TEST(Node_ReadWrite_BrowseName) {
  456. UA_QualifiedName browseName;
  457. UA_StatusCode retval = UA_Client_readBrowseNameAttribute(client, nodeReadWriteInt, &browseName);
  458. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  459. UA_QualifiedName orig = UA_QUALIFIEDNAME(1, "Int");
  460. ck_assert_int_eq(browseName.namespaceIndex, orig.namespaceIndex);
  461. ck_assert(UA_String_equal(&browseName.name, &orig.name));
  462. UA_QualifiedName_deleteMembers(&browseName);
  463. browseName = UA_QUALIFIEDNAME(1,"Int-Changed");
  464. retval = UA_Client_writeBrowseNameAttribute(client, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER), &browseName);
  465. ck_assert_uint_eq(retval, UA_STATUSCODE_BADUSERACCESSDENIED);
  466. retval = UA_Client_writeBrowseNameAttribute(client, nodeReadWriteInt, &browseName);
  467. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  468. UA_QualifiedName browseNameChangedRead;
  469. retval = UA_Client_readBrowseNameAttribute(client, nodeReadWriteInt, &browseNameChangedRead);
  470. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  471. ck_assert_int_eq(browseName.namespaceIndex, browseNameChangedRead.namespaceIndex);
  472. ck_assert(UA_String_equal(&browseName.name, &browseNameChangedRead.name));
  473. UA_QualifiedName_deleteMembers(&browseNameChangedRead);
  474. }
  475. END_TEST
  476. START_TEST(Node_ReadWrite_DisplayName) {
  477. UA_LocalizedText displayName;
  478. UA_StatusCode retval = UA_Client_readDisplayNameAttribute(client, nodeReadWriteInt, &displayName);
  479. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  480. UA_LocalizedText orig = UA_LOCALIZEDTEXT("en-US", "Int");
  481. ck_assert(UA_String_equal(&displayName.locale, &orig.locale));
  482. ck_assert(UA_String_equal(&displayName.text, &orig.text));
  483. UA_LocalizedText_deleteMembers(&displayName);
  484. UA_LocalizedText newLocale = UA_LOCALIZEDTEXT("en-US", "Int-Changed");
  485. retval = UA_Client_writeDisplayNameAttribute(client, nodeReadWriteInt, &newLocale);
  486. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  487. UA_LocalizedText displayNameChangedRead;
  488. retval = UA_Client_readDisplayNameAttribute(client, nodeReadWriteInt, &displayNameChangedRead);
  489. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  490. ck_assert(UA_String_equal(&newLocale.locale, &displayNameChangedRead.locale));
  491. ck_assert(UA_String_equal(&newLocale.text, &displayNameChangedRead.text));
  492. UA_LocalizedText_deleteMembers(&displayNameChangedRead);
  493. }
  494. END_TEST
  495. START_TEST(Node_ReadWrite_Description) {
  496. UA_LocalizedText description;
  497. UA_StatusCode retval = UA_Client_readDescriptionAttribute(client, nodeReadWriteInt, &description);
  498. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  499. UA_LocalizedText orig = UA_LOCALIZEDTEXT("en-US", "Int");
  500. ck_assert(UA_String_equal(&description.locale, &orig.locale));
  501. ck_assert(UA_String_equal(&description.text, &orig.text));
  502. UA_LocalizedText_deleteMembers(&description);
  503. UA_LocalizedText newLocale = UA_LOCALIZEDTEXT("en-US", "Int-Changed");
  504. retval = UA_Client_writeDescriptionAttribute(client, nodeReadWriteInt, &newLocale);
  505. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  506. UA_LocalizedText descriptionChangedRead;
  507. retval = UA_Client_readDescriptionAttribute(client, nodeReadWriteInt, &descriptionChangedRead);
  508. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  509. ck_assert(UA_String_equal(&newLocale.locale, &descriptionChangedRead.locale));
  510. ck_assert(UA_String_equal(&newLocale.text, &descriptionChangedRead.text));
  511. UA_LocalizedText_deleteMembers(&descriptionChangedRead);
  512. }
  513. END_TEST
  514. START_TEST(Node_ReadWrite_WriteMask) {
  515. UA_UInt32 writeMask;
  516. UA_StatusCode retval = UA_Client_readWriteMaskAttribute(client, nodeReadWriteInt, &writeMask);
  517. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  518. ck_assert_int_eq(writeMask, 0xFFFFFFFF);
  519. // Disable a random write mask bit
  520. UA_UInt32 newMask = 0xFFFFFFFF & ~UA_WRITEMASK_BROWSENAME;
  521. retval = UA_Client_writeWriteMaskAttribute(client, nodeReadWriteInt, &newMask);
  522. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  523. UA_UInt32 writeMaskChangedRead;
  524. retval = UA_Client_readWriteMaskAttribute(client, nodeReadWriteInt, &writeMaskChangedRead);
  525. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  526. ck_assert_int_eq(writeMaskChangedRead, newMask);
  527. }
  528. END_TEST
  529. START_TEST(Node_ReadWrite_UserWriteMask) {
  530. UA_UInt32 userWriteMask;
  531. UA_StatusCode retval = UA_Client_readUserWriteMaskAttribute(client, nodeReadWriteInt, &userWriteMask);
  532. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  533. ck_assert_int_eq(userWriteMask, 0xFFFFFFFF & ~UA_WRITEMASK_BROWSENAME);
  534. // Disable a random write mask bit
  535. UA_UInt32 newMask = 0xFFFFFFFF & ~UA_WRITEMASK_DISPLAYNAME;
  536. retval = UA_Client_writeUserWriteMaskAttribute(client, nodeReadWriteInt, &newMask);
  537. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  538. }
  539. END_TEST
  540. START_TEST(Node_ReadWrite_IsAbstract) {
  541. UA_Boolean isAbstract;
  542. UA_StatusCode retval = UA_Client_readIsAbstractAttribute(client, nodeReadWriteInt, &isAbstract);
  543. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  544. retval = UA_Client_readIsAbstractAttribute(client, nodeReadWriteTestObjectType, &isAbstract);
  545. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  546. ck_assert_int_eq(isAbstract, UA_FALSE);
  547. UA_Boolean newIsAbstract = UA_TRUE;
  548. retval = UA_Client_writeIsAbstractAttribute(client, nodeReadWriteTestObjectType, &newIsAbstract);
  549. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  550. retval = UA_Client_readIsAbstractAttribute(client, nodeReadWriteTestObjectType, &isAbstract);
  551. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  552. ck_assert_int_eq(isAbstract, newIsAbstract);
  553. }
  554. END_TEST
  555. START_TEST(Node_ReadWrite_Symmetric) {
  556. UA_Boolean symmetric;
  557. UA_StatusCode retval = UA_Client_readSymmetricAttribute(client, nodeReadWriteInt, &symmetric);
  558. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  559. retval = UA_Client_readSymmetricAttribute(client, nodeReadWriteTestHasSubSubType, &symmetric);
  560. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  561. ck_assert_int_eq(symmetric, UA_FALSE);
  562. UA_Boolean newSymmetric = UA_TRUE;
  563. retval = UA_Client_writeSymmetricAttribute(client, nodeReadWriteTestHasSubSubType, &newSymmetric);
  564. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  565. retval = UA_Client_readSymmetricAttribute(client, nodeReadWriteTestHasSubSubType, &symmetric);
  566. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  567. ck_assert_int_eq(symmetric, newSymmetric);
  568. }
  569. END_TEST
  570. START_TEST(Node_ReadWrite_InverseName) {
  571. UA_LocalizedText inverseName;
  572. UA_StatusCode retval = UA_Client_readInverseNameAttribute(client, nodeReadWriteTestHasSubSubType, &inverseName);
  573. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  574. UA_LocalizedText orig = UA_LOCALIZEDTEXT("en-US", "HasParentParentType");
  575. ck_assert(UA_String_equal(&inverseName.locale, &orig.locale));
  576. ck_assert(UA_String_equal(&inverseName.text, &orig.text));
  577. UA_LocalizedText_deleteMembers(&inverseName);
  578. UA_LocalizedText newLocale = UA_LOCALIZEDTEXT("en-US", "HasParentParentType-Changed");
  579. retval = UA_Client_writeInverseNameAttribute(client, nodeReadWriteTestHasSubSubType, &newLocale);
  580. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  581. UA_LocalizedText inverseNameChangedRead;
  582. retval = UA_Client_readInverseNameAttribute(client, nodeReadWriteTestHasSubSubType, &inverseNameChangedRead);
  583. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  584. ck_assert(UA_String_equal(&newLocale.locale, &inverseNameChangedRead.locale));
  585. ck_assert(UA_String_equal(&newLocale.text, &inverseNameChangedRead.text));
  586. UA_LocalizedText_deleteMembers(&inverseNameChangedRead);
  587. }
  588. END_TEST
  589. START_TEST(Node_ReadWrite_ContainsNoLoops) {
  590. UA_Boolean containsNoLoops;
  591. UA_StatusCode retval = UA_Client_readContainsNoLoopsAttribute(client, nodeReadWriteTestHasSubSubType, &containsNoLoops);
  592. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  593. retval = UA_Client_readContainsNoLoopsAttribute(client, nodeReadWriteView, &containsNoLoops);
  594. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  595. ck_assert_int_eq(containsNoLoops, UA_FALSE);
  596. UA_Boolean newContainsNoLoops = UA_TRUE;
  597. retval = UA_Client_writeContainsNoLoopsAttribute(client, nodeReadWriteView, &newContainsNoLoops);
  598. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  599. retval = UA_Client_readContainsNoLoopsAttribute(client, nodeReadWriteView, &containsNoLoops);
  600. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  601. ck_assert_int_eq(containsNoLoops, newContainsNoLoops);
  602. }
  603. END_TEST
  604. START_TEST(Node_ReadWrite_EventNotifier) {
  605. UA_Byte eventNotifier = 0;
  606. UA_StatusCode retval = UA_Client_readEventNotifierAttribute(client, nodeReadWriteTestHasSubSubType, &eventNotifier);
  607. ck_assert_uint_eq(retval, UA_STATUSCODE_BADATTRIBUTEIDINVALID);
  608. retval = UA_Client_readEventNotifierAttribute(client, nodeReadWriteView, &eventNotifier);
  609. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  610. ck_assert_int_eq(eventNotifier, 0);
  611. UA_Byte newEventNotifier = 1;
  612. retval = UA_Client_writeEventNotifierAttribute(client, nodeReadWriteView, &newEventNotifier);
  613. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  614. retval = UA_Client_readEventNotifierAttribute(client, nodeReadWriteView, &eventNotifier);
  615. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  616. ck_assert_int_eq(eventNotifier, newEventNotifier);
  617. }
  618. END_TEST
  619. START_TEST(Node_ReadWrite_Value) {
  620. UA_Int32 value = 0;
  621. UA_Variant *val = UA_Variant_new();
  622. UA_StatusCode retval = UA_Client_readValueAttribute(client, nodeReadWriteInt, val);
  623. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  624. ck_assert(UA_Variant_isScalar(val) && val->type == &UA_TYPES[UA_TYPES_INT32]);
  625. value = *(UA_Int32*)val->data;
  626. ck_assert_int_eq(value, 5678);
  627. UA_Variant_delete(val);
  628. /* Write attribute */
  629. value++;
  630. val = UA_Variant_new();
  631. UA_Variant_setScalarCopy(val, &value, &UA_TYPES[UA_TYPES_INT32]);
  632. retval = UA_Client_writeValueAttribute(client, nodeReadWriteInt, val);
  633. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  634. UA_Variant_delete(val);
  635. /* Read again to check value */
  636. val = UA_Variant_new();
  637. retval = UA_Client_readValueAttribute(client, nodeReadWriteInt, val);
  638. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  639. ck_assert(UA_Variant_isScalar(val) && val->type == &UA_TYPES[UA_TYPES_INT32]);
  640. value = *(UA_Int32*)val->data;
  641. ck_assert_int_eq(value, 5679);
  642. UA_Variant_delete(val);
  643. }
  644. END_TEST
  645. START_TEST(Node_ReadWrite_DataType) {
  646. UA_NodeId dataType;
  647. // read to check if node id was changed
  648. UA_StatusCode retval = UA_Client_readDataTypeAttribute(client, nodeReadWriteGeneric, &dataType);
  649. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  650. ck_assert_int_eq(dataType.identifierType, UA_NODEIDTYPE_NUMERIC);
  651. ck_assert_int_eq(dataType.namespaceIndex, 0);
  652. ck_assert_int_eq(dataType.identifier.numeric, UA_NS0ID_BASEDATATYPE);
  653. UA_NodeId newDataType = UA_TYPES[UA_TYPES_UINT32].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. // we want an array
  667. UA_Int32 newValueRank = 1;
  668. retval = UA_Client_writeValueRankAttribute(client, nodeReadWriteGeneric, &newValueRank);
  669. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  670. retval = UA_Client_readValueRankAttribute(client, nodeReadWriteGeneric, &valueRank);
  671. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  672. ck_assert_int_eq(valueRank, newValueRank);
  673. }
  674. END_TEST
  675. START_TEST(Node_ReadWrite_ArrayDimensions) {
  676. UA_UInt32 *arrayDimsRead;
  677. size_t arrayDimsReadSize;
  678. UA_StatusCode retval = UA_Client_readArrayDimensionsAttribute(client, nodeReadWriteGeneric, &arrayDimsRead , &arrayDimsReadSize);
  679. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  680. ck_assert_int_eq(arrayDimsReadSize, 0);
  681. UA_UInt32 arrayDimsNew[] = {3};
  682. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeReadWriteGeneric, arrayDimsNew , 1);
  683. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  684. retval = UA_Client_readArrayDimensionsAttribute(client, nodeReadWriteGeneric, &arrayDimsRead , &arrayDimsReadSize);
  685. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  686. ck_assert_int_eq(arrayDimsReadSize, 1);
  687. ck_assert_int_eq(arrayDimsRead[0], 3);
  688. UA_Array_delete(arrayDimsRead, arrayDimsReadSize, &UA_TYPES[UA_TYPES_UINT32]);
  689. }
  690. END_TEST
  691. START_TEST(Node_ReadWrite_AccessLevel) {
  692. UA_Byte accessLevel;
  693. UA_StatusCode retval = UA_Client_readAccessLevelAttribute(client, nodeReadWriteInt, &accessLevel);
  694. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  695. ck_assert_int_eq(accessLevel, UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE);
  696. UA_Byte newMask = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
  697. retval = UA_Client_writeAccessLevelAttribute(client, nodeReadWriteInt, &newMask);
  698. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  699. UA_Byte accessLevelChangedRead;
  700. retval = UA_Client_readAccessLevelAttribute(client, nodeReadWriteInt, &accessLevelChangedRead);
  701. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  702. ck_assert_int_eq(accessLevelChangedRead, newMask);
  703. }
  704. END_TEST
  705. START_TEST(Node_ReadWrite_UserAccessLevel) {
  706. UA_Byte userAccessLevel;
  707. UA_StatusCode retval = UA_Client_readUserAccessLevelAttribute(client, nodeReadWriteInt, &userAccessLevel);
  708. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  709. ck_assert_int_eq(userAccessLevel, UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD);
  710. UA_Byte newMask = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
  711. retval = UA_Client_writeUserAccessLevelAttribute(client, nodeReadWriteInt, &newMask);
  712. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  713. }
  714. END_TEST
  715. START_TEST(Node_ReadWrite_MinimumSamplingInterval) {
  716. UA_Double minimumSamplingInterval = 0;
  717. UA_StatusCode retval = UA_Client_readMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &minimumSamplingInterval);
  718. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  719. ck_assert(minimumSamplingInterval == 0);
  720. // we want an array
  721. UA_Double newMinimumSamplingInterval = 1;
  722. retval = UA_Client_writeMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &newMinimumSamplingInterval);
  723. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  724. retval = UA_Client_readMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &minimumSamplingInterval);
  725. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  726. ck_assert(minimumSamplingInterval == newMinimumSamplingInterval);
  727. }
  728. END_TEST
  729. START_TEST(Node_ReadWrite_Historizing) {
  730. UA_Boolean historizing;
  731. UA_StatusCode retval = UA_Client_readHistorizingAttribute(client, nodeReadWriteInt, &historizing);
  732. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  733. ck_assert_int_eq(historizing, UA_FALSE);
  734. UA_Boolean newHistorizing = UA_TRUE;
  735. retval = UA_Client_writeHistorizingAttribute(client, nodeReadWriteInt, &newHistorizing);
  736. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  737. retval = UA_Client_readHistorizingAttribute(client, nodeReadWriteInt, &historizing);
  738. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  739. ck_assert_int_eq(historizing, newHistorizing);
  740. }
  741. END_TEST
  742. START_TEST(Node_ReadWrite_Executable) {
  743. UA_Boolean executable;
  744. UA_StatusCode retval = UA_Client_readExecutableAttribute(client, nodeReadWriteMethod, &executable);
  745. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  746. ck_assert_int_eq(executable, UA_TRUE);
  747. UA_Boolean newExecutable = UA_FALSE;
  748. retval = UA_Client_writeExecutableAttribute(client, nodeReadWriteMethod, &newExecutable);
  749. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  750. retval = UA_Client_readExecutableAttribute(client, nodeReadWriteMethod, &executable);
  751. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  752. ck_assert_int_eq(executable, newExecutable);
  753. }
  754. END_TEST
  755. START_TEST(Node_ReadWrite_UserExecutable) {
  756. UA_Boolean userExecutable;
  757. UA_StatusCode retval = UA_Client_readUserExecutableAttribute(client, nodeReadWriteMethod, &userExecutable);
  758. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  759. ck_assert_int_eq(userExecutable, UA_FALSE);
  760. UA_Boolean newUserExecutable = UA_TRUE;
  761. retval = UA_Client_writeUserExecutableAttribute(client, nodeReadWriteMethod, &newUserExecutable);
  762. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  763. }
  764. END_TEST
  765. static Suite *testSuite_Client(void) {
  766. Suite *s = suite_create("Client Highlevel");
  767. TCase *tc_misc = tcase_create("Client Highlevel Misc");
  768. tcase_add_checked_fixture(tc_misc, setup, teardown);
  769. tcase_add_test(tc_misc, Misc_State);
  770. tcase_add_test(tc_misc, Misc_NamespaceGetIndex);
  771. suite_add_tcase(s, tc_misc);
  772. TCase *tc_nodes = tcase_create("Client Highlevel Node Management");
  773. tcase_add_checked_fixture(tc_nodes, setup, teardown);
  774. tcase_add_test(tc_nodes, Node_Add);
  775. tcase_add_test(tc_nodes, Node_Browse);
  776. tcase_add_test(tc_nodes, Node_Register);
  777. suite_add_tcase(s, tc_nodes);
  778. TCase *tc_readwrite = tcase_create("Client Highlevel Read/Write");
  779. tcase_add_unchecked_fixture(tc_readwrite, setup, teardown);
  780. // first add some nodes where we test on
  781. tcase_add_test(tc_readwrite, Node_AddReadWriteNodes);
  782. // Now run all the read write tests
  783. tcase_add_test(tc_readwrite, Node_ReadWrite_Id);
  784. tcase_add_test(tc_readwrite, Node_ReadWrite_Class);
  785. tcase_add_test(tc_readwrite, Node_ReadWrite_BrowseName);
  786. tcase_add_test(tc_readwrite, Node_ReadWrite_DisplayName);
  787. tcase_add_test(tc_readwrite, Node_ReadWrite_Description);
  788. tcase_add_test(tc_readwrite, Node_ReadWrite_WriteMask);
  789. tcase_add_test(tc_readwrite, Node_ReadWrite_UserWriteMask);
  790. tcase_add_test(tc_readwrite, Node_ReadWrite_IsAbstract);
  791. tcase_add_test(tc_readwrite, Node_ReadWrite_Symmetric);
  792. tcase_add_test(tc_readwrite, Node_ReadWrite_InverseName);
  793. tcase_add_test(tc_readwrite, Node_ReadWrite_ContainsNoLoops);
  794. tcase_add_test(tc_readwrite, Node_ReadWrite_EventNotifier);
  795. tcase_add_test(tc_readwrite, Node_ReadWrite_Value);
  796. tcase_add_test(tc_readwrite, Node_ReadWrite_DataType);
  797. tcase_add_test(tc_readwrite, Node_ReadWrite_ValueRank);
  798. tcase_add_test(tc_readwrite, Node_ReadWrite_ArrayDimensions);
  799. tcase_add_test(tc_readwrite, Node_ReadWrite_AccessLevel);
  800. tcase_add_test(tc_readwrite, Node_ReadWrite_UserAccessLevel);
  801. tcase_add_test(tc_readwrite, Node_ReadWrite_MinimumSamplingInterval);
  802. tcase_add_test(tc_readwrite, Node_ReadWrite_Historizing);
  803. tcase_add_test(tc_readwrite, Node_ReadWrite_Executable);
  804. tcase_add_test(tc_readwrite, Node_ReadWrite_UserExecutable);
  805. suite_add_tcase(s, tc_readwrite);
  806. return s;
  807. }
  808. int main(void) {
  809. Suite *s = testSuite_Client();
  810. SRunner *sr = srunner_create(s);
  811. srunner_set_fork_status(sr, CK_NOFORK);
  812. srunner_run_all(sr, CK_NORMAL);
  813. int number_failed = srunner_ntests_failed(sr);
  814. srunner_free(sr);
  815. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  816. }