check_client_highlevel.c 45 KB

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