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;
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()
ESTerminateEnrollee();
}
+TEST_F(EasysetupEnrolleeTest, ESInitEnrolleeFailedInvalidRsrcMask)
+{
+ ESResult ret = startEnrolleeWithInvalidRsrcMask();
+ EXPECT_EQ(ret, ES_ERROR);
+ ESTerminateEnrollee();
+}
+
TEST_F(EasysetupEnrolleeTest, ESInitEnrolleeFailedByWiFiCbIsNull)
{
ESResourceMask resourcemMask = (ESResourceMask)(ES_WIFI_RESOURCE |
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();
+}
#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;
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;
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)
{
}
}
+ 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)
}
}
}
+
+ 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));
+ }
+
+ }
+
+ }
+
};