check_client_highlevel.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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_Boolean *running;
  15. UA_ServerNetworkLayer nl;
  16. pthread_t 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. static void *serverloop(void *_) {
  21. while (*running)
  22. UA_Server_run_iterate(server, true);
  23. return NULL;
  24. }
  25. static void setup(void) {
  26. running = UA_Boolean_new();
  27. *running = true;
  28. UA_ServerConfig config = UA_ServerConfig_standard;
  29. nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
  30. config.networkLayers = &nl;
  31. config.networkLayersSize = 1;
  32. server = UA_Server_new(config);
  33. ck_assert_uint_eq(2, UA_Server_addNamespace(server, CUSTOM_NS));
  34. UA_Server_run_startup(server);
  35. pthread_create(&server_thread, NULL, serverloop, NULL);
  36. client = UA_Client_new(UA_ClientConfig_standard);
  37. UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:16664");
  38. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  39. }
  40. static void teardown(void) {
  41. UA_Client_disconnect(client);
  42. UA_Client_delete(client);
  43. *running = false;
  44. pthread_join(server_thread, NULL);
  45. UA_Server_run_shutdown(server);
  46. UA_Boolean_delete(running);
  47. UA_Server_delete(server);
  48. nl.deleteMembers(&nl);
  49. }
  50. START_TEST(Misc_State) {
  51. UA_ClientState state = UA_Client_getState(client);
  52. ck_assert_uint_eq(state, UA_CLIENTSTATE_CONNECTED);
  53. }
  54. END_TEST
  55. START_TEST(Misc_NamespaceGetIndex) {
  56. UA_UInt16 idx;
  57. UA_String ns = UA_STRING(CUSTOM_NS);
  58. UA_StatusCode retval = UA_Client_NamespaceGetIndex(client, &ns, &idx);
  59. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  60. ck_assert_uint_eq(idx, 2);
  61. // namespace uri is case sensitive
  62. ns = UA_STRING(CUSTOM_NS_UPPER);
  63. retval = UA_Client_NamespaceGetIndex(client, &ns, &idx);
  64. ck_assert_uint_eq(retval, UA_STATUSCODE_BADNOTFOUND);
  65. }
  66. END_TEST
  67. UA_NodeId newReferenceTypeId;
  68. UA_NodeId newObjectTypeId;
  69. UA_NodeId newDataTypeId;
  70. UA_NodeId newVariableTypeId;
  71. UA_NodeId newObjectId;
  72. UA_NodeId newVariableId;
  73. UA_NodeId newMethodId;
  74. UA_NodeId newViewId;
  75. START_TEST(Node_Add) {
  76. UA_StatusCode retval;
  77. // Create custom reference type 'HasSubSubType' as child of HasSubtype
  78. {
  79. UA_ReferenceTypeAttributes attr;
  80. UA_ReferenceTypeAttributes_init(&attr);
  81. attr.description = UA_LOCALIZEDTEXT("en_US", "Some HasSubSubType");
  82. attr.displayName = UA_LOCALIZEDTEXT("en_US", "HasSubSubType");
  83. retval = UA_Client_addReferenceTypeNode(client, UA_NODEID_NULL,
  84. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  85. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  86. UA_QUALIFIEDNAME(1, "HasSubSubType"), attr,
  87. &newReferenceTypeId);
  88. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  89. }
  90. // Create TestObjectType SubType within BaseObjectType
  91. {
  92. UA_ObjectTypeAttributes attr;
  93. UA_ObjectTypeAttributes_init(&attr);
  94. attr.description = UA_LOCALIZEDTEXT("en_US", "Some TestObjectType");
  95. attr.displayName = UA_LOCALIZEDTEXT("en_US", "TestObjectType");
  96. retval = UA_Client_addObjectTypeNode(client, UA_NODEID_NULL,
  97. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
  98. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  99. UA_QUALIFIEDNAME(1, "TestObjectType"), attr, &newObjectTypeId);
  100. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  101. }
  102. // Create Int128 DataType within Integer Datatype
  103. {
  104. UA_DataTypeAttributes attr;
  105. UA_DataTypeAttributes_init(&attr);
  106. attr.description = UA_LOCALIZEDTEXT("en_US", "Some Int128");
  107. attr.displayName = UA_LOCALIZEDTEXT("en_US", "Int128");
  108. retval = UA_Client_addDataTypeNode(client, UA_NODEID_NULL,
  109. UA_NODEID_NUMERIC(0, UA_NS0ID_INTEGER),
  110. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  111. UA_QUALIFIEDNAME(1, "Int128"), attr, &newDataTypeId);
  112. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  113. }
  114. // Create PointType VariableType within BaseDataVariableType
  115. {
  116. UA_VariableTypeAttributes attr;
  117. UA_VariableTypeAttributes_init(&attr);
  118. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  119. attr.valueRank = 1; /* array with one dimension */
  120. UA_UInt32 arrayDims[1] = {2};
  121. attr.arrayDimensions = arrayDims;
  122. attr.arrayDimensionsSize = 1;
  123. attr.displayName = UA_LOCALIZEDTEXT("en_US", "PointType");
  124. /* a matching default value is required */
  125. UA_Double zero[2] = {0.0, 0.0};
  126. UA_Variant_setArray(&attr.value, zero, 2, &UA_TYPES[UA_TYPES_INT32]);
  127. retval = UA_Client_addVariableTypeNode(client, UA_NODEID_NULL,
  128. UA_NODEID_NUMERIC(0, UA_NS0ID_BASEVARIABLETYPE),
  129. UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  130. UA_QUALIFIEDNAME(1, "PointType"), attr, &newVariableTypeId);
  131. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  132. }
  133. // create Coordinates Object within ObjectsFolder
  134. {
  135. UA_ObjectAttributes attr;
  136. UA_ObjectAttributes_init(&attr);
  137. attr.description = UA_LOCALIZEDTEXT("en_US", "Some Coordinates");
  138. attr.displayName = UA_LOCALIZEDTEXT("en_US", "Coordinates");
  139. retval = UA_Client_addObjectNode(client, UA_NODEID_NULL,
  140. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  141. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  142. UA_QUALIFIEDNAME(1, "Coordinates"),
  143. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), attr, &newObjectId);
  144. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  145. }
  146. // create Variable 'Top' within Coordinates Object
  147. {
  148. UA_VariableAttributes attr;
  149. UA_VariableAttributes_init(&attr);
  150. attr.description = UA_LOCALIZEDTEXT("en_US", "Top Coordinate");
  151. attr.displayName = UA_LOCALIZEDTEXT("en_US", "Top");
  152. UA_Int32 values[2] = {10, 20};
  153. UA_Variant_setArray(&attr.value, values, 2, &UA_TYPES[UA_TYPES_INT32]);
  154. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  155. attr.valueRank = 1; /* array with one dimension */
  156. UA_UInt32 arrayDims[1] = {2};
  157. attr.arrayDimensions = arrayDims;
  158. attr.arrayDimensionsSize = 1;
  159. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  160. newObjectId,
  161. UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY),
  162. UA_QUALIFIEDNAME(1, "Top"),
  163. newVariableTypeId, attr, &newVariableId);
  164. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  165. }
  166. // create Method 'Dummy' within Coordinates Object. Fails with BADNODECLASSINVALID
  167. {
  168. // creating a method from a client does not yet make much sense since the corresponding
  169. // action code can not be set from the client side
  170. UA_MethodAttributes attr;
  171. UA_MethodAttributes_init(&attr);
  172. attr.description = UA_LOCALIZEDTEXT("en_US", "Dummy method");
  173. attr.displayName = UA_LOCALIZEDTEXT("en_US", "Dummy");
  174. attr.executable = true;
  175. attr.userExecutable = true;
  176. retval = UA_Client_addMethodNode(client, UA_NODEID_NULL,
  177. newObjectId,
  178. UA_NODEID_NUMERIC(0, UA_NS0ID_HASORDEREDCOMPONENT),
  179. UA_QUALIFIEDNAME(1, "Dummy"),
  180. attr, &newMethodId);
  181. ck_assert_uint_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID);
  182. }
  183. // create View 'AllTopCoordinates' whithin Views Folder
  184. {
  185. UA_ViewAttributes attr;
  186. UA_ViewAttributes_init(&attr);
  187. attr.description = UA_LOCALIZEDTEXT("en_US", "List of all top coordinates");
  188. attr.displayName = UA_LOCALIZEDTEXT("en_US", "AllTopCoordinates");
  189. retval = UA_Client_addViewNode(client, UA_NODEID_NULL,
  190. UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER),
  191. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  192. UA_QUALIFIEDNAME(1, "AllTopCoordinates"),
  193. attr, &newViewId);
  194. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  195. }
  196. // Add 'Top' to view
  197. retval = UA_Client_addReference(client, newViewId, UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  198. UA_TRUE, UA_STRING_NULL,
  199. UA_EXPANDEDNODEID_NUMERIC(1, newObjectId.identifier.numeric),
  200. UA_NODECLASS_VARIABLE);
  201. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  202. // Delete 'Top' from view
  203. retval = UA_Client_deleteReference(client, newViewId,
  204. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), UA_TRUE,
  205. UA_EXPANDEDNODEID_NUMERIC(1, newObjectId.identifier.numeric), UA_TRUE);
  206. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  207. // Delete 'AllTopCoordinates' view
  208. retval = UA_Client_deleteNode(client, newViewId, UA_TRUE);
  209. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  210. }
  211. END_TEST
  212. unsigned int iteratedNodeCount = 0;
  213. UA_NodeId iteratedNodes[2];
  214. static UA_StatusCode
  215. nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, void *handle) {
  216. if (isInverse || (referenceTypeId.identifierType == UA_NODEIDTYPE_NUMERIC &&
  217. referenceTypeId.identifier.numeric == UA_NS0ID_HASTYPEDEFINITION))
  218. return UA_STATUSCODE_GOOD;
  219. if (iteratedNodeCount >= 2)
  220. return UA_STATUSCODE_BADINDEXRANGEINVALID;
  221. UA_NodeId_copy(&childId, &iteratedNodes[iteratedNodeCount]);
  222. iteratedNodeCount++;
  223. return UA_STATUSCODE_GOOD;
  224. }
  225. START_TEST(Node_ReadWrite) {
  226. UA_StatusCode retval;
  227. // Create a folder with two variables for testing
  228. UA_NodeId unitTestNodeId;
  229. UA_NodeId nodeArrayId;
  230. UA_NodeId nodeIntId;
  231. // create Coordinates Object within ObjectsFolder
  232. {
  233. UA_ObjectAttributes attr;
  234. UA_ObjectAttributes_init(&attr);
  235. attr.description = UA_LOCALIZEDTEXT("en_US", "UnitTest");
  236. attr.displayName = UA_LOCALIZEDTEXT("en_US", "UnitTest");
  237. retval = UA_Client_addObjectNode(client, UA_NODEID_NULL,
  238. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  239. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  240. UA_QUALIFIEDNAME(1, "UnitTest"),
  241. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), attr, &unitTestNodeId);
  242. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  243. }
  244. // create Variable 'Top' within UnitTest Object
  245. {
  246. UA_VariableAttributes attr;
  247. UA_VariableAttributes_init(&attr);
  248. attr.description = UA_LOCALIZEDTEXT("en_US", "Array");
  249. attr.displayName = UA_LOCALIZEDTEXT("en_US", "Array");
  250. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  251. attr.writeMask = UA_WRITEMASK_ARRRAYDIMENSIONS;
  252. UA_Int32 values[2];
  253. values[0] = 10;
  254. values[1] = 20;
  255. UA_Variant_setArray(&attr.value, values, 2, &UA_TYPES[UA_TYPES_INT32]);
  256. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  257. attr.valueRank = 1; /* array with one dimension */
  258. UA_UInt32 arrayDims[1] = {2};
  259. attr.arrayDimensions = arrayDims;
  260. attr.arrayDimensionsSize = 1;
  261. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  262. unitTestNodeId,
  263. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  264. UA_QUALIFIEDNAME(1, "Array"),
  265. UA_NODEID_NULL, attr, &nodeArrayId);
  266. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  267. }
  268. // create Variable 'Bottom' within UnitTest Object
  269. {
  270. UA_VariableAttributes attr;
  271. UA_VariableAttributes_init(&attr);
  272. attr.description = UA_LOCALIZEDTEXT("en_US", "Int");
  273. attr.displayName = UA_LOCALIZEDTEXT("en_US", "Int");
  274. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  275. UA_Int32 int_value = 5678;
  276. UA_Variant_setScalar(&attr.value, &int_value, &UA_TYPES[UA_TYPES_INT32]);
  277. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  278. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  279. unitTestNodeId,
  280. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  281. UA_QUALIFIEDNAME(1, "Int"),
  282. UA_NODEID_NULL, attr, &nodeIntId);
  283. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  284. }
  285. // iterate over children
  286. retval = UA_Client_forEachChildNodeCall(client, unitTestNodeId, nodeIter, NULL);
  287. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  288. ck_assert(UA_NodeId_equal(&nodeArrayId, &iteratedNodes[0]));
  289. ck_assert(UA_NodeId_equal(&nodeIntId, &iteratedNodes[1]));
  290. /* Read attribute */
  291. UA_Int32 value = 0;
  292. UA_Variant *val = UA_Variant_new();
  293. retval = UA_Client_readValueAttribute(client, nodeIntId, val);
  294. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  295. ck_assert(UA_Variant_isScalar(val) && val->type == &UA_TYPES[UA_TYPES_INT32]);
  296. value = *(UA_Int32*)val->data;
  297. ck_assert_int_eq(value, 5678);
  298. UA_Variant_delete(val);
  299. /* Write attribute */
  300. value++;
  301. val = UA_Variant_new();
  302. UA_Variant_setScalarCopy(val, &value, &UA_TYPES[UA_TYPES_INT32]);
  303. retval = UA_Client_writeValueAttribute(client, nodeIntId, val);
  304. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  305. UA_Variant_delete(val);
  306. /* Read again to check value */
  307. val = UA_Variant_new();
  308. retval = UA_Client_readValueAttribute(client, nodeIntId, val);
  309. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  310. ck_assert(UA_Variant_isScalar(val) && val->type == &UA_TYPES[UA_TYPES_INT32]);
  311. value = *(UA_Int32*)val->data;
  312. ck_assert_int_eq(value, 5679);
  313. UA_Variant_delete(val);
  314. // Disabled for now, we need a better unit test for this
  315. /*UA_UInt32 arrayDimsNew[] = {3};
  316. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeArrayId, arrayDimsNew , 1);
  317. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  318. UA_UInt32 *arrayDimsRead;
  319. size_t arrayDimsReadSize;
  320. retval = UA_Client_readArrayDimensionsAttribute(client, nodeArrayId, &arrayDimsRead , &arrayDimsReadSize);
  321. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  322. ck_assert_int_eq(arrayDimsReadSize, 1);
  323. ck_assert_int_eq(arrayDimsRead[0], 3);
  324. UA_Array_delete(arrayDimsRead, arrayDimsReadSize, &UA_TYPES[UA_TYPES_UINT32]);*/
  325. }
  326. END_TEST
  327. START_TEST(Node_Browse) {
  328. // Browse node in server folder
  329. UA_BrowseRequest bReq;
  330. UA_BrowseRequest_init(&bReq);
  331. // normally is set to 0, to get all the nodes, but we want to test browse next
  332. bReq.requestedMaxReferencesPerNode = 1;
  333. bReq.nodesToBrowse = UA_BrowseDescription_new();
  334. bReq.nodesToBrowseSize = 1;
  335. bReq.nodesToBrowse[0].nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER);
  336. bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL;
  337. UA_BrowseResponse bResp = UA_Client_Service_browse(client, bReq);
  338. ck_assert_uint_eq(bResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  339. ck_assert_uint_eq(bResp.resultsSize, 1);
  340. ck_assert_uint_eq(bResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  341. ck_assert_uint_eq(bResp.results[0].referencesSize, 1);
  342. /* References might have a different order in generated nodesets */
  343. /* UA_ReferenceDescription *ref = &(bResp.results[0].references[0]); */
  344. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVERTYPE); */
  345. // browse next
  346. UA_BrowseNextRequest bNextReq;
  347. UA_BrowseNextRequest_init(&bNextReq);
  348. // normally is set to 0, to get all the nodes, but we want to test browse next
  349. bNextReq.releaseContinuationPoints = UA_FALSE;
  350. bNextReq.continuationPoints = &bResp.results[0].continuationPoint;
  351. bNextReq.continuationPointsSize = 1;
  352. UA_BrowseNextResponse bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  353. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  354. ck_assert_uint_eq(bNextResp.resultsSize, 1);
  355. ck_assert_uint_eq(bNextResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  356. ck_assert_uint_eq(bNextResp.results[0].referencesSize, 1);
  357. /* ref = &(bNextResp.results[0].references[0]); */
  358. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVER_NAMESPACEARRAY); */
  359. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  360. bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  361. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  362. ck_assert_uint_eq(bNextResp.resultsSize, 1);
  363. ck_assert_uint_eq(bNextResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  364. ck_assert_uint_eq(bNextResp.results[0].referencesSize, 1);
  365. /* ref = &(bNextResp.results[0].references[0]); */
  366. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVER_SERVERARRAY); */
  367. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  368. // release continuation point. Result is then empty
  369. bNextReq.releaseContinuationPoints = UA_TRUE;
  370. bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  371. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  372. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  373. ck_assert_uint_eq(bNextResp.resultsSize, 0);
  374. UA_BrowseRequest_deleteMembers(&bReq);
  375. UA_BrowseResponse_deleteMembers(&bResp);
  376. // already deleted by browse request
  377. bNextReq.continuationPoints = NULL;
  378. bNextReq.continuationPointsSize = 0;
  379. UA_BrowseNextRequest_deleteMembers(&bNextReq);
  380. }
  381. END_TEST
  382. START_TEST(Node_Register) {
  383. UA_RegisterNodesRequest req;
  384. UA_RegisterNodesRequest_init(&req);
  385. req.nodesToRegister = UA_NodeId_new();
  386. req.nodesToRegister[0] = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
  387. req.nodesToRegisterSize = 1;
  388. UA_RegisterNodesResponse res = UA_Client_Service_registerNodes(client, req);
  389. ck_assert_uint_eq(res.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  390. ck_assert_uint_eq(res.registeredNodeIdsSize, 1);
  391. UA_UnregisterNodesRequest reqUn;
  392. UA_UnregisterNodesRequest_init(&reqUn);
  393. reqUn.nodesToUnregister = UA_NodeId_new();
  394. reqUn.nodesToUnregister[0] = res.registeredNodeIds[0];
  395. reqUn.nodesToUnregisterSize = 1;
  396. UA_UnregisterNodesResponse resUn = UA_Client_Service_unregisterNodes(client, reqUn);
  397. ck_assert_uint_eq(resUn.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  398. UA_UnregisterNodesRequest_deleteMembers(&reqUn);
  399. UA_UnregisterNodesResponse_deleteMembers(&resUn);
  400. UA_RegisterNodesRequest_deleteMembers(&req);
  401. UA_RegisterNodesResponse_deleteMembers(&res);
  402. }
  403. END_TEST
  404. static Suite *testSuite_Client(void) {
  405. Suite *s = suite_create("Client Highlevel");
  406. TCase *tc_misc = tcase_create("Client Highlevel Misc");
  407. tcase_add_checked_fixture(tc_misc, setup, teardown);
  408. tcase_add_test(tc_misc, Misc_State);
  409. tcase_add_test(tc_misc, Misc_NamespaceGetIndex);
  410. suite_add_tcase(s, tc_misc);
  411. TCase *tc_nodes = tcase_create("Client Highlevel Node Management");
  412. tcase_add_checked_fixture(tc_nodes, setup, teardown);
  413. tcase_add_test(tc_nodes, Node_Add);
  414. tcase_add_test(tc_nodes, Node_Browse);
  415. tcase_add_test(tc_nodes, Node_ReadWrite);
  416. tcase_add_test(tc_nodes, Node_Register);
  417. suite_add_tcase(s, tc_nodes);
  418. return s;
  419. }
  420. int main(void) {
  421. Suite *s = testSuite_Client();
  422. SRunner *sr = srunner_create(s);
  423. srunner_set_fork_status(sr, CK_NOFORK);
  424. srunner_run_all(sr, CK_NORMAL);
  425. int number_failed = srunner_ntests_failed(sr);
  426. srunner_free(sr);
  427. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  428. }