check_client_highlevel.c 20 KB

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