Bug Summary

File:core/object/IteratorTest.cc
Location:line 37, column 21
Description:Potential memory leak

Annotated Source Code

1#include <gtest/gtest.h>
2#include <gmock/gmock.h>
3
4#include "core/object/Iterator.h"
5#include "core/class/OrxonoxClass.h"
6#include "core/class/OrxonoxInterface.h"
7#include "core/CoreIncludes.h"
8#include "core/module/ModuleInstance.h"
9
10namespace orxonox
11{
12 namespace
13 {
14 class TestInterface : virtual public OrxonoxInterface
15 {
16 public:
17 TestInterface() { RegisterObject(TestInterface)if (ClassIdentifier<TestInterface>::getIdentifier()->
initializeObject(this)) return; else ((void)0)
; }
18 };
19
20 class TestClass : public OrxonoxClass, public TestInterface
21 {
22 public:
23 TestClass() { RegisterObject(TestClass)if (ClassIdentifier<TestClass>::getIdentifier()->initializeObject
(this)) return; else ((void)0)
; }
24 MOCK_METHOD0(test, void())::testing::internal::Function<void()>::Result test() { typedef
::testing::internal::CompileAssert<(bool(::std::tr1::tuple_size
< ::testing::internal::Function<void()>::ArgumentTuple
>::value == 0))> this_method_does_not_take_0_arguments[
bool(::std::tr1::tuple_size< ::testing::internal::Function
<void()>::ArgumentTuple>::value == 0) ? 1 : -1]; gmock0_test_24
.SetOwnerAndName(this, "test"); return gmock0_test_24.Invoke(
); } ::testing::MockSpec<void()>& gmock_test() { gmock0_test_24
.RegisterOwner(this); return gmock0_test_24.With(); } mutable
::testing::FunctionMocker<void()> gmock0_test_24
;
25 };
26
27 RegisterClassNoArgs(TestInterface)orxonox::SI_I& _TestInterfaceIdentifier = (*new orxonox::
SI_I(orxonox::registerClass<TestInterface>("TestInterface"
, new orxonox::ClassFactoryNoArgs<TestInterface>(), true
)))
;
28 RegisterClassNoArgs(TestClass)orxonox::SI_I& _TestClassIdentifier = (*new orxonox::SI_I
(orxonox::registerClass<TestClass>("TestClass", new orxonox
::ClassFactoryNoArgs<TestClass>(), true)))
;
29
30 // Fixture
31 class IteratorTest : public ::testing::Test
32 {
33 public:
34 virtual void SetUp() override
35 {
36 new IdentifierManager();
1
Memory is allocated
37 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
2
Potential memory leak
38 Context::setRootContext(new Context(nullptr));
39 }
40
41 virtual void TearDown() override
42 {
43 Context::destroyRootContext();
44 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
45 delete &IdentifierManager::getInstance();
46 }
47 };
48 }
49
50 TEST_F(IteratorTest, CanCreateIterator)class IteratorTest_CanCreateIterator_Test : public IteratorTest
{ public: IteratorTest_CanCreateIterator_Test() {} private: virtual
void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); IteratorTest_CanCreateIterator_Test
(IteratorTest_CanCreateIterator_Test const &); void operator
=(IteratorTest_CanCreateIterator_Test const &);};::testing
::TestInfo* const IteratorTest_CanCreateIterator_Test ::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IteratorTest"
, "CanCreateIterator", __null, __null, (::testing::internal::
GetTypeId<IteratorTest>()), IteratorTest::SetUpTestCase
, IteratorTest::TearDownTestCase, new ::testing::internal::TestFactoryImpl
< IteratorTest_CanCreateIterator_Test>);void IteratorTest_CanCreateIterator_Test
::TestBody()
51 {
52 Iterator<TestInterface> it;
53 }
54
55 TEST_F(IteratorTest, CanAssignIterator)class IteratorTest_CanAssignIterator_Test : public IteratorTest
{ public: IteratorTest_CanAssignIterator_Test() {} private: virtual
void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); IteratorTest_CanAssignIterator_Test
(IteratorTest_CanAssignIterator_Test const &); void operator
=(IteratorTest_CanAssignIterator_Test const &);};::testing
::TestInfo* const IteratorTest_CanAssignIterator_Test ::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IteratorTest"
, "CanAssignIterator", __null, __null, (::testing::internal::
GetTypeId<IteratorTest>()), IteratorTest::SetUpTestCase
, IteratorTest::TearDownTestCase, new ::testing::internal::TestFactoryImpl
< IteratorTest_CanAssignIterator_Test>);void IteratorTest_CanAssignIterator_Test
::TestBody()
56 {
57 ObjectList<TestInterface> list;
58 Iterator<TestInterface> it = list.begin();
59 }
60
61 TEST_F(IteratorTest, CanIterateOverEmptyList)class IteratorTest_CanIterateOverEmptyList_Test : public IteratorTest
{ public: IteratorTest_CanIterateOverEmptyList_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); IteratorTest_CanIterateOverEmptyList_Test
(IteratorTest_CanIterateOverEmptyList_Test const &); void
operator=(IteratorTest_CanIterateOverEmptyList_Test const &
);};::testing::TestInfo* const IteratorTest_CanIterateOverEmptyList_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"IteratorTest", "CanIterateOverEmptyList", __null, __null, (
::testing::internal::GetTypeId<IteratorTest>()), IteratorTest
::SetUpTestCase, IteratorTest::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< IteratorTest_CanIterateOverEmptyList_Test
>);void IteratorTest_CanIterateOverEmptyList_Test::TestBody
()
62 {
63 size_t i = 0;
64 ObjectList<TestInterface> list;
65 for (Iterator<TestInterface> it = list.begin(); it != list.end(); ++it)
66 ++i;
67 EXPECT_EQ(0u, i)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(0u)) == 1)>::Compare("0u",
"i", 0u, i))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 67, gtest_ar.failure_message()) = ::testing::Message()
;
68 }
69
70 TEST_F(IteratorTest, CanCallObjects)class IteratorTest_CanCallObjects_Test : public IteratorTest {
public: IteratorTest_CanCallObjects_Test() {} private: virtual
void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); IteratorTest_CanCallObjects_Test(IteratorTest_CanCallObjects_Test
const &); void operator=(IteratorTest_CanCallObjects_Test
const &);};::testing::TestInfo* const IteratorTest_CanCallObjects_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"IteratorTest", "CanCallObjects", __null, __null, (::testing
::internal::GetTypeId<IteratorTest>()), IteratorTest::SetUpTestCase
, IteratorTest::TearDownTestCase, new ::testing::internal::TestFactoryImpl
< IteratorTest_CanCallObjects_Test>);void IteratorTest_CanCallObjects_Test
::TestBody()
71 {
72 TestClass test1;
73 TestClass test2;
74 TestClass test3;
75
76 EXPECT_CALL(test1, test())((test1).gmock_test()).InternalExpectedAt("/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 76, "test1", "test()")
;
77 EXPECT_CALL(test2, test())((test2).gmock_test()).InternalExpectedAt("/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 77, "test2", "test()")
;
78 EXPECT_CALL(test3, test())((test3).gmock_test()).InternalExpectedAt("/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 78, "test3", "test()")
;
79
80 // iterate over interfaces but use a TestClass iterator - now we can call TestClass::test()
81 ObjectList<TestInterface> list;
82 for (Iterator<TestClass> it = list.begin(); it != list.end(); ++it)
83 it->test();
84 }
85
86 TEST_F(IteratorTest, CanIterateOverInterfaceListWithInterfaceIterator)class IteratorTest_CanIterateOverInterfaceListWithInterfaceIterator_Test
: public IteratorTest { public: IteratorTest_CanIterateOverInterfaceListWithInterfaceIterator_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); IteratorTest_CanIterateOverInterfaceListWithInterfaceIterator_Test
(IteratorTest_CanIterateOverInterfaceListWithInterfaceIterator_Test
const &); void operator=(IteratorTest_CanIterateOverInterfaceListWithInterfaceIterator_Test
const &);};::testing::TestInfo* const IteratorTest_CanIterateOverInterfaceListWithInterfaceIterator_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"IteratorTest", "CanIterateOverInterfaceListWithInterfaceIterator"
, __null, __null, (::testing::internal::GetTypeId<IteratorTest
>()), IteratorTest::SetUpTestCase, IteratorTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< IteratorTest_CanIterateOverInterfaceListWithInterfaceIterator_Test
>);void IteratorTest_CanIterateOverInterfaceListWithInterfaceIterator_Test
::TestBody()
87 {
88 TestClass testClass;
89 TestInterface testInterface;
90
91 size_t i = 0;
92 ObjectList<TestInterface> list;
93 for (Iterator<TestInterface> it = list.begin(); it != list.end(); ++it)
94 {
95 ++i;
96 if (i == 1u) EXPECT_EQ(&testClass, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&testClass)) == 1)>::Compare
("&testClass", "*it", &testClass, *it))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 96, gtest_ar.failure_message()) = ::testing::Message()
;
97 if (i == 2u) EXPECT_EQ(&testInterface, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&testInterface)) == 1)>
::Compare("&testInterface", "*it", &testInterface, *it
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 97, gtest_ar.failure_message()) = ::testing::Message()
;
98 }
99 EXPECT_EQ(2u, i)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(2u)) == 1)>::Compare("2u",
"i", 2u, i))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 99, gtest_ar.failure_message()) = ::testing::Message()
;
100 }
101
102 TEST_F(IteratorTest, CanIterateOverClassListWithClassIterator)class IteratorTest_CanIterateOverClassListWithClassIterator_Test
: public IteratorTest { public: IteratorTest_CanIterateOverClassListWithClassIterator_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); IteratorTest_CanIterateOverClassListWithClassIterator_Test
(IteratorTest_CanIterateOverClassListWithClassIterator_Test const
&); void operator=(IteratorTest_CanIterateOverClassListWithClassIterator_Test
const &);};::testing::TestInfo* const IteratorTest_CanIterateOverClassListWithClassIterator_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"IteratorTest", "CanIterateOverClassListWithClassIterator", __null
, __null, (::testing::internal::GetTypeId<IteratorTest>
()), IteratorTest::SetUpTestCase, IteratorTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< IteratorTest_CanIterateOverClassListWithClassIterator_Test
>);void IteratorTest_CanIterateOverClassListWithClassIterator_Test
::TestBody()
103 {
104 TestClass testClass;
105 TestInterface testInterface;
106
107 size_t i = 0;
108 ObjectList<TestClass> list;
109 for (Iterator<TestClass> it = list.begin(); it != list.end(); ++it)
110 {
111 ++i;
112 if (i == 1u) EXPECT_EQ(&testClass, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&testClass)) == 1)>::Compare
("&testClass", "*it", &testClass, *it))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 112, gtest_ar.failure_message()) = ::testing::Message()
;
113 }
114 EXPECT_EQ(1u, i)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(1u)) == 1)>::Compare("1u",
"i", 1u, i))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 114, gtest_ar.failure_message()) = ::testing::Message()
;
115 }
116
117 TEST_F(IteratorTest, CanIterateOverInterfaceListWithClassIterator)class IteratorTest_CanIterateOverInterfaceListWithClassIterator_Test
: public IteratorTest { public: IteratorTest_CanIterateOverInterfaceListWithClassIterator_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); IteratorTest_CanIterateOverInterfaceListWithClassIterator_Test
(IteratorTest_CanIterateOverInterfaceListWithClassIterator_Test
const &); void operator=(IteratorTest_CanIterateOverInterfaceListWithClassIterator_Test
const &);};::testing::TestInfo* const IteratorTest_CanIterateOverInterfaceListWithClassIterator_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"IteratorTest", "CanIterateOverInterfaceListWithClassIterator"
, __null, __null, (::testing::internal::GetTypeId<IteratorTest
>()), IteratorTest::SetUpTestCase, IteratorTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< IteratorTest_CanIterateOverInterfaceListWithClassIterator_Test
>);void IteratorTest_CanIterateOverInterfaceListWithClassIterator_Test
::TestBody()
118 {
119 TestClass testClass;
120 TestInterface testInterface;
121
122 size_t i = 0;
123 ObjectList<TestInterface> list;
124 for (Iterator<TestClass> it = list.begin(); it != list.end(); ++it)
125 {
126 ++i;
127 if (i == 1u) EXPECT_EQ(&testClass, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&testClass)) == 1)>::Compare
("&testClass", "*it", &testClass, *it))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 127, gtest_ar.failure_message()) = ::testing::Message()
;
128 if (i == 2u) EXPECT_EQ(nullptr, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(nullptr)) == 1)>::Compare(
"nullptr", "*it", nullptr, *it))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 128, gtest_ar.failure_message()) = ::testing::Message()
;
129 }
130 EXPECT_EQ(2u, i)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(2u)) == 1)>::Compare("2u",
"i", 2u, i))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 130, gtest_ar.failure_message()) = ::testing::Message()
;
131 }
132
133 TEST_F(IteratorTest, CanIterateOverClassListWithInterfaceIterator)class IteratorTest_CanIterateOverClassListWithInterfaceIterator_Test
: public IteratorTest { public: IteratorTest_CanIterateOverClassListWithInterfaceIterator_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); IteratorTest_CanIterateOverClassListWithInterfaceIterator_Test
(IteratorTest_CanIterateOverClassListWithInterfaceIterator_Test
const &); void operator=(IteratorTest_CanIterateOverClassListWithInterfaceIterator_Test
const &);};::testing::TestInfo* const IteratorTest_CanIterateOverClassListWithInterfaceIterator_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"IteratorTest", "CanIterateOverClassListWithInterfaceIterator"
, __null, __null, (::testing::internal::GetTypeId<IteratorTest
>()), IteratorTest::SetUpTestCase, IteratorTest::TearDownTestCase
, new ::testing::internal::TestFactoryImpl< IteratorTest_CanIterateOverClassListWithInterfaceIterator_Test
>);void IteratorTest_CanIterateOverClassListWithInterfaceIterator_Test
::TestBody()
134 {
135 TestClass testClass;
136 TestInterface testInterface;
137
138 size_t i = 0;
139 ObjectList<TestClass> list;
140 for (Iterator<TestInterface> it = list.begin(); it != list.end(); ++it)
141 {
142 ++i;
143 if (i == 1u) EXPECT_EQ(&testClass, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&testClass)) == 1)>::Compare
("&testClass", "*it", &testClass, *it))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 143, gtest_ar.failure_message()) = ::testing::Message()
;
144 }
145 EXPECT_EQ(1u, i)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(1u)) == 1)>::Compare("1u",
"i", 1u, i))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/IteratorTest.cc"
, 145, gtest_ar.failure_message()) = ::testing::Message()
;
146 }
147}