Remove dependency on OC from serverBuilder tests using mock
authorcoderhyme <jhyo.kim@samsung.com>
Wed, 1 Jul 2015 01:47:03 +0000 (10:47 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 2 Jul 2015 09:06:06 +0000 (09:06 +0000)
To keep unit tests simple and quick

Change-Id: I0bed8dc4c47eecfff3eb5b7a8437bf020324e9c6
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1465
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-manipulation/modules/serverBuilder/unittests/PrimitiveServerResourceTest.cpp
service/resource-manipulation/modules/serverBuilder/unittests/RequestHandlerTest.cpp

index 58f81a957cbe980103eedc4ff6f7e2e5e3c043f2..925a712ecb058a92907fd48b77de531495078282 100644 (file)
@@ -44,22 +44,32 @@ static constexpr char RESOURCE_URI[]{ "a/test" };
 static constexpr char RESOURCE_TYPE[]{ "resourceType" };
 static constexpr char KEY[]{ "key" };
 
-TEST(ServerResourceBuilderTest, ThrowIfUriIsInvalid)
+TEST(ServerResourceBuilderCreateTest, ThrowIfUriIsInvalid)
 {
     ASSERT_THROW(PrimitiveServerResource::Builder("", "", "").create(), PlatformException);
 }
 
-TEST(ServerResourceBuilderTest, RegisterResourceWhenCallCreate)
+class ServerResourceBuilderTest: public Test
 {
+public:
     MockRepository mocks;
 
-    mocks.ExpectCallFuncOverload(
-            static_cast<registerResourceSig>(OCPlatform::registerResource)).Return(OC_STACK_OK);
+protected:
+    void SetUp() override
+    {
+        mocks.OnCallFuncOverload(static_cast<registerResourceSig>(OCPlatform::registerResource))
+                .Return(OC_STACK_OK);
+    }
+};
 
+TEST_F(ServerResourceBuilderTest, RegisterResourceWhenCallCreate)
+{
+    mocks.ExpectCallFuncOverload(static_cast<registerResourceSig>(OCPlatform::registerResource))
+            .Return(OC_STACK_OK);
     PrimitiveServerResource::Builder(RESOURCE_URI, RESOURCE_TYPE, "").create();
 }
 
-TEST(ServerResourceBuilderTest, ResourceServerHasPropertiesSetByBuilder)
+TEST_F(ServerResourceBuilderTest, ResourceServerHasPropertiesSetByBuilder)
 {
     auto serverResource = PrimitiveServerResource::Builder(RESOURCE_URI, RESOURCE_TYPE, "").
             setDiscoverable(false).setObservable(true).create();
@@ -68,7 +78,7 @@ TEST(ServerResourceBuilderTest, ResourceServerHasPropertiesSetByBuilder)
     EXPECT_TRUE(serverResource->isObservable());
 }
 
-TEST(ServerResourceBuilderTest, ResourceServerHasAttrsSetByBuilder)
+TEST_F(ServerResourceBuilderTest, ResourceServerHasAttrsSetByBuilder)
 {
     ResourceAttributes attrs;
     attrs[KEY] = 100;
index b5bb49de1bcb2364c67fbbb76ee5d46bb1decf85..d5e258b29ec3fa00b1e59a4c0048c542f3108e57 100644 (file)
@@ -33,6 +33,9 @@ using namespace OIC::Service;
 constexpr char EXISTING[]{ "ext" };
 constexpr int ORIGIN_VALUE{ 100 };
 
+using RegisterResource = OCStackResult (*)(OCResourceHandle&, std::string&,
+        const std::string&, const std::string&, OC::EntityHandler, uint8_t);
+
 class SimpleRequestHandlerTest: public Test
 {
 public:
@@ -40,9 +43,14 @@ public:
 
     ResourceAttributes requestAttrs;
 
+    MockRepository mocks;
+
 protected:
     void SetUp() override
     {
+        mocks.OnCallFuncOverload(static_cast<RegisterResource>(OC::OCPlatform::registerResource))
+                .Return(OC_STACK_OK);
+
         server = PrimitiveServerResource::Builder("a/test", "resourceType", "").create();
 
         server->setAttribute(EXISTING, ORIGIN_VALUE);
@@ -91,9 +99,14 @@ public:
     ResourceAttributes requestAttrs;
     RequestHandler::Ptr setRequestProxyHandler;
 
+    MockRepository mocks;
+
 protected:
     void SetUp() override
     {
+        mocks.OnCallFuncOverload(static_cast<RegisterResource>(OC::OCPlatform::registerResource))
+                .Return(OC_STACK_OK);
+
         setRequestProxyHandler = make_shared<SetRequestProxyHandler>(
                 make_shared<SimpleRequestHandler>());