From 1897553fd6563f30e4841d2da608deaf569f4a91 Mon Sep 17 00:00:00 2001 From: Senthil Kumar G S Date: Wed, 4 Dec 2019 16:30:21 +0530 Subject: [PATCH] Add Unit Tests for EasySetup APIs. UT for some of the samsung specific APIs are added. https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/633 (cherry-picked from 1798784a33171c8902d64fd5cbb083c370a04e13) Change-Id: Ib37c3d3ce83a2272f82a43a6567dc996b0647199 Signed-off-by: Senthil Kumar G S Signed-off-by: Sudipto --- service/easy-setup/enrollee/SConscript | 6 +- .../enrollee/unittests/ESEnrolleeTest.cpp | 215 +++++++++++++++++++++ service/easy-setup/mediator/richsdk/SConscript | 6 +- tools/generate_report.sh | 3 +- 4 files changed, 223 insertions(+), 7 deletions(-) diff --git a/service/easy-setup/enrollee/SConscript b/service/easy-setup/enrollee/SConscript index b2401f2..8ace91e 100644 --- a/service/easy-setup/enrollee/SConscript +++ b/service/easy-setup/enrollee/SConscript @@ -124,10 +124,10 @@ if target_os == 'arduino': #if target_os == 'arduino': # SConscript('../sampleapp/enrollee/arduino/SConscript') -#if target_os in ['linux']: +if target_os in ['linux']: # SConscript('../sampleapp/enrollee/linux/SConscript') # SConscript('../sampleapp/enrollee/linux-samsung/SConscript') # #Build UnitTestcases for Enrollee -# if enrollee_env.get('SECURED') == '0': -# SConscript('../enrollee/unittests/SConscript') + if enrollee_env.get('SECURED') == '0': + SConscript('../enrollee/unittests/SConscript') diff --git a/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp b/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp index b041d1f..0a172bb 100755 --- a/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp +++ b/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp @@ -29,6 +29,9 @@ #include "ESMediatorSimulator.h" #include "easysetup.h" +extern "C" { +#include "samsung/sc_easysetup.h" +} using namespace OC; namespace @@ -532,3 +535,215 @@ TEST_F(EasysetupEnrolleeTest, ESSetCallabckForUserDataFailed) EXPECT_EQ(ret, ES_ERROR); ESTerminateEnrollee(); } + +TEST_F(EasysetupEnrolleeTest, ESSC_SetSCProperties) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + SCProperties properties; + strncpy(properties.candidateAPInfo[0].ssid, "x_5GHz", MAXLEN_STRING); + strncpy(properties.candidateAPInfo[0].passphrase, "12345678",MAXLEN_STRING); + properties.candidateAPInfo[0].channel = 149; + strncpy(properties.candidateAPInfo[0].bssid, "aa:bb:cc:dd:ee:01", MAXLEN_STRING); + strncpy(properties.candidateAPInfo[1].ssid, "5GHz", MAXLEN_STRING); + strncpy(properties.candidateAPInfo[1].passphrase, "12345678",MAXLEN_STRING); + properties.candidateAPInfo[1].channel = 161; + strncpy(properties.candidateAPInfo[1].bssid, "aa:bb:cc:dd:ee:02", MAXLEN_STRING); + properties.numCandidateAP=2; + + ret = SetSCProperties(&properties); + EXPECT_EQ(ret, ES_OK); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetNULLSCProperties) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetSCProperties(NULL); + EXPECT_EQ(ret, ES_ERROR); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetTncInfo) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + SCTncInfo info; + strncpy(info.header, "h1", MAXLEN_STRING); + strncpy(info.version, "v1",MAXLEN_STRING); + + ret = SetSCTncInfo(&info); + EXPECT_EQ(ret, ES_OK); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetNULLTncInfo) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetSCTncInfo(NULL); + EXPECT_EQ(ret, ES_ERROR); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetTncStatus) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetSCTncStatus(1); + EXPECT_EQ(ret, ES_OK); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetSCNetConnectionState) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetSCNetConnectionState(NET_STATE_INIT); + EXPECT_EQ(ret, ES_OK); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetRegisterSetDevice) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetRegisterSetDevice("fridge"); + EXPECT_EQ(ret, ES_OK); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetNULLRegisterSetDevice) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetRegisterSetDevice(NULL); + EXPECT_EQ(ret, ES_ERROR); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetNetworkProvInfo) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetNetworkProvInfo("netInfo"); + EXPECT_EQ(ret, ES_OK); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetNULLSetNetworkProvInfo) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetNetworkProvInfo(NULL); + EXPECT_EQ(ret, ES_ERROR); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetSCPnPPin) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetSCPnPPin("123456"); + EXPECT_EQ(ret, ES_OK); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetNULLSCPnPPin) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetSCPnPPin(NULL); + EXPECT_EQ(ret, ES_ERROR); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetESVersionInfo) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetESVersionInfo("1.0"); + EXPECT_EQ(ret, ES_OK); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetNULLESVersionInfo) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetESVersionInfo(NULL); + EXPECT_EQ(ret, ES_ERROR); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetSSOList) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetSSOList("xyz"); + EXPECT_EQ(ret, ES_OK); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ESSC_SetNULLSSOList) +{ + ESResult ret = startEnrollee(); + EXPECT_EQ(ret, ES_OK); + + ret = SetSSOList(NULL); + EXPECT_EQ(ret, ES_ERROR); + ESTerminateEnrollee(); +} + +TEST_F(EasysetupEnrolleeTest, ReadWriteUserCallback) +{ + int cntForReceivedCallbackWithSuccess = 0; + + mocks.OnCallFunc(deviceProvisioningStatusCallback).Do( + [& cntForReceivedCallbackWithSuccess](std::shared_ptr< DevicePropProvisioningStatus > status) + { + if(status->getESResult() == ES_OK) + cntForReceivedCallbackWithSuccess++; + }); + + mocks.OnCallFunc(WiFiConfProvCbInApp).Do( + [& cntForReceivedCallbackWithSuccess](ESWiFiConfData *data) + { + if(!strcmp(data->ssid, "Iotivity_SSID") && + !strcmp(data->pwd, "Iotivity_PWD") && + data->authtype == WPA2_PSK && + data->enctype == TKIP_AES) + { + cntForReceivedCallbackWithSuccess++; + } + }); + + startEnrollee(); + + EXPECT_EQ(ESSetCallbackForUserdata(&ReadUserdataCb, &WriteUserdataCb), ES_OK); + + g_mediatorSimul.provisionDeviceProperties(deviceProvisioningStatusCallback); + + std::unique_lock< std::mutex > lock{ mutexForCondition }; + responseCon.wait_for(lock, g_waitForResponse); + + EXPECT_EQ(cntForReceivedCallbackWithSuccess, 2); + + ESTerminateEnrollee(); +} + diff --git a/service/easy-setup/mediator/richsdk/SConscript b/service/easy-setup/mediator/richsdk/SConscript index eaf5422..585b1ff 100755 --- a/service/easy-setup/mediator/richsdk/SConscript +++ b/service/easy-setup/mediator/richsdk/SConscript @@ -173,7 +173,7 @@ if target_os in ['android']: ###################################################################### #Build UnitTestcases for Mediator[RichSDK] ################################################ ###################### -#if env.get('SECURED') == '0': -# if target_os == 'linux': -# SConscript('unittests/SConscript') +if env.get('SECURED') == '0': + if target_os == 'linux': + SConscript('unittests/SConscript') diff --git a/tools/generate_report.sh b/tools/generate_report.sh index 929ced0..dee43c2 100644 --- a/tools/generate_report.sh +++ b/tools/generate_report.sh @@ -200,13 +200,13 @@ generate_report_CA() tests_list=( "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/csdk/connectivity/test/catests" - "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/csdk/stack/test/stacktests" "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/csdk/stack/test/cbortests" "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/unittests/unittests" "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/c_common/ocrandom/test/randomtests" "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/c_common/oic_malloc/test/malloctests" "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/c_common/oic_string/test/stringtests" "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/c_common/oic_time/test/timetests" + "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/resource/csdk/stack/test/stacktests" ); for exe in ${tests_list[@]}; do @@ -481,6 +481,7 @@ generate_report_RE() tests_list=( "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/service/resource-encapsulation/src/serverBuilder/rcs_server_test" "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/service/resource-encapsulation/src/common/rcs_common_test" + "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/service/resource-encapsulation/unittests/rcs_client_test" "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/service/resource-encapsulation/src/resourceCache/unittests/cache_test" "${IOTIVITY_BASE}/out/${IOTIVITY_TARGET_OS}/${IOTIVITY_TARGET_ARCH}/debug/service/resource-encapsulation/src/resourceBroker/unittest/broker_test" ); -- 2.7.4