check_client_highlevel.c 43 KB

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