Using Hippomock, unittest codes for enrollee have been implemented.
Change-Id: I1c64a97aae20e0b27c605e7a78bd6a0ada14c6b9
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9923
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
enrollee_env.get('SRC_DIR') + '/resource/include',
enrollee_env.get('SRC_DIR') + '/resource/csdk/logger/include',
enrollee_env.get('SRC_DIR') + '/resource/oc_logger/include',
- enrollee_env.get('SRC_DIR') + '/resource/csdk/stack/include',
- enrollee_env.get('SRC_DIR') + '/resource/csdk/logger/include',
+ enrollee_env.get('SRC_DIR') + '/resource/csdk/stack/include',
+ enrollee_env.get('SRC_DIR') + '/resource/csdk/logger/include',
enrollee_env.get('SRC_DIR') + '/resource/csdk/security/include',
enrollee_env.get('SRC_DIR') + '/extlibs/cjson',
enrollee_env.get('SRC_DIR') + '/extlibs/sqlite3',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/inc',
- enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/inc',
- enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src',
- enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino'])
+ enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src'])
if enrollee_env.get('SECURED') == '1':
enrollee_env.AppendUnique(CPPPATH = [
if target_os not in ['windows']:
enrollee_env.AppendUnique(CXXFLAGS = ['-Wall', '-std=c++0x'])
+if not env.get('RELEASE'):
+ enrollee_env.PrependUnique(LIBS = ['gcov'])
+ enrollee_env.AppendUnique(CCFLAGS = ['--coverage'])
+
######################################################################
# Linux Enrollee
######################################################################
if target_os in ['linux']:
- enrollee_env.PrependUnique(CPPPATH = [
- enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi'])
-
enrollee_env.AppendUnique(LIBS = ['pthread', 'dl'])
enrollee_env.AppendUnique(LIBPATH = [enrollee_env.get('BUILD_DIR')])
enrollee_env.AppendUnique(RPATH = [enrollee_env.get('BUILD_DIR')])
enrollee_env.AppendUnique(LIBPATH = [enrollee_env.get('BUILD_DIR')])
enrollee_env.AppendUnique(RPATH = [enrollee_env.get('BUILD_DIR')])
enrollee_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
- enrollee_env.AppendUnique(CPPPATH = [
- enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/wifi'])
######################################################################
# Source files and Targets
######################################################################
es_enrollee_src = None
-if target_os == 'linux':
- es_enrollee_common_src = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
- enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c'
- ]
-
- enrollee_env.AppendUnique(es_enrollee_src = es_enrollee_common_src)
-
- enrollee_sdk_shared = enrollee_env.SharedLibrary('ESEnrolleeSDK', enrollee_env.get('es_enrollee_src'))
+if target_os in ['linux', 'tizen']:
+ es_enrollee_common_src = ['./src/easysetup.c','./src/resourcehandler.c']
+ enrollee_sdk_shared = enrollee_env.SharedLibrary('ESEnrolleeSDK', es_enrollee_common_src)
enrollee_env.InstallTarget(enrollee_sdk_shared, 'libESEnrollee')
-
-if target_os == 'tizen':
- es_enrollee_common_src = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
- enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c'
- ]
-
- enrollee_env.AppendUnique(es_enrollee_src = es_enrollee_common_src)
- enrollee_sdk_shared = enrollee_env.SharedLibrary('ESEnrolleeSDK', enrollee_env.get('es_enrollee_src'))
- enrollee_env.InstallTarget(enrollee_sdk_shared, 'libESEnrollee')
- enrollee_env.UserInstallTargetLib(enrollee_sdk_shared, 'libESEnrolleeSDK')
+ enrollee_env.UserInstallTargetLib(enrollee_sdk_shared, 'libESEnrollee')
if target_os == 'arduino':
- es_sdk_static = enrollee_env.StaticLibrary('ESEnrolleeSDK', [
- enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
- enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c'
- ])
-
- enrollee_env.InstallTarget(es_sdk_static, 'libESEnrolleeSDK')
+ es_enrollee_common_src = ['./src/easysetup.c','./src/resourcehandler.c']
+ enrollee_sdk_static = enrollee_env.StaticLibrary('ESEnrolleeSDK', es_enrollee_common_src)
+ enrollee_env.InstallTarget(enrollee_sdk_static, 'libESEnrolleeSDK')
+ enrollee_env.UserInstallTargetLib(enrollee_sdk_static, 'libESEnrollee')
#Go to build sample apps
#if target_os == 'arduino':
if target_os in ['linux']:
SConscript('../sampleapp/enrollee/linux/SConscript')
#Build UnitTestcases for Enrollee
-# SConscript('../enrollee/unittests/SConscript')
+ SConscript('../enrollee/unittests/SConscript')
#include "escommon.h"
#include "ESEnrolleeCommon.h"
-#include "ocpayload.h"
-
/**
* @file
*
}
if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
{
- if(callbacks.DevConfProvCb != NULL)
+ if(callbacks.CloudDataProvCb != NULL)
{
gESProvisioningCb.CloudDataProvCb = callbacks.CloudDataProvCb;
RegisterCloudRsrcEventCallBack(ESCloudRsrcCallback);
//-----------------------------------------------------------------------------
OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *ehRequest,
void *callback);
-const char *getResult(OCStackResult result);
OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
void updateWiFiResource(OCRepPayload* input);
void updateCloudResource(OCRepPayload* input);
void updateDevConfResource(OCRepPayload* input);
+const char *getResult(OCStackResult result);
ESWiFiCB gWifiRsrcEvtCb = NULL;
ESCloudCB gCloudRsrcEvtCb = NULL;
res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_LL);
if(res)
{
- OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
+ OIC_LOG_V(INFO, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
return res;
}
res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_BATCH);
if(res)
{
- OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
+ OIC_LOG_V(INFO, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
return res;
}
}
if(gReadUserdataCb)
+ {
gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_WIFI, wiFiData->userdata);
+ }
if(ssid || cred || authType!= -1 || encType != -1)
{
}
if(gReadUserdataCb)
+ {
gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER, cloudData->userdata);
+ }
if(authCode || authProvider || ciServer)
{
}
if(gReadUserdataCb)
+ {
gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_DEVCONF, devConfData->userdata);
+ }
if(country || language)
{
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) gWiFiResource.encType);
if(gWriteUserdataCb)
+ {
gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_WIFI);
+ }
return payload;
}
OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, gDevConfResource.country);
if(gWriteUserdataCb)
+ {
gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
+ }
return payload;
}
OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LINKS, gProvResource.ocfWebLinks);
if(gWriteUserdataCb)
+ {
gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_PROV);
+ }
if(ehRequest->query)
{
OCRepPayload *getResp = NULL;
if(ehRequest->resource == gProvResource.handle)
+ {
getResp = constructResponseOfProv(ehRequest);
+ }
else if(ehRequest->resource == gWiFiResource.handle)
+ {
getResp = constructResponseOfWiFi();
+ }
else if(ehRequest->resource == gCloudResource.handle)
+ {
getResp = constructResponseOfCloud();
+ }
else if(ehRequest->resource == gDevConfResource.handle)
+ {
getResp = constructResponseOfDevConf();
+ }
if (!getResp)
{
return ehResult;
}
- // TBD : Discuss about triggering flag (to be existed or not)
- // ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
- // A new request for provisioning means overriding existing network provisioning information.
-
if(ehRequest->resource == gProvResource.handle)
+ {
updateProvResource(ehRequest, input);
+ }
else if(ehRequest->resource == gWiFiResource.handle)
+ {
updateWiFiResource(input);
+ }
else if(ehRequest->resource == gCloudResource.handle)
+ {
updateCloudResource(input);
+ }
else if(ehRequest->resource == gDevConfResource.handle)
+ {
updateDevConfResource(input);
+ }
OCRepPayload *getResp = NULL;
if(ehRequest->resource == gProvResource.handle)
+ {
getResp = constructResponseOfProv(ehRequest);
+ }
else if(ehRequest->resource == gWiFiResource.handle)
+ {
getResp = constructResponseOfWiFi();
+ }
else if(ehRequest->resource == gCloudResource.handle)
+ {
getResp = constructResponseOfCloud();
+ }
else if(ehRequest->resource == gDevConfResource.handle)
+ {
getResp = constructResponseOfDevConf();
+ }
if (!getResp)
{
OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode OUT");
return OC_STACK_OK;
}
+
const char *getResult(OCStackResult result)
{
switch (result)
default:
return "UNKNOWN";
}
-}
-
+}
\ 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <gtest/gtest.h>
+#include <HippoMocks/hippomocks.h>
+#include <atomic>
+#include <functional>
+#include <condition_variable>
+#include <mutex>
+#include <chrono>
+
+#include "ESMediatorSimulator.h"
+#include "easysetup.h"
+
+using namespace OC;
+
+namespace
+{
+ std::atomic_bool g_isStartedStack(false);
+
+ std::chrono::milliseconds g_waitForResponse(1000);
+
+ std::condition_variable responseCon;
+ std::mutex mutexForCondition;
+
+ ESMediatorSimulator g_mediatorSimul;
+}
+
+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 EasysetupEnrolleeTest : public TestWithMock
+{
+public:
+ EasysetupEnrolleeTest() = default;
+ ~EasysetupEnrolleeTest() = default;
+
+ static void discoveredResource(std::shared_ptr<OC::OCResource>)
+ {
+ std::cout << __func__ << std::endl;
+ }
+
+ static void onGetStatus(std::shared_ptr< GetEnrolleeStatus >)
+ {
+ std::cout << __func__ << std::endl;
+ }
+
+ static void onGetConfiguration(std::shared_ptr< GetConfigurationStatus >)
+ {
+ std::cout << __func__ << std::endl;
+ }
+
+ static void deviceProvisioningStatusCallback(std::shared_ptr< DevicePropProvisioningStatus >)
+ {
+ std::cout << __func__ << std::endl;
+ }
+
+ static void cloudProvisioningStatusCallback(std::shared_ptr< CloudPropProvisioningStatus >)
+ {
+ std::cout << __func__ << std::endl;
+ }
+
+ static void WiFiProvCbInApp(ESWiFiProvData *)
+ {
+ std::cout << __func__ << std::endl;
+ }
+
+ static void DevConfProvCbInApp(ESDevConfProvData *)
+ {
+ std::cout << __func__ << std::endl;
+ }
+
+ static void CloudDataCbInApp(ESCloudProvData *)
+ {
+ std::cout << __func__ << std::endl;
+ }
+
+ ESResult startEnrollee()
+ {
+ ESResourceMask resourcemMask = (ESResourceMask)(ES_WIFI_RESOURCE |
+ ES_CLOUD_RESOURCE |
+ ES_DEVCONF_RESOURCE);
+ ESProvisioningCallbacks callbacks;
+ callbacks.WiFiProvCb = &EasysetupEnrolleeTest::WiFiProvCbInApp;
+ callbacks.DevConfProvCb = &EasysetupEnrolleeTest::DevConfProvCbInApp;
+ callbacks.CloudDataProvCb = &EasysetupEnrolleeTest::CloudDataCbInApp;
+
+ return ESInitEnrollee(false, resourcemMask, callbacks);
+ }
+
+ ESResult setDeviceProperty()
+ {
+ ESDeviceProperty deviceProperty = {
+ {{WIFI_11G, WiFi_EOF}, WIFI_5G}, {"Test Device"}
+ };
+
+ return ESSetDeviceProperty(&deviceProperty);
+ }
+
+protected:
+
+ void SetUp()
+ {
+ TestWithMock::SetUp();
+
+ if (g_isStartedStack == false)
+ {
+ if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
+ {
+ printf("OCStack init error!!\n");
+ return;
+ }
+
+ g_isStartedStack = true;
+ }
+ }
+
+ void TearDown()
+ {
+ TestWithMock::TearDown();
+ }
+
+};
+
+TEST_F(EasysetupEnrolleeTest, ESInitEnrolleeSuccess)
+{
+ ESResult ret = startEnrollee();
+ EXPECT_EQ(ret, ES_OK);
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, ESInitEnrolleeFailedByWiFiCbIsNull)
+{
+ ESResourceMask resourcemMask = (ESResourceMask)(ES_WIFI_RESOURCE |
+ ES_CLOUD_RESOURCE |
+ ES_DEVCONF_RESOURCE);
+ ESProvisioningCallbacks callbacks;
+ callbacks.WiFiProvCb = NULL;
+ callbacks.DevConfProvCb = &EasysetupEnrolleeTest::DevConfProvCbInApp;
+ callbacks.CloudDataProvCb = &EasysetupEnrolleeTest::CloudDataCbInApp;
+
+ ESResult ret = ESInitEnrollee(false, resourcemMask, callbacks);
+ EXPECT_EQ(ret, ES_ERROR);
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, ESInitEnrolleeFailedByDevConfCbIsNull)
+{
+ ESResourceMask resourcemMask = (ESResourceMask)(ES_WIFI_RESOURCE |
+ ES_CLOUD_RESOURCE |
+ ES_DEVCONF_RESOURCE);
+ ESProvisioningCallbacks callbacks;
+ callbacks.WiFiProvCb = &EasysetupEnrolleeTest::WiFiProvCbInApp;
+ callbacks.DevConfProvCb = NULL;
+ callbacks.CloudDataProvCb = &EasysetupEnrolleeTest::CloudDataCbInApp;
+
+ ESResult ret = ESInitEnrollee(false, resourcemMask, callbacks);
+ EXPECT_EQ(ret, ES_ERROR);
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, ESInitEnrolleeFailedByCloudCbIsNull)
+{
+ ESResourceMask resourcemMask = (ESResourceMask)(ES_WIFI_RESOURCE |
+ ES_CLOUD_RESOURCE |
+ ES_DEVCONF_RESOURCE);
+ ESProvisioningCallbacks callbacks;
+ callbacks.WiFiProvCb = &EasysetupEnrolleeTest::WiFiProvCbInApp;
+ callbacks.DevConfProvCb = &EasysetupEnrolleeTest::DevConfProvCbInApp;
+ callbacks.CloudDataProvCb = NULL;
+
+ ESResult ret = ESInitEnrollee(false, resourcemMask, callbacks);
+ EXPECT_EQ(ret, ES_ERROR);
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, FindProvisioningResourceAtEnrolleeWithSuccess)
+{
+ mocks.ExpectCallFunc(discoveredResource).Do(
+ [](std::shared_ptr<OC::OCResource> resource)
+ {
+ try
+ {
+ std::cout<<"DISCOVERED Resource:"<<std::endl;
+ // Get the resource host address
+ std::string uri = resource->uri();
+ std::cout << "\tURI of the resource: " << uri << std::endl;
+ } catch (OCException &e)
+ {
+ std::cout << e.reason() << std::endl;
+ }
+
+ });
+
+ ESResult ret = startEnrollee();
+
+ g_mediatorSimul.discoverRemoteEnrollee(discoveredResource);
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(ret, ES_OK);
+
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, SetDevicePropertyWithSuccess)
+{
+ ESResult ret = startEnrollee();
+ ret = setDeviceProperty();
+ EXPECT_EQ(ret, ES_OK);
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, SetProvStatusWithSuccess)
+{
+ ESResult ret = startEnrollee();
+ ret = ESSetState(ES_STATE_CONNECTED_TO_ENROLLER);
+ EXPECT_EQ(ret, ES_OK);
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, SetErrorCodeWithSuccess)
+{
+ ESResult ret = startEnrollee();
+ ret = ESSetErrorCode(ES_ERRCODE_PW_WRONG);
+ EXPECT_EQ(ret, ES_OK);
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, DevicePropertyIsWellConstructedInResponsePayload)
+{
+ bool isWellConstructed = false;
+ mocks.ExpectCallFunc(onGetConfiguration).Do(
+ [& isWellConstructed](std::shared_ptr< GetConfigurationStatus > status)
+ {
+ if(status->getESResult() == ES_OK)
+ {
+ EnrolleeConf conf = status->getEnrolleeConf();
+ if(conf.getWiFiModes().at(0) == WIFI_11G &&
+ conf.getWiFiFreq() == WIFI_5G &&
+ !strcmp(conf.getDeviceName().c_str(), "Test Device"))
+ {
+ isWellConstructed = true;
+ }
+ }
+ });
+ ESResult ret = startEnrollee();
+ ret = setDeviceProperty();
+
+ g_mediatorSimul.getConfiguration(onGetConfiguration);
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(ret, ES_OK);
+
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, ProvisioningPropertiesIsWellConstructedInResponsePayload)
+{
+ bool isWellConstructed = false;
+ mocks.ExpectCallFunc(onGetStatus).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;
+ }
+ });
+ ESResult ret = startEnrollee();
+ ret = setDeviceProperty();
+ ret = ESSetState(ES_STATE_CONNECTED_TO_ENROLLER);
+ ret = ESSetErrorCode(ES_ERRCODE_NO_INTERNETCONNECTION);
+
+ g_mediatorSimul.getStatus(onGetStatus);
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(ret, ES_OK);
+
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, WiFiAndDevConfProperiesProvisionedWithSuccess)
+{
+ int cntForReceivedCallbackWithSuccess = 0;
+
+ mocks.OnCallFunc(deviceProvisioningStatusCallback).Do(
+ [& cntForReceivedCallbackWithSuccess](std::shared_ptr< DevicePropProvisioningStatus > status)
+ {
+ if(status->getESResult() == ES_OK)
+ cntForReceivedCallbackWithSuccess++;
+ });
+
+ mocks.OnCallFunc(WiFiProvCbInApp).Do(
+ [& cntForReceivedCallbackWithSuccess](ESWiFiProvData *data)
+ {
+ if(!strcmp(data->ssid, "Iotivity_SSID") &&
+ !strcmp(data->pwd, "Iotivity_PWD") &&
+ data->authtype == WPA2_PSK &&
+ data->enctype == TKIP_AES)
+ cntForReceivedCallbackWithSuccess++;
+ });
+ mocks.OnCallFunc(DevConfProvCbInApp).Do(
+ [& cntForReceivedCallbackWithSuccess](ESDevConfProvData *data)
+ {
+ if(!strcmp(data->language, "korean") &&
+ !strcmp(data->country, "Korea"))
+ cntForReceivedCallbackWithSuccess++;
+ });
+
+ startEnrollee();
+
+ g_mediatorSimul.provisionDeviceProperties(deviceProvisioningStatusCallback);
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(cntForReceivedCallbackWithSuccess, 3);
+
+ ESTerminateEnrollee();
+}
+
+TEST_F(EasysetupEnrolleeTest, CloudServerProperiesProvisionedWithSuccess)
+{
+ int cntForReceivedCallbackWithSuccess = 0;
+
+ mocks.OnCallFunc(cloudProvisioningStatusCallback).Do(
+ [& cntForReceivedCallbackWithSuccess](std::shared_ptr< CloudPropProvisioningStatus > status)
+ {
+ // Will called twice
+ if(status->getESResult() == ES_OK)
+ cntForReceivedCallbackWithSuccess++;
+ });
+
+ mocks.OnCallFunc(CloudDataCbInApp).Do(
+ [& cntForReceivedCallbackWithSuccess](ESCloudProvData *data)
+ {
+ if(!strcmp(data->authCode, "authCode") &&
+ !strcmp(data->authProvider, "authProvider") &&
+ !strcmp(data->ciServer, "ciServer"))
+ cntForReceivedCallbackWithSuccess++;
+ });
+
+ startEnrollee();
+
+ g_mediatorSimul.provisionCloudProperties(cloudProvisioningStatusCallback);
+
+ std::unique_lock< std::mutex > lock{ mutexForCondition };
+ responseCon.wait_for(lock, g_waitForResponse);
+
+ EXPECT_EQ(cntForReceivedCallbackWithSuccess, 3);
+
+ 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef _ES_MEDIATOR_SIMULATOR_H_
+#define _ES_MEDIATOR_SIMULATOR_H_
+
+#include <iostream>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "oic_malloc.h"
+
+#include "EasySetup.h"
+#include "ESRichCommon.h"
+
+#define PROV_RESOURCE_TYPE "ocf.wk.prov"
+
+using namespace OIC::Service;
+
+class ESMediatorSimulator
+{
+private:
+ std::function<void(std::shared_ptr<OC::OCResource> resource)> m_discoveryCb;
+ std::function<void(std::shared_ptr< GetConfigurationStatus > status)> m_getConfigurationCb;
+ std::function<void(std::shared_ptr< GetEnrolleeStatus >)> m_getStatusCb;
+ std::function<void(std::shared_ptr< DevicePropProvisioningStatus >)> m_DevicePropProvisioningCb;
+ std::function<void(std::shared_ptr< CloudPropProvisioningStatus >)> m_CloudPropProvisioningCb;
+
+ std::shared_ptr<RemoteEnrollee> m_remoteEnrollee;
+
+public:
+ ESMediatorSimulator()
+ : m_remoteEnrollee(), m_discoveryCb(), m_getConfigurationCb(), m_getStatusCb(),
+ m_DevicePropProvisioningCb(), m_CloudPropProvisioningCb() { };
+ ~ESMediatorSimulator() = default;
+
+ ESMediatorSimulator(const ESMediatorSimulator &) = delete;
+ ESMediatorSimulator & operator = (const ESMediatorSimulator &) = delete;
+
+ ESMediatorSimulator(ESMediatorSimulator &&) = delete;
+ ESMediatorSimulator & operator = (ESMediatorSimulator &&) = delete;
+
+ void discoverRemoteEnrollee(std::function<void(std::shared_ptr<OC::OCResource> resource)> cb)
+ {
+ m_discoveryCb = cb;
+ std::string uri = std::string("/oic/res?rt=") + PROV_RESOURCE_TYPE;
+ OC::OCPlatform::findResource("", uri,
+ OCConnectivityType::CT_DEFAULT,
+ std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCb,
+ this, std::placeholders::_1));
+
+ }
+
+ void getConfiguration(std::function<void(std::shared_ptr< GetConfigurationStatus >)> cb)
+ {
+ m_getConfigurationCb = cb;
+ m_remoteEnrollee = NULL;
+ std::string uri = std::string("/oic/res?rt=") + PROV_RESOURCE_TYPE;
+ OC::OCPlatform::findResource("", uri,
+ OCConnectivityType::CT_DEFAULT,
+ std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetConfiguration,
+ this, std::placeholders::_1));
+ }
+
+ void getStatus(std::function<void(std::shared_ptr< GetEnrolleeStatus >)> cb)
+ {
+ m_getStatusCb = cb;
+ m_remoteEnrollee = NULL;
+ std::string uri = std::string("/oic/res?rt=") + PROV_RESOURCE_TYPE;
+ OC::OCPlatform::findResource("", uri,
+ OCConnectivityType::CT_DEFAULT,
+ std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetStatus,
+ this, std::placeholders::_1));
+ }
+
+ void provisionDeviceProperties(std::function<void(std::shared_ptr< DevicePropProvisioningStatus >)> cb)
+ {
+ m_DevicePropProvisioningCb = cb;
+ m_remoteEnrollee = NULL;
+ std::string uri = std::string("/oic/res?rt=") + PROV_RESOURCE_TYPE;
+ OC::OCPlatform::findResource("", uri,
+ OCConnectivityType::CT_DEFAULT,
+ std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToProvisionDeviceProperties,
+ this, std::placeholders::_1));
+ }
+
+ void provisionCloudProperties(std::function<void(std::shared_ptr< CloudPropProvisioningStatus >)> cb)
+ {
+ m_CloudPropProvisioningCb = cb;
+ m_remoteEnrollee = NULL;
+ std::string uri = std::string("/oic/res?rt=") + PROV_RESOURCE_TYPE;
+ OC::OCPlatform::findResource("", uri,
+ OCConnectivityType::CT_DEFAULT,
+ std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToProvisionCloudProperties,
+ this, std::placeholders::_1));
+ }
+
+private:
+
+ void discoverRemoteEnrolleeCb(std::shared_ptr<OC::OCResource> resource)
+ {
+ if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) && m_discoveryCb)
+ {
+ m_discoveryCb(resource);
+ m_discoveryCb = NULL;
+ }
+ }
+
+ void getConfigurationCallback(std::shared_ptr< GetConfigurationStatus > getConfigurationStatus)
+ {
+ if(m_getConfigurationCb != NULL)
+ {
+ m_getConfigurationCb(getConfigurationStatus);
+ m_getConfigurationCb = NULL;
+ }
+ }
+
+ void discoverRemoteEnrolleeCbToGetConfiguration(std::shared_ptr<OC::OCResource> resource)
+ {
+ if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) && m_getConfigurationCb
+ && !m_remoteEnrollee)
+ {
+ m_remoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(resource);
+
+ if(m_remoteEnrollee != NULL)
+ {
+ m_remoteEnrollee->getConfiguration(std::bind(
+ &ESMediatorSimulator::getConfigurationCallback, this, std::placeholders::_1));
+ }
+ }
+ }
+
+ void getStatusCallback(std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus)
+ {
+ if(m_getStatusCb != NULL)
+ {
+ m_getStatusCb(getEnrolleeStatus);
+ m_getStatusCb = NULL;
+ }
+ }
+
+ void discoverRemoteEnrolleeCbToGetStatus(std::shared_ptr<OC::OCResource> resource)
+ {
+ if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) && m_getStatusCb
+ && !m_remoteEnrollee)
+ {
+ m_remoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(resource);
+
+ if(m_remoteEnrollee != NULL)
+ {
+ m_remoteEnrollee->getStatus(std::bind(
+ &ESMediatorSimulator::getStatusCallback, this, std::placeholders::_1));
+ }
+ }
+ }
+
+ void deviceProvisioningStatusCallback(std::shared_ptr< DevicePropProvisioningStatus >
+ devicePropProvisioningStatus)
+ {
+ if(m_DevicePropProvisioningCb != NULL)
+ {
+ m_DevicePropProvisioningCb(devicePropProvisioningStatus);
+ m_DevicePropProvisioningCb = NULL;
+ }
+ }
+
+ void discoverRemoteEnrolleeCbToProvisionDeviceProperties(std::shared_ptr<OC::OCResource> resource)
+ {
+ if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) &&
+ m_DevicePropProvisioningCb && !m_remoteEnrollee)
+ {
+ m_remoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(resource);
+
+ if(m_remoteEnrollee != NULL)
+ {
+ DeviceProp devProp;
+ devProp.setWiFiProp("Iotivity_SSID", "Iotivity_PWD", WPA2_PSK, TKIP_AES);
+ devProp.setDevConfProp("korean", "Korea");
+
+ m_remoteEnrollee->provisionDeviceProperties(devProp,
+ std::bind(&ESMediatorSimulator::deviceProvisioningStatusCallback,
+ this, std::placeholders::_1));
+ }
+ }
+ }
+
+ void cloudProvisioningStatusCallback(std::shared_ptr< CloudPropProvisioningStatus >
+ cloudPropProvisioningStatus)
+ {
+ if(m_CloudPropProvisioningCb != NULL)
+ {
+ m_CloudPropProvisioningCb(cloudPropProvisioningStatus);
+ if(cloudPropProvisioningStatus->getESCloudState() == ES_CLOUD_PROVISIONING_SUCCESS)
+ m_CloudPropProvisioningCb = NULL;
+ }
+ }
+
+ void discoverRemoteEnrolleeCbToProvisionCloudProperties(std::shared_ptr<OC::OCResource> resource)
+ {
+ if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) &&
+ m_CloudPropProvisioningCb && !m_remoteEnrollee)
+ {
+ m_remoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(resource);
+
+ if(m_remoteEnrollee != NULL)
+ {
+ CloudProp cloudProp;
+ cloudProp.setCloudProp("authCode", "authProvider", "ciServer");
+
+ m_remoteEnrollee->provisionCloudProperties(cloudProp,
+ std::bind(&ESMediatorSimulator::cloudProvisioningStatusCallback,
+ this, std::placeholders::_1));
+ }
+ }
+ }
+};
+
+
+#endif //_NS_CONSUMER_SIMULATOR_H_
+
-#######################################################################
+#******************************************************************
+#
# Copyright 2016 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-import os
-import os.path
+##
+# Notification Unit Test build script
+##
+
+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'])
+
+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'
-# SConscript file for Local PKI google tests
-gtest_env = SConscript('#extlibs/gtest/SConscript')
-enrollee_test_env = gtest_env.Clone()
-src_dir = enrollee_test_env.get('SRC_DIR')
-target_os = enrollee_test_env.get('TARGET_OS')
+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])
+
+if target_os not in ['windows', 'winrt']:
+ easysetup_test_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+
+easysetup_test_env.AppendUnique(CXXFLAGS = ['-pthread'])
+easysetup_test_env.AppendUnique(LIBS = ['pthread'])
+
+easysetup_test_env.PrependUnique(CPPPATH = [ src_dir + '/extlibs/hippomocks-master', gtest_dir + '/include'])
-enrollee_test_env.PrependUnique(CPPPATH = [
- enrollee_test_env.get('SRC_DIR') + '/resource/c_common/ocrandom/include',
- enrollee_test_env.get('SRC_DIR') + '/resource/csdk/stack/include/internal',
- enrollee_test_env.get('SRC_DIR') + '/resource/csdk/connectivity/api',
- enrollee_test_env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',
- enrollee_test_env.get('SRC_DIR') + '/resource/include',
- enrollee_test_env.get('SRC_DIR') + '/resource/csdk/logger/include',
- enrollee_test_env.get('SRC_DIR') + '/resource/oc_logger/include',
- enrollee_test_env.get('SRC_DIR') + '/resource/csdk/stack/include',
- enrollee_test_env.get('SRC_DIR') + '/resource/csdk/stack/include/internal',
- enrollee_test_env.get('SRC_DIR') + '/resource/csdk/logger/include',
- enrollee_test_env.get('SRC_DIR') + '/resource/csdk/security/include',
- enrollee_test_env.get('SRC_DIR') + '/extlibs/cjson',
- enrollee_test_env.get('SRC_DIR') + '/extlibs/sqlite3',
- enrollee_test_env.get('SRC_DIR') + '/service/easy-setup/inc',
- enrollee_test_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi',
- enrollee_test_env.get('SRC_DIR') + '/service/easy-setup/enrollee/inc',
- enrollee_test_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src'])
-
-enrollee_test_env.AppendUnique(LIBPATH = [enrollee_test_env.get('BUILD_DIR')])
-enrollee_test_env.PrependUnique(LIBS = [ 'octbstack',
- 'ocsrm',
- 'connectivity_abstraction',
- 'coap'])
-if target_os not in ['windows']:
- enrollee_test_env.AppendUnique(LIBS = ['m'])
-
-if target_os != 'darwin':
- enrollee_test_env.PrependUnique(LIBS = ['oc_logger'])
-
-if enrollee_test_env.get('SECURED') == '1':
- enrollee_test_env.AppendUnique(LIBS = ['tinydtls'])
-
-if enrollee_test_env.get('LOGGING'):
- enrollee_test_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-
-if enrollee_test_env.get('ES_SOFTAP_MODE') == 'ENROLLEE_SOFTAP':
- print "ES_SOFTAP_MODE == ENROLLEE_SOFTAP"
- enrollee_test_env.AppendUnique(CPPDEFINES = ['ENROLLEE_SOFTAP'])
-
-enrollee_test_env.PrependUnique(LIBS = ['ESEnrolleeSDK'])
+easysetup_test_env.AppendUnique(CPPPATH = ['../../../../resource/include',
+ '../inc',
+ '../../inc',
+ '../../mediator/richsdk/inc'])
######################################################################
-# Source files and Targets
+# Build Test
######################################################################
-enrolleetests = enrollee_test_env.Program('enrolleetests', ['enrolleetests.cpp'])
-Alias("test", [enrolleetests])
+easysetup_enrollee_test_env = easysetup_test_env.Clone()
+easysetup_enrollee_test_env.AppendUnique(LIBS = ['ESEnrolleeSDK', 'ESMediatorRich'])
-enrolleetests.AppendTarget('test')
-if enrollee_test_env.get('TEST') == '1':
- if target_os in ['linux']:
- from tools.scons.RunTest import *
- run_test(enrollee_test_env,
- '',
- 'service/easy-setup/enrollee/unittests/enrolleetests')
+easysetup_enrollee_test_src = env.Glob('./ESEnrolleeTest.cpp')
+easysetup_enrollee_test = easysetup_enrollee_test_env.Program('easysetup_enrollee_test', easysetup_enrollee_test_src)
+Alias("easysetup_enrollee_test", easysetup_enrollee_test)
+env.AppendTarget('easysetup_enrollee_test')
+if env.get('TEST') == '1':
+ if target_os == 'linux':
+ from tools.scons.RunTest import *
+ run_test(easysetup_enrollee_test_env, '', 'service/easy-setup/enrollee/unittests/easysetup_enrollee_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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- * This file contains the implementation for EasySetup Enrollee testcases
- */
-
-#include "gtest/gtest.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-//-----------------------------------------------------------------------------
-// Includes
-//-----------------------------------------------------------------------------
-#include <stdio.h>
-#include <string.h>
-
-#include <iostream>
-#include <stdint.h>
-
-#include "ocstack.h"
-#include "logger.h"
-#include "oic_malloc.h"
-#include "escommon.h"
-#include "easysetup.h"
-#include "onboarding.h"
-#include "resourcehandler.h"
-#include "softap.h"
-#include "easysetupcallbacks.h"
-
-#include "gtesthelper.h"
-
-using namespace std;
-
-namespace itst = iotivity::test;
-
-#define DEFAULT_CONTEXT_VALUE 0x99
-
-//-----------------------------------------------------------------------------
-// Private variables
-//-----------------------------------------------------------------------------
-static const char TAG[] = "TestHarness";
-
-char ssid[] = "EasySetup123";
-char passwd[] = "EasySetup123";
-
-//-----------------------------------------------------------------------------
-// Callback functions
-//-----------------------------------------------------------------------------
-extern "C" void EventCallbackInApplication(ESResult esResult,
- ESEnrolleeState enrolleeState)
-{
- OIC_LOG(INFO, TAG, "Entering EventCallbackInApplication");
-
- if(esResult != ES_OK)
- {
- cout<<"Easy stup is failed at Enrollee state = "<<enrolleeState<<endl;
- }
- else
- {
- if(enrolleeState == ES_ON_BOARDED_STATE)
- {
- cout<<"Device is successfully OnBoared on Adhoc network"<<endl;
- }
- else if (enrolleeState == ES_PROVISIONED_STATE)
- {
- cout<<"Device is provisioned with target network's credentials"<<endl;
- }
- else if (enrolleeState == ES_ON_BOARDED_TARGET_NETWORK_STATE)
- {
- cout<<"Device is onboarded/connected with target network"<<endl;
- }
- else
- {
- cout<<"Wrong state !! Easy setup is failed at Enrollee state = "<<enrolleeState<<endl;
- }
- }
-}
-
-//-----------------------------------------------------------------------------
-// Local functions
-//-----------------------------------------------------------------------------
-
-void InitESEnrollee()
-{
- OIC_LOG(INFO, TAG, "Entering InitESEnrollee");
-
- EXPECT_EQ(ES_OK, ESInitEnrollee(CT_ADAPTER_IP,
- "EasySetup123",
- "EasySetup123",
- 0,
- EventCallbackInApplication));
- OIC_LOG(INFO, TAG, "Leaving InitESEnrollee");
-}
-
-//-----------------------------------------------------------------------------
-// Tests
-//-----------------------------------------------------------------------------
-
-TEST(ESEnrolleeInit, ESEnrolleeInitNullSSID)
-{
- EXPECT_EQ(ES_ERROR, ESInitEnrollee(CT_ADAPTER_IP, 0, passwd, 0, EventCallbackInApplication));
-}
-
-TEST(ESEnrolleeInit, ESEnrolleeInitNullPassword)
-{
- EXPECT_EQ(ES_ERROR, ESInitEnrollee(CT_ADAPTER_IP, ssid, 0, 0, EventCallbackInApplication));
-}
-
-TEST(ESEnrolleeInit, ESEnrolleeInitNullCb)
-{
- EXPECT_EQ(ES_ERROR, ESInitEnrollee(CT_ADAPTER_IP, ssid, passwd, 0, 0));
-}
-
-TEST(ESEnrolleeInit, ESEnrolleeESInitEnrolleeSuccess)
-{
- EXPECT_EQ(ES_OK, ESInitEnrollee(CT_ADAPTER_IP,
- ssid,
- passwd,
- 0,
- EventCallbackInApplication));
-}
-
-TEST(ESEnrolleeInit, ESEnrolleeBleOnboarding)
-{
- EXPECT_EQ(0, ESBleOnboarding());
-}
-
-TEST(ESEnrolleeInit, ESEnrolleeSoftapOnboarding)
-{
- EXPECT_EQ(true, ESSoftapOnboarding());
-}
-
-TEST(ESOCInit, ESOCInitNullIPAddr)
-{
- EXPECT_EQ(OC_STACK_OK, OCInit(0, 5683, OC_SERVER));
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
-TEST(ESOCInit, ESOCInitNullPort)
-{
- EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 0, OC_SERVER));
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
-TEST(ESOCInit, ESOCInitNullAddrAndPort)
-{
- EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
-TEST(ESOCInit, ESOCInitInvalidMode)
-{
- EXPECT_EQ(OC_STACK_ERROR, OCInit(0, 0, (OCMode)10));
- EXPECT_EQ(OC_STACK_ERROR, OCStop());
-}
-
-TEST(ESProvisioning, ESInitProvisioningResource)
-{
- EXPECT_EQ(ES_RESOURCECREATED, ESInitProvisioning());
-}
-
-TEST(ESProvisioning, ESInitProvisioningWithOCStackClientMode)
-{
- EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_CLIENT));
- EXPECT_EQ(ES_ERROR, ESInitProvisioning());
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
-TEST(ESProvisioningResource, ESCreateProvisioningResourceSecurityDisabled)
-{
- EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
- EXPECT_EQ(OC_STACK_OK, CreateProvisioningResource(0));
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
-TEST(ESProvisioningResource, ESCreateProvisioningResourceSecurityEnabled)
-{
- EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
- EXPECT_EQ(OC_STACK_OK, CreateProvisioningResource(1));
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
-TEST(ESProvisioningResource, ESDeleteProvisioningResource)
-{
- EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
- EXPECT_EQ(OC_STACK_OK, CreateProvisioningResource(0));
- EXPECT_EQ(OC_STACK_OK, DeleteProvisioningResource());
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
-TEST(ESProvisioningResource, ESDeleteProvisioningResourceWithoutCreating)
-{
- EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
- EXPECT_EQ(OC_STACK_NO_RESOURCE, DeleteProvisioningResource());
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
-TEST(ESOnboarding, ESOnboardingSoftAp)
-{
- EXPECT_EQ(1, ESOnboard(ssid, passwd, ESOnboardingCallback));
-}
-
-TEST(ESOnboarding, ESOnboardingSoftApEnrollee)
-{
-#ifdef ENROLLEE_SOFTAP
- EXPECT_EQ(1, ESSoftapAtEnrollee());
- EXPECT_EQ(0, ESSoftapAtMediator());
-#endif
-}
-
-TEST(ESOnboarding, ESOnboardingSoftApMediator)
-{
-#ifndef ENROLLEE_SOFTAP
- EXPECT_EQ(0, ESSoftapAtEnrollee());
- EXPECT_EQ(1, ESSoftapAtMediator());
-#endif
-}
-
-TEST(ESOnboarding, ESOnboardingSoftApHost)
-{
-#ifdef ENROLLEE_SOFTAP
- EXPECT_EQ(ENROLLEE, ESSoftapHost());
-#else
- EXPECT_EQ(MEDIATOR, ESSoftapHost());
-#endif
-}
-
-TEST(ESStop, ESTerminateEasysetupWithoutESInit)
-{
- EXPECT_EQ(ES_ERROR, ESTerminateEnrollee());
-}
-
-TEST(ESStop, ESTerminateEasysetupWithoutOCStack)
-{
- EXPECT_EQ(ES_OK, ESInitEnrollee(CT_ADAPTER_IP,
- ssid,
- passwd,
- 0,
- EventCallbackInApplication));
- EXPECT_EQ(ES_ERROR, ESTerminateEnrollee());
-}
-
-TEST(ESStop, ESTerminateEasysetupWithOutCreateProvisioningResource)
-{
- EXPECT_EQ(ES_OK, ESInitEnrollee(CT_ADAPTER_IP,
- ssid,
- passwd,
- 0,
- EventCallbackInApplication));
- EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
- EXPECT_EQ(ES_ERROR, ESTerminateEnrollee());
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
-TEST(ESStop, ESTerminateEasysetupWithoutProviosioningResource)
-{
- EXPECT_EQ(ES_OK, ESInitEnrollee(CT_ADAPTER_IP,
- ssid,
- passwd,
- 0,
- EventCallbackInApplication));
- EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_SERVER));
- EXPECT_EQ(ES_ERROR, ESTerminateEnrollee());
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
-TEST(ESStop, ESTerminateEasysetupSuccess)
-{
- EXPECT_EQ(ES_OK, ESInitEnrollee(CT_ADAPTER_IP,
- ssid,
- passwd,
- 0,
- EventCallbackInApplication));
- EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_SERVER));
- EXPECT_EQ(ES_RESOURCECREATED, ESInitProvisioning());
- EXPECT_EQ(ES_OK, ESTerminateEnrollee());
- EXPECT_EQ(OC_STACK_OK, OCStop());
-}
-
+++ /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 IOTY_GTEST_HELPER_H
-#define IOTY_GTEST_HELPER_H
-
-#include <atomic>
-#include <chrono>
-#include <condition_variable>
-#include <future>
-#include <mutex>
-#include <thread>
-
-namespace iotivity
-{
- namespace test
- {
- /**
- * Simple implementation of a deadman's timer that can be used to
- * terminate a test that hangs.
- *
- * Since there is no standard way to terminate an individual thread,
- * the entire process will be killed once time has been exceeded.
- *
- * @note provisions for watchdog thread cleanup are not currently added.
- * Testing has not yet shown any need for such complexity.
- */
- class DeadmanTimer
- {
- public:
-
- /**
- * Creates an instance of a timer set to kill the running process
- * after the specified timeout.
- *
- * If the destructor is invoked before time is up (aka this instance
- * goes out of scope) the timeout will not cause the program to be
- * terminated.
- *
- * @param time to wait before assuming the process is hung and must be
- * killed.
- * Examples of values that can be passed include
- * std::chrono::milliseconds(250), std::chrono::seconds(5),
- * std::chrono::minutes(3).
- */
- DeadmanTimer(std::chrono::milliseconds timeout) :
- m_ctx(new DeadmanCtx(timeout)),
- m_thread()
- {
- m_thread = std::thread([this](){run(m_ctx);});
- {
- std::unique_lock<std::mutex> lock(m_ctx->m_mutex);
- while (!m_ctx->m_isArmed)
- {
- m_ctx->m_cond.wait(lock);
- }
- }
- // Now that the thread is live, we can stop tracking it.
- m_thread.detach();
- }
-
- /**
- * Destructor that also will cancel the termination of the
- * running process.
- */
- ~DeadmanTimer()
- {
- std::unique_lock<std::mutex> lock(m_ctx->m_mutex);
- m_ctx->m_isArmed = false;
- }
-
- private:
-
- /**
- * Shared data that main and child thread might both need to
- * access.
- *
- * Avoids referencing data in class instances that have been
- * deleted.
- */
- class DeadmanCtx
- {
- public:
-
- DeadmanCtx(std::chrono::milliseconds timeout) :
- m_mutex(),
- m_cond(),
- m_isArmed(false),
- m_timeout(timeout)
- {
- }
-
- std::mutex m_mutex;
- std::condition_variable m_cond;
- bool m_isArmed;
- std::chrono::milliseconds m_timeout;
- };
-
- // Explicitly block assignment and copy ctor
- DeadmanTimer &operator=(const DeadmanTimer &rhs);
- DeadmanTimer(const iotivity::test::DeadmanTimer &rhs);
-
- std::shared_ptr<DeadmanCtx> m_ctx;
- std::thread m_thread;
-
-
- static void run(std::shared_ptr<DeadmanCtx> ctx)
- {
- // Let the calling thread know it can stop waiting:
- {
- std::unique_lock<std::mutex> lock(ctx->m_mutex);
- ctx->m_isArmed = true;
- ctx->m_cond.notify_all();
- }
-
- std::this_thread::sleep_for(ctx->m_timeout);
-
- std::unique_lock<std::mutex> lock(ctx->m_mutex);
- if (ctx->m_isArmed)
- {
- try {
- throw std::runtime_error("deadman timer expired");
- }
- catch (std::exception&)
- {
- std::terminate();
- }
- }
- }
- };
- } // namespace test
-} // namespace iotivity
-
-#endif // IOTY_GTEST_HELPER_H