check_services_subscriptions.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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 "ua_server.h"
  5. #include "server/ua_services.h"
  6. #include "server/ua_server_internal.h"
  7. #include "server/ua_subscription.h"
  8. #include "ua_config_default.h"
  9. #include "check.h"
  10. #include "testing_clock.h"
  11. static UA_Server *server = NULL;
  12. static UA_ServerConfig *config = NULL;
  13. static void setup(void) {
  14. config = UA_ServerConfig_new_default();
  15. server = UA_Server_new(config);
  16. UA_Server_run_startup(server);
  17. }
  18. static void teardown(void) {
  19. UA_Server_run_shutdown(server);
  20. UA_Server_delete(server);
  21. UA_ServerConfig_delete(config);
  22. }
  23. #ifdef UA_ENABLE_SUBSCRIPTIONS
  24. UA_UInt32 subscriptionId;
  25. UA_UInt32 monitoredItemId;
  26. START_TEST(Server_createSubscription) {
  27. /* Create a subscription */
  28. UA_CreateSubscriptionRequest request;
  29. UA_CreateSubscriptionRequest_init(&request);
  30. request.publishingEnabled = true;
  31. UA_CreateSubscriptionResponse response;
  32. UA_CreateSubscriptionResponse_init(&response);
  33. Service_CreateSubscription(server, &adminSession, &request, &response);
  34. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  35. subscriptionId = response.subscriptionId;
  36. UA_CreateSubscriptionResponse_deleteMembers(&response);
  37. }
  38. END_TEST
  39. START_TEST(Server_modifySubscription) {
  40. UA_ModifySubscriptionRequest request;
  41. UA_ModifySubscriptionRequest_init(&request);
  42. request.subscriptionId = subscriptionId;
  43. // just some arbitrary numbers to test. They have no specific reason
  44. request.requestedPublishingInterval = 100; // in ms
  45. request.requestedLifetimeCount = 1000;
  46. request.requestedMaxKeepAliveCount = 1000;
  47. request.maxNotificationsPerPublish = 1;
  48. request.priority = 10;
  49. UA_ModifySubscriptionResponse response;
  50. UA_ModifySubscriptionResponse_init(&response);
  51. Service_ModifySubscription(server, &adminSession, &request, &response);
  52. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  53. UA_ModifySubscriptionResponse_deleteMembers(&response);
  54. }
  55. END_TEST
  56. START_TEST(Server_setPublishingMode) {
  57. UA_SetPublishingModeRequest request;
  58. UA_SetPublishingModeRequest_init(&request);
  59. request.publishingEnabled = UA_TRUE;
  60. request.subscriptionIdsSize = 1;
  61. request.subscriptionIds = &subscriptionId;
  62. UA_SetPublishingModeResponse response;
  63. UA_SetPublishingModeResponse_init(&response);
  64. Service_SetPublishingMode(server, &adminSession, &request, &response);
  65. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  66. ck_assert_uint_eq(response.resultsSize, 1);
  67. ck_assert_uint_eq(response.results[0], UA_STATUSCODE_GOOD);
  68. UA_SetPublishingModeResponse_deleteMembers(&response);
  69. }
  70. END_TEST
  71. START_TEST(Server_republish) {
  72. UA_RepublishRequest request;
  73. UA_RepublishRequest_init(&request);
  74. request.subscriptionId = subscriptionId;
  75. request.retransmitSequenceNumber = 0;
  76. UA_RepublishResponse response;
  77. UA_RepublishResponse_init(&response);
  78. Service_Republish(server, &adminSession, &request, &response);
  79. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_BADMESSAGENOTAVAILABLE);
  80. UA_RepublishResponse_deleteMembers(&response);
  81. }
  82. END_TEST
  83. START_TEST(Server_republish_invalid) {
  84. UA_RepublishRequest request;
  85. UA_RepublishRequest_init(&request);
  86. request.subscriptionId = subscriptionId;
  87. request.retransmitSequenceNumber = 0;
  88. UA_RepublishResponse response;
  89. UA_RepublishResponse_init(&response);
  90. Service_Republish(server, &adminSession, &request, &response);
  91. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_BADSUBSCRIPTIONIDINVALID);
  92. UA_RepublishResponse_deleteMembers(&response);
  93. }
  94. END_TEST
  95. START_TEST(Server_deleteSubscription) {
  96. /* Remove the subscription */
  97. UA_DeleteSubscriptionsRequest del_request;
  98. UA_DeleteSubscriptionsRequest_init(&del_request);
  99. del_request.subscriptionIdsSize = 1;
  100. del_request.subscriptionIds = &subscriptionId;
  101. UA_DeleteSubscriptionsResponse del_response;
  102. UA_DeleteSubscriptionsResponse_init(&del_response);
  103. Service_DeleteSubscriptions(server, &adminSession, &del_request, &del_response);
  104. ck_assert_uint_eq(del_response.resultsSize, 1);
  105. ck_assert_uint_eq(del_response.results[0], UA_STATUSCODE_GOOD);
  106. UA_DeleteSubscriptionsResponse_deleteMembers(&del_response);
  107. }
  108. END_TEST
  109. START_TEST(Server_publishCallback) {
  110. /* Create a subscription */
  111. UA_CreateSubscriptionRequest request;
  112. UA_CreateSubscriptionResponse response;
  113. UA_CreateSubscriptionRequest_init(&request);
  114. request.publishingEnabled = true;
  115. UA_CreateSubscriptionResponse_init(&response);
  116. Service_CreateSubscription(server, &adminSession, &request, &response);
  117. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  118. UA_UInt32 subscriptionId1 = response.subscriptionId;
  119. UA_CreateSubscriptionResponse_deleteMembers(&response);
  120. /* Create a second subscription */
  121. UA_CreateSubscriptionRequest_init(&request);
  122. request.publishingEnabled = true;
  123. UA_CreateSubscriptionResponse_init(&response);
  124. Service_CreateSubscription(server, &adminSession, &request, &response);
  125. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  126. UA_UInt32 subscriptionId2 = response.subscriptionId;
  127. UA_Double publishingInterval = response.revisedPublishingInterval;
  128. ck_assert(publishingInterval > 0.0f);
  129. UA_CreateSubscriptionResponse_deleteMembers(&response);
  130. /* Keepalive is set to max initially */
  131. UA_Subscription *sub;
  132. LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry)
  133. ck_assert_uint_eq(sub->currentKeepAliveCount, sub->maxKeepAliveCount);
  134. /* Sleep until the publishing interval times out */
  135. UA_fakeSleep((UA_UInt32)publishingInterval + 1);
  136. UA_Server_run_iterate(server, false);
  137. UA_realSleep(100);
  138. LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
  139. if ((sub->subscriptionId == subscriptionId1) || (sub->subscriptionId == subscriptionId2))
  140. ck_assert_uint_eq(sub->currentKeepAliveCount, sub->maxKeepAliveCount+1);
  141. }
  142. /* Remove the subscriptions */
  143. UA_DeleteSubscriptionsRequest del_request;
  144. UA_DeleteSubscriptionsRequest_init(&del_request);
  145. UA_UInt32 removeIds[2] = {subscriptionId1, subscriptionId2};
  146. del_request.subscriptionIdsSize = 2;
  147. del_request.subscriptionIds = removeIds;
  148. UA_DeleteSubscriptionsResponse del_response;
  149. UA_DeleteSubscriptionsResponse_init(&del_response);
  150. Service_DeleteSubscriptions(server, &adminSession, &del_request, &del_response);
  151. ck_assert_uint_eq(del_response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  152. ck_assert_uint_eq(del_response.resultsSize, 2);
  153. ck_assert_uint_eq(del_response.results[0], UA_STATUSCODE_GOOD);
  154. ck_assert_uint_eq(del_response.results[1], UA_STATUSCODE_GOOD);
  155. UA_DeleteSubscriptionsResponse_deleteMembers(&del_response);
  156. }
  157. END_TEST
  158. START_TEST(Server_createMonitoredItems) {
  159. UA_CreateMonitoredItemsRequest request;
  160. UA_CreateMonitoredItemsRequest_init(&request);
  161. request.subscriptionId = subscriptionId;
  162. request.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
  163. UA_MonitoredItemCreateRequest item;
  164. UA_MonitoredItemCreateRequest_init(&item);
  165. UA_ReadValueId rvi;
  166. UA_ReadValueId_init(&rvi);
  167. rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER);
  168. rvi.attributeId = UA_ATTRIBUTEID_BROWSENAME;
  169. rvi.indexRange = UA_STRING_NULL;
  170. item.itemToMonitor = rvi;
  171. item.monitoringMode = UA_MONITORINGMODE_REPORTING;
  172. UA_MonitoringParameters params;
  173. UA_MonitoringParameters_init(&params);
  174. item.requestedParameters = params;
  175. request.itemsToCreateSize = 1;
  176. request.itemsToCreate = &item;
  177. UA_CreateMonitoredItemsResponse response;
  178. UA_CreateMonitoredItemsResponse_init(&response);
  179. Service_CreateMonitoredItems(server, &adminSession, &request, &response);
  180. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  181. ck_assert_uint_eq(response.resultsSize, 1);
  182. ck_assert_uint_eq(response.results[0].statusCode, UA_STATUSCODE_GOOD);
  183. monitoredItemId = response.results[0].monitoredItemId;
  184. ck_assert_uint_gt(monitoredItemId, 0);
  185. UA_MonitoredItemCreateRequest_deleteMembers(&item);
  186. UA_CreateMonitoredItemsResponse_deleteMembers(&response);
  187. }
  188. END_TEST
  189. START_TEST(Server_modifyMonitoredItems) {
  190. UA_ModifyMonitoredItemsRequest request;
  191. UA_ModifyMonitoredItemsRequest_init(&request);
  192. request.subscriptionId = subscriptionId;
  193. request.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
  194. UA_MonitoredItemModifyRequest item;
  195. UA_MonitoredItemModifyRequest_init(&item);
  196. UA_ReadValueId rvi;
  197. UA_ReadValueId_init(&rvi);
  198. rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER);
  199. rvi.attributeId = UA_ATTRIBUTEID_DESCRIPTION;
  200. rvi.indexRange = UA_STRING_NULL;
  201. item.monitoredItemId = monitoredItemId;
  202. UA_MonitoringParameters params;
  203. UA_MonitoringParameters_init(&params);
  204. item.requestedParameters = params;
  205. request.itemsToModifySize = 1;
  206. request.itemsToModify = &item;
  207. UA_ModifyMonitoredItemsResponse response;
  208. UA_ModifyMonitoredItemsResponse_init(&response);
  209. Service_ModifyMonitoredItems(server, &adminSession, &request, &response);
  210. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  211. ck_assert_uint_eq(response.resultsSize, 1);
  212. ck_assert_uint_eq(response.results[0].statusCode, UA_STATUSCODE_GOOD);
  213. UA_MonitoredItemModifyRequest_deleteMembers(&item);
  214. UA_ModifyMonitoredItemsResponse_deleteMembers(&response);
  215. }
  216. END_TEST
  217. START_TEST(Server_overflow) {
  218. /* Create a subscription */
  219. UA_CreateSubscriptionRequest createSubscriptionRequest;
  220. UA_CreateSubscriptionResponse createSubscriptionResponse;
  221. UA_CreateSubscriptionRequest_init(&createSubscriptionRequest);
  222. createSubscriptionRequest.publishingEnabled = true;
  223. UA_CreateSubscriptionResponse_init(&createSubscriptionResponse);
  224. Service_CreateSubscription(server, &adminSession, &createSubscriptionRequest, &createSubscriptionResponse);
  225. ck_assert_uint_eq(createSubscriptionResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  226. UA_UInt32 localSubscriptionId = createSubscriptionResponse.subscriptionId;
  227. UA_Double publishingInterval = createSubscriptionResponse.revisedPublishingInterval;
  228. ck_assert(publishingInterval > 0.0f);
  229. UA_CreateSubscriptionResponse_deleteMembers(&createSubscriptionResponse);
  230. /* Create a monitoredItem */
  231. UA_CreateMonitoredItemsRequest createMonitoredItemsRequest;
  232. UA_CreateMonitoredItemsRequest_init(&createMonitoredItemsRequest);
  233. createMonitoredItemsRequest.subscriptionId = localSubscriptionId;
  234. createMonitoredItemsRequest.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
  235. UA_MonitoredItemCreateRequest item;
  236. UA_MonitoredItemCreateRequest_init(&item);
  237. UA_ReadValueId rvi;
  238. UA_ReadValueId_init(&rvi);
  239. rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
  240. rvi.attributeId = UA_ATTRIBUTEID_BROWSENAME;
  241. rvi.indexRange = UA_STRING_NULL;
  242. item.itemToMonitor = rvi;
  243. item.monitoringMode = UA_MONITORINGMODE_REPORTING;
  244. UA_MonitoringParameters params;
  245. UA_MonitoringParameters_init(&params);
  246. item.requestedParameters = params;
  247. item.requestedParameters.queueSize = 3;
  248. item.requestedParameters.discardOldest = true;
  249. createMonitoredItemsRequest.itemsToCreateSize = 1;
  250. createMonitoredItemsRequest.itemsToCreate = &item;
  251. UA_CreateMonitoredItemsResponse createMonitoredItemsResponse;
  252. UA_CreateMonitoredItemsResponse_init(&createMonitoredItemsResponse);
  253. Service_CreateMonitoredItems(server, &adminSession, &createMonitoredItemsRequest, &createMonitoredItemsResponse);
  254. ck_assert_uint_eq(createMonitoredItemsResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  255. ck_assert_uint_eq(createMonitoredItemsResponse.resultsSize, 1);
  256. ck_assert_uint_eq(createMonitoredItemsResponse.results[0].statusCode, UA_STATUSCODE_GOOD);
  257. UA_UInt32 localMonitoredItemId = createMonitoredItemsResponse.results[0].monitoredItemId;
  258. ck_assert_uint_gt(localMonitoredItemId, 0);
  259. UA_MonitoredItemCreateRequest_deleteMembers(&item);
  260. UA_CreateMonitoredItemsResponse_deleteMembers(&createMonitoredItemsResponse);
  261. UA_MonitoredItem *mon = NULL;
  262. UA_Subscription *sub;
  263. LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
  264. if(sub->subscriptionId == localSubscriptionId)
  265. mon = UA_Subscription_getMonitoredItem(sub, localMonitoredItemId);
  266. }
  267. ck_assert_ptr_ne(mon, NULL);
  268. UA_assert(mon);
  269. ck_assert_uint_eq(mon->currentQueueSize, 1);
  270. ck_assert_uint_eq(mon->maxQueueSize, 3);
  271. MonitoredItem_queuedValue *queueItem;
  272. queueItem = TAILQ_LAST(&mon->queue, QueuedValueQueue);
  273. ck_assert_uint_eq(queueItem->value.hasStatus, false);
  274. UA_ByteString_deleteMembers(&mon->lastSampledValue);
  275. UA_MonitoredItem_SampleCallback(server, mon);
  276. ck_assert_uint_eq(mon->currentQueueSize, 2);
  277. ck_assert_uint_eq(mon->maxQueueSize, 3);
  278. queueItem = TAILQ_LAST(&mon->queue, QueuedValueQueue);
  279. ck_assert_uint_eq(queueItem->value.hasStatus, false);
  280. UA_ByteString_deleteMembers(&mon->lastSampledValue);
  281. UA_MonitoredItem_SampleCallback(server, mon);
  282. ck_assert_uint_eq(mon->currentQueueSize, 3);
  283. ck_assert_uint_eq(mon->maxQueueSize, 3);
  284. queueItem = TAILQ_LAST(&mon->queue, QueuedValueQueue);
  285. ck_assert_uint_eq(queueItem->value.hasStatus, false);
  286. UA_ByteString_deleteMembers(&mon->lastSampledValue);
  287. UA_MonitoredItem_SampleCallback(server, mon);
  288. ck_assert_uint_eq(mon->currentQueueSize, 3);
  289. ck_assert_uint_eq(mon->maxQueueSize, 3);
  290. queueItem = TAILQ_FIRST(&mon->queue);
  291. ck_assert_uint_eq(queueItem->value.hasStatus, true);
  292. ck_assert_uint_eq(queueItem->value.status, UA_STATUSCODE_INFOTYPE_DATAVALUE | UA_STATUSCODE_INFOBITS_OVERFLOW);
  293. /* Remove status for next test */
  294. queueItem->value.hasStatus = false;
  295. queueItem->value.status = 0;
  296. /* Modify the MonitoredItem */
  297. UA_ModifyMonitoredItemsRequest modifyMonitoredItemsRequest;
  298. UA_ModifyMonitoredItemsRequest_init(&modifyMonitoredItemsRequest);
  299. modifyMonitoredItemsRequest.subscriptionId = localSubscriptionId;
  300. modifyMonitoredItemsRequest.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
  301. UA_MonitoredItemModifyRequest itemToModify;
  302. UA_MonitoredItemModifyRequest_init(&itemToModify);
  303. itemToModify.monitoredItemId = localMonitoredItemId;
  304. UA_MonitoringParameters_init(&params);
  305. itemToModify.requestedParameters = params;
  306. itemToModify.requestedParameters.queueSize = 2;
  307. itemToModify.requestedParameters.discardOldest = true;
  308. modifyMonitoredItemsRequest.itemsToModifySize = 1;
  309. modifyMonitoredItemsRequest.itemsToModify = &itemToModify;
  310. UA_ModifyMonitoredItemsResponse modifyMonitoredItemsResponse;
  311. UA_ModifyMonitoredItemsResponse_init(&modifyMonitoredItemsResponse);
  312. Service_ModifyMonitoredItems(server, &adminSession, &modifyMonitoredItemsRequest, &modifyMonitoredItemsResponse);
  313. ck_assert_uint_eq(modifyMonitoredItemsResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  314. ck_assert_uint_eq(modifyMonitoredItemsResponse.resultsSize, 1);
  315. ck_assert_uint_eq(modifyMonitoredItemsResponse.results[0].statusCode, UA_STATUSCODE_GOOD);
  316. UA_MonitoredItemModifyRequest_deleteMembers(&itemToModify);
  317. UA_ModifyMonitoredItemsResponse_deleteMembers(&modifyMonitoredItemsResponse);
  318. ck_assert_uint_eq(mon->currentQueueSize, 2);
  319. ck_assert_uint_eq(mon->maxQueueSize, 2);
  320. queueItem = TAILQ_FIRST(&mon->queue);
  321. ck_assert_uint_eq(queueItem->value.hasStatus, true);
  322. ck_assert_uint_eq(queueItem->value.status, UA_STATUSCODE_INFOTYPE_DATAVALUE | UA_STATUSCODE_INFOBITS_OVERFLOW);
  323. /* Modify the MonitoredItem */
  324. UA_ModifyMonitoredItemsRequest_init(&modifyMonitoredItemsRequest);
  325. modifyMonitoredItemsRequest.subscriptionId = localSubscriptionId;
  326. modifyMonitoredItemsRequest.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
  327. UA_MonitoredItemModifyRequest_init(&itemToModify);
  328. itemToModify.monitoredItemId = localMonitoredItemId;
  329. UA_MonitoringParameters_init(&params);
  330. itemToModify.requestedParameters = params;
  331. itemToModify.requestedParameters.queueSize = 1;
  332. modifyMonitoredItemsRequest.itemsToModifySize = 1;
  333. modifyMonitoredItemsRequest.itemsToModify = &itemToModify;
  334. UA_ModifyMonitoredItemsResponse_init(&modifyMonitoredItemsResponse);
  335. Service_ModifyMonitoredItems(server, &adminSession, &modifyMonitoredItemsRequest, &modifyMonitoredItemsResponse);
  336. ck_assert_uint_eq(modifyMonitoredItemsResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  337. ck_assert_uint_eq(modifyMonitoredItemsResponse.resultsSize, 1);
  338. ck_assert_uint_eq(modifyMonitoredItemsResponse.results[0].statusCode, UA_STATUSCODE_GOOD);
  339. UA_MonitoredItemModifyRequest_deleteMembers(&itemToModify);
  340. UA_ModifyMonitoredItemsResponse_deleteMembers(&modifyMonitoredItemsResponse);
  341. ck_assert_uint_eq(mon->currentQueueSize, 1);
  342. ck_assert_uint_eq(mon->maxQueueSize, 1);
  343. queueItem = TAILQ_LAST(&mon->queue, QueuedValueQueue);
  344. ck_assert_uint_eq(queueItem->value.hasStatus, false);
  345. /* Modify the MonitoredItem */
  346. UA_ModifyMonitoredItemsRequest_init(&modifyMonitoredItemsRequest);
  347. modifyMonitoredItemsRequest.subscriptionId = localSubscriptionId;
  348. modifyMonitoredItemsRequest.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
  349. UA_MonitoredItemModifyRequest_init(&itemToModify);
  350. itemToModify.monitoredItemId = localMonitoredItemId;
  351. UA_MonitoringParameters_init(&params);
  352. itemToModify.requestedParameters = params;
  353. itemToModify.requestedParameters.discardOldest = false;
  354. itemToModify.requestedParameters.queueSize = 1;
  355. modifyMonitoredItemsRequest.itemsToModifySize = 1;
  356. modifyMonitoredItemsRequest.itemsToModify = &itemToModify;
  357. UA_ModifyMonitoredItemsResponse_init(&modifyMonitoredItemsResponse);
  358. Service_ModifyMonitoredItems(server, &adminSession, &modifyMonitoredItemsRequest,
  359. &modifyMonitoredItemsResponse);
  360. ck_assert_uint_eq(modifyMonitoredItemsResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  361. ck_assert_uint_eq(modifyMonitoredItemsResponse.resultsSize, 1);
  362. ck_assert_uint_eq(modifyMonitoredItemsResponse.results[0].statusCode, UA_STATUSCODE_GOOD);
  363. UA_MonitoredItemModifyRequest_deleteMembers(&itemToModify);
  364. UA_ModifyMonitoredItemsResponse_deleteMembers(&modifyMonitoredItemsResponse);
  365. UA_MonitoredItem_SampleCallback(server, mon);
  366. ck_assert_uint_eq(mon->currentQueueSize, 1);
  367. ck_assert_uint_eq(mon->maxQueueSize, 1);
  368. queueItem = TAILQ_FIRST(&mon->queue);
  369. ck_assert_uint_eq(queueItem->value.hasStatus, false); /* the infobit is only set if the queue is larger than one */
  370. /* Remove the subscriptions */
  371. UA_DeleteSubscriptionsRequest deleteSubscriptionsRequest;
  372. UA_DeleteSubscriptionsRequest_init(&deleteSubscriptionsRequest);
  373. UA_UInt32 removeId = localSubscriptionId;
  374. deleteSubscriptionsRequest.subscriptionIdsSize = 1;
  375. deleteSubscriptionsRequest.subscriptionIds = &removeId;
  376. UA_DeleteSubscriptionsResponse deleteSubscriptionsResponse;
  377. UA_DeleteSubscriptionsResponse_init(&deleteSubscriptionsResponse);
  378. Service_DeleteSubscriptions(server, &adminSession, &deleteSubscriptionsRequest, &deleteSubscriptionsResponse);
  379. ck_assert_uint_eq(deleteSubscriptionsResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  380. ck_assert_uint_eq(deleteSubscriptionsResponse.resultsSize, 1);
  381. ck_assert_uint_eq(deleteSubscriptionsResponse.results[0], UA_STATUSCODE_GOOD);
  382. UA_DeleteSubscriptionsResponse_deleteMembers(&deleteSubscriptionsResponse);
  383. }
  384. END_TEST
  385. START_TEST(Server_setMonitoringMode) {
  386. UA_SetMonitoringModeRequest request;
  387. UA_SetMonitoringModeRequest_init(&request);
  388. request.subscriptionId = subscriptionId;
  389. request.monitoringMode = UA_MONITORINGMODE_DISABLED;
  390. request.monitoredItemIdsSize = 1;
  391. request.monitoredItemIds = &monitoredItemId;
  392. UA_SetMonitoringModeResponse response;
  393. UA_SetMonitoringModeResponse_init(&response);
  394. Service_SetMonitoringMode(server, &adminSession, &request, &response);
  395. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  396. ck_assert_uint_eq(response.resultsSize, 1);
  397. ck_assert_uint_eq(response.results[0], UA_STATUSCODE_GOOD);
  398. UA_SetMonitoringModeResponse_deleteMembers(&response);
  399. }
  400. END_TEST
  401. START_TEST(Server_deleteMonitoredItems) {
  402. UA_DeleteMonitoredItemsRequest request;
  403. UA_DeleteMonitoredItemsRequest_init(&request);
  404. request.subscriptionId = subscriptionId;
  405. request.monitoredItemIdsSize = 1;
  406. request.monitoredItemIds = &monitoredItemId;
  407. UA_DeleteMonitoredItemsResponse response;
  408. UA_DeleteMonitoredItemsResponse_init(&response);
  409. Service_DeleteMonitoredItems(server, &adminSession, &request, &response);
  410. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  411. ck_assert_uint_eq(response.resultsSize, 1);
  412. ck_assert_uint_eq(response.results[0], UA_STATUSCODE_GOOD);
  413. UA_DeleteMonitoredItemsResponse_deleteMembers(&response);
  414. }
  415. END_TEST
  416. #endif /* UA_ENABLE_SUBSCRIPTIONS */
  417. static Suite* testSuite_Client(void) {
  418. Suite *s = suite_create("Server Subscription");
  419. TCase *tc_server = tcase_create("Server Subscription Basic");
  420. tcase_add_checked_fixture(tc_server, setup, teardown);
  421. #ifdef UA_ENABLE_SUBSCRIPTIONS
  422. tcase_add_test(tc_server, Server_createSubscription);
  423. tcase_add_test(tc_server, Server_modifySubscription);
  424. tcase_add_test(tc_server, Server_setPublishingMode);
  425. tcase_add_test(tc_server, Server_createMonitoredItems);
  426. tcase_add_test(tc_server, Server_modifyMonitoredItems);
  427. tcase_add_test(tc_server, Server_overflow);
  428. tcase_add_test(tc_server, Server_setMonitoringMode);
  429. tcase_add_test(tc_server, Server_deleteMonitoredItems);
  430. tcase_add_test(tc_server, Server_republish);
  431. tcase_add_test(tc_server, Server_deleteSubscription);
  432. tcase_add_test(tc_server, Server_republish_invalid);
  433. tcase_add_test(tc_server, Server_publishCallback);
  434. #endif /* UA_ENABLE_SUBSCRIPTIONS */
  435. suite_add_tcase(s, tc_server);
  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. }