Fixed tests in resource-encapsulation by using move ctor
authorPhilippe Coval <philippe.coval@osg.samsung.com>
Thu, 3 Mar 2016 17:25:47 +0000 (18:25 +0100)
committerUze Choi <uzchoi@samsung.com>
Sun, 6 Mar 2016 08:32:23 +0000 (08:32 +0000)
DiscoveryTaskPtr is a unique_ptr, therefore it is a move-only object,
which is why ScopeTask's copy constructor is deleted.

This change Fix FTBFS by declaring move constructor (C++11 &&) in Task class
and also use it also in instance declaration to avoid copies.

Issue appeared with g++-4.9.2 on Tizen:Common and probably other setup

Reported error message is in this form :

  service/resource-encapsulation/unittests/DiscoveryManagerTest.cpp: \
  In member function 'virtual void DiscoveryManagerTest_CallbackWouldNotBeCalledForSameRemoteResource_Test::TestBody()':

  service/resource-encapsulation/unittests/DiscoveryManagerTest.cpp:139:33: \
  error: use of deleted function 'ScopedTask::ScopedTask(const ScopedTask&)'
             onResourceDiscovered);
                                 ^

Change-Id: I0fe6d5c4037ddf90e83185d96f99c9378c56caa7
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5361
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-encapsulation/unittests/DiscoveryManagerTest.cpp

index 0ede8c2..ef5aaa2 100755 (executable)
@@ -45,7 +45,7 @@ void onResourceDiscovered(RCSRemoteResourceObject::Ptr) {}
 class ScopedTask
 {
 public:
-    ScopedTask(DiscoveryTaskPtr task) :
+    ScopedTask(DiscoveryTaskPtr&& task) :
         m_task{ std::move(task) }
     {
     }
@@ -92,8 +92,8 @@ TEST(DiscoveryManagerTest, DiscoverInvokesFindResource)
         }
     ).Return(OC_STACK_OK);
 
-    ScopedTask task RCSDiscoveryManager::getInstance()->discoverResourceByType(
-            RCSAddress::multicast(), RESOURCE_URI, RESOURCE_TYPE, onResourceDiscovered);
+    ScopedTask task {RCSDiscoveryManager::getInstance()->discoverResourceByType(
+            RCSAddress::multicast(), RESOURCE_URI, RESOURCE_TYPE, onResourceDiscovered)};
 }
 
 TEST(DiscoveryManagerTest, DiscoverWithMultipleTypesInvokesFindResourceMultipleTimes)
@@ -110,18 +110,18 @@ TEST(DiscoveryManagerTest, DiscoverWithMultipleTypesInvokesFindResourceMultipleT
         }
     ).Return(OC_STACK_OK);
 
-    ScopedTask task RCSDiscoveryManager::getInstance()->discoverResourceByTypes(
-            RCSAddress::multicast(), resourceTypes, onResourceDiscovered);
+    ScopedTask task {RCSDiscoveryManager::getInstance()->discoverResourceByTypes(
+            RCSAddress::multicast(), resourceTypes, onResourceDiscovered)};
 
     EXPECT_EQ(counter, resourceTypes.size());
 }
 
 TEST(DiscoveryManagerTest, TaskCanBeCanceled)
 {
-    ScopedTask aTask =  RCSDiscoveryManager::getInstance()->discoverResource(RCSAddress::multicast(),
-            onResourceDiscovered);
-    ScopedTask aTaskToBeCanceled RCSDiscoveryManager::getInstance()->discoverResource(
-            RCSAddress::multicast(), onResourceDiscovered);
+    ScopedTask aTask {RCSDiscoveryManager::getInstance()->discoverResource(RCSAddress::multicast(),
+            onResourceDiscovered)};
+    ScopedTask aTaskToBeCanceled {RCSDiscoveryManager::getInstance()->discoverResource(
+            RCSAddress::multicast(), onResourceDiscovered)};
 
     aTaskToBeCanceled->cancel();
 
@@ -141,8 +141,8 @@ TEST(DiscoveryManagerTest, CallbackWouldNotBeCalledForSameRemoteResource) {
        }
    ).Return(OC_STACK_OK);
 
-    ScopedTask aTask =  RCSDiscoveryManager::getInstance()->discoverResource(RCSAddress::multicast(),
-            onResourceDiscovered);
+    ScopedTask aTask {RCSDiscoveryManager::getInstance()->discoverResource(RCSAddress::multicast(),
+            onResourceDiscovered)};
 
     std::vector< std::string > interfaces{ "interface" };
     std::vector< std::string > resourceTypes{ "resource.type" };