From b45dd0c6399942c9442b83fab5ad5ac037be29bd Mon Sep 17 00:00:00 2001 From: Jihun Ha Date: Thu, 18 Aug 2016 09:06:57 +0900 Subject: [PATCH] Fix unittest of easy setup for TCP option build 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/10559 Reviewed-by: Heewon Park Tested-by: jenkins-iotivity Reviewed-by: Jaehong Jo Reviewed-by: Uze Choi --- .../enrollee/unittests/ESMediatorSimulator.h | 60 ++++++++++++++++++++++ service/easy-setup/enrollee/unittests/SConscript | 11 ++-- .../mediator/richsdk/unittests/ESMediatorTest.cpp | 41 +++++++++++++++ .../mediator/richsdk/unittests/SConscript | 3 +- 4 files changed, 109 insertions(+), 6 deletions(-) mode change 100644 => 100755 service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp diff --git a/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h b/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h index b2969fb..aa43055 100755 --- a/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h +++ b/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h @@ -30,6 +30,10 @@ #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 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 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 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 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 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 resource) { + if(!isValidResourceToTest(resource)) + { + return ; + } + if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) && m_CloudPropProvisioningCb && !m_remoteEnrollee) { diff --git a/service/easy-setup/enrollee/unittests/SConscript b/service/easy-setup/enrollee/unittests/SConscript index 0a25af4..84eb2c0 100644 --- a/service/easy-setup/enrollee/unittests/SConscript +++ b/service/easy-setup/enrollee/unittests/SConscript @@ -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 diff --git a/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp b/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp old mode 100644 new mode 100755 index 1ee6057..f55177b --- a/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp +++ b/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp @@ -35,6 +35,10 @@ #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 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 resource) { + if(!isValidResourceToTest(resource)) + { + return ; + } + if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE)) { m_enrolleeResource = resource; diff --git a/service/easy-setup/mediator/richsdk/unittests/SConscript b/service/easy-setup/mediator/richsdk/unittests/SConscript index 6519619..bc0e032 100644 --- a/service/easy-setup/mediator/richsdk/unittests/SConscript +++ b/service/easy-setup/mediator/richsdk/unittests/SConscript @@ -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']) -- 2.7.4