check_client_highlevel.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  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 "ua_server.h"
  5. #include "ua_client.h"
  6. #include "ua_config_default.h"
  7. #include "ua_client_highlevel.h"
  8. #include "ua_network_tcp.h"
  9. #include "check.h"
  10. #include "thread_wrapper.h"
  11. UA_Server *server;
  12. UA_ServerConfig *config;
  13. UA_Boolean running;
  14. UA_ServerNetworkLayer nl;
  15. THREAD_HANDLE server_thread;
  16. UA_Client *client;
  17. #define CUSTOM_NS "http://open62541.org/ns/test"
  18. #define CUSTOM_NS_UPPER "http://open62541.org/ns/Test"
  19. THREAD_CALLBACK(serverloop) {
  20. while (running)
  21. UA_Server_run_iterate(server, true);
  22. return 0;
  23. }
  24. static void setup(void) {
  25. running = true;
  26. config = UA_ServerConfig_new_default();
  27. server = UA_Server_new(config);
  28. ck_assert_uint_eq(2, UA_Server_addNamespace(server, CUSTOM_NS));
  29. UA_Server_run_startup(server);
  30. THREAD_CREATE(server_thread, serverloop);
  31. client = UA_Client_new();
  32. UA_ClientConfig_setDefault(UA_Client_getConfig(client));
  33. UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
  34. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  35. }
  36. static void teardown(void) {
  37. UA_Client_disconnect(client);
  38. UA_Client_delete(client);
  39. running = false;
  40. THREAD_JOIN(server_thread);
  41. UA_Server_run_shutdown(server);
  42. UA_Server_delete(server);
  43. UA_ServerConfig_delete(config);
  44. }
  45. START_TEST(Misc_State) {
  46. UA_ClientState state = UA_Client_getState(client);
  47. ck_assert_uint_eq(state, UA_CLIENTSTATE_SESSION);
  48. }
  49. END_TEST
  50. START_TEST(Misc_NamespaceGetIndex) {
  51. UA_UInt16 idx;
  52. UA_String ns = UA_STRING(CUSTOM_NS);
  53. UA_StatusCode retval = UA_Client_NamespaceGetIndex(client, &ns, &idx);
  54. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  55. ck_assert_uint_eq(idx, 2);
  56. // namespace uri is case sensitive
  57. ns = UA_STRING(CUSTOM_NS_UPPER);
  58. retval = UA_Client_NamespaceGetIndex(client, &ns, &idx);
  59. ck_assert_uint_eq(retval, UA_STATUSCODE_BADNOTFOUND);
  60. } END_TEST
  61. UA_NodeId newReferenceTypeId;
  62. UA_NodeId newObjectTypeId;
  63. UA_NodeId newDataTypeId;
  64. UA_NodeId newVariableTypeId;
  65. UA_NodeId newObjectId;
  66. UA_NodeId newVariableId;
  67. UA_NodeId newMethodId;
  68. UA_NodeId newViewId;
  69. #ifdef UA_ENABLE_NODEMANAGEMENT
  70. START_TEST(Node_Add) {
  71. UA_StatusCode retval;
  72. // Create custom reference type 'HasSubSubType' as child of HasSubtype
  73. {
  74. UA_ReferenceTypeAttributes attr = UA_ReferenceTypeAttributes_default;
  75. attr.description = UA_LOCALIZEDTEXT("en-US", "Some HasSubSubType");
  76. attr.displayName = UA_LOCALIZEDTEXT("en-US", "HasSubSubType");
  77. retval = UA_Client_addReferenceTypeNode(client, UA_NODEID_NULL,
  78. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  79. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  80. UA_QUALIFIEDNAME(1, "HasSubSubType"), attr,
  81. &newReferenceTypeId);
  82. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  83. }
  84. // Create TestObjectType SubType within BaseObjectType
  85. {
  86. UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;
  87. attr.description = UA_LOCALIZEDTEXT("en-US", "Some TestObjectType");
  88. attr.displayName = UA_LOCALIZEDTEXT("en-US", "TestObjectType");
  89. retval = UA_Client_addObjectTypeNode(client, UA_NODEID_NULL,
  90. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
  91. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  92. UA_QUALIFIEDNAME(1, "TestObjectType"), attr, &newObjectTypeId);
  93. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  94. }
  95. // Create Int128 DataType within Integer Datatype
  96. {
  97. UA_DataTypeAttributes attr = UA_DataTypeAttributes_default;
  98. attr.description = UA_LOCALIZEDTEXT("en-US", "Some Int128");
  99. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Int128");
  100. retval = UA_Client_addDataTypeNode(client, UA_NODEID_NULL,
  101. UA_NODEID_NUMERIC(0, UA_NS0ID_INTEGER),
  102. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  103. UA_QUALIFIEDNAME(1, "Int128"), attr, &newDataTypeId);
  104. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  105. }
  106. // Create PointType VariableType within BaseDataVariableType
  107. {
  108. UA_VariableTypeAttributes attr = UA_VariableTypeAttributes_default;
  109. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  110. attr.valueRank = UA_VALUERANK_ONE_DIMENSION;
  111. UA_UInt32 arrayDims[1] = {2};
  112. attr.arrayDimensions = arrayDims;
  113. attr.arrayDimensionsSize = 1;
  114. attr.displayName = UA_LOCALIZEDTEXT("en-US", "PointType");
  115. /* a matching default value is required */
  116. UA_Double zero[2] = {0.0, 0.0};
  117. UA_Variant_setArray(&attr.value, zero, 2, &UA_TYPES[UA_TYPES_INT32]);
  118. retval = UA_Client_addVariableTypeNode(client, UA_NODEID_NULL,
  119. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEVARIABLETYPE),
  120. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  121. UA_QUALIFIEDNAME(1, "PointType"), attr, &newVariableTypeId);
  122. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  123. }
  124. // create Coordinates Object within ObjectsFolder
  125. {
  126. UA_ObjectAttributes attr = UA_ObjectAttributes_default;
  127. attr.description = UA_LOCALIZEDTEXT("en-US", "Some Coordinates");
  128. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Coordinates");
  129. retval = UA_Client_addObjectNode(client, UA_NODEID_NULL,
  130. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  131. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  132. UA_QUALIFIEDNAME(1, "Coordinates"),
  133. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), attr, &newObjectId);
  134. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  135. }
  136. // create Variable 'Top' within Coordinates Object
  137. {
  138. UA_VariableAttributes attr = UA_VariableAttributes_default;
  139. attr.description = UA_LOCALIZEDTEXT("en-US", "Top Coordinate");
  140. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Top");
  141. UA_Int32 values[2] = {10, 20};
  142. UA_Variant_setArray(&attr.value, values, 2, &UA_TYPES[UA_TYPES_INT32]);
  143. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  144. attr.valueRank = UA_VALUERANK_ONE_DIMENSION;
  145. UA_UInt32 arrayDims[1] = {2};
  146. attr.arrayDimensions = arrayDims;
  147. attr.arrayDimensionsSize = 1;
  148. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  149. newObjectId,
  150. UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY),
  151. UA_QUALIFIEDNAME(1, "Top"),
  152. newVariableTypeId, attr, &newVariableId);
  153. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  154. }
  155. // create Method 'Dummy' within Coordinates Object.
  156. {
  157. UA_MethodAttributes attr = UA_MethodAttributes_default;
  158. attr.description = UA_LOCALIZEDTEXT("en-US", "Dummy method");
  159. attr.displayName = UA_LOCALIZEDTEXT("en-US", "Dummy");
  160. attr.executable = true;
  161. attr.userExecutable = true;
  162. retval = UA_Client_addMethodNode(client, UA_NODEID_NULL,
  163. newObjectId,
  164. UA_NODEID_NUMERIC(0, UA_NS0ID_HASORDEREDCOMPONENT),
  165. UA_QUALIFIEDNAME(1, "Dummy"),
  166. attr, &newMethodId);
  167. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  168. }
  169. // create View 'AllTopCoordinates' whithin Views Folder
  170. {
  171. UA_ViewAttributes attr = UA_ViewAttributes_default;
  172. attr.description = UA_LOCALIZEDTEXT("en-US", "List of all top coordinates");
  173. attr.displayName = UA_LOCALIZEDTEXT("en-US", "AllTopCoordinates");
  174. retval = UA_Client_addViewNode(client, UA_NODEID_NULL,
  175. UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
  176. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  177. UA_QUALIFIEDNAME(1, "AllTopCoordinates"),
  178. attr, &newViewId);
  179. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  180. }
  181. UA_ExpandedNodeId target = UA_EXPANDEDNODEID_NULL;
  182. target.nodeId = newObjectId;
  183. // Add 'Top' to view
  184. retval = UA_Client_addReference(client, newViewId, UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  185. UA_TRUE, UA_STRING_NULL, target, UA_NODECLASS_VARIABLE);
  186. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  187. // Delete 'Top' from view
  188. retval = UA_Client_deleteReference(client, newViewId,
  189. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  190. true, target, true);
  191. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  192. // Delete 'AllTopCoordinates' view
  193. retval = UA_Client_deleteNode(client, newViewId, UA_TRUE);
  194. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  195. }
  196. END_TEST
  197. unsigned int iteratedNodeCount = 0;
  198. UA_NodeId iteratedNodes[4];
  199. static UA_StatusCode
  200. nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, void *handle) {
  201. if (isInverse || (referenceTypeId.identifierType == UA_NODEIDTYPE_NUMERIC &&
  202. referenceTypeId.identifier.numeric == UA_NS0ID_HASTYPEDEFINITION))
  203. return UA_STATUSCODE_GOOD;
  204. if (iteratedNodeCount >= 4)
  205. return UA_STATUSCODE_BADINDEXRANGEINVALID;
  206. UA_NodeId_copy(&childId, &iteratedNodes[iteratedNodeCount]);
  207. iteratedNodeCount++;
  208. return UA_STATUSCODE_GOOD;
  209. }
  210. #endif
  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. #ifdef UA_ENABLE_NODEMANAGEMENT
  298. START_TEST(Node_AddReadWriteNodes) {
  299. UA_StatusCode retval;
  300. // Create a folder with two variables for testing
  301. // create Coordinates Object within ObjectsFolder
  302. {
  303. UA_ObjectAttributes attr = UA_ObjectAttributes_default;
  304. attr.description = UA_LOCALIZEDTEXT("en-US", "UnitTest");
  305. attr.displayName = UA_LOCALIZEDTEXT("en-US", "UnitTest");
  306. retval = UA_Client_addObjectNode(client, UA_NODEID_NULL,
  307. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  308. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  309. UA_QUALIFIEDNAME(1, "UnitTest"),
  310. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE),
  311. 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. // Set a vector of size 1 as the value
  704. UA_Double vec2[2] = {0.0, 0.0};
  705. UA_Variant value;
  706. UA_Variant_setArray(&value, vec2, 2, &UA_TYPES[UA_TYPES_DOUBLE]);
  707. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  708. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  709. // writing the array dimensions shall fail at first
  710. // because the current value is not conformant
  711. UA_UInt32 arrayDimsNew[] = {1};
  712. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeReadWriteGeneric, 1, arrayDimsNew);
  713. ck_assert(retval != UA_STATUSCODE_GOOD);
  714. // Set a vector of size 1 as the value
  715. UA_Double vec1[1] = {0.0};
  716. UA_Variant_setArray(&value, vec1, 1, &UA_TYPES[UA_TYPES_DOUBLE]);
  717. retval = UA_Client_writeValueAttribute(client, nodeReadWriteGeneric, &value);
  718. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  719. // Now we can set matching array-dimensions
  720. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeReadWriteGeneric, 1, arrayDimsNew);
  721. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  722. retval = UA_Client_readArrayDimensionsAttribute(client, nodeReadWriteGeneric,
  723. &arrayDimsReadSize, &arrayDimsRead);
  724. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  725. ck_assert_int_eq(arrayDimsReadSize, 1);
  726. ck_assert_int_eq(arrayDimsRead[0], 1);
  727. UA_Array_delete(arrayDimsRead, arrayDimsReadSize, &UA_TYPES[UA_TYPES_UINT32]);
  728. }
  729. END_TEST
  730. START_TEST(Node_ReadWrite_AccessLevel) {
  731. UA_Byte accessLevel;
  732. UA_StatusCode retval = UA_Client_readAccessLevelAttribute(client, nodeReadWriteInt, &accessLevel);
  733. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  734. ck_assert_int_eq(accessLevel, UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE);
  735. UA_Byte newMask = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
  736. retval = UA_Client_writeAccessLevelAttribute(client, nodeReadWriteInt, &newMask);
  737. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  738. UA_Byte accessLevelChangedRead;
  739. retval = UA_Client_readAccessLevelAttribute(client, nodeReadWriteInt, &accessLevelChangedRead);
  740. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  741. ck_assert_int_eq(accessLevelChangedRead, newMask);
  742. }
  743. END_TEST
  744. START_TEST(Node_ReadWrite_UserAccessLevel) {
  745. UA_Byte userAccessLevel;
  746. UA_StatusCode retval = UA_Client_readUserAccessLevelAttribute(client, nodeReadWriteInt, &userAccessLevel);
  747. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  748. ck_assert_int_eq(userAccessLevel, UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD);
  749. UA_Byte newMask = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
  750. retval = UA_Client_writeUserAccessLevelAttribute(client, nodeReadWriteInt, &newMask);
  751. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  752. }
  753. END_TEST
  754. START_TEST(Node_ReadWrite_MinimumSamplingInterval) {
  755. UA_Double minimumSamplingInterval = 0;
  756. UA_StatusCode retval = UA_Client_readMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &minimumSamplingInterval);
  757. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  758. ck_assert(minimumSamplingInterval == 0);
  759. // we want an array
  760. UA_Double newMinimumSamplingInterval = 1;
  761. retval = UA_Client_writeMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &newMinimumSamplingInterval);
  762. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  763. retval = UA_Client_readMinimumSamplingIntervalAttribute(client, nodeReadWriteGeneric, &minimumSamplingInterval);
  764. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  765. ck_assert(minimumSamplingInterval == newMinimumSamplingInterval);
  766. }
  767. END_TEST
  768. START_TEST(Node_ReadWrite_Historizing) {
  769. UA_Boolean historizing;
  770. UA_StatusCode retval = UA_Client_readHistorizingAttribute(client, nodeReadWriteInt, &historizing);
  771. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  772. ck_assert_int_eq(historizing, UA_FALSE);
  773. UA_Boolean newHistorizing = UA_TRUE;
  774. retval = UA_Client_writeHistorizingAttribute(client, nodeReadWriteInt, &newHistorizing);
  775. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  776. retval = UA_Client_readHistorizingAttribute(client, nodeReadWriteInt, &historizing);
  777. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  778. ck_assert_int_eq(historizing, newHistorizing);
  779. }
  780. END_TEST
  781. START_TEST(Node_ReadWrite_Executable) {
  782. UA_Boolean executable;
  783. UA_StatusCode retval = UA_Client_readExecutableAttribute(client, nodeReadWriteMethod, &executable);
  784. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  785. ck_assert_int_eq(executable, UA_TRUE);
  786. UA_Boolean newExecutable = UA_FALSE;
  787. retval = UA_Client_writeExecutableAttribute(client, nodeReadWriteMethod, &newExecutable);
  788. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  789. retval = UA_Client_readExecutableAttribute(client, nodeReadWriteMethod, &executable);
  790. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  791. ck_assert_int_eq(executable, newExecutable);
  792. }
  793. END_TEST
  794. START_TEST(Node_ReadWrite_UserExecutable) {
  795. UA_Boolean userExecutable;
  796. UA_StatusCode retval = UA_Client_readUserExecutableAttribute(client, nodeReadWriteMethod, &userExecutable);
  797. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  798. ck_assert_int_eq(userExecutable, UA_FALSE);
  799. UA_Boolean newUserExecutable = UA_TRUE;
  800. retval = UA_Client_writeUserExecutableAttribute(client, nodeReadWriteMethod, &newUserExecutable);
  801. ck_assert_uint_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED);
  802. }
  803. END_TEST
  804. #endif
  805. static Suite *testSuite_Client(void) {
  806. Suite *s = suite_create("Client Highlevel");
  807. TCase *tc_misc = tcase_create("Client Highlevel Misc");
  808. tcase_add_checked_fixture(tc_misc, setup, teardown);
  809. tcase_add_test(tc_misc, Misc_State);
  810. tcase_add_test(tc_misc, Misc_NamespaceGetIndex);
  811. suite_add_tcase(s, tc_misc);
  812. TCase *tc_nodes = tcase_create("Client Highlevel Node Management");
  813. tcase_add_checked_fixture(tc_nodes, setup, teardown);
  814. #ifdef UA_ENABLE_NODEMANAGEMENT
  815. tcase_add_test(tc_nodes, Node_Add);
  816. #endif
  817. tcase_add_test(tc_nodes, Node_Browse);
  818. tcase_add_test(tc_nodes, Node_Register);
  819. suite_add_tcase(s, tc_nodes);
  820. #ifdef UA_ENABLE_NODEMANAGEMENT
  821. TCase *tc_readwrite = tcase_create("Client Highlevel Read/Write");
  822. tcase_add_unchecked_fixture(tc_readwrite, setup, teardown);
  823. // first add some nodes where we test on
  824. tcase_add_test(tc_readwrite, Node_AddReadWriteNodes);
  825. // Now run all the read write tests
  826. tcase_add_test(tc_readwrite, Node_ReadWrite_Id);
  827. tcase_add_test(tc_readwrite, Node_ReadWrite_Class);
  828. tcase_add_test(tc_readwrite, Node_ReadWrite_BrowseName);
  829. tcase_add_test(tc_readwrite, Node_ReadWrite_DisplayName);
  830. tcase_add_test(tc_readwrite, Node_ReadWrite_Description);
  831. tcase_add_test(tc_readwrite, Node_ReadWrite_WriteMask);
  832. tcase_add_test(tc_readwrite, Node_ReadWrite_UserWriteMask);
  833. tcase_add_test(tc_readwrite, Node_ReadWrite_IsAbstract);
  834. tcase_add_test(tc_readwrite, Node_ReadWrite_Symmetric);
  835. tcase_add_test(tc_readwrite, Node_ReadWrite_InverseName);
  836. tcase_add_test(tc_readwrite, Node_ReadWrite_ContainsNoLoops);
  837. tcase_add_test(tc_readwrite, Node_ReadWrite_EventNotifier);
  838. tcase_add_test(tc_readwrite, Node_ReadWrite_Value);
  839. tcase_add_test(tc_readwrite, Node_ReadWrite_DataType);
  840. tcase_add_test(tc_readwrite, Node_ReadWrite_ValueRank);
  841. tcase_add_test(tc_readwrite, Node_ReadWrite_ArrayDimensions);
  842. tcase_add_test(tc_readwrite, Node_ReadWrite_AccessLevel);
  843. tcase_add_test(tc_readwrite, Node_ReadWrite_UserAccessLevel);
  844. tcase_add_test(tc_readwrite, Node_ReadWrite_MinimumSamplingInterval);
  845. tcase_add_test(tc_readwrite, Node_ReadWrite_Historizing);
  846. tcase_add_test(tc_readwrite, Node_ReadWrite_Executable);
  847. tcase_add_test(tc_readwrite, Node_ReadWrite_UserExecutable);
  848. suite_add_tcase(s, tc_readwrite);
  849. #endif
  850. return s;
  851. }
  852. int main(void) {
  853. Suite *s = testSuite_Client();
  854. SRunner *sr = srunner_create(s);
  855. srunner_set_fork_status(sr, CK_NOFORK);
  856. srunner_run_all(sr, CK_NORMAL);
  857. int number_failed = srunner_ntests_failed(sr);
  858. srunner_free(sr);
  859. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  860. }