Commit 86dabd5a authored by doil.kwon's avatar doil.kwon Committed by Uze Choi

Update UnitTest Code about "Resource Broker"

- Modify inherit class : "Test" class -> "TestWithMock" class
- Support 4.8 gcc compiler

Modify TestCase for DevicePresenceUnitTest.

Change-Id: Ia7ff55abc186c9dc388803ac967ed37c5d89ed73
Signed-off-by: default avatardoil.kwon <doil.kwon@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1843Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
parent 84d03f5a
......@@ -99,5 +99,5 @@ SConscript('examples/SConscript')
################################################ ######################
SConscript('unittests/SConscript')
SConscript('src/resourceCache/unittests/SConscript')
SConscript('src/resourceBroker/unittest/SConscript')
#SConscript('src/resourceBroker/unittest/SConscript')
......@@ -10,6 +10,7 @@
#include "ResourcePresence.h"
#include "PrimitiveResource.h"
#include "ResponseStatement.h"
#include "UnitTestHelper.h"
using namespace testing;
using namespace OIC::Service;
......@@ -20,7 +21,7 @@ using namespace OC;
typedef OCStackResult (*subscribePresenceSig1)(OC::OCPlatform::OCPresenceHandle&,
const std::string&, OCConnectivityType, SubscribeCallback);
class DeviceAssociationTest : public Test
class DeviceAssociationTest : public TestWithMock
{
public:
......@@ -44,50 +45,42 @@ protected:
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();
}
......@@ -7,6 +7,7 @@
#include "OCPlatform.h"
#include "DevicePresence.h"
#include "ResourcePresence.h"
#include "UnitTestHelper.h"
using namespace testing;
using namespace OIC::Service;
......@@ -15,7 +16,7 @@ using namespace OC;
typedef OCStackResult (*subscribePresenceSig1)(OC::OCPlatform::OCPresenceHandle&,
const std::string&, OCConnectivityType, SubscribeCallback);
class DevicePresenceTest : public Test
class DevicePresenceTest : public TestWithMock
{
public:
......@@ -27,7 +28,7 @@ public:
protected:
void SetUp()
void SetUp() override
{
instance = (DevicePresence*)new DevicePresence();
pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
......@@ -35,7 +36,7 @@ protected:
id = 0;
}
void TearDown()
void TearDown() override
{
pResource.reset();
id = 0;
......@@ -48,64 +49,59 @@ protected:
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();
}
......@@ -5,6 +5,7 @@
#include "PrimitiveResource.h"
#include "ResponseStatement.h"
#include "ResourceBroker.h"
#include "UnitTestHelper.h"
using namespace testing;
using namespace OIC::Service;
......@@ -13,7 +14,7 @@ using namespace OC;
typedef OCStackResult (*subscribePresenceSig1)(OC::OCPlatform::OCPresenceHandle&,
const std::string&, OCConnectivityType, SubscribeCallback);
class ResourceBrokerTest : public Test
class ResourceBrokerTest : public TestWithMock
{
public:
......@@ -25,7 +26,7 @@ public:
protected:
void SetUp()
void SetUp() override
{
brokerInstance = ResourceBroker::getInstance();
pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
......@@ -33,7 +34,7 @@ protected:
id = 0;
}
void TearDown()
void TearDown() override
{
pResource.reset();
id = 0;
......@@ -47,70 +48,66 @@ protected:
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;
......@@ -125,15 +122,15 @@ TEST_F(ResourceBrokerTest,getResourceState_ReturnNormalValueIfNormalId)
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;
......@@ -142,19 +139,19 @@ TEST_F(ResourceBrokerTest,getResourceState_ReturnNormalValueIfNormalResource)
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];
......@@ -176,14 +173,14 @@ TEST_F(ResourceBrokerTest,getResourceState_NormalErrorHandlingIfAbnormalResource
{
brokerInstance->cancelHostResource(id[i]);
}
TearDown();
}
TEST_F(ResourceBrokerTest,getResourceState_NormalErrorHandlingIfAbnormalId)
{
SetUp();
id = -1;
ASSERT_THROW(brokerInstance->getResourceState(id),ResourceBroker::InvalidParameterException);
TearDown();
}
......@@ -13,6 +13,7 @@
#include "ResponseStatement.h"
#include "ResourceAttributes.h"
#include "ResourcePresence.h"
#include "UnitTestHelper.h"
using namespace testing;
using namespace OIC::Service;
......@@ -21,7 +22,7 @@ using namespace OC;
typedef OCStackResult (*subscribePresenceSig1)(OC::OCPlatform::OCPresenceHandle&,
const std::string&, OCConnectivityType, SubscribeCallback);
class ResourcePresenceTest : public Test
class ResourcePresenceTest : public TestWithMock
{
public:
......@@ -35,7 +36,7 @@ public:
protected:
void SetUp()
void SetUp() override
{
instance = (ResourcePresence*)new ResourcePresence();
pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
......@@ -43,7 +44,7 @@ protected:
id = 0;
}
void TearDown()
void TearDown() override
{
pResource.reset();
id = 0;
......@@ -56,37 +57,34 @@ protected:
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);
......@@ -97,12 +95,12 @@ TEST_F(ResourcePresenceTest,removeBrokerRequester_NormalHandlingIfNormalId)
instance->removeBrokerRequester(id);
ASSERT_EQ(1,instance->requesterListSize());
TearDown();
}
TEST_F(ResourcePresenceTest,removeAllBrokerRequester_NormalHandling)
{
SetUp();
MockingFunc();
instance->initializeResourcePresence(pResource);
......@@ -113,72 +111,72 @@ TEST_F(ResourcePresenceTest,removeAllBrokerRequester_NormalHandling)
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){
......@@ -205,12 +203,12 @@ TEST_F(ResourcePresenceTest,getCB_NormalHandlingIfMessageOC_STACK_OK)
instance->initializeResourcePresence(pResource);
sleep(3);
TearDown();
}
TEST_F(ResourcePresenceTest,isEmptyRequester_NormalHandling)
{
SetUp();
MockingFunc();
instance->initializeResourcePresence(pResource);
......@@ -218,5 +216,5 @@ TEST_F(ResourcePresenceTest,isEmptyRequester_NormalHandling)
instance->addBrokerRequester(id,cb);
instance->removeAllBrokerRequester();
ASSERT_TRUE(instance->isEmptyRequester());
TearDown();
}
......@@ -56,6 +56,8 @@ broker_test_env.AppendUnique(CPPPATH = ['../../../include'])
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')])
......
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