[Mediator]Unit Test cases for C & C++ SDK 33/5133/3
authorJay Sharma <jay.sharma@samsung.com>
Tue, 23 Feb 2016 15:04:45 +0000 (20:34 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Wed, 24 Feb 2016 00:52:30 +0000 (00:52 +0000)
- 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>
service/easy-setup/mediator/csdk/SConscript
service/easy-setup/mediator/csdk/src/prov_adapter.cpp
service/easy-setup/mediator/csdk/unittests/MediatorCSDKTest.cpp [new file with mode: 0644]
service/easy-setup/mediator/csdk/unittests/SConscript [new file with mode: 0644]
service/easy-setup/mediator/csdk/unittests/UnitTestHelper.h [new file with mode: 0644]
service/easy-setup/mediator/richsdk/SConscript
service/easy-setup/mediator/richsdk/unittests/MediatorRichTest.cpp [new file with mode: 0644]
service/easy-setup/mediator/richsdk/unittests/SConscript [new file with mode: 0644]
service/easy-setup/mediator/richsdk/unittests/UnitTestHelper.h [new file with mode: 0644]

index 39ff052..d1163eb 100644 (file)
@@ -67,19 +67,19 @@ easy_setup_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
 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')])
@@ -89,9 +89,9 @@ if target_os == 'android':
                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',
@@ -121,7 +121,11 @@ if target_os == 'linux':
        #Go to build sample apps
        SConscript('../../sampleapp/mediator/linux/csdk_sample/SConscript')
 
-
+######################################################################
+#Build UnitTestcases for Mediator[CSDK]
+################################################ ######################
+if target_os == 'linux':
+    SConscript('unittests/SConscript')
 
 
 
index 878e5e9..d2ed0f8 100644 (file)
@@ -89,6 +89,10 @@ OCStackResult StartProvisioning(const ProvConfig *provConfig, WiFiOnboadingConne
 
     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
diff --git a/service/easy-setup/mediator/csdk/unittests/MediatorCSDKTest.cpp b/service/easy-setup/mediator/csdk/unittests/MediatorCSDKTest.cpp
new file mode 100644 (file)
index 0000000..57b6e63
--- /dev/null
@@ -0,0 +1,121 @@
+//******************************************************************
+//
+// 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);
+}
+
+
diff --git a/service/easy-setup/mediator/csdk/unittests/SConscript b/service/easy-setup/mediator/csdk/unittests/SConscript
new file mode 100644 (file)
index 0000000..734f051
--- /dev/null
@@ -0,0 +1,103 @@
+#******************************************************************
+#
+# 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
diff --git a/service/easy-setup/mediator/csdk/unittests/UnitTestHelper.h b/service/easy-setup/mediator/csdk/unittests/UnitTestHelper.h
new file mode 100644 (file)
index 0000000..2bf7424
--- /dev/null
@@ -0,0 +1,48 @@
+//******************************************************************
+//
+// 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
index b4b2d39..71364d0 100644 (file)
@@ -124,8 +124,15 @@ if target_os in ['android','linux']:
 
 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')
 
diff --git a/service/easy-setup/mediator/richsdk/unittests/MediatorRichTest.cpp b/service/easy-setup/mediator/richsdk/unittests/MediatorRichTest.cpp
new file mode 100644 (file)
index 0000000..afe86bb
--- /dev/null
@@ -0,0 +1,304 @@
+//******************************************************************
+//
+// 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());
+}
+
diff --git a/service/easy-setup/mediator/richsdk/unittests/SConscript b/service/easy-setup/mediator/richsdk/unittests/SConscript
new file mode 100644 (file)
index 0000000..480df19
--- /dev/null
@@ -0,0 +1,108 @@
+#******************************************************************
+#
+# 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
diff --git a/service/easy-setup/mediator/richsdk/unittests/UnitTestHelper.h b/service/easy-setup/mediator/richsdk/unittests/UnitTestHelper.h
new file mode 100644 (file)
index 0000000..2bf7424
--- /dev/null
@@ -0,0 +1,48 @@
+//******************************************************************
+//
+// 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