123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664 |
- /* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
- /* TODO add event based testing */
- #include "ua_server.h"
- #include "server/ua_services.h"
- #include "server/ua_server_internal.h"
- #include "server/ua_subscription.h"
- #include "ua_config_default.h"
- #include "check.h"
- #include "testing_clock.h"
- static UA_Server *server = NULL;
- static UA_ServerConfig *config = NULL;
- static void setup(void) {
- config = UA_ServerConfig_new_default();
- server = UA_Server_new(config);
- UA_Server_run_startup(server);
- }
- static void teardown(void) {
- UA_Server_run_shutdown(server);
- UA_Server_delete(server);
- UA_ServerConfig_delete(config);
- }
- #ifdef UA_ENABLE_SUBSCRIPTIONS
- UA_UInt32 subscriptionId;
- UA_UInt32 monitoredItemId;
- START_TEST(Server_createSubscription) {
- /* Create a subscription */
- UA_CreateSubscriptionRequest request;
- UA_CreateSubscriptionRequest_init(&request);
- request.publishingEnabled = true;
- UA_CreateSubscriptionResponse response;
- UA_CreateSubscriptionResponse_init(&response);
- Service_CreateSubscription(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- subscriptionId = response.subscriptionId;
- UA_CreateSubscriptionResponse_deleteMembers(&response);
- }
- END_TEST
- START_TEST(Server_modifySubscription) {
- UA_ModifySubscriptionRequest request;
- UA_ModifySubscriptionRequest_init(&request);
- request.subscriptionId = subscriptionId;
- // just some arbitrary numbers to test. They have no specific reason
- request.requestedPublishingInterval = 100; // in ms
- request.requestedLifetimeCount = 1000;
- request.requestedMaxKeepAliveCount = 1000;
- request.maxNotificationsPerPublish = 1;
- request.priority = 10;
- UA_ModifySubscriptionResponse response;
- UA_ModifySubscriptionResponse_init(&response);
- Service_ModifySubscription(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- UA_ModifySubscriptionResponse_deleteMembers(&response);
- }
- END_TEST
- START_TEST(Server_setPublishingMode) {
- UA_SetPublishingModeRequest request;
- UA_SetPublishingModeRequest_init(&request);
- request.publishingEnabled = UA_TRUE;
- request.subscriptionIdsSize = 1;
- request.subscriptionIds = &subscriptionId;
- UA_SetPublishingModeResponse response;
- UA_SetPublishingModeResponse_init(&response);
- Service_SetPublishingMode(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(response.resultsSize, 1);
- ck_assert_uint_eq(response.results[0], UA_STATUSCODE_GOOD);
- UA_SetPublishingModeResponse_deleteMembers(&response);
- }
- END_TEST
- START_TEST(Server_republish) {
- UA_RepublishRequest request;
- UA_RepublishRequest_init(&request);
- request.subscriptionId = subscriptionId;
- request.retransmitSequenceNumber = 0;
- UA_RepublishResponse response;
- UA_RepublishResponse_init(&response);
- Service_Republish(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_BADMESSAGENOTAVAILABLE);
- UA_RepublishResponse_deleteMembers(&response);
- }
- END_TEST
- START_TEST(Server_republish_invalid) {
- UA_RepublishRequest request;
- UA_RepublishRequest_init(&request);
- request.subscriptionId = subscriptionId;
- request.retransmitSequenceNumber = 0;
- UA_RepublishResponse response;
- UA_RepublishResponse_init(&response);
- Service_Republish(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_BADSUBSCRIPTIONIDINVALID);
- UA_RepublishResponse_deleteMembers(&response);
- }
- END_TEST
- START_TEST(Server_deleteSubscription) {
- /* Remove the subscription */
- UA_DeleteSubscriptionsRequest del_request;
- UA_DeleteSubscriptionsRequest_init(&del_request);
- del_request.subscriptionIdsSize = 1;
- del_request.subscriptionIds = &subscriptionId;
- UA_DeleteSubscriptionsResponse del_response;
- UA_DeleteSubscriptionsResponse_init(&del_response);
- Service_DeleteSubscriptions(server, &adminSession, &del_request, &del_response);
- ck_assert_uint_eq(del_response.resultsSize, 1);
- ck_assert_uint_eq(del_response.results[0], UA_STATUSCODE_GOOD);
- UA_DeleteSubscriptionsResponse_deleteMembers(&del_response);
- }
- END_TEST
- START_TEST(Server_publishCallback) {
- /* Create a subscription */
- UA_CreateSubscriptionRequest request;
- UA_CreateSubscriptionResponse response;
- UA_CreateSubscriptionRequest_init(&request);
- request.publishingEnabled = true;
- UA_CreateSubscriptionResponse_init(&response);
- Service_CreateSubscription(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- UA_UInt32 subscriptionId1 = response.subscriptionId;
- UA_CreateSubscriptionResponse_deleteMembers(&response);
- /* Create a second subscription */
- UA_CreateSubscriptionRequest_init(&request);
- request.publishingEnabled = true;
- UA_CreateSubscriptionResponse_init(&response);
- Service_CreateSubscription(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- UA_UInt32 subscriptionId2 = response.subscriptionId;
- UA_Double publishingInterval = response.revisedPublishingInterval;
- ck_assert(publishingInterval > 0.0f);
- UA_CreateSubscriptionResponse_deleteMembers(&response);
- /* Keepalive is set to max initially */
- UA_Subscription *sub;
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry)
- ck_assert_uint_eq(sub->currentKeepAliveCount, sub->maxKeepAliveCount);
- /* Sleep until the publishing interval times out */
- UA_fakeSleep((UA_UInt32)publishingInterval + 1);
- UA_Server_run_iterate(server, false);
- UA_realSleep(100);
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
- if ((sub->subscriptionId == subscriptionId1) || (sub->subscriptionId == subscriptionId2))
- ck_assert_uint_eq(sub->currentKeepAliveCount, sub->maxKeepAliveCount+1);
- }
- /* Remove the subscriptions */
- UA_DeleteSubscriptionsRequest del_request;
- UA_DeleteSubscriptionsRequest_init(&del_request);
- UA_UInt32 removeIds[2] = {subscriptionId1, subscriptionId2};
- del_request.subscriptionIdsSize = 2;
- del_request.subscriptionIds = removeIds;
- UA_DeleteSubscriptionsResponse del_response;
- UA_DeleteSubscriptionsResponse_init(&del_response);
- Service_DeleteSubscriptions(server, &adminSession, &del_request, &del_response);
- ck_assert_uint_eq(del_response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(del_response.resultsSize, 2);
- ck_assert_uint_eq(del_response.results[0], UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(del_response.results[1], UA_STATUSCODE_GOOD);
- UA_DeleteSubscriptionsResponse_deleteMembers(&del_response);
- }
- END_TEST
- START_TEST(Server_createMonitoredItems) {
- UA_CreateMonitoredItemsRequest request;
- UA_CreateMonitoredItemsRequest_init(&request);
- request.subscriptionId = subscriptionId;
- request.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
- UA_MonitoredItemCreateRequest item;
- UA_MonitoredItemCreateRequest_init(&item);
- UA_ReadValueId rvi;
- UA_ReadValueId_init(&rvi);
- rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER);
- rvi.attributeId = UA_ATTRIBUTEID_BROWSENAME;
- rvi.indexRange = UA_STRING_NULL;
- item.itemToMonitor = rvi;
- item.monitoringMode = UA_MONITORINGMODE_REPORTING;
- UA_MonitoringParameters params;
- UA_MonitoringParameters_init(¶ms);
- item.requestedParameters = params;
- request.itemsToCreateSize = 1;
- request.itemsToCreate = &item;
- UA_CreateMonitoredItemsResponse response;
- UA_CreateMonitoredItemsResponse_init(&response);
- Service_CreateMonitoredItems(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(response.resultsSize, 1);
- ck_assert_uint_eq(response.results[0].statusCode, UA_STATUSCODE_GOOD);
- monitoredItemId = response.results[0].monitoredItemId;
- ck_assert_uint_gt(monitoredItemId, 0);
- UA_MonitoredItemCreateRequest_deleteMembers(&item);
- UA_CreateMonitoredItemsResponse_deleteMembers(&response);
- }
- END_TEST
- START_TEST(Server_modifyMonitoredItems) {
- UA_ModifyMonitoredItemsRequest request;
- UA_ModifyMonitoredItemsRequest_init(&request);
- request.subscriptionId = subscriptionId;
- request.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
- UA_MonitoredItemModifyRequest item;
- UA_MonitoredItemModifyRequest_init(&item);
- UA_ReadValueId rvi;
- UA_ReadValueId_init(&rvi);
- rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER);
- rvi.attributeId = UA_ATTRIBUTEID_DESCRIPTION;
- rvi.indexRange = UA_STRING_NULL;
- item.monitoredItemId = monitoredItemId;
- UA_MonitoringParameters params;
- UA_MonitoringParameters_init(¶ms);
- item.requestedParameters = params;
- request.itemsToModifySize = 1;
- request.itemsToModify = &item;
- UA_ModifyMonitoredItemsResponse response;
- UA_ModifyMonitoredItemsResponse_init(&response);
- Service_ModifyMonitoredItems(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(response.resultsSize, 1);
- ck_assert_uint_eq(response.results[0].statusCode, UA_STATUSCODE_GOOD);
- UA_MonitoredItemModifyRequest_deleteMembers(&item);
- UA_ModifyMonitoredItemsResponse_deleteMembers(&response);
- }
- END_TEST
- START_TEST(Server_overflow) {
- /* Create a subscription */
- UA_CreateSubscriptionRequest createSubscriptionRequest;
- UA_CreateSubscriptionResponse createSubscriptionResponse;
- UA_CreateSubscriptionRequest_init(&createSubscriptionRequest);
- createSubscriptionRequest.publishingEnabled = true;
- UA_CreateSubscriptionResponse_init(&createSubscriptionResponse);
- Service_CreateSubscription(server, &adminSession, &createSubscriptionRequest, &createSubscriptionResponse);
- ck_assert_uint_eq(createSubscriptionResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- UA_UInt32 localSubscriptionId = createSubscriptionResponse.subscriptionId;
- UA_Double publishingInterval = createSubscriptionResponse.revisedPublishingInterval;
- ck_assert(publishingInterval > 0.0f);
- UA_CreateSubscriptionResponse_deleteMembers(&createSubscriptionResponse);
- /* Create a monitoredItem */
- UA_CreateMonitoredItemsRequest createMonitoredItemsRequest;
- UA_CreateMonitoredItemsRequest_init(&createMonitoredItemsRequest);
- createMonitoredItemsRequest.subscriptionId = localSubscriptionId;
- createMonitoredItemsRequest.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
- UA_MonitoredItemCreateRequest item;
- UA_MonitoredItemCreateRequest_init(&item);
- UA_ReadValueId rvi;
- UA_ReadValueId_init(&rvi);
- rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
- rvi.attributeId = UA_ATTRIBUTEID_BROWSENAME;
- rvi.indexRange = UA_STRING_NULL;
- item.itemToMonitor = rvi;
- item.monitoringMode = UA_MONITORINGMODE_REPORTING;
- UA_MonitoringParameters params;
- UA_MonitoringParameters_init(¶ms);
- item.requestedParameters = params;
- item.requestedParameters.queueSize = 3;
- item.requestedParameters.discardOldest = true;
- createMonitoredItemsRequest.itemsToCreateSize = 1;
- createMonitoredItemsRequest.itemsToCreate = &item;
- UA_CreateMonitoredItemsResponse createMonitoredItemsResponse;
- UA_CreateMonitoredItemsResponse_init(&createMonitoredItemsResponse);
- Service_CreateMonitoredItems(server, &adminSession, &createMonitoredItemsRequest, &createMonitoredItemsResponse);
- ck_assert_uint_eq(createMonitoredItemsResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(createMonitoredItemsResponse.resultsSize, 1);
- ck_assert_uint_eq(createMonitoredItemsResponse.results[0].statusCode, UA_STATUSCODE_GOOD);
- UA_UInt32 localMonitoredItemId = createMonitoredItemsResponse.results[0].monitoredItemId;
- ck_assert_uint_gt(localMonitoredItemId, 0);
- UA_MonitoredItemCreateRequest_deleteMembers(&item);
- UA_CreateMonitoredItemsResponse_deleteMembers(&createMonitoredItemsResponse);
- UA_MonitoredItem *mon = NULL;
- UA_Subscription *sub;
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry) {
- if(sub->subscriptionId == localSubscriptionId)
- mon = UA_Subscription_getMonitoredItem(sub, localMonitoredItemId);
- }
- ck_assert_ptr_ne(mon, NULL);
- UA_assert(mon);
- ck_assert_uint_eq(mon->currentQueueSize, 1);
- ck_assert_uint_eq(mon->maxQueueSize, 3);
- MonitoredItem_queuedValue *queueItem;
- queueItem = TAILQ_LAST(&mon->queue, QueuedValueQueue);
- ck_assert_uint_eq(queueItem->data.value.hasStatus, false);
- UA_ByteString_deleteMembers(&mon->lastSampledValue);
- UA_MonitoredItem_SampleCallback(server, mon);
- ck_assert_uint_eq(mon->currentQueueSize, 2);
- ck_assert_uint_eq(mon->maxQueueSize, 3);
- queueItem = TAILQ_LAST(&mon->queue, QueuedValueQueue);
- ck_assert_uint_eq(queueItem->data.value.hasStatus, false);
- UA_ByteString_deleteMembers(&mon->lastSampledValue);
- UA_MonitoredItem_SampleCallback(server, mon);
- ck_assert_uint_eq(mon->currentQueueSize, 3);
- ck_assert_uint_eq(mon->maxQueueSize, 3);
- queueItem = TAILQ_LAST(&mon->queue, QueuedValueQueue);
- ck_assert_uint_eq(queueItem->data.value.hasStatus, false);
- UA_ByteString_deleteMembers(&mon->lastSampledValue);
- UA_MonitoredItem_SampleCallback(server, mon);
- ck_assert_uint_eq(mon->currentQueueSize, 3);
- ck_assert_uint_eq(mon->maxQueueSize, 3);
- queueItem = TAILQ_FIRST(&mon->queue);
- ck_assert_uint_eq(queueItem->data.value.hasStatus, true);
- ck_assert_uint_eq(queueItem->data.value.status, UA_STATUSCODE_INFOTYPE_DATAVALUE | UA_STATUSCODE_INFOBITS_OVERFLOW);
- /* Remove status for next test */
- queueItem->data.value.hasStatus = false;
- queueItem->data.value.status = 0;
- /* Modify the MonitoredItem */
- UA_ModifyMonitoredItemsRequest modifyMonitoredItemsRequest;
- UA_ModifyMonitoredItemsRequest_init(&modifyMonitoredItemsRequest);
- modifyMonitoredItemsRequest.subscriptionId = localSubscriptionId;
- modifyMonitoredItemsRequest.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
- UA_MonitoredItemModifyRequest itemToModify;
- UA_MonitoredItemModifyRequest_init(&itemToModify);
- itemToModify.monitoredItemId = localMonitoredItemId;
- UA_MonitoringParameters_init(¶ms);
- itemToModify.requestedParameters = params;
- itemToModify.requestedParameters.queueSize = 2;
- itemToModify.requestedParameters.discardOldest = true;
- modifyMonitoredItemsRequest.itemsToModifySize = 1;
- modifyMonitoredItemsRequest.itemsToModify = &itemToModify;
- UA_ModifyMonitoredItemsResponse modifyMonitoredItemsResponse;
- UA_ModifyMonitoredItemsResponse_init(&modifyMonitoredItemsResponse);
- Service_ModifyMonitoredItems(server, &adminSession, &modifyMonitoredItemsRequest, &modifyMonitoredItemsResponse);
- ck_assert_uint_eq(modifyMonitoredItemsResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(modifyMonitoredItemsResponse.resultsSize, 1);
- ck_assert_uint_eq(modifyMonitoredItemsResponse.results[0].statusCode, UA_STATUSCODE_GOOD);
- UA_MonitoredItemModifyRequest_deleteMembers(&itemToModify);
- UA_ModifyMonitoredItemsResponse_deleteMembers(&modifyMonitoredItemsResponse);
- ck_assert_uint_eq(mon->currentQueueSize, 2);
- ck_assert_uint_eq(mon->maxQueueSize, 2);
- queueItem = TAILQ_FIRST(&mon->queue);
- ck_assert_uint_eq(queueItem->data.value.hasStatus, true);
- ck_assert_uint_eq(queueItem->data.value.status, UA_STATUSCODE_INFOTYPE_DATAVALUE | UA_STATUSCODE_INFOBITS_OVERFLOW);
- /* Modify the MonitoredItem */
- UA_ModifyMonitoredItemsRequest_init(&modifyMonitoredItemsRequest);
- modifyMonitoredItemsRequest.subscriptionId = localSubscriptionId;
- modifyMonitoredItemsRequest.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
- UA_MonitoredItemModifyRequest_init(&itemToModify);
- itemToModify.monitoredItemId = localMonitoredItemId;
- UA_MonitoringParameters_init(¶ms);
- itemToModify.requestedParameters = params;
- itemToModify.requestedParameters.queueSize = 1;
- modifyMonitoredItemsRequest.itemsToModifySize = 1;
- modifyMonitoredItemsRequest.itemsToModify = &itemToModify;
- UA_ModifyMonitoredItemsResponse_init(&modifyMonitoredItemsResponse);
- Service_ModifyMonitoredItems(server, &adminSession, &modifyMonitoredItemsRequest, &modifyMonitoredItemsResponse);
- ck_assert_uint_eq(modifyMonitoredItemsResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(modifyMonitoredItemsResponse.resultsSize, 1);
- ck_assert_uint_eq(modifyMonitoredItemsResponse.results[0].statusCode, UA_STATUSCODE_GOOD);
- UA_MonitoredItemModifyRequest_deleteMembers(&itemToModify);
- UA_ModifyMonitoredItemsResponse_deleteMembers(&modifyMonitoredItemsResponse);
- ck_assert_uint_eq(mon->currentQueueSize, 1);
- ck_assert_uint_eq(mon->maxQueueSize, 1);
- queueItem = TAILQ_LAST(&mon->queue, QueuedValueQueue);
- ck_assert_uint_eq(queueItem->data.value.hasStatus, false);
- /* Modify the MonitoredItem */
- UA_ModifyMonitoredItemsRequest_init(&modifyMonitoredItemsRequest);
- modifyMonitoredItemsRequest.subscriptionId = localSubscriptionId;
- modifyMonitoredItemsRequest.timestampsToReturn = UA_TIMESTAMPSTORETURN_SERVER;
- UA_MonitoredItemModifyRequest_init(&itemToModify);
- itemToModify.monitoredItemId = localMonitoredItemId;
- UA_MonitoringParameters_init(¶ms);
- itemToModify.requestedParameters = params;
- itemToModify.requestedParameters.discardOldest = false;
- itemToModify.requestedParameters.queueSize = 1;
- modifyMonitoredItemsRequest.itemsToModifySize = 1;
- modifyMonitoredItemsRequest.itemsToModify = &itemToModify;
- UA_ModifyMonitoredItemsResponse_init(&modifyMonitoredItemsResponse);
- Service_ModifyMonitoredItems(server, &adminSession, &modifyMonitoredItemsRequest,
- &modifyMonitoredItemsResponse);
- ck_assert_uint_eq(modifyMonitoredItemsResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(modifyMonitoredItemsResponse.resultsSize, 1);
- ck_assert_uint_eq(modifyMonitoredItemsResponse.results[0].statusCode, UA_STATUSCODE_GOOD);
- UA_MonitoredItemModifyRequest_deleteMembers(&itemToModify);
- UA_ModifyMonitoredItemsResponse_deleteMembers(&modifyMonitoredItemsResponse);
- UA_MonitoredItem_SampleCallback(server, mon);
- ck_assert_uint_eq(mon->currentQueueSize, 1);
- ck_assert_uint_eq(mon->maxQueueSize, 1);
- queueItem = TAILQ_FIRST(&mon->queue);
- ck_assert_uint_eq(queueItem->data.value.hasStatus, false); /* the infobit is only set if the queue is larger than one */
- /* Remove the subscriptions */
- UA_DeleteSubscriptionsRequest deleteSubscriptionsRequest;
- UA_DeleteSubscriptionsRequest_init(&deleteSubscriptionsRequest);
- UA_UInt32 removeId = localSubscriptionId;
- deleteSubscriptionsRequest.subscriptionIdsSize = 1;
- deleteSubscriptionsRequest.subscriptionIds = &removeId;
- UA_DeleteSubscriptionsResponse deleteSubscriptionsResponse;
- UA_DeleteSubscriptionsResponse_init(&deleteSubscriptionsResponse);
- Service_DeleteSubscriptions(server, &adminSession, &deleteSubscriptionsRequest, &deleteSubscriptionsResponse);
- ck_assert_uint_eq(deleteSubscriptionsResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(deleteSubscriptionsResponse.resultsSize, 1);
- ck_assert_uint_eq(deleteSubscriptionsResponse.results[0], UA_STATUSCODE_GOOD);
- UA_DeleteSubscriptionsResponse_deleteMembers(&deleteSubscriptionsResponse);
- }
- END_TEST
- START_TEST(Server_setMonitoringMode) {
- UA_SetMonitoringModeRequest request;
- UA_SetMonitoringModeRequest_init(&request);
- request.subscriptionId = subscriptionId;
- request.monitoringMode = UA_MONITORINGMODE_DISABLED;
- request.monitoredItemIdsSize = 1;
- request.monitoredItemIds = &monitoredItemId;
- UA_SetMonitoringModeResponse response;
- UA_SetMonitoringModeResponse_init(&response);
- Service_SetMonitoringMode(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(response.resultsSize, 1);
- ck_assert_uint_eq(response.results[0], UA_STATUSCODE_GOOD);
- UA_SetMonitoringModeResponse_deleteMembers(&response);
- }
- END_TEST
- START_TEST(Server_deleteMonitoredItems) {
- UA_DeleteMonitoredItemsRequest request;
- UA_DeleteMonitoredItemsRequest_init(&request);
- request.subscriptionId = subscriptionId;
- request.monitoredItemIdsSize = 1;
- request.monitoredItemIds = &monitoredItemId;
- UA_DeleteMonitoredItemsResponse response;
- UA_DeleteMonitoredItemsResponse_init(&response);
- Service_DeleteMonitoredItems(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(response.resultsSize, 1);
- ck_assert_uint_eq(response.results[0], UA_STATUSCODE_GOOD);
- UA_DeleteMonitoredItemsResponse_deleteMembers(&response);
- }
- END_TEST
- START_TEST(Server_lifeTimeCount) {
- /* Create a subscription */
- UA_CreateSubscriptionRequest request;
- UA_CreateSubscriptionResponse response;
- UA_CreateSubscriptionRequest_init(&request);
- request.publishingEnabled = true;
- request.requestedLifetimeCount = 3;
- request.requestedMaxKeepAliveCount = 1;
- UA_CreateSubscriptionResponse_init(&response);
- Service_CreateSubscription(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(response.revisedMaxKeepAliveCount, 1);
- ck_assert_uint_eq(response.revisedLifetimeCount, 3);
- UA_CreateSubscriptionResponse_deleteMembers(&response);
- /* Create a second subscription */
- UA_CreateSubscriptionRequest_init(&request);
- request.publishingEnabled = true;
- request.requestedLifetimeCount = 4;
- request.requestedMaxKeepAliveCount = 2;
- UA_CreateSubscriptionResponse_init(&response);
- Service_CreateSubscription(server, &adminSession, &request, &response);
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
- ck_assert_uint_eq(response.revisedMaxKeepAliveCount, 2);
- /* revisedLifetimeCount is revised to 3*MaxKeepAliveCount */
- ck_assert_uint_eq(response.revisedLifetimeCount, 6);
- UA_Double publishingInterval = response.revisedPublishingInterval;
- ck_assert(publishingInterval > 0.0f);
- UA_CreateSubscriptionResponse_deleteMembers(&response);
- UA_Server_run_iterate(server, false);
- UA_UInt32 count = 0;
- UA_Subscription *sub;
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
- ck_assert_uint_eq(sub->currentLifetimeCount, 0);
- count++;
- }
- ck_assert_uint_eq(count, 2);
- UA_fakeSleep((UA_UInt32)publishingInterval + 1);
- UA_Server_run_iterate(server, false);
- count = 0;
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
- ck_assert_uint_eq(sub->currentLifetimeCount, 1);
- count++;
- }
- ck_assert_uint_eq(count, 2);
- /* Sleep until the publishing interval times out */
- UA_fakeSleep((UA_UInt32)publishingInterval + 1);
- UA_Server_run_iterate(server, false);
- count = 0;
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
- ck_assert_uint_eq(sub->currentLifetimeCount, 2);
- count++;
- }
- ck_assert_uint_eq(count, 2);
- /* Sleep until the publishing interval times out */
- UA_fakeSleep((UA_UInt32)publishingInterval + 1);
- UA_Server_run_iterate(server, false);
- count = 0;
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
- ck_assert_uint_eq(sub->currentLifetimeCount, 3);
- count++;
- }
- ck_assert_uint_eq(count, 2);
- /* Sleep until the publishing interval times out */
- UA_fakeSleep((UA_UInt32)publishingInterval + 1);
- UA_Server_run_iterate(server, false);
- count = 0;
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
- ck_assert_uint_eq(sub->currentLifetimeCount, 4);
- count++;
- }
- ck_assert_uint_eq(count, 1);
- /* Sleep until the publishing interval times out */
- UA_fakeSleep((UA_UInt32)publishingInterval + 1);
- UA_Server_run_iterate(server, false);
- count = 0;
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
- ck_assert_uint_eq(sub->currentLifetimeCount, 5);
- count++;
- }
- ck_assert_uint_eq(count, 1);
- /* Sleep until the publishing interval times out */
- UA_fakeSleep((UA_UInt32)publishingInterval + 1);
- UA_Server_run_iterate(server, false);
- count = 0;
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
- ck_assert_uint_eq(sub->currentLifetimeCount, 6);
- count++;
- }
- ck_assert_uint_eq(count, 1);
- /* Sleep until the publishing interval times out */
- UA_fakeSleep((UA_UInt32)publishingInterval + 1);
- UA_Server_run_iterate(server, false);
- count = 0;
- LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry){
- count++;
- }
- ck_assert_uint_eq(count, 0);
- }
- END_TEST
- #endif /* UA_ENABLE_SUBSCRIPTIONS */
- static Suite* testSuite_Client(void) {
- Suite *s = suite_create("Server Subscription");
- TCase *tc_server = tcase_create("Server Subscription Basic");
- tcase_add_checked_fixture(tc_server, setup, teardown);
- #ifdef UA_ENABLE_SUBSCRIPTIONS
- tcase_add_test(tc_server, Server_createSubscription);
- tcase_add_test(tc_server, Server_modifySubscription);
- tcase_add_test(tc_server, Server_setPublishingMode);
- tcase_add_test(tc_server, Server_createMonitoredItems);
- tcase_add_test(tc_server, Server_modifyMonitoredItems);
- tcase_add_test(tc_server, Server_overflow);
- tcase_add_test(tc_server, Server_setMonitoringMode);
- tcase_add_test(tc_server, Server_deleteMonitoredItems);
- tcase_add_test(tc_server, Server_republish);
- tcase_add_test(tc_server, Server_deleteSubscription);
- tcase_add_test(tc_server, Server_republish_invalid);
- tcase_add_test(tc_server, Server_publishCallback);
- tcase_add_test(tc_server, Server_lifeTimeCount);
- #endif /* UA_ENABLE_SUBSCRIPTIONS */
- suite_add_tcase(s, tc_server);
- return s;
- }
- int main(void) {
- Suite *s = testSuite_Client();
- SRunner *sr = srunner_create(s);
- srunner_set_fork_status(sr, CK_NOFORK);
- srunner_run_all(sr,CK_NORMAL);
- int number_failed = srunner_ntests_failed(sr);
- srunner_free(sr);
- return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
- }
|