Added unit tests for StackResource
authorRavi Nanjundappa <nravi.n@samsung.com>
Tue, 23 Jun 2015 04:52:05 +0000 (10:22 +0530)
committerErich Keane <erich.keane@intel.com>
Tue, 23 Jun 2015 16:44:10 +0000 (16:44 +0000)
Unit test exercise code paths to check OCCreateResource() for
OC_LIENT mode and also to check if resource type name is invalid
i.e., null terminated or not.
This also includes the bug fix related to checking if resource type
name is invalid i.e., null terminated or not.

Change-Id: I7f8767a4e8b9586de9cb0926dd8a4afcd03b792c
Signed-off-by: Ravi Nanjundappa <nravi.n@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1391
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/stack/src/ocstack.c
resource/csdk/stack/test/stacktests.cpp

index 9fe41fc..bdc6839 100644 (file)
@@ -2594,7 +2594,7 @@ OCStackResult OCCreateResource(OCResourceHandle *handle,
         return OC_STACK_INVALID_URI;
     }
     // Is it presented during resource discovery?
-    if (!handle || !resourceTypeName)
+    if (!handle || !resourceTypeName || resourceTypeName[0] == '\0' )
     {
         OC_LOG(ERROR, TAG, PCF("Input parameter is NULL"));
         return OC_STACK_INVALID_PARAM;
index 5d893ce..8ec27f4 100644 (file)
@@ -423,6 +423,24 @@ TEST(StackResource, CreateResourceSuccess)
     EXPECT_EQ(OC_STACK_OK, OCStop());
 }
 
+TEST(StackResource, CreateResourceWithClientStackMode)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    OC_LOG(INFO, TAG, "Starting CreateResourceSuccess test");
+    InitStack(OC_CLIENT);
+
+    OCResourceHandle handle;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCreateResource(&handle,
+                                            "core.led",
+                                            "core.rw",
+                                            "/a/led",
+                                            0,
+                                            NULL,
+                                            OC_DISCOVERABLE|OC_OBSERVABLE));
+
+    EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
 TEST(StackResource, CreateResourceFailDuplicateUri)
 {
     itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
@@ -510,6 +528,15 @@ TEST(StackResource, CreateResourceBadResoureType)
                                             NULL,
                                             OC_DISCOVERABLE|OC_OBSERVABLE));
 
+    OCResourceHandle handle2;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCreateResource(&handle2,
+                                            "",
+                                            "core.rw",
+                                            "/a/led",
+                                            0,
+                                            NULL,
+                                            OC_DISCOVERABLE|OC_OBSERVABLE));
+
     EXPECT_EQ(OC_STACK_OK, OCStop());
 }