Bug Summary

File:core/class/SubclassIdentifierTest.cc
Location:line 34, column 21
Description:Potential memory leak

Annotated Source Code

1#include <gtest/gtest.h>
2#include "core/CoreIncludes.h"
3#include "core/class/Identifiable.h"
4#include "core/class/SubclassIdentifier.h"
5#include "core/class/OrxonoxClass.h"
6#include "core/module/ModuleInstance.h"
7
8namespace orxonox
9{
10 namespace
11 {
12 class TestClass : public OrxonoxClass
13 {
14 public:
15 TestClass(Context* context = nullptr) { RegisterObject(TestClass)if (ClassIdentifier<TestClass>::getIdentifier()->initializeObject
(this)) return; else ((void)0)
; }
16 };
17
18 class TestSubclass : public TestClass
19 {
20 public:
21 TestSubclass(Context* context = nullptr) { RegisterObject(TestSubclass)if (ClassIdentifier<TestSubclass>::getIdentifier()->
initializeObject(this)) return; else ((void)0)
; }
22 };
23
24 RegisterClass(TestClass)orxonox::SI_I& _TestClassIdentifier = (*new orxonox::SI_I
(orxonox::registerClass<TestClass>("TestClass", new orxonox
::ClassFactoryWithContext<TestClass>(), true)))
;
25 RegisterClass(TestSubclass)orxonox::SI_I& _TestSubclassIdentifier = (*new orxonox::SI_I
(orxonox::registerClass<TestSubclass>("TestSubclass", new
orxonox::ClassFactoryWithContext<TestSubclass>(), true
)))
;
26
27 // Fixture
28 class SubclassIdentifierTest : public ::testing::Test
29 {
30 public:
31 virtual void SetUp() override
32 {
33 new IdentifierManager();
1
Memory is allocated
34 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
2
Potential memory leak
35 Context::setRootContext(new Context(nullptr));
36 Identifier::initConfigValues_s = false; // TODO: hack!
37 IdentifierManager::getInstance().createClassHierarchy();
38 }
39
40 virtual void TearDown() override
41 {
42 IdentifierManager::getInstance().destroyClassHierarchy();
43 Context::destroyRootContext();
44 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
45 delete &IdentifierManager::getInstance();
46 }
47 };
48 }
49
50 TEST_F(SubclassIdentifierTest, CanCreateIdentifier)class SubclassIdentifierTest_CanCreateIdentifier_Test : public
SubclassIdentifierTest { public: SubclassIdentifierTest_CanCreateIdentifier_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); SubclassIdentifierTest_CanCreateIdentifier_Test
(SubclassIdentifierTest_CanCreateIdentifier_Test const &)
; void operator=(SubclassIdentifierTest_CanCreateIdentifier_Test
const &);};::testing::TestInfo* const SubclassIdentifierTest_CanCreateIdentifier_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"SubclassIdentifierTest", "CanCreateIdentifier", __null, __null
, (::testing::internal::GetTypeId<SubclassIdentifierTest>
()), SubclassIdentifierTest::SetUpTestCase, SubclassIdentifierTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
SubclassIdentifierTest_CanCreateIdentifier_Test>);void SubclassIdentifierTest_CanCreateIdentifier_Test
::TestBody()
51 {
52 TestSubclass test;
53
54 SubclassIdentifier<TestClass> subclassIdentifier;
55 }
56
57 TEST_F(SubclassIdentifierTest, DefaultsToNormalIdentifier)class SubclassIdentifierTest_DefaultsToNormalIdentifier_Test :
public SubclassIdentifierTest { public: SubclassIdentifierTest_DefaultsToNormalIdentifier_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); SubclassIdentifierTest_DefaultsToNormalIdentifier_Test
(SubclassIdentifierTest_DefaultsToNormalIdentifier_Test const
&); void operator=(SubclassIdentifierTest_DefaultsToNormalIdentifier_Test
const &);};::testing::TestInfo* const SubclassIdentifierTest_DefaultsToNormalIdentifier_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"SubclassIdentifierTest", "DefaultsToNormalIdentifier", __null
, __null, (::testing::internal::GetTypeId<SubclassIdentifierTest
>()), SubclassIdentifierTest::SetUpTestCase, SubclassIdentifierTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
SubclassIdentifierTest_DefaultsToNormalIdentifier_Test>);
void SubclassIdentifierTest_DefaultsToNormalIdentifier_Test::
TestBody()
58 {
59 TestSubclass test;
60
61 SubclassIdentifier<TestClass> subclassIdentifier;
62 EXPECT_EQ(Class(TestClass), subclassIdentifier.getIdentifier())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(orxonox::ClassIdentifier<TestClass
>::getIdentifier())) == 1)>::Compare("orxonox::ClassIdentifier<TestClass>::getIdentifier()"
, "subclassIdentifier.getIdentifier()", orxonox::ClassIdentifier
<TestClass>::getIdentifier(), subclassIdentifier.getIdentifier
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/SubclassIdentifierTest.cc"
, 62, gtest_ar.failure_message()) = ::testing::Message()
;
63 }
64
65 TEST_F(SubclassIdentifierTest, CanAssignIdentifierOfSubclass)class SubclassIdentifierTest_CanAssignIdentifierOfSubclass_Test
: public SubclassIdentifierTest { public: SubclassIdentifierTest_CanAssignIdentifierOfSubclass_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); SubclassIdentifierTest_CanAssignIdentifierOfSubclass_Test
(SubclassIdentifierTest_CanAssignIdentifierOfSubclass_Test const
&); void operator=(SubclassIdentifierTest_CanAssignIdentifierOfSubclass_Test
const &);};::testing::TestInfo* const SubclassIdentifierTest_CanAssignIdentifierOfSubclass_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"SubclassIdentifierTest", "CanAssignIdentifierOfSubclass", __null
, __null, (::testing::internal::GetTypeId<SubclassIdentifierTest
>()), SubclassIdentifierTest::SetUpTestCase, SubclassIdentifierTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
SubclassIdentifierTest_CanAssignIdentifierOfSubclass_Test>
);void SubclassIdentifierTest_CanAssignIdentifierOfSubclass_Test
::TestBody()
66 {
67 TestSubclass test;
68 SubclassIdentifier<TestClass> subclassIdentifier;
69 subclassIdentifier = Class(TestSubclass)orxonox::ClassIdentifier<TestSubclass>::getIdentifier();
70 EXPECT_EQ(Class(TestSubclass), subclassIdentifier.getIdentifier())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(orxonox::ClassIdentifier<TestSubclass
>::getIdentifier())) == 1)>::Compare("orxonox::ClassIdentifier<TestSubclass>::getIdentifier()"
, "subclassIdentifier.getIdentifier()", orxonox::ClassIdentifier
<TestSubclass>::getIdentifier(), subclassIdentifier.getIdentifier
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/SubclassIdentifierTest.cc"
, 70, gtest_ar.failure_message()) = ::testing::Message()
;
71 }
72
73 TEST_F(SubclassIdentifierTest, CanCreateSubclass)class SubclassIdentifierTest_CanCreateSubclass_Test : public SubclassIdentifierTest
{ public: SubclassIdentifierTest_CanCreateSubclass_Test() {}
private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); SubclassIdentifierTest_CanCreateSubclass_Test
(SubclassIdentifierTest_CanCreateSubclass_Test const &); void
operator=(SubclassIdentifierTest_CanCreateSubclass_Test const
&);};::testing::TestInfo* const SubclassIdentifierTest_CanCreateSubclass_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"SubclassIdentifierTest", "CanCreateSubclass", __null, __null
, (::testing::internal::GetTypeId<SubclassIdentifierTest>
()), SubclassIdentifierTest::SetUpTestCase, SubclassIdentifierTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
SubclassIdentifierTest_CanCreateSubclass_Test>);void SubclassIdentifierTest_CanCreateSubclass_Test
::TestBody()
74 {
75 TestSubclass test;
76 SubclassIdentifier<TestClass> subclassIdentifier;
77 subclassIdentifier = Class(TestSubclass)orxonox::ClassIdentifier<TestSubclass>::getIdentifier();
78
79 TestClass* instance = subclassIdentifier.fabricate(nullptr);
80 ASSERT_TRUE(instance != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(instance != nullptr))
; else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/SubclassIdentifierTest.cc"
, 80, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "instance != nullptr", "false", "true").c_str()) = ::testing
::Message()
;
81 EXPECT_EQ(Class(TestSubclass), instance->getIdentifier())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(orxonox::ClassIdentifier<TestSubclass
>::getIdentifier())) == 1)>::Compare("orxonox::ClassIdentifier<TestSubclass>::getIdentifier()"
, "instance->getIdentifier()", orxonox::ClassIdentifier<
TestSubclass>::getIdentifier(), instance->getIdentifier
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/SubclassIdentifierTest.cc"
, 81, gtest_ar.failure_message()) = ::testing::Message()
;
82 delete instance;
83 }
84}