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. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  260. attr.writeMask = UA_WRITEMASK_ARRRAYDIMENSIONS;
  261. UA_Int32 values[2];
  262. values[0] = 10;
  263. values[1] = 20;
  264. UA_Variant_setArray(&attr.value, values, 2, &UA_TYPES[UA_TYPES_INT32]);
  265. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  266. attr.valueRank = 1; /* array with one dimension */
  267. UA_UInt32 arrayDims[1] = {2};
  268. attr.arrayDimensions = arrayDims;
  269. attr.arrayDimensionsSize = 1;
  270. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  271. unitTestNodeId,
  272. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  273. UA_QUALIFIEDNAME(1, "Array"),
  274. UA_NODEID_NULL, attr, &nodeArrayId);
  275. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  276. }
  277. // create Variable 'Bottom' within UnitTest Object
  278. {
  279. UA_VariableAttributes attr;
  280. UA_VariableAttributes_init(&attr);
  281. attr.description = UA_LOCALIZEDTEXT("en_US", "Int");
  282. attr.displayName = UA_LOCALIZEDTEXT("en_US", "Int");
  283. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  284. UA_Int32 int_value = 5678;
  285. UA_Variant_setScalar(&attr.value, &int_value, &UA_TYPES[UA_TYPES_INT32]);
  286. attr.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  287. retval = UA_Client_addVariableNode(client, UA_NODEID_NULL,
  288. unitTestNodeId,
  289. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  290. UA_QUALIFIEDNAME(1, "Int"),
  291. UA_NODEID_NULL, attr, &nodeIntId);
  292. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  293. }
  294. // iterate over children
  295. {
  296. retval = UA_Client_forEachChildNodeCall(client, unitTestNodeId,
  297. nodeIter, NULL);
  298. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  299. ck_assert(UA_NodeId_equal(&nodeArrayId, &iteratedNodes[0]));
  300. ck_assert(UA_NodeId_equal(&nodeIntId, &iteratedNodes[1]));
  301. }
  302. /* Read attribute */
  303. UA_Int32 value = 0;
  304. UA_Variant *val = UA_Variant_new();
  305. retval = UA_Client_readValueAttribute(client, nodeIntId, val);
  306. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  307. ck_assert(UA_Variant_isScalar(val) && val->type == &UA_TYPES[UA_TYPES_INT32]);
  308. value = *(UA_Int32*)val->data;
  309. ck_assert_int_eq(value, 5678);
  310. UA_Variant_delete(val);
  311. /* Write attribute */
  312. value++;
  313. val = UA_Variant_new();
  314. UA_Variant_setScalarCopy(val, &value, &UA_TYPES[UA_TYPES_INT32]);
  315. retval = UA_Client_writeValueAttribute(client, nodeIntId, val);
  316. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  317. UA_Variant_delete(val);
  318. /* Read again to check value */
  319. val = UA_Variant_new();
  320. retval = UA_Client_readValueAttribute(client, nodeIntId, val);
  321. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  322. ck_assert(UA_Variant_isScalar(val) && val->type == &UA_TYPES[UA_TYPES_INT32]);
  323. value = *(UA_Int32*)val->data;
  324. ck_assert_int_eq(value, 5679);
  325. UA_Variant_delete(val);
  326. // Disabled for now, we need a better unit test for this
  327. /*UA_UInt32 arrayDimsNew[] = {3};
  328. retval = UA_Client_writeArrayDimensionsAttribute(client, nodeArrayId, arrayDimsNew , 1);
  329. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  330. UA_UInt32 *arrayDimsRead;
  331. size_t arrayDimsReadSize;
  332. retval = UA_Client_readArrayDimensionsAttribute(client, nodeArrayId, &arrayDimsRead , &arrayDimsReadSize);
  333. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  334. ck_assert_int_eq(arrayDimsReadSize, 1);
  335. ck_assert_int_eq(arrayDimsRead[0], 3);
  336. UA_Array_delete(arrayDimsRead, arrayDimsReadSize, &UA_TYPES[UA_TYPES_UINT32]);*/
  337. }
  338. END_TEST
  339. START_TEST(Node_Browse)
  340. {
  341. // Browse node in server folder
  342. {
  343. UA_BrowseRequest bReq;
  344. UA_BrowseRequest_init(&bReq);
  345. // normally is set to 0, to get all the nodes, but we want to test browse next
  346. bReq.requestedMaxReferencesPerNode = 1;
  347. bReq.nodesToBrowse = UA_BrowseDescription_new();
  348. bReq.nodesToBrowseSize = 1;
  349. bReq.nodesToBrowse[0].nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER);
  350. bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL;
  351. UA_BrowseResponse bResp = UA_Client_Service_browse(client, bReq);
  352. ck_assert_uint_eq(bResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  353. ck_assert_uint_eq(bResp.resultsSize, 1);
  354. ck_assert_uint_eq(bResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  355. ck_assert_uint_eq(bResp.results[0].referencesSize, 1);
  356. /* References might have a different order in generated nodesets */
  357. /* UA_ReferenceDescription *ref = &(bResp.results[0].references[0]); */
  358. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVERTYPE); */
  359. // browse next
  360. UA_BrowseNextRequest bNextReq;
  361. UA_BrowseNextRequest_init(&bNextReq);
  362. // normally is set to 0, to get all the nodes, but we want to test browse next
  363. bNextReq.releaseContinuationPoints = UA_FALSE;
  364. bNextReq.continuationPoints = &bResp.results[0].continuationPoint;
  365. bNextReq.continuationPointsSize = 1;
  366. UA_BrowseNextResponse bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  367. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  368. ck_assert_uint_eq(bNextResp.resultsSize, 1);
  369. ck_assert_uint_eq(bNextResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  370. ck_assert_uint_eq(bNextResp.results[0].referencesSize, 1);
  371. /* ref = &(bNextResp.results[0].references[0]); */
  372. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVER_NAMESPACEARRAY); */
  373. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  374. bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  375. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  376. ck_assert_uint_eq(bNextResp.resultsSize, 1);
  377. ck_assert_uint_eq(bNextResp.results[0].statusCode, UA_STATUSCODE_GOOD);
  378. ck_assert_uint_eq(bNextResp.results[0].referencesSize, 1);
  379. /* ref = &(bNextResp.results[0].references[0]); */
  380. /* ck_assert_uint_eq(ref->nodeId.nodeId.identifier.numeric, UA_NS0ID_SERVER_SERVERARRAY); */
  381. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  382. // release continuation point. Result is then empty
  383. bNextReq.releaseContinuationPoints = UA_TRUE;
  384. bNextResp = UA_Client_Service_browseNext(client, bNextReq);
  385. UA_BrowseNextResponse_deleteMembers(&bNextResp);
  386. ck_assert_uint_eq(bNextResp.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  387. ck_assert_uint_eq(bNextResp.resultsSize, 0);
  388. UA_BrowseRequest_deleteMembers(&bReq);
  389. UA_BrowseResponse_deleteMembers(&bResp);
  390. // already deleted by browse request
  391. bNextReq.continuationPoints = NULL;
  392. bNextReq.continuationPointsSize = 0;
  393. UA_BrowseNextRequest_deleteMembers(&bNextReq);
  394. }
  395. }
  396. END_TEST
  397. START_TEST(Node_Register)
  398. {
  399. {
  400. UA_RegisterNodesRequest req;
  401. UA_RegisterNodesRequest_init(&req);
  402. req.nodesToRegister = UA_NodeId_new();
  403. req.nodesToRegister[0] = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
  404. req.nodesToRegisterSize = 1;
  405. UA_RegisterNodesResponse res = UA_Client_Service_registerNodes(client, req);
  406. ck_assert_uint_eq(res.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  407. ck_assert_uint_eq(res.registeredNodeIdsSize, 1);
  408. UA_UnregisterNodesRequest reqUn;
  409. UA_UnregisterNodesRequest_init(&reqUn);
  410. reqUn.nodesToUnregister = UA_NodeId_new();
  411. reqUn.nodesToUnregister[0] = res.registeredNodeIds[0];
  412. reqUn.nodesToUnregisterSize = 1;
  413. UA_UnregisterNodesResponse resUn = UA_Client_Service_unregisterNodes(client, reqUn);
  414. ck_assert_uint_eq(resUn.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  415. UA_UnregisterNodesRequest_deleteMembers(&reqUn);
  416. UA_UnregisterNodesResponse_deleteMembers(&resUn);
  417. UA_RegisterNodesRequest_deleteMembers(&req);
  418. UA_RegisterNodesResponse_deleteMembers(&res);
  419. }
  420. }
  421. END_TEST
  422. static Suite *testSuite_Client(void) {
  423. Suite *s = suite_create("Client Highlevel");
  424. TCase *tc_misc = tcase_create("Client Highlevel Misc");
  425. tcase_add_checked_fixture(tc_misc, setup, teardown);
  426. tcase_add_test(tc_misc, Misc_State);
  427. tcase_add_test(tc_misc, Misc_NamespaceGetIndex);
  428. suite_add_tcase(s, tc_misc);
  429. TCase *tc_nodes = tcase_create("Client Highlevel Node Management");
  430. tcase_add_checked_fixture(tc_nodes, setup, teardown);
  431. tcase_add_test(tc_nodes, Node_Add);
  432. tcase_add_test(tc_nodes, Node_Browse);
  433. tcase_add_test(tc_nodes, Node_ReadWrite);
  434. tcase_add_test(tc_nodes, Node_Register);
  435. suite_add_tcase(s, tc_nodes);
  436. return s;
  437. }
  438. int main(void) {
  439. Suite *s = testSuite_Client();
  440. SRunner *sr = srunner_create(s);
  441. srunner_set_fork_status(sr, CK_NOFORK);
  442. srunner_run_all(sr, CK_NORMAL);
  443. int number_failed = srunner_ntests_failed(sr);
  444. srunner_free(sr);
  445. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  446. }