resource: Add test for ConstructResourceObject with InvalidUri
authorRavi Nanjundappa <nravi.n@samsung.com>
Wed, 9 Sep 2015 10:05:39 +0000 (15:35 +0530)
committerJon A. Cruz <jonc@osg.samsung.com>
Fri, 11 Sep 2015 05:03:03 +0000 (05:03 +0000)
Added a test case for ConstructResourceTest to simulate the scenario
of Resource creation with uri having of not having "/" as its prefix.

Change-Id: Iadfc60fa67e3f5d0d2653720f5557c4a0e5279dd
Signed-off-by: Ravi Nanjundappa <nravi.n@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2418
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
resource/src/OCResource.cpp
resource/unittests/OCResourceTest.cpp

index fe80366..d9742fc 100644 (file)
@@ -87,6 +87,12 @@ OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
                 interfaces.empty(), m_clientWrapper.expired(), false, false);
     }
 
+    if (uri[0] != '/')
+    {
+        throw ResourceInitException(m_uri.empty(), resourceTypes.empty(),
+                interfaces.empty(), m_clientWrapper.expired(), false, false);
+    }
+
     // construct the devAddr from the pieces we have
     m_devAddr.adapter = static_cast<OCTransportAdapter>(connectivityType >> CT_ADAPTER_SHIFT);
     m_devAddr.flags = static_cast<OCTransportFlags>(connectivityType & CT_MASK_FLAGS);
index ca09937..fa74d28 100644 (file)
@@ -91,6 +91,11 @@ namespace OCResourceTest
         EXPECT_ANY_THROW(ConstructResourceObject("coap://192.168.1.2:5000", "/"));
     }
 
+    TEST(ConstructResourceTest, ConstructResourceObjectInvalidUri2)
+    {
+        EXPECT_ANY_THROW(ConstructResourceObject("coap://192.168.1.2:5000", "resource"));
+    }
+
     TEST(ResourceGetTest, DISABLED_ResourceGetForValidUri)
     {
         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");