################################################ ######################
SConscript('unittests/SConscript')
SConscript('src/resourceCache/unittests/SConscript')
-SConscript('src/resourceBroker/unittest/SConscript')
+#SConscript('src/resourceBroker/unittest/SConscript')
#include "ResourcePresence.h"
#include "PrimitiveResource.h"
#include "ResponseStatement.h"
+#include "UnitTestHelper.h"
using namespace testing;
using namespace OIC::Service;
typedef OCStackResult (*subscribePresenceSig1)(OC::OCPlatform::OCPresenceHandle&,
const std::string&, OCConnectivityType, SubscribeCallback);
-class DeviceAssociationTest : public Test
+class DeviceAssociationTest : public TestWithMock
{
public:
instance->addDevice(device);
}
- void SetUp()
+ void SetUp() override
{
instance = DeviceAssociation::getInstance();
device = (DevicePresencePtr)new DevicePresence();
pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
}
- void TearDown()
+ void TearDown() override
{
device.reset();
pResource.reset();
}
- virtual ~DeviceAssociationTest() noexcept(true)
- {
- }
-
-
};
TEST_F(DeviceAssociationTest,findDevice_ReturnNormalValueIfNormalParam)
{
- SetUp();
+
SetAssociationDevice();
ASSERT_NE(nullptr,instance->findDevice(pResource->getHost()));
- TearDown();
+
}
TEST_F(DeviceAssociationTest,addDevice_NormalHandlingIfNormalParam)
{
- SetUp();
+
SetAssociationDevice();
ASSERT_FALSE(instance->isEmptyDeviceList());
- TearDown();
-
}
TEST_F(DeviceAssociationTest,removeDevice_NormalHandlingIfNormalParam)
{
- SetUp();
+
SetAssociationDevice();
instance->removeDevice(device);
ASSERT_TRUE(instance->isEmptyDeviceList());
- TearDown();
}
#include "OCPlatform.h"
#include "DevicePresence.h"
#include "ResourcePresence.h"
+#include "UnitTestHelper.h"
using namespace testing;
using namespace OIC::Service;
typedef OCStackResult (*subscribePresenceSig1)(OC::OCPlatform::OCPresenceHandle&,
const std::string&, OCConnectivityType, SubscribeCallback);
-class DevicePresenceTest : public Test
+class DevicePresenceTest : public TestWithMock
{
public:
protected:
- void SetUp()
+ void SetUp() override
{
instance = (DevicePresence*)new DevicePresence();
pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
id = 0;
}
- void TearDown()
+ void TearDown() override
{
pResource.reset();
id = 0;
mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return(std::string());
mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Return(OC_STACK_OK);
}
-
- virtual ~DevicePresenceTest() noexcept(true)
- {
- }
-
};
TEST_F(DevicePresenceTest,initializeDevicePresence_NormalHandlingIfNormalResource)
{
- SetUp();
+
MockingFunc();
ASSERT_NO_THROW(instance->initializeDevicePresence(pResource));
- TearDown();
+
}
TEST_F(DevicePresenceTest,initializeDevicePresence_ErrorHandlingIfAbnormalResource)
{
- SetUp();
+
MockingFunc();
mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Return(OC_STACK_ERROR);
ASSERT_THROW(instance->initializeDevicePresence(pResource),PlatformException);
- TearDown();
+
}
TEST_F(DevicePresenceTest,addPresenceResource_NormalHandlingIfNormalResource)
{
- SetUp();
+
ResourcePresence * resource = (ResourcePresence *)new ResourcePresence();
instance->addPresenceResource(resource);
- ASSERT_EQ(false,instance->isEmptyResourcePresence());
- TearDown();
+ ASSERT_FALSE(instance->isEmptyResourcePresence());
+
}
TEST_F(DevicePresenceTest,isEmptyResourcePresence_NormalHandling)
{
- SetUp();
+
MockingFunc();
ASSERT_TRUE(instance->isEmptyResourcePresence());
- TearDown();
+
}
TEST_F(DevicePresenceTest,getAddress_NormalHandling)
{
- SetUp();
+
MockingFunc();
instance->initializeDevicePresence(pResource);
instance->getAddress();
- TearDown();
+
}
TEST_F(DevicePresenceTest,NormalHandlingWhenReceivedCallbackMessage)
{
- SetUp();
+
MockingFunc();
- TearDown();
+
}
#include "PrimitiveResource.h"
#include "ResponseStatement.h"
#include "ResourceBroker.h"
+#include "UnitTestHelper.h"
using namespace testing;
using namespace OIC::Service;
typedef OCStackResult (*subscribePresenceSig1)(OC::OCPlatform::OCPresenceHandle&,
const std::string&, OCConnectivityType, SubscribeCallback);
-class ResourceBrokerTest : public Test
+class ResourceBrokerTest : public TestWithMock
{
public:
protected:
- void SetUp()
+ void SetUp() override
{
brokerInstance = ResourceBroker::getInstance();
pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
id = 0;
}
- void TearDown()
+ void TearDown() override
{
pResource.reset();
id = 0;
mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Return(OC_STACK_OK);
}
- virtual ~ResourceBrokerTest() noexcept(true)
- {
- }
-
};
TEST_F(ResourceBrokerTest,HostResource_ReturnNormalValueIfNormalParams)
{
- SetUp();
+
MockingFunc();
BrokerID ret;
ASSERT_NE(ret = brokerInstance->hostResource(pResource,cb),0);
brokerInstance->cancelHostResource(ret);
- TearDown();
+
}
TEST_F(ResourceBrokerTest, HostResource_NormalErrorHandlingIfResourceNull)
{
- SetUp();
+
ASSERT_THROW(brokerInstance->hostResource(nullptr, cb),ResourceBroker::InvalidParameterException);
- TearDown();
+
}
TEST_F(ResourceBrokerTest, HostResource_NormalErrorHandlingIfCbFuncNull)
{
- SetUp();
+
ASSERT_THROW(brokerInstance->hostResource(pResource,nullptr),ResourceBroker::InvalidParameterException);
- TearDown();
+
}
TEST_F(ResourceBrokerTest,CancelHostResource_NoThrowIfNormalParams)
{
- SetUp();
+
MockingFunc();
BrokerID ret;
ret = brokerInstance->hostResource(pResource,cb);
ASSERT_NO_THROW(brokerInstance->cancelHostResource(ret));
- TearDown();
+
}
TEST_F(ResourceBrokerTest,CancelHostResource_NormalErrorHandlingIfAbNormalIdZero)
{
- SetUp();
+
id = 0;
ASSERT_THROW(brokerInstance->cancelHostResource(id),ResourceBroker::InvalidParameterException);
- TearDown();
+
}
TEST_F(ResourceBrokerTest,CancelHostResource_NormalErrorHandlingIfAbNormalIdOutOfRangeValue)
{
- SetUp();
+
id = -1;
ASSERT_THROW(brokerInstance->cancelHostResource(id),ResourceBroker::InvalidParameterException);
- TearDown();
+
}
TEST_F(ResourceBrokerTest,getResourceState_ReturnNormalValueIfNormalId)
{
- SetUp();
+
MockingFunc();
BrokerID ret;
TEST_F(ResourceBrokerTest,getResourceState_NormalErrorHandlingIfIdZero)
{
- SetUp();
+
id = 0;
ASSERT_THROW(brokerInstance->getResourceState(id),ResourceBroker::InvalidParameterException);
- TearDown();
+
}
TEST_F(ResourceBrokerTest,getResourceState_ReturnNormalValueIfNormalResource)
{
- SetUp();
+
MockingFunc();
BrokerID ret;
ASSERT_NE(brokerInstance->getResourceState(pResource),BROKER_STATE::NONE);
brokerInstance->cancelHostResource(ret);
- TearDown();
+
}
TEST_F(ResourceBrokerTest,getResourceState_NormalErrorHandlingIfResourceNull)
{
- SetUp();
+
ASSERT_THROW(brokerInstance->getResourceState((PrimitiveResource::Ptr)nullptr),ResourceBroker::InvalidParameterException);
- TearDown();
+
}
TEST_F(ResourceBrokerTest,getResourceState_NormalErrorHandlingIfAbnormalResource)
{
- SetUp();
+
MockingFunc();
PrimitiveResource::Ptr resource[3];
{
brokerInstance->cancelHostResource(id[i]);
}
- TearDown();
+
}
TEST_F(ResourceBrokerTest,getResourceState_NormalErrorHandlingIfAbnormalId)
{
- SetUp();
+
id = -1;
ASSERT_THROW(brokerInstance->getResourceState(id),ResourceBroker::InvalidParameterException);
- TearDown();
+
}
#include "ResponseStatement.h"
#include "ResourceAttributes.h"
#include "ResourcePresence.h"
+#include "UnitTestHelper.h"
using namespace testing;
using namespace OIC::Service;
typedef OCStackResult (*subscribePresenceSig1)(OC::OCPlatform::OCPresenceHandle&,
const std::string&, OCConnectivityType, SubscribeCallback);
-class ResourcePresenceTest : public Test
+class ResourcePresenceTest : public TestWithMock
{
public:
protected:
- void SetUp()
+ void SetUp() override
{
instance = (ResourcePresence*)new ResourcePresence();
pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
id = 0;
}
- void TearDown()
+ void TearDown() override
{
pResource.reset();
id = 0;
mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return(std::string());
mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Return(OC_STACK_OK);
}
- virtual ~ResourcePresenceTest() noexcept(true)
- {
- }
};
TEST_F(ResourcePresenceTest,initializeResourcePresence_NormalhandlingIfNormalResource)
{
- SetUp();
+
MockingFunc();
instance->initializeResourcePresence(pResource);
ASSERT_NE(nullptr,instance->getPrimitiveResource());
- TearDown();
+
}
TEST_F(ResourcePresenceTest,addBrokerRequester_ReturnNormalValueIfNormalParams)
{
- SetUp();
+
MockingFunc();
instance->initializeResourcePresence(pResource);
id = 1;
instance->addBrokerRequester(id,cb);
EXPECT_FALSE(instance->isEmptyRequester());
- TearDown();
+
}
TEST_F(ResourcePresenceTest,removeBrokerRequester_NormalHandlingIfNormalId)
{
- SetUp();
+
MockingFunc();
instance->initializeResourcePresence(pResource);
instance->removeBrokerRequester(id);
ASSERT_EQ(1,instance->requesterListSize());
- TearDown();
+
}
TEST_F(ResourcePresenceTest,removeAllBrokerRequester_NormalHandling)
{
- SetUp();
+
MockingFunc();
instance->initializeResourcePresence(pResource);
instance->removeAllBrokerRequester();
ASSERT_TRUE(instance->isEmptyRequester());
- TearDown();
+
}
TEST_F(ResourcePresenceTest,removeAllBrokerRequester_ErrorHandlingIfListNull)
{
- SetUp();
+
MockingFunc();
instance->initializeResourcePresence(pResource);
instance->removeAllBrokerRequester();
- TearDown();
+
}
TEST_F(ResourcePresenceTest,requestResourceState_NormalHandling)
{
- SetUp();
+
MockingFunc();
instance->initializeResourcePresence(pResource);
ASSERT_NO_THROW(instance->requestResourceState());
- TearDown();
+
}
TEST_F(ResourcePresenceTest,changePresenceMode_NormalHandlingIfNewModeDifferent)
{
- SetUp();
+
MockingFunc();
instance->initializeResourcePresence(pResource);
instance->changePresenceMode(BROKER_MODE::DEVICE_PRESENCE_MODE);
- TearDown();
+
}
TEST_F(ResourcePresenceTest,getResourceState_NormalHandling)
{
- SetUp();
+
ASSERT_EQ(BROKER_STATE::REQUESTED,instance->getResourceState());
- TearDown();
+
}
TEST_F(ResourcePresenceTest,changePresenceMode_NormalHandlingIfNewModeSame)
{
- SetUp();
+
MockingFunc();
instance->initializeResourcePresence(pResource);
instance->changePresenceMode(BROKER_MODE::NON_PRESENCE_MODE);
- TearDown();
+
}
TEST_F(ResourcePresenceTest,getPrimitiveResource_NormalHandling)
{
- SetUp();
+
MockingFunc();
instance->initializeResourcePresence(pResource);
ASSERT_NE(nullptr,instance->getPrimitiveResource());
- TearDown();
+
}
TEST_F(ResourcePresenceTest,getCB_NormalHandlingIfMessageOC_STACK_OK)
{
- SetUp();
+
mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet).Do(
[](GetCallback callback){
instance->initializeResourcePresence(pResource);
sleep(3);
- TearDown();
+
}
TEST_F(ResourcePresenceTest,isEmptyRequester_NormalHandling)
{
- SetUp();
+
MockingFunc();
instance->initializeResourcePresence(pResource);
instance->addBrokerRequester(id,cb);
instance->removeAllBrokerRequester();
ASSERT_TRUE(instance->isEmptyRequester());
- TearDown();
+
}
broker_test_env.AppendUnique(CPPPATH = ['../../common/primitiveResource/include'])
broker_test_env.AppendUnique(CPPPATH = ['../../common/expiryTimer/include'])
broker_test_env.AppendUnique(CPPPATH = ['../../common/expiryTimer/src'])
+broker_test_env.AppendUnique(CPPPATH = ['../../common/utils/include'])
+
broker_test_env.PrependUnique(CPPPATH = [env.get('SRC_DIR')+'/extlibs/hippomocks-master',
gtest_dir + '/include'])
broker_test_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])