Bug Summary

File:core/object/ObjectListIteratorTest.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/ObjectListIterator.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 ObjectListIteratorTest : 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(ObjectListIteratorTest, CanCreateIterator)class ObjectListIteratorTest_CanCreateIterator_Test : public ObjectListIteratorTest
{ public: ObjectListIteratorTest_CanCreateIterator_Test() {}
private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); ObjectListIteratorTest_CanCreateIterator_Test
(ObjectListIteratorTest_CanCreateIterator_Test const &); void
operator=(ObjectListIteratorTest_CanCreateIterator_Test const
&);};::testing::TestInfo* const ObjectListIteratorTest_CanCreateIterator_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"ObjectListIteratorTest", "CanCreateIterator", __null, __null
, (::testing::internal::GetTypeId<ObjectListIteratorTest>
()), ObjectListIteratorTest::SetUpTestCase, ObjectListIteratorTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
ObjectListIteratorTest_CanCreateIterator_Test>);void ObjectListIteratorTest_CanCreateIterator_Test
::TestBody()
51 {
52 ObjectListIterator<TestClass> it;
53 }
54
55 TEST_F(ObjectListIteratorTest, CanAssignIterator)class ObjectListIteratorTest_CanAssignIterator_Test : public ObjectListIteratorTest
{ public: ObjectListIteratorTest_CanAssignIterator_Test() {}
private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); ObjectListIteratorTest_CanAssignIterator_Test
(ObjectListIteratorTest_CanAssignIterator_Test const &); void
operator=(ObjectListIteratorTest_CanAssignIterator_Test const
&);};::testing::TestInfo* const ObjectListIteratorTest_CanAssignIterator_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"ObjectListIteratorTest", "CanAssignIterator", __null, __null
, (::testing::internal::GetTypeId<ObjectListIteratorTest>
()), ObjectListIteratorTest::SetUpTestCase, ObjectListIteratorTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
ObjectListIteratorTest_CanAssignIterator_Test>);void ObjectListIteratorTest_CanAssignIterator_Test
::TestBody()
56 {
57 ObjectList<TestClass> list;
58 ObjectListIterator<TestClass> it = list.begin();
59 }
60
61 TEST_F(ObjectListIteratorTest, CanIterateOverEmptyList)class ObjectListIteratorTest_CanIterateOverEmptyList_Test : public
ObjectListIteratorTest { public: ObjectListIteratorTest_CanIterateOverEmptyList_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); ObjectListIteratorTest_CanIterateOverEmptyList_Test
(ObjectListIteratorTest_CanIterateOverEmptyList_Test const &
); void operator=(ObjectListIteratorTest_CanIterateOverEmptyList_Test
const &);};::testing::TestInfo* const ObjectListIteratorTest_CanIterateOverEmptyList_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"ObjectListIteratorTest", "CanIterateOverEmptyList", __null,
__null, (::testing::internal::GetTypeId<ObjectListIteratorTest
>()), ObjectListIteratorTest::SetUpTestCase, ObjectListIteratorTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
ObjectListIteratorTest_CanIterateOverEmptyList_Test>);void
ObjectListIteratorTest_CanIterateOverEmptyList_Test::TestBody
()
62 {
63 size_t i = 0;
64 ObjectList<TestClass> list;
65 for (ObjectListIterator<TestClass> 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/ObjectListIteratorTest.cc"
, 67, gtest_ar.failure_message()) = ::testing::Message()
;
68 }
69
70 TEST_F(ObjectListIteratorTest, CanIterateOverFullList)class ObjectListIteratorTest_CanIterateOverFullList_Test : public
ObjectListIteratorTest { public: ObjectListIteratorTest_CanIterateOverFullList_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); ObjectListIteratorTest_CanIterateOverFullList_Test
(ObjectListIteratorTest_CanIterateOverFullList_Test const &
); void operator=(ObjectListIteratorTest_CanIterateOverFullList_Test
const &);};::testing::TestInfo* const ObjectListIteratorTest_CanIterateOverFullList_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"ObjectListIteratorTest", "CanIterateOverFullList", __null, __null
, (::testing::internal::GetTypeId<ObjectListIteratorTest>
()), ObjectListIteratorTest::SetUpTestCase, ObjectListIteratorTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
ObjectListIteratorTest_CanIterateOverFullList_Test>);void
ObjectListIteratorTest_CanIterateOverFullList_Test::TestBody
()
71 {
72 TestClass test1;
73 TestClass test2;
74 TestClass test3;
75 TestInterface interface;
76
77 size_t i = 0;
78 ObjectList<TestClass> list;
79 for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it)
80 {
81 ++i;
82 if (i == 1u) EXPECT_EQ(&test1, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&test1)) == 1)>::Compare
("&test1", "*it", &test1, *it))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 82, gtest_ar.failure_message()) = ::testing::Message()
;
83 if (i == 2u) EXPECT_EQ(&test2, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&test2)) == 1)>::Compare
("&test2", "*it", &test2, *it))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 83, gtest_ar.failure_message()) = ::testing::Message()
;
84 if (i == 3u) EXPECT_EQ(&test3, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&test3)) == 1)>::Compare
("&test3", "*it", &test3, *it))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 84, gtest_ar.failure_message()) = ::testing::Message()
;
85 }
86 EXPECT_EQ(3u, i)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(3u)) == 1)>::Compare("3u",
"i", 3u, i))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 86, gtest_ar.failure_message()) = ::testing::Message()
;
87 }
88
89 TEST_F(ObjectListIteratorTest, CanIterateReverseOverFullList)class ObjectListIteratorTest_CanIterateReverseOverFullList_Test
: public ObjectListIteratorTest { public: ObjectListIteratorTest_CanIterateReverseOverFullList_Test
() {} private: virtual void TestBody(); static ::testing::TestInfo
* const test_info_ __attribute__ ((unused)); ObjectListIteratorTest_CanIterateReverseOverFullList_Test
(ObjectListIteratorTest_CanIterateReverseOverFullList_Test const
&); void operator=(ObjectListIteratorTest_CanIterateReverseOverFullList_Test
const &);};::testing::TestInfo* const ObjectListIteratorTest_CanIterateReverseOverFullList_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"ObjectListIteratorTest", "CanIterateReverseOverFullList", __null
, __null, (::testing::internal::GetTypeId<ObjectListIteratorTest
>()), ObjectListIteratorTest::SetUpTestCase, ObjectListIteratorTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
ObjectListIteratorTest_CanIterateReverseOverFullList_Test>
);void ObjectListIteratorTest_CanIterateReverseOverFullList_Test
::TestBody()
90 {
91 TestClass test1;
92 TestClass test2;
93 TestClass test3;
94 TestInterface interface;
95
96 size_t i = 0;
97 ObjectList<TestClass> list;
98 for (ObjectListIterator<TestClass> it = list.rbegin(); it != list.rend(); --it)
99 {
100 ++i;
101 if (i == 1u) EXPECT_EQ(&test3, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&test3)) == 1)>::Compare
("&test3", "*it", &test3, *it))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 101, gtest_ar.failure_message()) = ::testing::Message()
;
102 if (i == 2u) EXPECT_EQ(&test2, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&test2)) == 1)>::Compare
("&test2", "*it", &test2, *it))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 102, gtest_ar.failure_message()) = ::testing::Message()
;
103 if (i == 3u) EXPECT_EQ(&test1, *it)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(&test1)) == 1)>::Compare
("&test1", "*it", &test1, *it))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 103, gtest_ar.failure_message()) = ::testing::Message()
;
104 }
105 EXPECT_EQ(3u, i)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing
::internal::IsNullLiteralHelper(3u)) == 1)>::Compare("3u",
"i", 3u, i))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 105, gtest_ar.failure_message()) = ::testing::Message()
;
106 }
107
108 TEST_F(ObjectListIteratorTest, CanCallObjects)class ObjectListIteratorTest_CanCallObjects_Test : public ObjectListIteratorTest
{ public: ObjectListIteratorTest_CanCallObjects_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); ObjectListIteratorTest_CanCallObjects_Test
(ObjectListIteratorTest_CanCallObjects_Test const &); void
operator=(ObjectListIteratorTest_CanCallObjects_Test const &
);};::testing::TestInfo* const ObjectListIteratorTest_CanCallObjects_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"ObjectListIteratorTest", "CanCallObjects", __null, __null, (
::testing::internal::GetTypeId<ObjectListIteratorTest>(
)), ObjectListIteratorTest::SetUpTestCase, ObjectListIteratorTest
::TearDownTestCase, new ::testing::internal::TestFactoryImpl<
ObjectListIteratorTest_CanCallObjects_Test>);void ObjectListIteratorTest_CanCallObjects_Test
::TestBody()
109 {
110 TestClass test1;
111 TestClass test2;
112 TestClass test3;
113 TestInterface interface;
114
115 EXPECT_CALL(test1, test())((test1).gmock_test()).InternalExpectedAt("/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 115, "test1", "test()")
;
116 EXPECT_CALL(test2, test())((test2).gmock_test()).InternalExpectedAt("/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 116, "test2", "test()")
;
117 EXPECT_CALL(test3, test())((test3).gmock_test()).InternalExpectedAt("/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListIteratorTest.cc"
, 117, "test3", "test()")
;
118
119 ObjectList<TestClass> list;
120 for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it)
121 it->test();
122 }
123}