From 9dfd9fc86f7934486d0b0b806746db3e9ea68e49 Mon Sep 17 00:00:00 2001 From: Selva Suba Jenifer Joseph Date: Mon, 22 Jul 2019 11:34:59 +0530 Subject: [PATCH] PubSub: Unit test for adding Multiple ReaderGroups - Verify multiple ReaderGroups and DataSetReaders addition using unit test case Change-Id: Icbdab133e0860e680d4f6b959f4e1769da5e3f12 --- tests/pubsub/check_pubsub_subscribe.c | 75 +++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/tests/pubsub/check_pubsub_subscribe.c b/tests/pubsub/check_pubsub_subscribe.c index 4a5991f760b..b4f8e711ab0 100644 --- a/tests/pubsub/check_pubsub_subscribe.c +++ b/tests/pubsub/check_pubsub_subscribe.c @@ -22,6 +22,8 @@ #define PUBLISHVARIABLE_NODEID 1000 /* Published data nodeId */ #define SUBSCRIBEOBJECT_NODEID 1001 /* Object nodeId */ #define SUBSCRIBEVARIABLE_NODEID 1002 /* Subscribed data nodeId */ +#define READERGROUP_COUNT 2 /* Value to add readergroup to connection */ +#define CHECK_READERGROUP_COUNT 3 /* Value to check readergroup count */ /* Global declaration for test cases */ UA_Server *server = NULL; @@ -55,6 +57,7 @@ static void setup(void) { &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]); connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp"); UA_Server_addPubSubConnection(server, &connectionConfig, &connection_test); + UA_PubSubConnection_regist(server, &connection_test); } /* teardown() is to delete the environment set for test cases */ @@ -137,6 +140,41 @@ START_TEST(RemoveReaderGroupWithInvalidIdentifier) { UA_Server_removeReaderGroup(server, localreaderGroup); } END_TEST +START_TEST(AddRemoveMultipleAddReaderGroupWithValidConfiguration) { + UA_StatusCode retVal = UA_STATUSCODE_GOOD; + UA_ReaderGroupConfig readerGroupConfig; + memset(&readerGroupConfig, 0, sizeof(readerGroupConfig)); + readerGroupConfig.name = UA_STRING("ReaderGroup 1"); + UA_NodeId localReaderGroup; + /* Add ReaderGroup */ + retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localReaderGroup); + ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD); + /* Remove added ReaderGroup */ + retVal |= UA_Server_removeReaderGroup(server, localReaderGroup); + ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD); + size_t readerGroupCount = 0; + UA_ReaderGroup *readerGroup; + LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry) { + readerGroupCount++; + } + + /* Check ReaderGroup Count */ + ck_assert_int_eq(readerGroupCount, 0); + /* Add Multiple ReaderGroups */ + for (int iterator = 0; iterator <= READERGROUP_COUNT; iterator++) { + retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localReaderGroup); + ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD); + } + + readerGroupCount = 0; + /* Find ReaderGroup count */ + LIST_FOREACH(readerGroup, &UA_PubSubConnection_findConnectionbyId(server, connection_test)->readerGroups, listEntry) { + readerGroupCount++; + } + /* Check ReaderGroup Count */ + ck_assert_int_eq(readerGroupCount, CHECK_READERGROUP_COUNT); + } END_TEST + START_TEST(UpdateReaderGroupWithInvalidIdentifier) { /* Check status of updating ReaderGroup with invalid identifier */ UA_StatusCode retVal = UA_STATUSCODE_GOOD; @@ -266,6 +304,41 @@ START_TEST(RemoveDataSetReaderWithInvalidIdentifier) { ck_assert_int_ne(retVal, UA_STATUSCODE_GOOD); } END_TEST +START_TEST(AddMultipleDataSetReaderWithValidConfiguration) { + UA_StatusCode retVal = UA_STATUSCODE_GOOD; + UA_ReaderGroupConfig readerGroupConfig; + memset(&readerGroupConfig, 0, sizeof(readerGroupConfig)); + readerGroupConfig.name = UA_STRING("ReaderGroup 1"); + UA_NodeId localReaderGroup; + UA_NodeId localReaderGroup2; + /* DataSetReader configuration */ + UA_DataSetReaderConfig readerConfig; + memset (&readerConfig, 0, sizeof(readerConfig)); + readerConfig.name = UA_STRING("DataSet Reader 1"); + UA_NodeId dataSetReader; + /* Add ReaderGroup */ + retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localReaderGroup); + ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD); + retVal |= UA_Server_addReaderGroup(server, connection_test, &readerGroupConfig, &localReaderGroup2); + ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD); + UA_ReaderGroup *readerGroupIdent1 = UA_ReaderGroup_findRGbyId(server, localReaderGroup); + UA_ReaderGroup *readerGroupIdent2 = UA_ReaderGroup_findRGbyId(server, localReaderGroup2); + /* Add DataSetReaders to first ReaderGroup */ + retVal = UA_Server_addDataSetReader(server, localReaderGroup, &readerConfig, &dataSetReader); + ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD); + ck_assert_int_eq(readerGroupIdent1->readersCount, 1); + retVal = UA_Server_addDataSetReader(server, localReaderGroup, &readerConfig, &dataSetReader); + ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD); + ck_assert_int_eq(readerGroupIdent1->readersCount, 2); + /* Add DataSetReaders to second ReaderGroup */ + retVal = UA_Server_addDataSetReader(server, localReaderGroup2, &readerConfig, &dataSetReader); + ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD); + ck_assert_int_eq(readerGroupIdent2->readersCount, 1); + retVal = UA_Server_addDataSetReader(server, localReaderGroup2, &readerConfig, &dataSetReader); + ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD); + ck_assert_int_eq(readerGroupIdent2->readersCount, 2); + } END_TEST + START_TEST(UpdateDataSetReaderConfigWithInvalidId) { /* Check status of updatting DataSetReader with invalid configuration */ UA_StatusCode retVal = UA_STATUSCODE_GOOD; @@ -1014,6 +1087,7 @@ int main(void) { tcase_add_test(tc_add_pubsub_readergroup, AddReaderGroupWithNullConfig); tcase_add_test(tc_add_pubsub_readergroup, AddReaderGroupWithInvalidConnectionId); tcase_add_test(tc_add_pubsub_readergroup, RemoveReaderGroupWithInvalidIdentifier); + tcase_add_test(tc_add_pubsub_readergroup, AddRemoveMultipleAddReaderGroupWithValidConfiguration); tcase_add_test(tc_add_pubsub_readergroup, UpdateReaderGroupWithInvalidIdentifier); tcase_add_test(tc_add_pubsub_readergroup, GetReaderGroupConfigWithInvalidConfig); tcase_add_test(tc_add_pubsub_readergroup, GetReaderGroupConfigWithInvalidIdentifier); @@ -1024,6 +1098,7 @@ int main(void) { tcase_add_test(tc_add_pubsub_readergroup, AddDataSetReaderWithNullConfig); tcase_add_test(tc_add_pubsub_readergroup, RemoveDataSetReaderWithValidConfiguration); tcase_add_test(tc_add_pubsub_readergroup, RemoveDataSetReaderWithInvalidIdentifier); + tcase_add_test(tc_add_pubsub_readergroup, AddMultipleDataSetReaderWithValidConfiguration); tcase_add_test(tc_add_pubsub_readergroup, UpdateDataSetReaderConfigWithInvalidId); tcase_add_test(tc_add_pubsub_readergroup, GetDataSetReaderConfigWithValidConfiguration); tcase_add_test(tc_add_pubsub_readergroup, GetDataSetReaderConfigWithInvalidConfiguration);