File: | core/object/ObjectListTest.cc |
Location: | line 30, column 21 |
Description: | Potential memory leak |
1 | #include <gtest/gtest.h> | |||
2 | #include <gmock/gmock.h> | |||
3 | ||||
4 | #include "core/object/ObjectListIterator.h" | |||
5 | #include "core/object/Listable.h" | |||
6 | #include "core/CoreIncludes.h" | |||
7 | #include "core/module/ModuleInstance.h" | |||
8 | ||||
9 | namespace orxonox | |||
10 | { | |||
11 | namespace | |||
12 | { | |||
13 | class ListableTest : public Listable | |||
14 | { | |||
15 | public: | |||
16 | ListableTest() { RegisterObject(ListableTest)if (ClassIdentifier<ListableTest>::getIdentifier()-> initializeObject(this)) return; else ((void)0); } | |||
17 | ListableTest(Context* context) : Listable(context) { RegisterObject(ListableTest)if (ClassIdentifier<ListableTest>::getIdentifier()-> initializeObject(this)) return; else ((void)0); } | |||
18 | 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_18 .SetOwnerAndName(this, "test"); return gmock0_test_18.Invoke( ); } ::testing::MockSpec<void()>& gmock_test() { gmock0_test_18 .RegisterOwner(this); return gmock0_test_18.With(); } mutable ::testing::FunctionMocker<void()> gmock0_test_18; | |||
19 | }; | |||
20 | ||||
21 | RegisterClassNoArgs(ListableTest)orxonox::SI_I& _ListableTestIdentifier = (*new orxonox::SI_I (orxonox::registerClass<ListableTest>("ListableTest", new orxonox::ClassFactoryNoArgs<ListableTest>(), true))); | |||
22 | ||||
23 | // Fixture | |||
24 | class ObjectListTest : public ::testing::Test | |||
25 | { | |||
26 | public: | |||
27 | virtual void SetUp() override | |||
28 | { | |||
29 | new IdentifierManager(); | |||
| ||||
30 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); | |||
| ||||
31 | Context::setRootContext(new Context(nullptr)); | |||
32 | } | |||
33 | ||||
34 | virtual void TearDown() override | |||
35 | { | |||
36 | Context::destroyRootContext(); | |||
37 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); | |||
38 | delete &IdentifierManager::getInstance(); | |||
39 | } | |||
40 | }; | |||
41 | } | |||
42 | ||||
43 | TEST_F(ObjectListTest, CanIterateOverEmptyList)class ObjectListTest_CanIterateOverEmptyList_Test : public ObjectListTest { public: ObjectListTest_CanIterateOverEmptyList_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ObjectListTest_CanIterateOverEmptyList_Test (ObjectListTest_CanIterateOverEmptyList_Test const &); void operator=(ObjectListTest_CanIterateOverEmptyList_Test const & );};::testing::TestInfo* const ObjectListTest_CanIterateOverEmptyList_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ObjectListTest", "CanIterateOverEmptyList", __null, __null, (::testing::internal::GetTypeId<ObjectListTest>()), ObjectListTest ::SetUpTestCase, ObjectListTest::TearDownTestCase, new ::testing ::internal::TestFactoryImpl< ObjectListTest_CanIterateOverEmptyList_Test >);void ObjectListTest_CanIterateOverEmptyList_Test::TestBody () | |||
44 | { | |||
45 | size_t i = 0; | |||
46 | for (ListableTest* object : ObjectList<ListableTest>()) | |||
47 | { | |||
48 | ++i; | |||
49 | ((void*)object); // avoid warning about unused variable | |||
50 | } | |||
51 | 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/ObjectListTest.cc" , 51, gtest_ar.failure_message()) = ::testing::Message(); | |||
52 | } | |||
53 | ||||
54 | TEST_F(ObjectListTest, CanIterateOverFullList)class ObjectListTest_CanIterateOverFullList_Test : public ObjectListTest { public: ObjectListTest_CanIterateOverFullList_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ObjectListTest_CanIterateOverFullList_Test (ObjectListTest_CanIterateOverFullList_Test const &); void operator=(ObjectListTest_CanIterateOverFullList_Test const & );};::testing::TestInfo* const ObjectListTest_CanIterateOverFullList_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ObjectListTest", "CanIterateOverFullList", __null, __null, ( ::testing::internal::GetTypeId<ObjectListTest>()), ObjectListTest ::SetUpTestCase, ObjectListTest::TearDownTestCase, new ::testing ::internal::TestFactoryImpl< ObjectListTest_CanIterateOverFullList_Test >);void ObjectListTest_CanIterateOverFullList_Test::TestBody () | |||
55 | { | |||
56 | ListableTest test1; | |||
57 | ListableTest test2; | |||
58 | ListableTest test3; | |||
59 | ||||
60 | size_t i = 0; | |||
61 | for (ListableTest* object : ObjectList<ListableTest>()) | |||
62 | { | |||
63 | ++i; | |||
64 | if (i == 1u) EXPECT_EQ(&test1, object)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&test1)) == 1)>::Compare ("&test1", "object", &test1, object))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 64, gtest_ar.failure_message()) = ::testing::Message(); | |||
65 | if (i == 2u) EXPECT_EQ(&test2, object)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&test2)) == 1)>::Compare ("&test2", "object", &test2, object))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 65, gtest_ar.failure_message()) = ::testing::Message(); | |||
66 | if (i == 3u) EXPECT_EQ(&test3, object)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&test3)) == 1)>::Compare ("&test3", "object", &test3, object))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 66, gtest_ar.failure_message()) = ::testing::Message(); | |||
67 | } | |||
68 | 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/ObjectListTest.cc" , 68, gtest_ar.failure_message()) = ::testing::Message(); | |||
69 | } | |||
70 | ||||
71 | TEST_F(ObjectListTest, CanIterateOverFullList_Expanded)class ObjectListTest_CanIterateOverFullList_Expanded_Test : public ObjectListTest { public: ObjectListTest_CanIterateOverFullList_Expanded_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); ObjectListTest_CanIterateOverFullList_Expanded_Test (ObjectListTest_CanIterateOverFullList_Expanded_Test const & ); void operator=(ObjectListTest_CanIterateOverFullList_Expanded_Test const &);};::testing::TestInfo* const ObjectListTest_CanIterateOverFullList_Expanded_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ObjectListTest", "CanIterateOverFullList_Expanded", __null, __null, (::testing::internal::GetTypeId<ObjectListTest> ()), ObjectListTest::SetUpTestCase, ObjectListTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< ObjectListTest_CanIterateOverFullList_Expanded_Test >);void ObjectListTest_CanIterateOverFullList_Expanded_Test ::TestBody() | |||
72 | { | |||
73 | ListableTest test1; | |||
74 | ListableTest test2; | |||
75 | ListableTest test3; | |||
76 | ||||
77 | size_t i = 0; | |||
78 | ObjectList<ListableTest>&& __range = ObjectList<ListableTest>(); | |||
79 | ObjectListIterator<ListableTest> __begin = __range.begin(); | |||
80 | ObjectListIterator<ListableTest>__end = __range.end(); | |||
81 | for (; __begin != __end; ++__begin) | |||
82 | { | |||
83 | ListableTest* object = *__begin; | |||
84 | ||||
85 | ++i; | |||
86 | if (i == 1u) EXPECT_EQ(&test1, object)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&test1)) == 1)>::Compare ("&test1", "object", &test1, object))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 86, gtest_ar.failure_message()) = ::testing::Message(); | |||
87 | if (i == 2u) EXPECT_EQ(&test2, object)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&test2)) == 1)>::Compare ("&test2", "object", &test2, object))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 87, gtest_ar.failure_message()) = ::testing::Message(); | |||
88 | if (i == 3u) EXPECT_EQ(&test3, object)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&test3)) == 1)>::Compare ("&test3", "object", &test3, object))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 88, gtest_ar.failure_message()) = ::testing::Message(); | |||
89 | } | |||
90 | 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/ObjectListTest.cc" , 90, gtest_ar.failure_message()) = ::testing::Message(); | |||
91 | } | |||
92 | ||||
93 | TEST_F(ObjectListTest, CanCallObjects)class ObjectListTest_CanCallObjects_Test : public ObjectListTest { public: ObjectListTest_CanCallObjects_Test() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ObjectListTest_CanCallObjects_Test (ObjectListTest_CanCallObjects_Test const &); void operator =(ObjectListTest_CanCallObjects_Test const &);};::testing ::TestInfo* const ObjectListTest_CanCallObjects_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ObjectListTest" , "CanCallObjects", __null, __null, (::testing::internal::GetTypeId <ObjectListTest>()), ObjectListTest::SetUpTestCase, ObjectListTest ::TearDownTestCase, new ::testing::internal::TestFactoryImpl< ObjectListTest_CanCallObjects_Test>);void ObjectListTest_CanCallObjects_Test ::TestBody() | |||
94 | { | |||
95 | ListableTest test1; | |||
96 | ListableTest test2; | |||
97 | ListableTest test3; | |||
98 | ||||
99 | EXPECT_CALL(test1, test())((test1).gmock_test()).InternalExpectedAt("/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 99, "test1", "test()"); | |||
100 | EXPECT_CALL(test2, test())((test2).gmock_test()).InternalExpectedAt("/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 100, "test2", "test()"); | |||
101 | EXPECT_CALL(test3, test())((test3).gmock_test()).InternalExpectedAt("/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 101, "test3", "test()"); | |||
102 | ||||
103 | for (ListableTest* object : ObjectList<ListableTest>()) | |||
104 | object->test(); | |||
105 | } | |||
106 | ||||
107 | TEST_F(ObjectListTest, UsesCorrectContext)class ObjectListTest_UsesCorrectContext_Test : public ObjectListTest { public: ObjectListTest_UsesCorrectContext_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ObjectListTest_UsesCorrectContext_Test (ObjectListTest_UsesCorrectContext_Test const &); void operator =(ObjectListTest_UsesCorrectContext_Test const &);};::testing ::TestInfo* const ObjectListTest_UsesCorrectContext_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ObjectListTest" , "UsesCorrectContext", __null, __null, (::testing::internal:: GetTypeId<ObjectListTest>()), ObjectListTest::SetUpTestCase , ObjectListTest::TearDownTestCase, new ::testing::internal:: TestFactoryImpl< ObjectListTest_UsesCorrectContext_Test> );void ObjectListTest_UsesCorrectContext_Test::TestBody() | |||
108 | { | |||
109 | Context context1(Context::getRootContext()); | |||
110 | Context context2(Context::getRootContext()); | |||
111 | ||||
112 | ListableTest test1(&context1); | |||
113 | ListableTest test2(&context1); | |||
114 | ListableTest test3(&context2); | |||
115 | ||||
116 | EXPECT_EQ(3u, ObjectList<ListableTest>().size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(3u)) == 1)>::Compare("3u", "ObjectList<ListableTest>().size()", 3u, ObjectList< ListableTest>().size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 116, gtest_ar.failure_message()) = ::testing::Message(); | |||
117 | EXPECT_EQ(2u, ObjectList<ListableTest>(&context1).size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(2u)) == 1)>::Compare("2u", "ObjectList<ListableTest>(&context1).size()", 2u, ObjectList <ListableTest>(&context1).size()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 117, gtest_ar.failure_message()) = ::testing::Message(); | |||
118 | EXPECT_EQ(1u, ObjectList<ListableTest>(&context2).size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(1u)) == 1)>::Compare("1u", "ObjectList<ListableTest>(&context2).size()", 1u, ObjectList <ListableTest>(&context2).size()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 118, gtest_ar.failure_message()) = ::testing::Message(); | |||
119 | } | |||
120 | ||||
121 | TEST_F(ObjectListTest, CanIterateOverCorrectContext)class ObjectListTest_CanIterateOverCorrectContext_Test : public ObjectListTest { public: ObjectListTest_CanIterateOverCorrectContext_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); ObjectListTest_CanIterateOverCorrectContext_Test (ObjectListTest_CanIterateOverCorrectContext_Test const & ); void operator=(ObjectListTest_CanIterateOverCorrectContext_Test const &);};::testing::TestInfo* const ObjectListTest_CanIterateOverCorrectContext_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ObjectListTest", "CanIterateOverCorrectContext", __null, __null , (::testing::internal::GetTypeId<ObjectListTest>()), ObjectListTest ::SetUpTestCase, ObjectListTest::TearDownTestCase, new ::testing ::internal::TestFactoryImpl< ObjectListTest_CanIterateOverCorrectContext_Test >);void ObjectListTest_CanIterateOverCorrectContext_Test:: TestBody() | |||
122 | { | |||
123 | Context context1(Context::getRootContext()); | |||
124 | Context context2(Context::getRootContext()); | |||
125 | ||||
126 | ListableTest test1(&context1); | |||
127 | ListableTest test2(&context1); | |||
128 | ListableTest test3(&context2); | |||
129 | ||||
130 | { | |||
131 | size_t i = 0; | |||
132 | for (ListableTest* object : ObjectList<ListableTest>(&context1)) | |||
133 | { | |||
134 | ++i; | |||
135 | if (i == 1u) EXPECT_EQ(&test1, object)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&test1)) == 1)>::Compare ("&test1", "object", &test1, object))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 135, gtest_ar.failure_message()) = ::testing::Message(); | |||
136 | if (i == 2u) EXPECT_EQ(&test2, object)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&test2)) == 1)>::Compare ("&test2", "object", &test2, object))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 136, gtest_ar.failure_message()) = ::testing::Message(); | |||
137 | } | |||
138 | 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/ObjectListTest.cc" , 138, gtest_ar.failure_message()) = ::testing::Message(); | |||
139 | } | |||
140 | { | |||
141 | size_t i = 0; | |||
142 | for (ListableTest* object : ObjectList<ListableTest>(&context2)) | |||
143 | { | |||
144 | ++i; | |||
145 | if (i == 1u) EXPECT_EQ(&test3, object)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&test3)) == 1)>::Compare ("&test3", "object", &test3, object))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ObjectListTest.cc" , 145, gtest_ar.failure_message()) = ::testing::Message(); | |||
146 | } | |||
147 | 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/ObjectListTest.cc" , 147, gtest_ar.failure_message()) = ::testing::Message(); | |||
148 | } | |||
149 | } | |||
150 | } |