Updated unit test for Resource Hosting.
authorjyong2.kim <jyong2.kim@samsung.com>
Mon, 29 Feb 2016 09:31:49 +0000 (18:31 +0900)
committerHabib Virji <habib.virji@samsung.com>
Wed, 2 Mar 2016 06:43:57 +0000 (06:43 +0000)
a couple of unit test is added at RH unit test.
disable install of unit test file to build root path.

Change-Id: I1882973addf5eb3a86132dd9d0ccfda6fc10199c
Signed-off-by: jyong2.kim <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5267
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Habib Virji <habib.virji@samsung.com>
service/resource-hosting/unittest/HostingObjectUnitTest.cpp
service/resource-hosting/unittest/SConscript

index 96d7700..b56a4cf 100755 (executable)
@@ -42,9 +42,12 @@ namespace
     HostingObject::Ptr instance;
     RCSRemoteResourceObject::Ptr discoveredResource;
 
-    void onDestroy(){ }
+    std::condition_variable responseCon;
+
+    void onDestroy() { }
     void onDiscoveryResource(RCSRemoteResourceObject::Ptr){ }
     void onUpdatedCache(const RCSResourceAttributes &) { }
+    void onSetAttributes(const RCSResourceAttributes &, int) { }
 
     void setup()
     {
@@ -78,7 +81,6 @@ class HostingObjectTest : public TestWithMock
 {
 public:
     std::mutex mutexForCondition;
-    std::condition_variable responseCon;
 
 protected:
 
@@ -175,3 +177,38 @@ TEST_F(HostingObjectTest, UpdateCachedDataWhenChangedOriginResource)
     EXPECT_EQ(result.toString(), settingValue.toString());
 
 }
+
+TEST_F(HostingObjectTest, SetDataToMirroredResource)
+{
+    int waitForResponse = 1000;
+    RCSResourceAttributes::Value result = { };
+
+    mocks.ExpectCallFunc(onSetAttributes).Do(
+            [this, & result](const RCSResourceAttributes &att, int)
+            {
+                result = att.at(TEST_ATT_KEY);
+                notifyCondition();
+            });
+    RCSResourceAttributes setAttrs;
+    RCSResourceAttributes::Value settingValue = 20;
+    setAttrs[TEST_ATT_KEY] = settingValue;
+    discoveredResource->setRemoteAttributes(setAttrs, onSetAttributes);
+    waitForCondition(waitForResponse);
+
+    EXPECT_EQ(result.toString(), settingValue.toString());
+}
+
+TEST_F(HostingObjectTest, ExpectCallOnDestroyWhenStopHostingObject)
+{
+    int waitForResponse = 1000;
+
+    mocks.ExpectCallFunc(onDestroy).Do(
+            [& responseCon]()
+            {
+                responseCon.notify_all();
+            });
+
+    testObject.destroy();
+    instance.reset();
+    waitForCondition(waitForResponse);
+}
index 49ea8ed..2b15b0a 100644 (file)
@@ -79,7 +79,6 @@ hosting_test_src = env.Glob('./*.cpp')
 hosting_test = hosting_test_env.Program('hosting_test', hosting_test_src)
 Alias("hosting_test", hosting_test)
 env.AppendTarget('hosting_test')
-hosting_test_env.InstallTarget(hosting_test, 'hosting_test')
 
 if env.get('TEST') == '1':
     target_os = env.get('TARGET_OS')