Fix unittest of easy setup for TCP option build
authorJihun Ha <jihun.ha@samsung.com>
Thu, 18 Aug 2016 00:06:57 +0000 (09:06 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 18 Aug 2016 05:34:44 +0000 (05:34 +0000)
With TCP option build, two resources per each network interface are
discovered. We have to filter out the resource with TCP flag.
Additionally, Easysetup unittest tries to discover a real provisioning
resource in a network to the test. So if there is other provisioning
resources in a network, the test would fails. To resolve the problem,
we have to filter out resources running on difference machine.

Change-Id: I130f134b051b598d6f783a6ffa9d0365fec2c172
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10559
Reviewed-by: Heewon Park <h_w.park@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/enrollee/unittests/ESMediatorSimulator.h
service/easy-setup/enrollee/unittests/SConscript
service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/unittests/SConscript

index b2969fb..aa43055 100755 (executable)
 #include "EasySetup.h"
 #include "ESRichCommon.h"
 
+#include "ocrandom.h"
+#include "cainterface.h"
+#include "OCPlatform.h"
+
 #define PROV_RESOURCE_TYPE "ocf.wk.prov"
 
 using namespace OIC::Service;
@@ -115,9 +119,45 @@ public:
     }
 
 private:
+    bool isValidResourceToTest(std::shared_ptr<OC::OCResource> resource)
+    {
+        if((resource->connectivityType() & CT_ADAPTER_TCP) == CT_ADAPTER_TCP)
+        {
+            return false;
+        }
+
+        CAEndpoint_t *tempInfo = NULL;
+        uint32_t tempSize = 0;
+
+        CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
+        if (CA_STATUS_OK != res || NULL == tempInfo || 0 >= tempSize)
+        {
+            free(tempInfo);
+            return false;
+        }
+
+        for (uint32_t index = 0; index  < tempSize; index++)
+        {
+            if (CA_ADAPTER_IP == tempInfo[index].adapter)
+            {
+                if(resource->host().find(tempInfo[index].addr) != std::string::npos &&
+                    resource->host().find(std::to_string(tempInfo[index].port).c_str()) != std::string::npos)
+                {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
 
     void discoverRemoteEnrolleeCb(std::shared_ptr<OC::OCResource> resource)
     {
+        if(!isValidResourceToTest(resource))
+        {
+            return ;
+        }
+
         if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) && m_discoveryCb)
         {
             m_discoveryCb(resource);
@@ -136,6 +176,11 @@ private:
 
     void discoverRemoteEnrolleeCbToGetConfiguration(std::shared_ptr<OC::OCResource> resource)
     {
+        if(!isValidResourceToTest(resource))
+        {
+            return ;
+        }
+
         if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) && m_getConfigurationCb
                                                                            && !m_remoteEnrollee)
         {
@@ -160,6 +205,11 @@ private:
 
     void discoverRemoteEnrolleeCbToGetStatus(std::shared_ptr<OC::OCResource> resource)
     {
+        if(!isValidResourceToTest(resource))
+        {
+            return ;
+        }
+
         if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) && m_getStatusCb
                                                                             && !m_remoteEnrollee)
         {
@@ -185,6 +235,11 @@ private:
 
     void discoverRemoteEnrolleeCbToProvisionDeviceProperties(std::shared_ptr<OC::OCResource> resource)
     {
+        if(!isValidResourceToTest(resource))
+        {
+            return ;
+        }
+
         if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) &&
                                                 m_DevicePropProvisioningCb && !m_remoteEnrollee)
         {
@@ -218,6 +273,11 @@ private:
 
     void discoverRemoteEnrolleeCbToProvisionCloudProperties(std::shared_ptr<OC::OCResource> resource)
     {
+        if(!isValidResourceToTest(resource))
+        {
+            return ;
+        }
+
         if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) &&
                                                 m_CloudPropProvisioningCb && !m_remoteEnrollee)
         {
index 0a25af4..84eb2c0 100644 (file)
@@ -52,7 +52,7 @@ GTest = File(gtest_dir + '/lib/.libs/libgtest.a')
 GTest_Main = File(gtest_dir + '/lib/.libs/libgtest_main.a')
 
 easysetup_test_env.AppendUnique(LIBPATH = [lib_env.get('BUILD_DIR')])
-easysetup_test_env.AppendUnique(LIBS = [
+easysetup_test_env.PrependUnique(LIBS = [
     'connectivity_abstraction', 'oc', 'octbstack', 'oc_logger', 'coap',
     GTest_Main, GTest])
 
@@ -64,10 +64,11 @@ easysetup_test_env.AppendUnique(LIBS = ['pthread'])
 
 easysetup_test_env.PrependUnique(CPPPATH = [ src_dir + '/extlibs/hippomocks-master', gtest_dir + '/include'])
 
-easysetup_test_env.AppendUnique(CPPPATH = ['../../../../resource/include',
-                                         '../inc',
-                                         '../../inc',
-                                         '../../mediator/richsdk/inc'])
+easysetup_test_env.AppendUnique(CPPPATH = [src_dir + '/resource/include',
+                                          src_dir + '/resource/csdk/connectivity/api',
+                                          src_dir + '/service/easy-setup/inc',
+                                          src_dir + '/service/easy-setup/enrollee/inc',
+                                          src_dir + '/service/easy-setup/mediator/richsdk/inc'])
 
 ######################################################################
 # Build Test
old mode 100644 (file)
new mode 100755 (executable)
index 1ee6057..f55177b
 #include "ESEnrolleeCommon.h"
 #include "easysetup.h"
 
+#include "ocrandom.h"
+#include "cainterface.h"
+#include "OCPlatform.h"
+
 #define PROV_RESOURCE_TYPE "ocf.wk.prov"
 
 using namespace OC;
@@ -134,8 +138,45 @@ protected:
     }
 
 private:
+    bool isValidResourceToTest(std::shared_ptr<OC::OCResource> resource)
+    {
+        if((resource->connectivityType() & CT_ADAPTER_TCP) == CT_ADAPTER_TCP)
+        {
+            return false;
+        }
+
+        CAEndpoint_t *tempInfo = NULL;
+        uint32_t tempSize = 0;
+
+        CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
+        if (CA_STATUS_OK != res || NULL == tempInfo || 0 >= tempSize)
+        {
+            free(tempInfo);
+            return false;
+        }
+
+        for (uint32_t index = 0; index  < tempSize; index++)
+        {
+            if (CA_ADAPTER_IP == tempInfo[index].adapter)
+            {
+                if(resource->host().find(tempInfo[index].addr) != std::string::npos &&
+                    resource->host().find(std::to_string(tempInfo[index].port).c_str()) != std::string::npos)
+                {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
     void discoverRemoteEnrolleeCb(std::shared_ptr<OC::OCResource> resource)
     {
+        if(!isValidResourceToTest(resource))
+        {
+            return ;
+        }
+
         if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE))
         {
             m_enrolleeResource = resource;
index 6519619..bc0e032 100644 (file)
@@ -52,7 +52,7 @@ GTest = File(gtest_dir + '/lib/.libs/libgtest.a')
 GTest_Main = File(gtest_dir + '/lib/.libs/libgtest_main.a')
 
 easysetup_test_env.AppendUnique(LIBPATH = [lib_env.get('BUILD_DIR')])
-easysetup_test_env.AppendUnique(LIBS = [
+easysetup_test_env.PrependUnique(LIBS = [
     'connectivity_abstraction', 'oc', 'octbstack', 'oc_logger', 'coap',
     GTest_Main, GTest])
 
@@ -65,6 +65,7 @@ easysetup_test_env.AppendUnique(LIBS = ['pthread'])
 easysetup_test_env.PrependUnique(CPPPATH = [ src_dir + '/extlibs/hippomocks-master', gtest_dir + '/include'])
 
 easysetup_test_env.AppendUnique(CPPPATH = [ src_dir + '/resource/include',
+                                           src_dir + '/resource/csdk/connectivity/api',
                                             src_dir + '/service/easy-setup/mediator/richsdk/inc',
                                             src_dir + '/service/easy-setup/inc',
                                             src_dir + '/service/easy-setup/enrollee/inc'])