check_client_highlevel.c 44 KB

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