The class is to avoid aborting test execution, when expectation is not fulfilled on GCC 4.8.
The issue is caused by a difference of destructor's noexcept specifier between MockRepository of HippoMock and Test of gtest.
This class allows test fixtures have same usage regardless of GCC version.
Change-Id: I247a63009ca2625b27a29eb5320a1a6e3ebbd71b
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1779
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service_common_test_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
service_common_test_env.PrependUnique(CPPPATH = [
env.get('SRC_DIR')+'/extlibs/hippomocks-master',
- gtest_dir + '/include'
+ gtest_dir + '/include',
+ '../utils/include'
])
gtest = File(gtest_dir + '/lib/.libs/libgtest.a')
'connectivity_abstraction',
'coap',
'service_common',
- 'pthread',
gtest,
- gtest_main
+ gtest_main,
+ 'pthread'
])
-#service_common_test_src = env.Glob('unittests/*.cpp')
+service_common_test_src = env.Glob('unittests/*.cpp')
-#service_common_test = service_common_test_env.Program('service_common_test', service_common_test_src)
-#Alias("service_common_test", service_common_test)
-#env.AppendTarget('service_common_test')
+service_common_test = service_common_test_env.Program('service_common_test', service_common_test_src)
+Alias("service_common_test", service_common_test)
+env.AppendTarget('service_common_test')
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include <gtest/gtest.h>
-#include <HippoMocks/hippomocks.h>
+#include <UnitTestHelper.h>
#include <PresenceSubscriber.h>
#include <RCSException.h>
#include <OCPlatform.h>
-using namespace testing;
using namespace OIC::Service;
-typedef OCStackResult (*subscribePresenceSig1)(OC::OCPlatform::OCPresenceHandle&,
+typedef OCStackResult (*SubscribePresence1)(OC::OCPlatform::OCPresenceHandle&,
const std::string&, OCConnectivityType, SubscribeCallback);
-typedef OCStackResult (*subscribePresenceSig2)(OC::OCPlatform::OCPresenceHandle&,
+typedef OCStackResult (*SubscribePresence2)(OC::OCPlatform::OCPresenceHandle&,
const std::string&, const std::string&, OCConnectivityType, SubscribeCallback);
const std::string HOST{ "host" };
const OCConnectivityType CONTYPE{ };
-class PresenceSubscriberNonMemberTest: public Test
+
+class PresenceSubscriberNonMemberTest: public TestWithMock
{
public:
OCDoHandle handle;
- MockRepository mocks;
-
};
TEST_F(PresenceSubscriberNonMemberTest, OCPlatformSubscribePresenceWillBeCalled)
{
mocks.ExpectCallFuncOverload(
- static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence))
+ static_cast< SubscribePresence1 >(OC::OCPlatform::subscribePresence))
.With(_, HOST,CONTYPE, _).Return(OC_STACK_OK);
subscribePresence(handle, HOST, CONTYPE, SubscribeCallback());
TEST_F(PresenceSubscriberNonMemberTest, SubscribePresenceThrowsIfResultIsNotOK)
{
mocks.ExpectCallFuncOverload(
- static_cast< subscribePresenceSig1>(OC::OCPlatform::subscribePresence))
+ static_cast< SubscribePresence1>(OC::OCPlatform::subscribePresence))
.Return(OC_STACK_ERROR);
ASSERT_THROW(subscribePresence(handle, "", CONTYPE, SubscribeCallback()), PlatformException);
ASSERT_THROW(unsubscribePresence(handle), PlatformException);
}
-
-
-class PresenceSubscriberTest: public Test
+class PresenceSubscriberTest: public TestWithMock
{
-public:
- MockRepository mocks;
-
protected:
void SetUp() {
mocks.OnCallFuncOverload(
- static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Do(
+ static_cast< SubscribePresence1 >(OC::OCPlatform::subscribePresence)).Do(
[](OC::OCPlatform::OCPresenceHandle& handle, const std::string&,
OCConnectivityType, SubscribeCallback) -> OCStackResult
mocks.OnCallFunc(OC::OCPlatform::unsubscribePresence).Return(OC_STACK_OK);
}
+
};
TEST_F(PresenceSubscriberTest, IsNotSubscribingWhenCreatedWithDefaultConstructor)
TEST_F(PresenceSubscriberTest, ConstructorCallOCPlatformSubscribe)
{
mocks.ExpectCallFuncOverload(
- static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence))
+ static_cast< SubscribePresence1 >(OC::OCPlatform::subscribePresence))
.With(_, HOST, CONTYPE, _).Return(OC_STACK_OK);
PresenceSubscriber subscriber{ HOST, CONTYPE, SubscribeCallback() };
const std::string resType { "resType" };
mocks.ExpectCallFuncOverload(
- static_cast< subscribePresenceSig2 >(OC::OCPlatform::subscribePresence))
+ static_cast< SubscribePresence2 >(OC::OCPlatform::subscribePresence))
.With(_, HOST, resType, CONTYPE, _).Return(OC_STACK_OK);
PresenceSubscriber subscriber{ HOST, resType, CONTYPE, SubscribeCallback() };
TEST_F(PresenceSubscriberTest, ConstructorThrowsIfResultIsNotOK)
{
mocks.ExpectCallFuncOverload(
- static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence))
+ static_cast< SubscribePresence1 >(OC::OCPlatform::subscribePresence))
.Return(OC_STACK_ERROR);
ASSERT_THROW(PresenceSubscriber(HOST, CONTYPE, SubscribeCallback()), PlatformException);
TEST_F(PresenceSubscriberTest, UnsubscribeWillBeCalledWhenSubscriberIsDestoryed)
{
mocks.ExpectCallFunc(OC::OCPlatform::unsubscribePresence).Return(OC_STACK_OK);
- {
- PresenceSubscriber subscriber{ HOST, CONTYPE, SubscribeCallback() };
- }
+
+ PresenceSubscriber subscriber{ HOST, CONTYPE, SubscribeCallback() };
}
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include <gtest/gtest.h>
-#include <HippoMocks/hippomocks.h>
+#include <UnitTestHelper.h>
#include <PrimitiveResourceImpl.h>
#include <AssertUtils.h>
#include <OCResource.h>
#include <OCPlatform.h>
-using namespace testing;
using namespace OIC::Service;
const std::string KEY{ "key" };
virtual bool isObservable() const = 0;
};
-class PrimitiveResourceTest: public Test
+class PrimitiveResourceTest: public TestWithMock
{
public:
- MockRepository mocks;
PrimitiveResource::Ptr resource;
FakeOCResource* fakeResource;
protected:
void SetUp() {
+ TestWithMock::SetUp();
+
fakeResource = mocks.Mock< FakeOCResource >();
resource.reset(new PrimitiveResourceImpl< FakeOCResource >{
}
-class DiscoverResourceTest: public Test
+class DiscoverResourceTest: public TestWithMock
{
public:
- MockRepository mocks;
-
typedef OCStackResult (*FindResource)(const std::string&, const std::string&,
OCConnectivityType, OC::FindCallback);
- static void discovered(std::shared_ptr< PrimitiveResource >)
- {
- }
-
+public:
+ static void discovered(std::shared_ptr< PrimitiveResource >) {}
};
TEST_F(DiscoverResourceTest, CallbackIsInvokedWhenResourceIsDiscovered)
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 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 COMMON_UTILS_UNITTESTHELPER_H
+#define COMMON_UTILS_UNITTESTHELPER_H
+
+#include <gtest/gtest.h>
+#include <HippoMocks/hippomocks.h>
+
+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;
+ }
+ }
+};
+
+#endif // COMMON_UTILS_UNITTESTHELPER_H
server_builder_test_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
server_builder_test_env.AppendUnique(CPPPATH = [
env.get('SRC_DIR')+'/extlibs/hippomocks-master',
- gtest_dir + '/include'
+ gtest_dir + '/include',
+ '../common/utils/include'
])
gtest = File(gtest_dir + '/lib/.libs/libgtest.a')
server_builder_test_env.PrependUnique(LIBS = [
'server_builder',
'service_common',
- 'pthread',
'oc',
'octbstack',
'oc_logger',
'coap',
gtest,
gtest_main,
+ 'pthread',
])
-#server_builder_test_src = env.Glob('unittests/*.cpp')
+server_builder_test_src = env.Glob('unittests/*.cpp')
-#server_builder_test = server_builder_test_env.Program('server_builder_test', server_builder_test_src)
-#Alias("server_builder_test", server_builder_test)
-#env.AppendTarget('server_builder_test')
+server_builder_test = server_builder_test_env.Program('server_builder_test', server_builder_test_src)
+Alias("server_builder_test", server_builder_test)
+env.AppendTarget('server_builder_test')
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include <gtest/gtest.h>
-#include <HippoMocks/hippomocks.h>
+#include <UnitTestHelper.h>
#include <RCSResponse.h>
#include <ResourceObject.h>
using namespace std;
-using namespace testing;
-
using namespace OIC::Service;
using namespace OC;
}
-class RCSResponseTest: public Test
+class RCSResponseTest: public TestWithMock
{
public:
- MockRepository mocks;
-
-public:
template< typename T >
shared_ptr< OCResourceResponse > buildResponse(const T& response)
{
protected:
void SetUp()
{
+ TestWithMock::SetUp();
+
mocks.OnCallFuncOverload(static_cast< registerResourceSig >(OCPlatform::registerResource))
.Return(OC_STACK_OK);
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include <gtest/gtest.h>
-#include <HippoMocks/hippomocks.h>
+#include <UnitTestHelper.h>
#include <RequestHandler.h>
using namespace std;
-using namespace testing;
using namespace OIC::Service;
constexpr char EXISTING[]{ "ext" };
typedef OCStackResult (*RegisterResource)(OCResourceHandle&, std::string&,
const std::string&, const std::string&, OC::EntityHandler, uint8_t);
-class RequestHandlerTest: public Test
+class RequestHandlerTest: public TestWithMock
{
public:
ResourceObject::Ptr server;
- MockRepository mocks;
-
protected:
void SetUp()
{
+ TestWithMock::SetUp();
+
mocks.OnCallFuncOverload(static_cast<RegisterResource>(OC::OCPlatform::registerResource))
.Return(OC_STACK_OK);
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include <gtest/gtest.h>
-#include <HippoMocks/hippomocks.h>
+#include <UnitTestHelper.h>
#include <ResourceObject.h>
using namespace std;
using namespace std::placeholders;
-using namespace testing;
-
using namespace OIC::Service;
using namespace OC;
ASSERT_THROW(ResourceObject::Builder("", "", "").build(), PlatformException);
}
-class ResourceObjectBuilderTest: public Test
+class ResourceObjectBuilderTest: public TestWithMock
{
-public:
- MockRepository mocks;
-
protected:
void SetUp()
{
+ TestWithMock::SetUp();
+
mocks.OnCallFuncOverload(static_cast< registerResource >(OCPlatform::registerResource))
.Return(OC_STACK_OK);
}
}
-class ResourceObjectTest: public Test
+class ResourceObjectTest: public TestWithMock
{
public:
- MockRepository mocks;
ResourceObject::Ptr server;
protected:
void SetUp()
{
+ TestWithMock::SetUp();
+
initMocks();
server = ResourceObject::Builder(RESOURCE_URI, RESOURCE_TYPE, "").build();