env.get('SRC_DIR') + '/resource/csdk/security/provisioning/include/internal',
env.get('SRC_DIR') + '/resource/csdk/security/provisioning/include/oxm'])
+if not env.get('RELEASE'):
+ easy_setup_env.PrependUnique(LIBS = ['gcov'])
+ easy_setup_env.AppendUnique(CCFLAGS = ['--coverage'])
+
######################################################################
# Source files and Targets
######################################################################
-
print"easysetup_path %s" % easysetup_path
es_src = None
######################################################################
#Build UnitTestcases for Mediator[RichSDK]
################################################ ######################
-#if target_os == 'linux':
-# SConscript('unittests/SConscript')
+if target_os == 'linux':
+ SConscript('unittests/SConscript')
*
* @return an auth code to be delivered.
*/
- std::string getAuthCode()
+ std::string getAuthCode() const
{
if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
{
*
* @return an auth provider which issued an auth code
*/
- std::string getAuthProvider()
+ std::string getAuthProvider() const
{
if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
{
*
* @return a CI server to be delivered
*/
- std::string getCiServer()
+ std::string getCiServer() const
{
if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
{
*
* @return a SSID of enroller
*/
- std::string getSsid()
+ std::string getSsid() const
{
if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
{
*
* @return a password of enroller
*/
- std::string getPassword()
+ std::string getPassword() const
{
if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
{
*
* @see WIFI_AUTHTYPE
*/
- WIFI_AUTHTYPE getAuthType()
+ WIFI_AUTHTYPE getAuthType() const
{
if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
{
*
* @see WIFI_ENCTYPE
*/
- WIFI_ENCTYPE getEncType()
+ WIFI_ENCTYPE getEncType() const
{
if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
{
*
* @return a language to be set
*/
- std::string getLanguage()
+ std::string getLanguage() const
{
if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
{
*
* @return a country to be set
*/
- std::string getCountry()
+ std::string getCountry() const
{
if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
{
*
* @return a device name of Enrollee
*/
- std::string getDeviceName()
+ std::string getDeviceName() const
{
if(m_DevConfRep.hasAttribute(OC_RSRVD_ES_DEVNAME))
return m_DevConfRep.getValue<std::string>(OC_RSRVD_ES_DEVNAME);
*
* @see WIFI_MODE
*/
- vector<WIFI_MODE> getWiFiModes()
+ vector<WIFI_MODE> getWiFiModes() const
{
vector<WIFI_MODE> modes;
modes.clear();
*
* @see WIFI_FREQ
*/
- WIFI_FREQ getWiFiFreq()
+ WIFI_FREQ getWiFiFreq() const
{
if(m_WiFiRep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
return static_cast<WIFI_FREQ>(
*
* @return an accessibility to cloud server of an Enrollee
*/
- bool isCloudAccessible()
+ bool isCloudAccessible() const
{
if(m_CloudRep.getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
{
std::shared_ptr<RemoteEnrollee> EasySetup::createRemoteEnrollee (std::shared_ptr< OC::OCResource > resource)
{
- if(resource->getResourceTypes().at(0) != OC_RSRVD_ES_RES_TYPE_PROV)
+ if(resource)
{
- OIC_LOG_V (DEBUG, EASYSETUP_TAG, "createRemoteEnrollee : invalid reousrce");
- return nullptr;
+ if(resource->getResourceTypes().at(0) != OC_RSRVD_ES_RES_TYPE_PROV)
+ {
+ OIC_LOG_V (DEBUG, EASYSETUP_TAG, "createRemoteEnrollee : invalid reousrce");
+ return nullptr;
+ }
+ return std::shared_ptr< RemoteEnrollee > (new RemoteEnrollee(resource));
}
- return std::shared_ptr< RemoteEnrollee > (new RemoteEnrollee(resource));
+ return nullptr;
}
}
}
throw ESBadRequestException ("Device not created");
}
- if(!deviceProp.toOCRepresentation().hasAttribute(OC_RSRVD_ES_SSID))
+ if(deviceProp.getSsid().empty())
{
throw ESBadRequestException ("Invalid Provisiong Data.");
}
m_cloudPropProvStatusCb = callback;
- if(!cloudProp.toOCRepresentation().hasAttribute(OC_RSRVD_ES_AUTHCODE) ||
- !cloudProp.toOCRepresentation().hasAttribute(OC_RSRVD_ES_AUTHPROVIDER) ||
- !cloudProp.toOCRepresentation().hasAttribute(OC_RSRVD_ES_CISERVER))
+ if(cloudProp.getAuthCode().empty() ||
+ cloudProp.getAuthProvider().empty() ||
+ cloudProp.getCiServer().empty())
{
throw ESBadRequestException ("Invalid Cloud Provisiong Info.");
}
--- /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 _ES_MEDIATOR_SIMULATOR_H_
+#define _ES_MEDIATOR_SIMULATOR_H_
+
+#include <iostream>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "oic_malloc.h"
+
+#include "escommon.h"
+#include "ESEnrolleeCommon.h"
+#include "easysetup.h"
+
+#define PROV_RESOURCE_TYPE "ocf.wk.prov"
+
+class ESEnrolleeSimulator
+{
+public:
+ ESEnrolleeSimulator()
+ {
+ };
+ ~ESEnrolleeSimulator() = default;
+
+ ESEnrolleeSimulator(const ESEnrolleeSimulator &) = delete;
+ ESEnrolleeSimulator & operator = (const ESEnrolleeSimulator &) = delete;
+
+ ESEnrolleeSimulator(ESEnrolleeSimulator &&) = delete;
+ ESEnrolleeSimulator & operator = (ESEnrolleeSimulator &&) = delete;
+
+ ESResult initEnrollee()
+ {
+ ESResourceMask resourcemMask = (ESResourceMask)(ES_WIFI_RESOURCE |
+ ES_CLOUD_RESOURCE |
+ ES_DEVCONF_RESOURCE);
+ ESProvisioningCallbacks callbacks;
+
+ callbacks.WiFiProvCb = &onWiFiProvisioning;
+ callbacks.DevConfProvCb = &onDevConfProvisioning;
+ callbacks.CloudDataProvCb = &onCloudProvisioning;
+
+ return ESInitEnrollee(false, resourcemMask, callbacks);
+ }
+
+ ESResult setDeviceProperty()
+ {
+ ESDeviceProperty deviceProperty = {
+ {{WIFI_11G, WiFi_EOF}, WIFI_5G}, {"Test Device"}
+ };
+
+ return ESSetDeviceProperty(&deviceProperty);
+ }
+
+ ESResult setESState()
+ {
+ return ESSetState(ES_STATE_CONNECTED_TO_ENROLLER);
+ }
+
+ ESResult setESErrorCode()
+ {
+ return ESSetErrorCode(ES_ERRCODE_NO_INTERNETCONNECTION);
+ }
+
+private:
+ static void onWiFiProvisioning(ESWiFiProvData* /*data*/)
+ {
+ }
+
+ static void onDevConfProvisioning(ESDevConfProvData* /*data*/)
+ {
+ }
+
+ static void onCloudProvisioning(ESCloudProvData* /*data*/)
+ {
+ }
+};
+
+#endif //_NS_CONSUMER_SIMULATOR_H_
--- /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 <gtest/gtest.h>
+#include <HippoMocks/hippomocks.h>
+#include <atomic>
+#include <functional>
+#include <condition_variable>
+#include <mutex>
+#include <chrono>
+
+#include "ESEnrolleeSimulator.h"
+#include "escommon.h"
+#include "ESRichCommon.h"
+#include "EasySetup.h"
+#include "RemoteEnrollee.h"
+
+#include "ESEnrolleeCommon.h"
+#include "easysetup.h"
+
+#define PROV_RESOURCE_TYPE "ocf.wk.prov"
+
+using namespace OC;
+using namespace OIC::Service;
+
+namespace
+{
+ std::atomic_bool g_isStartedStack(false);
+
+ std::chrono::milliseconds g_waitForResponse(1000);
+
+ std::condition_variable responseCon;
+ std::mutex mutexForCondition;
+
+ ESEnrolleeSimulator g_enrolleeSimul;
+ std::shared_ptr<RemoteEnrollee> g_remoteEnrollee;
+}
+
+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;
+ }
+ }
+};
+
+class EasysetupMediatorTest : public TestWithMock
+{
+public:
+ std::shared_ptr<OC::OCResource> m_enrolleeResource;
+
+public:
+ EasysetupMediatorTest() = default;
+ ~EasysetupMediatorTest() = default;
+
+ std::shared_ptr<OC::OCResource> CreateNotProvResource()
+ {
+ OCConnectivityType connectivityType = CT_DEFAULT;
+ std::vector<std::string> types = {"ocf.wk.notprov"};
+ std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
+
+ return OCPlatform::constructResourceObject("coap://192.168.1.2:5000",
+ "/NotProvisioningResURI",
+ connectivityType,
+ false,
+ types,
+ ifaces);
+ }
+
+ void discoverRemoteEnrollee()
+ {
+ std::string uri = std::string("/oic/res?rt=") + PROV_RESOURCE_TYPE;
+ OC::OCPlatform::findResource("", uri,
+ OCConnectivityType::CT_DEFAULT,
+ std::bind(&EasysetupMediatorTest::discoverRemoteEnrolleeCb,
+ this, std::placeholders::_1));
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+ }
+
+protected:
+ void SetUp()
+ {
+ TestWithMock::SetUp();
+ if (g_isStartedStack == false)
+ {
+ if (OCInit(NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK)
+ {
+ printf("OCStack init error!!\n");
+ return;
+ }
+ g_enrolleeSimul.initEnrollee();
+ g_isStartedStack = true;
+ }
+ }
+
+ void TearDown()
+ {
+ TestWithMock::TearDown();
+ }
+
+private:
+ void discoverRemoteEnrolleeCb(std::shared_ptr<OC::OCResource> resource)
+ {
+ if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE))
+ {
+ m_enrolleeResource = resource;
+ }
+ }
+};
+
+TEST_F(EasysetupMediatorTest, createremoteenrolleeFailedWithNotProvResource)
+{
+ auto remoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(CreateNotProvResource());
+
+ EXPECT_EQ(nullptr, remoteEnrollee);
+}
+
+TEST_F(EasysetupMediatorTest, createremoteenrolleeSucceedWithProvResource)
+{
+ discoverRemoteEnrollee();
+ g_remoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(m_enrolleeResource);
+
+ ASSERT_NE(nullptr, g_remoteEnrollee);
+}
+
+class GetConfigurationTest : public EasysetupMediatorTest
+{
+public:
+ GetConfigurationTest() = default;
+ ~GetConfigurationTest() = default;
+
+ static void onGetConfigurationCb(shared_ptr< GetConfigurationStatus > /*status*/)
+ {
+ }
+
+protected:
+ void SetUp()
+ {
+ TestWithMock::SetUp();
+ }
+
+ void TearDown()
+ {
+ TestWithMock::TearDown();
+ }
+};
+
+TEST_F(GetConfigurationTest, ThrowExceptionWhenGetConfigurationFailedByCallbackIsNull)
+{
+ EXPECT_ANY_THROW(g_remoteEnrollee->getConfiguration(nullptr));
+}
+
+TEST_F(GetConfigurationTest, GetConfigurationSucceed)
+{
+ bool isWellConstructed = false;
+
+ g_enrolleeSimul.setDeviceProperty();
+
+ mocks.ExpectCallFunc(onGetConfigurationCb).Do(
+ [&isWellConstructed](std::shared_ptr< GetConfigurationStatus > status)
+ {
+ if(status->getESResult() == ES_OK)
+ {
+ EnrolleeConf conf = status->getEnrolleeConf();
+ if(!conf.getWiFiModes().empty())
+ {
+ if(conf.getWiFiModes().at(0) == WIFI_11G &&
+ conf.getWiFiFreq() == WIFI_5G &&
+ !strcmp(conf.getDeviceName().c_str(), "Test Device"))
+ {
+ isWellConstructed = true;
+ }
+ }
+ }
+ });
+
+ g_remoteEnrollee->getConfiguration(onGetConfigurationCb);
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_TRUE(isWellConstructed);
+}
+
+class GetStatusTest : public EasysetupMediatorTest
+{
+
+public:
+ GetStatusTest() = default;
+ ~GetStatusTest() = default;
+
+ static void onGetStatusCb(shared_ptr< GetEnrolleeStatus > /*status*/)
+ {
+ }
+
+protected:
+ void SetUp()
+ {
+ TestWithMock::SetUp();
+ }
+
+ void TearDown()
+ {
+ TestWithMock::TearDown();
+ }
+};
+
+TEST_F(GetStatusTest, ThrowExceptionWhenGetStatusFailedByCallbackIsNull)
+{
+ EXPECT_ANY_THROW(g_remoteEnrollee->getStatus(nullptr));
+}
+
+TEST_F(GetStatusTest, GetStatusSucceed)
+{
+ g_enrolleeSimul.setESState();
+ g_enrolleeSimul.setESErrorCode();
+
+ bool isWellConstructed = false;
+ mocks.ExpectCallFunc(onGetStatusCb).Do(
+ [&isWellConstructed](std::shared_ptr< GetEnrolleeStatus > status)
+ {
+ if(status->getESResult() == ES_OK)
+ {
+ EnrolleeStatus enrolleeStatus = status->getEnrolleeStatus();
+
+ if(enrolleeStatus.getProvStatus() == ES_STATE_CONNECTED_TO_ENROLLER &&
+ enrolleeStatus.getLastErrCode() == ES_ERRCODE_NO_INTERNETCONNECTION)
+ {
+ isWellConstructed = true;
+ }
+ }
+ });
+
+ g_remoteEnrollee->getStatus(onGetStatusCb);
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_TRUE(isWellConstructed);
+}
+
+class ProvisionDevicePropertiesTest : public EasysetupMediatorTest
+{
+
+public:
+ ProvisionDevicePropertiesTest() = default;
+ ~ProvisionDevicePropertiesTest() = default;
+
+ static void deviceProvisioningStatusCb(
+ shared_ptr< DevicePropProvisioningStatus > /*status*/)
+ {
+ }
+
+protected:
+ void SetUp()
+ {
+ TestWithMock::SetUp();
+ }
+
+ void TearDown()
+ {
+ TestWithMock::TearDown();
+ }
+};
+
+TEST_F(ProvisionDevicePropertiesTest,
+ ThrowExceptionWhenProvisionDeviceProperiesFailedByCallbackIsNull)
+{
+ DeviceProp devProp;
+ devProp.setWiFiProp("Iotivity_SSID", "Iotivity_PWD", WPA2_PSK, TKIP_AES);
+ devProp.setDevConfProp("korean", "Korea");
+
+ EXPECT_ANY_THROW(g_remoteEnrollee->provisionDeviceProperties(devProp, nullptr));
+}
+
+TEST_F(ProvisionDevicePropertiesTest,
+ ThrowExceptionWhenProvisionDeviceProperiesFailedWithoutSSID)
+{
+ DeviceProp devProp;
+ devProp.setWiFiProp("", "Iotivity_PWD", WPA2_PSK, TKIP_AES);
+ devProp.setDevConfProp("korean", "Korea");
+ EXPECT_ANY_THROW(g_remoteEnrollee->provisionDeviceProperties(devProp,
+ deviceProvisioningStatusCb));
+}
+
+TEST_F(ProvisionDevicePropertiesTest,
+ ProvisionDeviceProperiesSucceed)
+{
+ DeviceProp devProp;
+ devProp.setWiFiProp("Iotivity_SSID", "Iotivity_PWD", WPA2_PSK, TKIP_AES);
+ devProp.setDevConfProp("korean", "Korea");
+
+ int cntForReceivedCallbackWithSuccess = 0;
+
+ mocks.OnCallFunc(deviceProvisioningStatusCb).Do(
+ [&cntForReceivedCallbackWithSuccess]
+ (std::shared_ptr< DevicePropProvisioningStatus > status)
+ {
+ if(status->getESResult() == ES_OK)
+ {
+ cntForReceivedCallbackWithSuccess++;
+ }
+
+ });
+
+ g_remoteEnrollee->provisionDeviceProperties(devProp, deviceProvisioningStatusCb);
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(cntForReceivedCallbackWithSuccess, 1);
+}
+
+class ProvisionCloudPropertiesTest : public EasysetupMediatorTest
+{
+
+public:
+ ProvisionCloudPropertiesTest() = default;
+ ~ProvisionCloudPropertiesTest() = default;
+
+ static void cloudPropProvStatusCb(shared_ptr< CloudPropProvisioningStatus > /*status*/)
+ {
+ }
+
+protected:
+ void SetUp()
+ {
+ TestWithMock::SetUp();
+ }
+
+ void TearDown()
+ {
+ TestWithMock::TearDown();
+ }
+};
+
+TEST_F(ProvisionCloudPropertiesTest,
+ ThrowExceptionWhenProvisionCloudPropertiesFailedByCallbackIsNull)
+{
+ CloudProp cloudProp;
+ cloudProp.setCloudProp("authCode", "authProvider", "ciServer");
+ cloudProp.setCloudID("f002ae8b-c42c-40d3-8b8d-1927c17bd1b3");
+
+ EXPECT_ANY_THROW(g_remoteEnrollee->provisionCloudProperties(cloudProp, nullptr));
+}
+
+TEST_F(ProvisionCloudPropertiesTest,
+ ThrowExceptionWhenProvisionCloudPropertiesFailedWithoutAuthCode)
+{
+ CloudProp cloudProp;
+ cloudProp.setCloudProp("", "authProvider", "ciServer");
+ cloudProp.setCloudID("f002ae8b-c42c-40d3-8b8d-1927c17bd1b3");
+ EXPECT_ANY_THROW(g_remoteEnrollee->provisionCloudProperties(cloudProp,
+ cloudPropProvStatusCb));
+}
+
+TEST_F(ProvisionCloudPropertiesTest,
+ ThrowExceptionWhenProvisionCloudPropertiesFailedWithoutAuthProvider)
+{
+ CloudProp cloudProp;
+ cloudProp.setCloudProp("authCode", "", "ciServer");
+ cloudProp.setCloudID("f002ae8b-c42c-40d3-8b8d-1927c17bd1b3");
+ EXPECT_ANY_THROW(g_remoteEnrollee->provisionCloudProperties(cloudProp,
+ cloudPropProvStatusCb));
+}
+
+TEST_F(ProvisionCloudPropertiesTest,
+ ThrowExceptionWhenProvisionCloudPropertiesFailedWithoutCIServer)
+{
+ CloudProp cloudProp;
+ cloudProp.setCloudProp("authCode", "authProvider", "");
+ cloudProp.setCloudID("f002ae8b-c42c-40d3-8b8d-1927c17bd1b3");
+ EXPECT_ANY_THROW(g_remoteEnrollee->provisionCloudProperties(cloudProp,
+ cloudPropProvStatusCb));
+}
+
+TEST_F(ProvisionCloudPropertiesTest, ProvisionCloudPropertiesSucceed)
+{
+ CloudProp cloudProp;
+ cloudProp.setCloudProp("authCode", "authProvider", "ciServer");
+ cloudProp.setCloudID("f002ae8b-c42c-40d3-8b8d-1927c17bd1b3");
+
+ int cntForReceivedCallbackWithSuccess = 0;
+
+ mocks.OnCallFunc(cloudPropProvStatusCb).Do(
+ [& cntForReceivedCallbackWithSuccess](std::shared_ptr< CloudPropProvisioningStatus > status)
+ {
+ // Will called twice
+ if(status->getESResult() == ES_OK)
+ {
+ cntForReceivedCallbackWithSuccess++;
+ }
+ });
+
+ g_remoteEnrollee->provisionCloudProperties(cloudProp, cloudPropProvStatusCb);
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(cntForReceivedCallbackWithSuccess, 2);
+
+ ESTerminateEnrollee();
+}
+++ /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();
-
- 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());
-
- //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);
-
-#ifdef REMOTE_ARDUINO_ENROLEE
- EXPECT_NO_THROW(remoteEnrollee->startProvisioning());
-
-#else
- /* It will throw the exception
- * as it will not able to discover the provisioning resource in the network
- */
- EXPECT_ANY_THROW(remoteEnrollee->startProvisioning());
-#endif
-}
-
-//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, so 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);
-
-#ifdef REMOTE_ARDUINO_ENROLEE
- EXPECT_NO_THROW(remoteEnrollee->startProvisioning());
- EXPECT_NO_THROW(remoteEnrollee->stopProvisioning());
-
-#else
- /* It will throw the exception as
- * it will not able to discover the provisioning resource in the network
- */
- EXPECT_ANY_THROW(remoteEnrollee->startProvisioning());
-
- /* It will throw an exception
- * as internally resource will be empty [startProvisioning is not succeed]
- */
- EXPECT_ANY_THROW(remoteEnrollee->stopProvisioning());
-#endif
-}
-
-//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());
-}
-
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
##
-# Mediator[RichSDK] Unit Test build script
+# Notification Unit Test build script
##
-import os
-# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-lib_env = gtest_env.Clone()
+Import('env')
-if lib_env.get('RELEASE'):
- lib_env.AppendUnique(CCFLAGS = ['-Os'])
- lib_env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+if env.get('RELEASE'):
+ env.AppendUnique(CCFLAGS = ['-Os'])
+ env.AppendUnique(CPPDEFINES = ['NDEBUG'])
else:
- lib_env.AppendUnique(CCFLAGS = ['-g'])
+ env.AppendUnique(CCFLAGS = ['-g'])
-if lib_env.get('LOGGING'):
- lib_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+if env.get('LOGGING'):
+ env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-# Add third party libraries
-SConscript('#service/third_party_libs.scons', 'lib_env')
-
-target_os = lib_env.get('TARGET_OS')
-if target_os in ['linux']:
- # Verify that 'hippomocks' mocking code is installed. If not,
- # get it and install it
- SConscript('#extlibs/hippomocks.scons')
-
-mediator_rich_test_env = lib_env.Clone()
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
######################################################################
#unit test setting
######################################################################
src_dir = lib_env.get('SRC_DIR')
+gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0'
+
+easysetup_test_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
######################################################################
# Build flags
######################################################################
+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 = [
+ 'connectivity_abstraction', 'oc', 'octbstack', 'oc_logger', 'coap',
+ GTest_Main, GTest])
-mediator_rich_test_env.AppendUnique(
- CPPPATH = [
- src_dir + '/extlibs/hippomocks-master',
- '../inc',
- '../../../inc',
- ])
+if target_os not in ['windows', 'winrt']:
+ easysetup_test_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
-if mediator_rich_test_env.get('SECURED') == '1':
- mediator_rich_test_env.PrependUnique(LIBS = ['tinydtls','ocprovision', 'ocpmapi', 'timer'])
+easysetup_test_env.AppendUnique(CXXFLAGS = ['-pthread'])
+easysetup_test_env.AppendUnique(LIBS = ['pthread'])
-mediator_rich_test_env.PrependUnique(LIBS = [
- 'ESMediatorRich',
- 'oc',
- 'octbstack',
- 'oc_logger'])
+easysetup_test_env.PrependUnique(CPPPATH = [ src_dir + '/extlibs/hippomocks-master', gtest_dir + '/include'])
+
+easysetup_test_env.AppendUnique(CPPPATH = [ src_dir + '/resource/include',
+ src_dir + '/service/easy-setup/mediator/richsdk/inc',
+ src_dir + '/service/easy-setup/inc',
+ src_dir + '/service/easy-setup/enrollee/inc'])
######################################################################
# Build Test
######################################################################
-mediator_richsdk_test_src = mediator_rich_test_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)
-mediator_rich_test_env.AppendTarget('mediator_richsdk_test')
+easysetup_mediator_test_env = easysetup_test_env.Clone()
+easysetup_mediator_test_env.AppendUnique(LIBS = ['ESEnrolleeSDK', 'ESMediatorRich'])
+
+easysetup_mediator_test_src = env.Glob(src_dir + '/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp')
+easysetup_mediator_test = easysetup_mediator_test_env.Program('easysetup_mediator_test', easysetup_mediator_test_src)
+Alias("easysetup_mediator_test", easysetup_mediator_test)
+env.AppendTarget('easysetup_mediator_test')
+
+if env.get('TEST') == '1':
+ if target_os == 'linux':
+ from tools.scons.RunTest import *
+ run_test(easysetup_mediator_test_env, '', 'service/easy-setup/mediator/richsdk/unittests/easysetup_mediator_test')
-if mediator_rich_test_env.get('TEST') == '1':
- if target_os in ['linux']:
- from tools.scons.RunTest import *
- run_test(mediator_rich_test_env, '', 'service/easy-setup/mediator/richsdk/unittests/mediator_richsdk_test')
+++ /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