Bug Summary

File:core/class/IdentifierTest.cc
Location:line 32, 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/module/ModuleInstance.h"
5
6namespace orxonox
7{
8 namespace
9 {
10 class TestClass : public Identifiable
11 {
12 public:
13 TestClass() { RegisterObject(TestClass)if (ClassIdentifier<TestClass>::getIdentifier()->initializeObject
(this)) return; else ((void)0)
; }
14 };
15
16 class TestSubclass : public TestClass
17 {
18 public:
19 TestSubclass() { RegisterObject(TestSubclass)if (ClassIdentifier<TestSubclass>::getIdentifier()->
initializeObject(this)) return; else ((void)0)
; }
20 };
21
22 RegisterClassNoArgs(TestClass)orxonox::SI_I& _TestClassIdentifier = (*new orxonox::SI_I
(orxonox::registerClass<TestClass>("TestClass", new orxonox
::ClassFactoryNoArgs<TestClass>(), true)))
;
23 RegisterClassNoArgs(TestSubclass)orxonox::SI_I& _TestSubclassIdentifier = (*new orxonox::SI_I
(orxonox::registerClass<TestSubclass>("TestSubclass", new
orxonox::ClassFactoryNoArgs<TestSubclass>(), true)))
;
24
25 // Fixture
26 class IdentifierTest : public ::testing::Test
27 {
28 public:
29 virtual void SetUp() override
30 {
31 new IdentifierManager();
1
Memory is allocated
32 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
2
Potential memory leak
33 }
34
35 virtual void TearDown() override
36 {
37 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
38 delete &IdentifierManager::getInstance();
39 }
40 };
41 }
42
43 TEST_F(IdentifierTest, IdentifierExistsOfClass)class IdentifierTest_IdentifierExistsOfClass_Test : public IdentifierTest
{ public: IdentifierTest_IdentifierExistsOfClass_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); IdentifierTest_IdentifierExistsOfClass_Test
(IdentifierTest_IdentifierExistsOfClass_Test const &); void
operator=(IdentifierTest_IdentifierExistsOfClass_Test const &
);};::testing::TestInfo* const IdentifierTest_IdentifierExistsOfClass_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"IdentifierTest", "IdentifierExistsOfClass", __null, __null,
(::testing::internal::GetTypeId<IdentifierTest>()), IdentifierTest
::SetUpTestCase, IdentifierTest::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< IdentifierTest_IdentifierExistsOfClass_Test
>);void IdentifierTest_IdentifierExistsOfClass_Test::TestBody
()
44 {
45 TestClass test;
46
47 Identifier* identifier = Class(TestClass)orxonox::ClassIdentifier<TestClass>::getIdentifier();
48 EXPECT_TRUE(identifier != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(identifier != nullptr
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/IdentifierTest.cc"
, 48, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identifier != nullptr", "false", "true").c_str()) = ::testing
::Message()
;
49 }
50
51 TEST_F(IdentifierTest, IdentifierExistsOfSubclass)class IdentifierTest_IdentifierExistsOfSubclass_Test : public
IdentifierTest { public: IdentifierTest_IdentifierExistsOfSubclass_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); IdentifierTest_IdentifierExistsOfSubclass_Test
(IdentifierTest_IdentifierExistsOfSubclass_Test const &);
void operator=(IdentifierTest_IdentifierExistsOfSubclass_Test
const &);};::testing::TestInfo* const IdentifierTest_IdentifierExistsOfSubclass_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"IdentifierTest", "IdentifierExistsOfSubclass", __null, __null
, (::testing::internal::GetTypeId<IdentifierTest>()), IdentifierTest
::SetUpTestCase, IdentifierTest::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< IdentifierTest_IdentifierExistsOfSubclass_Test
>);void IdentifierTest_IdentifierExistsOfSubclass_Test::TestBody
()
52 {
53 TestSubclass test;
54
55 Identifier* identifier = Class(TestSubclass)orxonox::ClassIdentifier<TestSubclass>::getIdentifier();
56 EXPECT_TRUE(identifier != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(identifier != nullptr
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/IdentifierTest.cc"
, 56, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identifier != nullptr", "false", "true").c_str()) = ::testing
::Message()
;
57 }
58
59 TEST_F(IdentifierTest, HasNameOfClass)class IdentifierTest_HasNameOfClass_Test : public IdentifierTest
{ public: IdentifierTest_HasNameOfClass_Test() {} private: virtual
void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); IdentifierTest_HasNameOfClass_Test
(IdentifierTest_HasNameOfClass_Test const &); void operator
=(IdentifierTest_HasNameOfClass_Test const &);};::testing
::TestInfo* const IdentifierTest_HasNameOfClass_Test ::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IdentifierTest"
, "HasNameOfClass", __null, __null, (::testing::internal::GetTypeId
<IdentifierTest>()), IdentifierTest::SetUpTestCase, IdentifierTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
IdentifierTest_HasNameOfClass_Test>);void IdentifierTest_HasNameOfClass_Test
::TestBody()
60 {
61 TestClass test;
62
63 Identifier* identifier = Class(TestClass)orxonox::ClassIdentifier<TestClass>::getIdentifier();
64 EXPECT_EQ("TestClass", identifier->getName())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper("TestClass")) == 1)>::Compare
("\"TestClass\"", "identifier->getName()", "TestClass", identifier
->getName()))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/IdentifierTest.cc"
, 64, gtest_ar.failure_message()) = ::testing::Message()
;
65 }
66
67 TEST_F(IdentifierTest, HasNameOfSubClass)class IdentifierTest_HasNameOfSubClass_Test : public IdentifierTest
{ public: IdentifierTest_HasNameOfSubClass_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); IdentifierTest_HasNameOfSubClass_Test
(IdentifierTest_HasNameOfSubClass_Test const &); void operator
=(IdentifierTest_HasNameOfSubClass_Test const &);};::testing
::TestInfo* const IdentifierTest_HasNameOfSubClass_Test ::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IdentifierTest"
, "HasNameOfSubClass", __null, __null, (::testing::internal::
GetTypeId<IdentifierTest>()), IdentifierTest::SetUpTestCase
, IdentifierTest::TearDownTestCase, new ::testing::internal::
TestFactoryImpl< IdentifierTest_HasNameOfSubClass_Test>
);void IdentifierTest_HasNameOfSubClass_Test::TestBody()
68 {
69 TestSubclass test;
70
71 Identifier* identifier = Class(TestSubclass)orxonox::ClassIdentifier<TestSubclass>::getIdentifier();
72 EXPECT_EQ("TestSubclass", identifier->getName())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper("TestSubclass")) == 1)>::Compare
("\"TestSubclass\"", "identifier->getName()", "TestSubclass"
, identifier->getName()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/IdentifierTest.cc"
, 72, gtest_ar.failure_message()) = ::testing::Message()
;
73 }
74}