File: | core/object/ClassFactoryTest.cc |
Location: | line 19, column 21 |
Description: | Potential memory leak |
1 | #include <gtest/gtest.h> | |||
2 | #include "core/object/ClassFactory.h" | |||
3 | #include "core/BaseObject.h" | |||
4 | #include "core/object/Context.h" | |||
5 | #include "core/module/ModuleInstance.h" | |||
6 | #include "core/CoreIncludes.h" | |||
7 | ||||
8 | namespace orxonox | |||
9 | { | |||
10 | namespace | |||
11 | { | |||
12 | // Fixture | |||
13 | class ClassFactoryTest : public ::testing::Test | |||
14 | { | |||
15 | public: | |||
16 | virtual void SetUp() override | |||
17 | { | |||
18 | new IdentifierManager(); | |||
| ||||
19 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); | |||
| ||||
20 | Context::setRootContext(new Context(nullptr)); | |||
21 | } | |||
22 | ||||
23 | virtual void TearDown() override | |||
24 | { | |||
25 | Context::destroyRootContext(); | |||
26 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); | |||
27 | delete &IdentifierManager::getInstance(); | |||
28 | } | |||
29 | }; | |||
30 | } | |||
31 | ||||
32 | TEST_F(ClassFactoryTest, CanFabricateObject)class ClassFactoryTest_CanFabricateObject_Test : public ClassFactoryTest { public: ClassFactoryTest_CanFabricateObject_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ClassFactoryTest_CanFabricateObject_Test (ClassFactoryTest_CanFabricateObject_Test const &); void operator =(ClassFactoryTest_CanFabricateObject_Test const &);};::testing ::TestInfo* const ClassFactoryTest_CanFabricateObject_Test :: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ClassFactoryTest" , "CanFabricateObject", __null, __null, (::testing::internal:: GetTypeId<ClassFactoryTest>()), ClassFactoryTest::SetUpTestCase , ClassFactoryTest::TearDownTestCase, new ::testing::internal ::TestFactoryImpl< ClassFactoryTest_CanFabricateObject_Test >);void ClassFactoryTest_CanFabricateObject_Test::TestBody () | |||
33 | { | |||
34 | Factory* factory = new ClassFactoryWithContext<BaseObject>(); | |||
35 | Identifiable* object = factory->fabricate(nullptr); | |||
36 | ASSERT_TRUE(object != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(object != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ClassFactoryTest.cc" , 36, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "object != nullptr", "false", "true").c_str()) = ::testing:: Message(); | |||
37 | BaseObject* baseObject = dynamic_cast<BaseObject*>(object); | |||
38 | EXPECT_TRUE(baseObject != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(baseObject != nullptr )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ClassFactoryTest.cc" , 38, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "baseObject != nullptr", "false", "true").c_str()) = ::testing ::Message(); | |||
39 | delete object; | |||
40 | // don't delete factory - it remains in the identifier | |||
41 | } | |||
42 | } |