Commit cf2d4e67 authored by sy01.youn's avatar sy01.youn Committed by Madan Lanka

Add & fix unittest of easy setup.

- Add unit test cases
(1) Enrollee handles individual get request from client.
(2) Enrollee handles put request from client.
(3) ESSetCallbackForUserdata API unit test is added.


- Remove GetTargetNetworkInfoFromProvResource API in resourcehandler.
  . This API is not need anymore.

Change-Id: If634923b0daaf9760b78b3d7e853c823769db6ba
Signed-off-by: default avatarsy01.youn <sy01.youn@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10603Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarJihun Ha <jihun.ha@samsung.com>
Reviewed-by: default avatarMadan Lanka <lanka.madan@samsung.com>
parent 9943d85a
......@@ -107,15 +107,6 @@ void UnRegisterResourceEventCallBack()
}
}
void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
{
if (name != NULL && pass != NULL)
{
OICStrcpy(name, MAX_WEBLINKLEN, gWiFiResource.ssid);
OICStrcpy(pass, MAX_WEBLINKLEN, gWiFiResource.cred);
}
}
OCStackResult initProvResource(bool isSecured)
{
gProvResource.status = ES_STATE_INIT;
......
......@@ -87,7 +87,6 @@ OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty);
OCStackResult SetEnrolleeState(ESEnrolleeState esState);
OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode);
void GetTargetNetworkInfoFromProvResource(char *, char *);
void RegisterWifiRsrcEventCallBack(ESWiFiCB);
void RegisterCloudRsrcEventCallBack(ESCloudCB);
void RegisterDevConfRsrcEventCallBack(ESDevConfCB);
......
......@@ -88,6 +88,26 @@ public:
std::cout << __func__ << std::endl;
}
static void onGetWifiRsrc(const OCRepresentation& )
{
std::cout << __func__ << std::endl;
}
static void onGetCloudRsrc(const OCRepresentation& )
{
std::cout << __func__ << std::endl;
}
static void onGetDeviceConf(const OCRepresentation& )
{
std::cout << __func__ << std::endl;
}
static void onPutRequest(const OCRepresentation& )
{
std::cout << __func__ << std::endl;
}
static void deviceProvisioningStatusCallback(std::shared_ptr< DevicePropProvisioningStatus >)
{
std::cout << __func__ << std::endl;
......@@ -126,15 +146,30 @@ public:
return ESInitEnrollee(false, resourcemMask, callbacks);
}
ESResult startEnrolleeWithInvalidRsrcMask()
{
ESProvisioningCallbacks callbacks;
callbacks.WiFiProvCb = &EasysetupEnrolleeTest::WiFiProvCbInApp;
callbacks.DevConfProvCb = &EasysetupEnrolleeTest::DevConfProvCbInApp;
callbacks.CloudDataProvCb = &EasysetupEnrolleeTest::CloudDataCbInApp;
return ESInitEnrollee(false, (ESResourceMask)0, callbacks);
}
ESResult setDeviceProperty()
{
ESDeviceProperty deviceProperty = {
{{WIFI_11G, WiFi_EOF}, WIFI_5G}, {"Test Device"}
{{WIFI_11G, WiFi_EOF}, WIFI_5G}, {"Test Device", "Test Model Number"}
};
return ESSetDeviceProperty(&deviceProperty);
}
ESResult setCallabckForUserDataNULL()
{
return ESSetCallbackForUserdata(NULL, NULL);
}
protected:
void SetUp()
......@@ -167,6 +202,13 @@ TEST_F(EasysetupEnrolleeTest, ESInitEnrolleeSuccess)
ESTerminateEnrollee();
}
TEST_F(EasysetupEnrolleeTest, ESInitEnrolleeFailedInvalidRsrcMask)
{
ESResult ret = startEnrolleeWithInvalidRsrcMask();
EXPECT_EQ(ret, ES_ERROR);
ESTerminateEnrollee();
}
TEST_F(EasysetupEnrolleeTest, ESInitEnrolleeFailedByWiFiCbIsNull)
{
ESResourceMask resourcemMask = (ESResourceMask)(ES_WIFI_RESOURCE |
......@@ -410,4 +452,93 @@ TEST_F(EasysetupEnrolleeTest, CloudServerProperiesProvisionedWithSuccess)
ESTerminateEnrollee();
}
TEST_F(EasysetupEnrolleeTest, GetWifiRsrcTest)
{
bool isRepFlag = false;
mocks.ExpectCallFunc(onGetWifiRsrc).Do(
[& isRepFlag](const OCRepresentation& /*rep*/)
{
isRepFlag = true;
});
ESResult ret = startEnrollee();
g_mediatorSimul.getWifiRsrc(onGetWifiRsrc);
std::unique_lock< std::mutex > lock{ mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
EXPECT_EQ(ret, ES_OK);
ESTerminateEnrollee();
}
TEST_F(EasysetupEnrolleeTest, GetCloudRsrcTest)
{
bool isRepFlag = false;
mocks.ExpectCallFunc(onGetCloudRsrc).Do(
[& isRepFlag](const OCRepresentation& /*rep*/)
{
isRepFlag = true;
});
ESResult ret = startEnrollee();
g_mediatorSimul.getCloudRsrc(onGetCloudRsrc);
std::unique_lock< std::mutex > lock{ mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
EXPECT_EQ(ret, ES_OK);
ESTerminateEnrollee();
}
TEST_F(EasysetupEnrolleeTest, GetDevConfTest)
{
bool isRepFlag = false;
mocks.ExpectCallFunc(onGetDeviceConf).Do(
[& isRepFlag](const OCRepresentation& /*rep*/)
{
isRepFlag = true;
});
ESResult ret = startEnrollee();
ret = setDeviceProperty();
g_mediatorSimul.getDevConfiguration(onGetDeviceConf);
std::unique_lock< std::mutex > lock{ mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
EXPECT_EQ(ret, ES_OK);
ESTerminateEnrollee();
}
TEST_F(EasysetupEnrolleeTest, PutRequestTest)
{
bool isRepFlag = false;
mocks.ExpectCallFunc(onPutRequest).Do(
[& isRepFlag](const OCRepresentation& /*rep*/)
{
isRepFlag = true;
});
ESResult ret = startEnrollee();
g_mediatorSimul.putProvRsrc(onPutRequest);
std::unique_lock< std::mutex > lock{ mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
EXPECT_EQ(ret, ES_OK);
ESTerminateEnrollee();
}
TEST_F(EasysetupEnrolleeTest, ESSetCallabckForUserDataFailed)
{
ESResult ret = setCallabckForUserDataNULL();
EXPECT_EQ(ret, ES_ERROR);
ESTerminateEnrollee();
}
......@@ -35,24 +35,31 @@
#include "OCPlatform.h"
#define PROV_RESOURCE_TYPE "ocf.wk.prov"
#define WIFI_RESOURCE_TYPE "ocf.wk.wifi"
#define DEV_RESOURCE_TYPE "ocf.wk.devconf"
#define CLOUD_RESOURCE_TYPE "ocf.wk.cloudserver"
using namespace OIC::Service;
class ESMediatorSimulator
{
private:
std::shared_ptr<RemoteEnrollee> m_remoteEnrollee;
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;
std::function<void(const OCRepresentation&)> m_getWifiCb;
std::function<void(const OCRepresentation&)> m_getCloudCb;
std::function<void(const OCRepresentation&)> m_getDevConfCb;
std::function<void(const OCRepresentation&)> m_provPutCb;
public:
ESMediatorSimulator()
: m_remoteEnrollee(), m_discoveryCb(), m_getConfigurationCb(), m_getStatusCb(),
m_DevicePropProvisioningCb(), m_CloudPropProvisioningCb()
m_DevicePropProvisioningCb(), m_CloudPropProvisioningCb(),
m_getWifiCb(), m_getCloudCb(), m_getDevConfCb(), m_provPutCb()
{
};
~ESMediatorSimulator() = default;
......@@ -85,6 +92,36 @@ public:
this, std::placeholders::_1));
}
void getWifiRsrc(std::function<void(const OCRepresentation& rep)> cb)
{
m_getWifiCb = cb;
std::string uri = std::string("/oic/res?rt=") + WIFI_RESOURCE_TYPE;
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetWifiRsrc,
this, std::placeholders::_1));
}
void getCloudRsrc(std::function<void(const OCRepresentation& rep)> cb)
{
m_getCloudCb = cb;
std::string uri = std::string("/oic/res?rt=") + CLOUD_RESOURCE_TYPE;
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetCloudRsrc,
this, std::placeholders::_1));
}
void getDevConfiguration(std::function<void(const OCRepresentation& rep)> cb)
{
m_getDevConfCb = cb;
std::string uri = std::string("/oic/res?rt=") + DEV_RESOURCE_TYPE;
OC::OCPlatform::findResource("", uri,
OCConnectivityType::CT_DEFAULT,
std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetDevConf,
this, std::placeholders::_1));
}
void getStatus(std::function<void(std::shared_ptr< GetEnrolleeStatus >)> cb)
{
m_getStatusCb = cb;
......@@ -118,6 +155,17 @@ public:
this, std::placeholders::_1));
}
void putProvRsrc(std::function<void(const OCRepresentation& rep)> cb)
{
m_provPutCb = 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::discoverRemoteEnrolleeCbToPutProvRsrc,
this, std::placeholders::_1));
}
private:
bool isValidResourceToTest(std::shared_ptr<OC::OCResource> resource)
{
......@@ -194,6 +242,118 @@ private:
}
}
void getWifiRsrcCallback(const HeaderOptions& , const OCRepresentation& rep, const int eCode)
{
try
{
if(eCode == OC_STACK_OK)
{
std::cout << "GET request was successful" << std::endl;
std::cout << "Resource URI: " << rep.getUri() << std::endl;
if(m_getWifiCb != NULL)
{
m_getWifiCb(rep);
m_getWifiCb = NULL;
}
}
else
{
std::cout << "onGET Response error: " << eCode << std::endl;
std::exit(-1);
}
}
catch(std::exception& e)
{
std::cout << "Exception: " << e.what() << " in onGet" << std::endl;
}
}
void discoverRemoteEnrolleeCbToGetWifiRsrc(std::shared_ptr<OC::OCResource> resource)
{
if(!resource->getResourceTypes().at(0).compare(WIFI_RESOURCE_TYPE) && m_getWifiCb)
{
QueryParamsMap test;
resource->get(test, std::bind(
&ESMediatorSimulator::getWifiRsrcCallback, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
}
}
void getCloudRsrcCallback(const HeaderOptions& , const OCRepresentation& rep, const int eCode)
{
try
{
if(eCode == OC_STACK_OK)
{
std::cout << "GET request was successful" << std::endl;
std::cout << "Resource URI: " << rep.getUri() << std::endl;
if(m_getCloudCb != NULL)
{
m_getCloudCb(rep);
m_getCloudCb = NULL;
}
}
else
{
std::cout << "onGET Response error: " << eCode << std::endl;
std::exit(-1);
}
}
catch(std::exception& e)
{
std::cout << "Exception: " << e.what() << " in onGet" << std::endl;
}
}
void discoverRemoteEnrolleeCbToGetCloudRsrc(std::shared_ptr<OC::OCResource> resource)
{
if(!resource->getResourceTypes().at(0).compare(CLOUD_RESOURCE_TYPE) && m_getCloudCb)
{
QueryParamsMap test;
resource->get(test, std::bind(
&ESMediatorSimulator::getCloudRsrcCallback, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
}
}
void getDevConfCallback(const HeaderOptions&, const OCRepresentation& rep, const int eCode)
{
try
{
if(eCode == OC_STACK_OK)
{
std::cout << "GET request was successful" << std::endl;
std::cout << "Resource URI: " << rep.getUri() << std::endl;
if(m_getDevConfCb != NULL)
{
m_getDevConfCb(rep);
m_getDevConfCb = NULL;
}
}
else
{
std::cout << "onGET Response error: " << eCode << std::endl;
std::exit(-1);
}
}
catch(std::exception& e)
{
std::cout << "Exception: " << e.what() << " in onGet" << std::endl;
}
}
void discoverRemoteEnrolleeCbToGetDevConf(std::shared_ptr<OC::OCResource> resource)
{
if(!resource->getResourceTypes().at(0).compare(DEV_RESOURCE_TYPE) && m_getDevConfCb)
{
QueryParamsMap test;
resource->get(test, std::bind(
&ESMediatorSimulator::getDevConfCallback, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
}
}
void getStatusCallback(std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus)
{
if(m_getStatusCb != NULL)
......@@ -294,6 +454,37 @@ private:
}
}
}
void putProvRsrcCallabck(const HeaderOptions&, const OCRepresentation& rep, const int )
{
cout << "putProvRsrcCallback is called" << endl;
if(m_provPutCb != NULL){
m_provPutCb(rep);
m_provPutCb = NULL;
}
}
void discoverRemoteEnrolleeCbToPutProvRsrc(std::shared_ptr<OC::OCResource> resource)
{
m_remoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(resource);
if(m_remoteEnrollee != NULL)
{
if(m_provPutCb)
{
OCRepresentation rep;
QueryParamsMap test;
resource->put(rep, test, std::bind(
&ESMediatorSimulator::putProvRsrcCallabck, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
}
}
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment