- gtest cases for Mediator CSDK.
- gtest cases for Mediator C++SDK [Rich].
- Fix for the one unit test case of CSDK.
- Build fix for secure flag
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Change-Id: I49ed095f44a94fa577b8828cd4812a673ab08ef5
Reviewed-on: https://gerrit.iotivity.org/gerrit/5133
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
if target_os == 'linux':
easy_setup_env.AppendUnique(LIBS = ['pthread', 'dl'])
-
+
######################################################################
# Linux Mediator
-######################################################################
+######################################################################
if target_os == 'linux':
easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
easy_setup_env.AppendUnique(CXXFLAGS = ['-pthread'])
easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
-
+
######################################################################
# Android Mediator
-######################################################################
+######################################################################
if target_os == 'android':
easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
easy_setup_env.AppendUnique(LIBS = ['log'])
-if target_os in ['android','linux']:
+if target_os in ['android','linux']:
easy_setup_env.PrependUnique(CPPPATH = [
- env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',
+ env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',
env.get('SRC_DIR') + '/resource/csdk/connectivity/common/inc',
env.get('SRC_DIR') + '/resource/csdk/connectivity/api',
env.get('SRC_DIR') + '/resource/csdk/stack/include',
#Go to build sample apps
SConscript('../../sampleapp/mediator/linux/csdk_sample/SConscript')
-
+######################################################################
+#Build UnitTestcases for Mediator[CSDK]
+################################################ ######################
+if target_os == 'linux':
+ SConscript('unittests/SConscript')
char findQuery[64] = {0};
+ if(provConfig == NULL || onboardConn == NULL){
+ return OC_STACK_ERROR;
+ }
+
#ifdef REMOTE_ARDUINO_ENROLEE
//Arduino Enrollee needs mediator application provide IP and port55555 which is specific
// to Arduino WiFi enrollee
--- /dev/null
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "UnitTestHelper.h"
+
+#include "ocstack.h"
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "oic_string.h"
+#include "logger.h"
+
+#include "prov_adapter.h"
+#include "provisioning.h"
+#include "escommon.h"
+
+#include <iostream>
+#include <string.h>
+#include <functional>
+#include <pthread.h>
+#include <condition_variable>
+
+class MediatorCSDKTest: public TestWithMock
+{
+
+ protected:
+ void SetUp()
+ {
+ TestWithMock::SetUp();
+ }
+
+ void TearDown()
+ {
+ TestWithMock::TearDown();
+ }
+
+};
+
+//callbacks
+void OCProvisioningStatusCallback(EasySetupInfo *easySetupInfo) {}
+
+/* Test cases for prov_adapter*/
+
+//InitProvProcess
+TEST_F(MediatorCSDKTest, testInitProvProcess)
+{
+ OCStackResult result = InitProvProcess();
+ ASSERT_EQ(OC_STACK_OK, result);
+}
+
+//ResetProvProcess
+TEST_F(MediatorCSDKTest, testResetProvProcess)
+{
+ OCStackResult result = ResetProvProcess();
+ ASSERT_EQ(OC_STACK_OK, result);
+}
+
+//RegisterCallback [positive]
+TEST_F(MediatorCSDKTest, testRegisterCallback)
+{
+ OCStackResult result = RegisterCallback(&OCProvisioningStatusCallback);
+ ASSERT_EQ(OC_STACK_OK, result);
+}
+
+//RegisterCallback [Negative]
+TEST_F(MediatorCSDKTest, testRegisterCallbackNegative)
+{
+ OCStackResult result = RegisterCallback(NULL);
+ ASSERT_EQ(OC_STACK_ERROR, result);
+}
+
+//StartProvisioning [positive]
+TEST_F(MediatorCSDKTest, testStartProvisioning)
+{
+ ProvConfig provConfig;
+ WiFiOnboadingConnection onboardConn;
+
+ strncpy(onboardConn.ipAddress, "1.1.1.1", IPV4_ADDR_SIZE - 1);
+
+ strncpy(provConfig.provData.WIFI.ssid, "testAP", NET_WIFI_SSID_SIZE - 1);
+ strncpy(provConfig.provData.WIFI.pwd, "test@123", NET_WIFI_PWD_SIZE - 1);
+ provConfig.connType = CT_ADAPTER_IP;
+
+ //API Call
+ OCStackResult result = StartProvisioning(&provConfig, &onboardConn);
+
+ ASSERT_EQ(OC_STACK_OK, result);
+}
+
+//StartProvisioning [Negative]
+TEST_F(MediatorCSDKTest, testStartProvisioningNegative)
+{
+ OCStackResult result = StartProvisioning(NULL, NULL);
+ ASSERT_EQ(OC_STACK_ERROR, result);
+}
+
+//StopProvisioning
+TEST_F(MediatorCSDKTest, testStopProvisioning)
+{
+ // This API always return success
+ OCStackResult result = StopProvisioning(CT_ADAPTER_IP);
+ ASSERT_EQ(OC_STACK_OK, result);
+}
+
+
--- /dev/null
+#******************************************************************
+#
+# Copyright 2016 Samsung Electronics All Rights Reserved.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# Mediator[CSDK] Unit Test build script
+##
+import os
+Import('env')
+
+if env.get('RELEASE'):
+ env.AppendUnique(CCFLAGS = ['-Os'])
+ env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+ env.AppendUnique(CCFLAGS = ['-g'])
+
+if env.get('LOGGING'):
+ env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+target_os = env.get('TARGET_OS')
+if target_os == 'linux':
+ # Verify that 'google unit test' library is installed. If not,
+ # get it and install it
+ SConscript(env.get('SRC_DIR') + '/extlibs/gtest/SConscript')
+
+ # Verify that 'hippomocks' mocking code is installed. If not,
+ # get it and install it
+ SConscript(env.get('SRC_DIR') + '/extlibs/hippomocks.scons')
+
+mediator_csdk_test_env = lib_env.Clone()
+
+######################################################################
+#unit test setting
+######################################################################
+src_dir = lib_env.get('SRC_DIR')
+gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0'
+
+######################################################################
+# Build flags
+######################################################################
+gtest = File(gtest_dir + '/lib/.libs/libgtest.a')
+gtest_main = File(gtest_dir + '/lib/.libs/libgtest_main.a')
+
+mediator_csdk_test_env.AppendUnique(
+ CPPPATH = [
+ src_dir + '/extlibs/hippomocks-master',
+ src_dir + '/extlibs/gtest/gtest-1.7.0/include',
+ '../inc',
+ '../../../inc',
+ ])
+
+if target_os not in ['windows', 'winrt']:
+ mediator_csdk_test_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
+ if target_os != 'android':
+ mediator_csdk_test_env.AppendUnique(CXXFLAGS = ['-pthread'])
+ mediator_csdk_test_env.AppendUnique(LIBS = ['pthread'])
+
+mediator_csdk_test_env.PrependUnique(LIBS = [
+ 'ESMediatorCSDK',
+ 'oc',
+ 'octbstack',
+ 'oc_logger',
+ 'oc_logger_core',
+ 'connectivity_abstraction',
+ gtest,
+ gtest_main])
+
+mediator_csdk_test_env.AppendUnique(LIBS = ['dl'])
+
+######################################################################
+# Build Test
+######################################################################
+mediator_csdk_test_src = env.Glob('./*.cpp')
+
+mediator_csdk_test = mediator_csdk_test_env.Program('mediator_csdk_test', mediator_csdk_test_src)
+Alias("mediator_csdk_test", mediator_csdk_test)
+env.AppendTarget('mediator_csdk_test')
+
+if env.get('TEST') == '1':
+ target_os = env.get('TARGET_OS')
+ if target_os == 'linux':
+ from tools.scons.RunTest import *
+ run_test(mediator_csdk_test_env, '', 'service/easy-setup/mediator/csdk/unittests/mediator_csdk_test')
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef COMMON_UTILS_UNITTESTHELPER_H
+#define COMMON_UTILS_UNITTESTHELPER_H
+
+#include <gtest/gtest.h>
+#include <HippoMocks/hippomocks.h>
+
+class TestWithMock: public testing::Test
+{
+ public:
+ MockRepository mocks;
+
+ protected:
+ virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test())) {}
+
+ virtual void TearDown()
+ {
+ try
+ {
+ mocks.VerifyAll();
+ }
+ catch (...)
+ {
+ mocks.reset();
+ throw;
+ }
+ }
+};
+#endif // COMMON_UTILS_UNITTESTHELPER_H
print "Files path is %s" % env.get('es_src')
-#Go to build sample apps
+######################################################################
+# Build RichSDK Mediator Sample App
+################################################ ######################
if target_os == 'linux':
SConscript('../../sampleapp/mediator/linux/richsdk_sample/SConscript')
+######################################################################
+#Build UnitTestcases for Mediator[RichSDK]
+################################################ ######################
+if target_os == 'linux':
+ SConscript('unittests/SConscript')
--- /dev/null
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "UnitTestHelper.h"
+
+#include "ocstack.h"
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "oic_string.h"
+#include "logger.h"
+
+#include "EasySetup.h"
+#include "RemoteEnrollee.h"
+#include "ESException.h"
+
+#include <iostream>
+#include <functional>
+#include <pthread.h>
+#include <condition_variable>
+
+using namespace OIC::Service;
+
+const std::string ipaddress = "1.1.1.1";
+const std::string ssid = "test";
+const std::string pwd = "test@123";
+
+class MediatorRichTest: public TestWithMock
+{
+ protected:
+ void SetUp()
+ {
+ TestWithMock::SetUp();
+ }
+
+ void TearDown()
+ {
+ TestWithMock::TearDown();
+ }
+};
+
+//callbacks
+void easySetupStatusCallback (std::shared_ptr< EasySetupStatus > easySetupStatus) {}
+
+/* Test cases for easysetyup class*/
+
+//getInstance
+TEST_F(MediatorRichTest, testGetInstance)
+{
+ EasySetup *easySetupIntance1 = EasySetup::getInstance();
+ EasySetup *easySetupIntance2 = EasySetup::getInstance();
+
+ EXPECT_EQ(easySetupIntance1, easySetupIntance2);
+}
+
+//createEnrolleeDevice [positive]
+TEST_F(MediatorRichTest, testCreateEnrolleeDevice)
+{
+ RemoteEnrollee::shared_ptr remoteEnrollee = NULL;
+ ProvConfig netInfo;
+ WiFiOnboadingConnection onboardingConn;
+
+ netInfo.connType = CT_ADAPTER_IP;
+
+ OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+ OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+ onboardingConn.isSecured = false;
+ OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
+
+ remoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo, onboardingConn);
+
+ EXPECT_TRUE(remoteEnrollee != NULL);
+}
+
+//createEnrolleeDevice [Negative]
+TEST_F(MediatorRichTest, testCreateEnrolleeDeviceNegative)
+{
+ RemoteEnrollee::shared_ptr remoteEnrollee = NULL;
+ ProvConfig netInfo ;
+ WiFiOnboadingConnection onboardingConn;
+ EasySetup *easysetupInstance = EasySetup::getInstance();
+
+ //calling the createEnrolleeDevice
+ remoteEnrollee = easysetupInstance->createEnrolleeDevice(netInfo, onboardingConn);
+ //calling again the createEnrolleeDevice with same config & connection info [API throws the exception]
+ EXPECT_ANY_THROW(easysetupInstance->createEnrolleeDevice(netInfo, onboardingConn));
+}
+
+//createEnrolleeDevice [positive (creating the two RemoteEnrolleeDevice with different config)]
+TEST_F(MediatorRichTest, testCreateEnrolleeMultipleDevice)
+{
+ RemoteEnrollee::shared_ptr remoteEnrollee1 = NULL;
+ RemoteEnrollee::shared_ptr remoteEnrollee2 = NULL;
+ WiFiOnboadingConnection onboardingConn1;
+ WiFiOnboadingConnection onboardingConn2;
+ ProvConfig netInfo1;
+ ProvConfig netInfo2;
+ std::string ipaddress2 = "0.0.0.0";
+
+ //calling the API for the first device
+ netInfo1.connType = CT_ADAPTER_IP;
+ OICStrcpy(netInfo1.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+ OICStrcpy(netInfo1.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+ onboardingConn1.isSecured = false;
+ OICStrcpy(onboardingConn1.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
+ remoteEnrollee1 = EasySetup::getInstance()->createEnrolleeDevice(netInfo1, onboardingConn1);
+
+ //calling the API for the second device
+ netInfo1.connType = CT_ADAPTER_IP;
+ OICStrcpy(netInfo1.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+ OICStrcpy(netInfo1.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+ onboardingConn1.isSecured = false;
+ OICStrcpy(onboardingConn1.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress2.c_str());
+ remoteEnrollee2 = EasySetup::getInstance()->createEnrolleeDevice(netInfo2, onboardingConn2);
+
+ EXPECT_TRUE(remoteEnrollee1 != NULL);
+ EXPECT_TRUE(remoteEnrollee2 != NULL);
+}
+
+/*Test cases for RemoteEnrollee class*/
+
+//registerEasySetupStatusHandler [positive]
+TEST_F(MediatorRichTest, testRegisterEasySetupStatusHandler)
+{
+ //creation of the Remote Enrollee Device
+ RemoteEnrollee::shared_ptr remoteEnrollee = NULL;
+ ProvConfig netInfo;
+ WiFiOnboadingConnection onboardingConn;
+
+ netInfo.connType = CT_ADAPTER_IP;
+
+ OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+ OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+ onboardingConn.isSecured = false;
+ OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
+
+ remoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo, onboardingConn);
+
+ //calling the API
+ EXPECT_NO_THROW( remoteEnrollee->registerEasySetupStatusHandler(&easySetupStatusCallback));
+}
+
+//registerEasySetupStatusHandler [Negative]
+TEST_F(MediatorRichTest, testRegisterEasySetupStatusHandlerNegative)
+{
+ //creation of the Remote Enrollee Device
+ RemoteEnrollee::shared_ptr remoteEnrollee = NULL;
+ ProvConfig netInfo;
+ WiFiOnboadingConnection onboardingConn;
+
+ netInfo.connType = CT_ADAPTER_IP;
+
+ OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+ OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+ onboardingConn.isSecured = false;
+ OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
+
+ remoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo, onboardingConn);
+
+ //calling the API
+ EXPECT_ANY_THROW( remoteEnrollee->registerEasySetupStatusHandler(NULL));
+}
+
+//isEnrolleeProvisioned
+TEST_F(MediatorRichTest, testIsEnrolleeProvisioned)
+{
+ //creation of the Remote Enrollee Device
+ RemoteEnrollee::shared_ptr remoteEnrollee = NULL;
+ ProvConfig netInfo;
+ WiFiOnboadingConnection onboardingConn;
+
+ netInfo.connType = CT_ADAPTER_IP;
+
+ OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+ OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+ onboardingConn.isSecured = false;
+ OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
+
+ remoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo, onboardingConn);
+
+ //calling the API
+ bool isEnrolleeProvisioned = remoteEnrollee->isEnrolleeProvisioned();
+
+ EXPECT_TRUE(false == isEnrolleeProvisioned);
+}
+
+//startProvisioning [positive]
+TEST_F(MediatorRichTest, testStartProvisioning)
+{
+ //creation of the Remote Enrollee Device
+ RemoteEnrollee::shared_ptr remoteEnrollee = NULL;
+ ProvConfig netInfo;
+ WiFiOnboadingConnection onboardingConn;
+
+ netInfo.connType = CT_ADAPTER_IP;
+
+ OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+ OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+ onboardingConn.isSecured = false;
+ OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
+
+ remoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo, onboardingConn);
+ remoteEnrollee->registerEasySetupStatusHandler(&easySetupStatusCallback);
+
+ //calling the APIs
+ EXPECT_NO_THROW(remoteEnrollee->startProvisioning());
+}
+
+//startProvisioning [Negative]
+TEST_F(MediatorRichTest, testStartProvisioningNegative)
+{
+ //creation of the Remote Enrollee Device
+ RemoteEnrollee::shared_ptr remoteEnrollee = NULL;
+ ProvConfig netInfo;
+ WiFiOnboadingConnection onboardingConn;
+
+ netInfo.connType = CT_ADAPTER_IP;
+
+ OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+ OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+ onboardingConn.isSecured = false;
+ OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
+
+ remoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo, onboardingConn);
+
+ /*We are not registering the EasySetupStatusHandler that is why startProvisioning
+ will throw the Exception & we are checking the same
+ */
+ EXPECT_ANY_THROW(remoteEnrollee->startProvisioning());
+}
+
+//stopProvisioning [positive]
+TEST_F(MediatorRichTest, testStopProvisioning)
+{
+ //creation of the Remote Enrollee Device
+ RemoteEnrollee::shared_ptr remoteEnrollee = NULL;
+ ProvConfig netInfo;
+ WiFiOnboadingConnection onboardingConn;
+
+ netInfo.connType = CT_ADAPTER_IP;
+
+ OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+ OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+ onboardingConn.isSecured = false;
+ OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
+
+ remoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo, onboardingConn);
+ remoteEnrollee->registerEasySetupStatusHandler(&easySetupStatusCallback);
+
+ remoteEnrollee->startProvisioning();
+
+ EXPECT_NO_THROW(remoteEnrollee->stopProvisioning());
+}
+
+//stopProvisioning [Negative]
+TEST_F(MediatorRichTest, testStopProvisioningNegative)
+{
+ //creation of the Remote Enrollee Device
+ RemoteEnrollee::shared_ptr remoteEnrollee = NULL;
+ ProvConfig netInfo;
+ WiFiOnboadingConnection onboardingConn;
+
+ netInfo.connType = CT_ADAPTER_IP;
+
+ OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+ OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+ onboardingConn.isSecured = false;
+ OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
+
+ remoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo, onboardingConn);
+ remoteEnrollee->registerEasySetupStatusHandler(&easySetupStatusCallback);
+
+ /* we didn't call the start provisioning API and directly calling stopProvisioning API.
+ In this case API will throw the exception & we are checking the same.
+ */
+ EXPECT_ANY_THROW(remoteEnrollee->stopProvisioning());
+}
+
--- /dev/null
+#******************************************************************
+#
+# Copyright 2016 Samsung Electronics All Rights Reserved.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# Mediator[RichSDK] Unit Test build script
+##
+import os
+Import('env')
+
+if env.get('RELEASE'):
+ env.AppendUnique(CCFLAGS = ['-Os'])
+ env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+ env.AppendUnique(CCFLAGS = ['-g'])
+
+if env.get('LOGGING'):
+ env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+target_os = env.get('TARGET_OS')
+if target_os == 'linux':
+ # Verify that 'google unit test' library is installed. If not,
+ # get it and install it
+ SConscript(env.get('SRC_DIR') + '/extlibs/gtest/SConscript')
+
+ # Verify that 'hippomocks' mocking code is installed. If not,
+ # get it and install it
+ SConscript(env.get('SRC_DIR') + '/extlibs/hippomocks.scons')
+
+mediator_rich_test_env = lib_env.Clone()
+
+######################################################################
+#unit test setting
+######################################################################
+src_dir = lib_env.get('SRC_DIR')
+gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0'
+
+######################################################################
+# Build flags
+######################################################################
+gtest = File(gtest_dir + '/lib/.libs/libgtest.a')
+gtest_main = File(gtest_dir + '/lib/.libs/libgtest_main.a')
+
+mediator_rich_test_env.AppendUnique(
+ CPPPATH = [
+ src_dir + '/extlibs/hippomocks-master',
+ src_dir + '/extlibs/gtest/gtest-1.7.0/include',
+ '../inc',
+ '../../../inc',
+ ])
+
+if target_os not in ['windows', 'winrt']:
+ mediator_rich_test_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
+ if target_os != 'android':
+ mediator_rich_test_env.AppendUnique(CXXFLAGS = ['-pthread'])
+ mediator_rich_test_env.AppendUnique(LIBS = ['pthread'])
+
+
+if env.get('SECURED') == '1':
+ mediator_rich_test_env.PrependUnique(LIBS = ['tinydtls','ocprovision', 'ocpmapi'])
+
+mediator_rich_test_env.PrependUnique(LIBS = [
+ 'oc',
+ 'octbstack',
+ 'oc_logger',
+ 'oc_logger_core',
+ 'connectivity_abstraction',
+ 'coap',
+ 'ESMediatorRich',
+ gtest,
+ gtest_main])
+
+mediator_rich_test_env.AppendUnique(LIBS = ['dl'])
+
+######################################################################
+# Build Test
+######################################################################
+mediator_richsdk_test_src = env.Glob('./*.cpp')
+
+mediator_richsdk_test = mediator_rich_test_env.Program('mediator_richsdk_test', mediator_richsdk_test_src)
+Alias("mediator_richsdk_test", mediator_richsdk_test)
+env.AppendTarget('mediator_richsdk_test')
+
+if env.get('TEST') == '1':
+ target_os = env.get('TARGET_OS')
+ if target_os == 'linux':
+ from tools.scons.RunTest import *
+ run_test(mediator_rich_test_env, '', 'service/easy-setup/mediator/richsdk/unittests/mediator_richsdk_test')
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef COMMON_UTILS_UNITTESTHELPER_H
+#define COMMON_UTILS_UNITTESTHELPER_H
+
+#include <gtest/gtest.h>
+#include <HippoMocks/hippomocks.h>
+
+class TestWithMock: public testing::Test
+{
+ public:
+ MockRepository mocks;
+
+ protected:
+ virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test())) {}
+
+ virtual void TearDown()
+ {
+ try
+ {
+ mocks.VerifyAll();
+ }
+ catch (...)
+ {
+ mocks.reset();
+ throw;
+ }
+ }
+};
+#endif // COMMON_UTILS_UNITTESTHELPER_H