summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSourav Bhuwalka <s.bhuwalka@samsung.com>2020-05-01 06:10:53 +0530
committerSudipto <sudipto.bal@samsung.com>2020-06-16 16:23:15 +0530
commit50d57929479525797303e47631a1b261db797a91 (patch)
treefa3c7e2c19717b413daef8346ca4776560c53ed1
parent58601b5f496839508a612132f9dc58d8dc61582c (diff)
downloadiotivity-50d57929479525797303e47631a1b261db797a91.tar.gz
iotivity-50d57929479525797303e47631a1b261db797a91.tar.bz2
iotivity-50d57929479525797303e47631a1b261db797a91.zip
[Unit Tests]:Added unit tests for oicgroup.c
Added the unit tests for oicgroup.c file https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/695 (cherry-picked from eb626ad01918d9fea35df2f322e5186b126c090d) Change-Id: I87af29913e9d9277af9eb274378b9b1350e04d99 Signed-off-by: Sudipto <sudipto.bal@samsung.com>
-rw-r--r--resource/csdk/stack/test/SConscript4
-rw-r--r--resource/csdk/stack/test/oicgroup_test.cpp189
-rw-r--r--tools/generate_report.sh1
3 files changed, 194 insertions, 0 deletions
diff --git a/resource/csdk/stack/test/SConscript b/resource/csdk/stack/test/SConscript
index 309dfee2d..746829467 100644
--- a/resource/csdk/stack/test/SConscript
+++ b/resource/csdk/stack/test/SConscript
@@ -69,6 +69,7 @@ else:
stacktests = stacktest_env.Program('stacktests', ['stacktests.cpp'])
cbortests = stacktest_env.Program('cbortests', ['cbortests.cpp'])
keepalivetests = stacktest_env.Program('keepalivetests', ['oickeepalive_test.cpp'])
+oicgrouptests = stacktest_env.Program('oicgrouptests', ['oicgroup_test.cpp'])
Alias("test", [stacktests, cbortests, keepalivetests])
@@ -85,3 +86,6 @@ if stacktest_env.get('TEST') == '1':
run_test(stacktest_env,
'resource_csdk_stack_keepalivetests.memcheck',
'resource/csdk/stack/test/keepalivetests')
+ run_test(stacktest_env,
+ 'resource_csdk_stack_oicgrouptests.memcheck',
+ 'resource/csdk/stack/test/oicgrouptests')
diff --git a/resource/csdk/stack/test/oicgroup_test.cpp b/resource/csdk/stack/test/oicgroup_test.cpp
new file mode 100644
index 000000000..e62f57eb4
--- /dev/null
+++ b/resource/csdk/stack/test/oicgroup_test.cpp
@@ -0,0 +1,189 @@
+//******************************************************************
+//
+// Copyright 2020 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#define _POSIX_C_SOURCE 200112L
+
+#include "iotivity_config.h"
+
+#include <string.h>
+#include <gtest/gtest.h>
+
+#include "oicgroup.h"
+#include "ocpayload.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "occollection.h"
+#include "ocserverrequest.h"
+#include <stdio.h>
+
+TEST(InitializeScheduleResourceListTest, InitializeScheduleResourceList)
+{
+ EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_SERVER));
+}
+TEST(TerminateScheduleResourceListTest, TerminateScheduleResourceList)
+{
+ EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_SERVER));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+static OCActionSet *createAction(char *actionName)
+{
+ OCActionSet *actionSet;
+ actionSet = (OCActionSet*)OICMalloc(sizeof(OCActionSet));
+ actionSet->timesteps = 5;
+ actionSet->type = 1;
+ actionSet->actionsetName = (char*)OICMalloc(strlen(actionName)+1);
+ strncpy(actionSet->actionsetName, actionName, strlen(actionName)+1);
+ OCAction *action = (OCAction*)OICMalloc(sizeof(OCAction));
+ action->resourceUri = (char*)OICMalloc(20);
+ strncpy(action->resourceUri , "/a/light" , 9);
+ action->next = NULL;
+ OCCapability *cap=(OCCapability*)OICMalloc(sizeof(OCCapability));
+ cap->capability = (char*)OICMalloc(7);
+ strncpy(cap->capability, "switch", 7);
+ cap->status = (char*)OICMalloc(3);
+ strncpy(cap->status, "on", 3);
+ cap->next = NULL;
+ action->head = cap;
+ actionSet->head = action;
+ actionSet->next = NULL;
+ return actionSet;
+}
+TEST(BuildActionSetFromStringTest, BuildActionSetFromString)
+{
+ char temp[1024] = {0};
+ strncat(temp, "house*",6);
+ strncat(temp, "5 1", 3);
+ strncat(temp, "*uri=/a/light|switch=on*uri=/a/fan|switch=off", 45);
+ char *val = OICStrdup(temp);
+ OCActionSet *set = NULL;
+ EXPECT_EQ(OC_STACK_OK, BuildActionSetFromString(&set, val));
+}
+TEST(BuildStringFromActionSetTest, BuildStringFromActionSet)
+{
+ OCActionSet *actionSet = createAction("house");
+ char *s;
+ EXPECT_EQ(OC_STACK_OK, BuildStringFromActionSet(actionSet, &s));
+}
+TEST(FindAndDeleteActionSetTest, FindAndDeleteActionSet)
+{
+ OCResource *res;
+ res = (OCResource*)OICMalloc(sizeof(OCResource));
+ res->next = NULL;
+ OCActionSet *action = createAction("house");
+ res->actionsetHead = action;
+ char *actionsetFindName = (char*)OICMalloc(6);
+ strncpy(actionsetFindName, "house", 6);
+ EXPECT_EQ(OC_STACK_OK, FindAndDeleteActionSet(&res, actionsetFindName));
+}
+TEST(FindAndDeleteActionSetTestWithMultipleActions, FindAndDeleteActionSet)
+{
+ OCResource *res;
+ res = (OCResource*)OICMalloc(sizeof(OCResource));
+ res->next = NULL;
+ OCActionSet *action1 = createAction("house");
+ OCActionSet *action2 = createAction("kitchen");
+ action1->next = action2;
+ res->actionsetHead = action1;
+ char *actionsetFindName = (char*)OICMalloc(8);
+ strncpy(actionsetFindName, "kitchen", 8);
+ EXPECT_EQ(OC_STACK_OK, FindAndDeleteActionSet(&res, actionsetFindName));
+}
+TEST(AddActionSetTest, AddActionSet)
+{
+ OCActionSet *head = createAction("house");
+ OCActionSet *action = createAction("kitchen");
+ OCServerRequest *request;
+ EXPECT_EQ(OC_STACK_OK, AddActionSet(&head, action));
+}
+TEST(BuildCollectionGroupActionCBORResponsePutWithSameActionTest, BuildCollectionGroupActionCBORResponse)
+{
+ OCResource *res = (OCResource*)OICMalloc(sizeof(OCResource));
+ OCEntityHandlerRequest *request = (OCEntityHandlerRequest*)OICMalloc(sizeof(OCEntityHandlerRequest));
+ OCRepPayload *RepPayload = OCRepPayloadCreate();
+ char temp[1024] = {0};
+ strncat(temp, "house*",6);
+ strncat(temp, "5 1", 3);
+ strncat(temp, "*uri=/a/light|switch=on*uri=/a/fan|switch=off", 45);
+ char *val = OICStrdup(temp);
+ OCRepPayloadSetPropString(RepPayload, "ActionSet", temp);
+ request->payload = (OCPayload*)RepPayload;
+ res->actionsetHead = createAction("house");
+ EXPECT_EQ(OC_STACK_ERROR, BuildCollectionGroupActionCBORResponse(OC_REST_PUT, res, request));
+}
+TEST(BuildCollectionGroupActionCBORResponseDeleteTest, BuildCollectionGroupActionCBORResponse)
+{
+ OCResource *res = (OCResource*)OICMalloc(sizeof(OCResource));
+ OCEntityHandlerRequest *request = (OCEntityHandlerRequest*)OICMalloc(sizeof(OCEntityHandlerRequest));
+ OCRepPayload *RepPayload = OCRepPayloadCreate();
+ char temp[1024] = {0};
+ strncat(temp, "house", 5);
+ char *val = OICStrdup(temp);
+ OCRepPayloadSetPropString(RepPayload, "DelActionSet", temp);
+ request->payload = (OCPayload*)RepPayload;
+ res->actionsetHead = createAction("house");
+ EXPECT_EQ(OC_STACK_ERROR, BuildCollectionGroupActionCBORResponse(OC_REST_PUT, res, request));
+}
+TEST(BuildCollectionGroupActionCBORResponsePOSTTest, BuildCollectionGroupActionCBORResponse)
+{
+ OCResource *res = (OCResource*)OICMalloc(sizeof(OCResource));
+ OCEntityHandlerRequest *request = (OCEntityHandlerRequest*)OICMalloc(sizeof(OCEntityHandlerRequest));
+ OCRepPayload *RepPayload = OCRepPayloadCreate();
+ char temp[1024] = {0};
+ strncat(temp, "house*1", 7);
+ char *val = OICStrdup(temp);
+ OCRepPayloadSetPropString(RepPayload, "DoScheduledAction", temp);
+ request->payload = (OCPayload*)RepPayload;
+ res->actionsetHead = createAction("house");
+ res->uri = (char*)OICMalloc(9);
+ strncpy(res->uri , "/a/light" , 9);
+ EXPECT_EQ(OC_STACK_ERROR, BuildCollectionGroupActionCBORResponse(OC_REST_POST, res, request));
+}
+TEST(BuildCollectionGroupActionCBORResponseCancelActionTest, BuildCollectionGroupActionCBORResponse)
+{
+ OCResource *res = (OCResource*)OICMalloc(sizeof(OCResource));
+ OCEntityHandlerRequest *request = (OCEntityHandlerRequest*)OICMalloc(sizeof(OCEntityHandlerRequest));
+ OCRepPayload *RepPayload = OCRepPayloadCreate();
+ char temp[1024] = {0};
+ strncat(temp, "house", 5);
+ char *val = OICStrdup(temp);
+ OCRepPayloadSetPropString(RepPayload, "CancelAction", temp);
+ request->payload = (OCPayload*)RepPayload;
+ res->actionsetHead = createAction("house");
+ res->uri = (char*)OICMalloc(9);
+ strncpy(res->uri , "/a/light" , 9);
+ EXPECT_EQ(OC_STACK_ERROR, BuildCollectionGroupActionCBORResponse(OC_REST_POST, res, request));
+}
+TEST(BuildCollectionGroupActionCBORResponseGetActionTest, BuildCollectionGroupActionCBORResponse)
+{
+ OCResource *res = (OCResource*)OICMalloc(sizeof(OCResource));
+ OCEntityHandlerRequest *request = (OCEntityHandlerRequest*)OICMalloc(sizeof(OCEntityHandlerRequest));
+ OCRepPayload *RepPayload = OCRepPayloadCreate();
+ char temp[1024] = {0};
+ strncat(temp, "house", 5);
+ char *val = OICStrdup(temp);
+ OCRepPayloadSetPropString(RepPayload, "GetActionSet", temp);
+ request->payload = (OCPayload*)RepPayload;
+ res->actionsetHead = createAction("house");
+ res->uri = (char*)OICMalloc(9);
+ strncpy(res->uri , "/a/light" , 9);
+ EXPECT_EQ(OC_STACK_ERROR, BuildCollectionGroupActionCBORResponse(OC_REST_POST, res, request));
+}
+
+
diff --git a/tools/generate_report.sh b/tools/generate_report.sh
index fcdc92ab8..587f3283e 100644
--- a/tools/generate_report.sh
+++ b/tools/generate_report.sh
@@ -202,6 +202,7 @@ generate_report_CA()
"${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/csdk/connectivity/test/catests"
"${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/csdk/stack/test/cbortests"
"${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/csdk/stack/test/keepalivetests"
+ "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/csdk/stack/test/oicgrouptests"
"${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/unittests/unittests"
"${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/c_common/ocrandom/test/randomtests"
"${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/c_common/oic_malloc/test/malloctests"