check_client_highlevel.c 22 KB

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