Browse Source

Merge pull request #1026 from open62541/feature/unit_tests_subscription

Unit tests for subscription and small bug fix
Stefan Profanter 7 years ago
parent
commit
d33372266f

+ 1 - 1
examples/server_readspeed.c

@@ -49,7 +49,7 @@ int main(int argc, char** argv) {
     rvi.nodeId = myIntegerNodeId;
     rvi.attributeId = UA_ATTRIBUTEID_VALUE;
     rvi.indexRange = UA_STRING_NULL;
-    rvi.dataEncoding = UA_QUALIFIEDNAME(0, "DefaultBinary");
+    rvi.dataEncoding = UA_QUALIFIEDNAME(0, "Default Binary");
     request.timestampsToReturn = UA_TIMESTAMPSTORETURN_NEITHER;
     request.nodesToReadSize = 1;
     request.nodesToRead = &rvi;

+ 2 - 2
src/server/ua_services_attribute.c

@@ -649,8 +649,8 @@ writeIsAbstractAttribute(UA_Node *node, UA_Boolean value) {
 /* Read Service */
 /****************/
 
-static const UA_String binEncoding = {sizeof("DefaultBinary")-1, (UA_Byte*)"DefaultBinary"};
-/* static const UA_String xmlEncoding = {sizeof("DefaultXml")-1, (UA_Byte*)"DefaultXml"}; */
+static const UA_String binEncoding = {sizeof("Default Binary")-1, (UA_Byte*)"Default Binary"};
+/* static const UA_String xmlEncoding = {sizeof("Default Xml")-1, (UA_Byte*)"Default Xml"}; */
 
 #define CHECK_NODECLASS(CLASS)                                  \
     if(!(node->nodeClass & (CLASS))) {                          \

+ 1 - 0
src/server/ua_services_subscription.c

@@ -192,6 +192,7 @@ setMonitoredItemSettings(UA_Server *server, UA_MonitoredItem *mon,
 }
 
 static const UA_String binaryEncoding = {sizeof("Default Binary")-1, (UA_Byte*)"Default Binary"};
+/* static const UA_String xmlEncoding = {sizeof("Default Xml")-1, (UA_Byte*)"Default Xml"}; */
 
 static void
 Service_CreateMonitoredItems_single(UA_Server *server, UA_Session *session,

+ 209 - 1
tests/check_services_subscriptions.c

@@ -23,6 +23,9 @@ static void teardown(void) {
     UA_Server_delete(server);
 }
 
+UA_UInt32 subscriptionId;
+UA_UInt32 monitoredItemId;
+
 START_TEST(Server_createSubscription) {
     /* Create a subscription */
     UA_CreateSubscriptionRequest request;
@@ -34,10 +37,89 @@ START_TEST(Server_createSubscription) {
 
     Service_CreateSubscription(server, &adminSession, &request, &response);
     ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
-    UA_UInt32 subscriptionId = response.subscriptionId;
+    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);
@@ -108,6 +190,7 @@ START_TEST(Server_publishCallback) {
     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);
@@ -116,13 +199,138 @@ START_TEST(Server_publishCallback) {
 }
 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(&params);
+    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;
+
+    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(&params);
+    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_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
+
+
 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);
     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_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);
     suite_add_tcase(s, tc_server);
+
     return s;
 }