File: | core/object/ContextTest.cc |
Location: | line 26, column 21 |
Description: | Potential memory leak |
1 | #include <gtest/gtest.h> | |||
2 | #include "core/object/Context.h" | |||
3 | #include "core/class/OrxonoxClass.h" | |||
4 | #include "core/CoreIncludes.h" | |||
5 | #include "core/module/ModuleInstance.h" | |||
6 | ||||
7 | namespace orxonox | |||
8 | { | |||
9 | namespace | |||
10 | { | |||
11 | class SubclassContext : public OrxonoxClass, public Context | |||
12 | { | |||
13 | public: | |||
14 | SubclassContext() : Context(nullptr) { RegisterObject(SubclassContext)if (ClassIdentifier<SubclassContext>::getIdentifier()-> initializeObject(this)) return; else ((void)0); } | |||
15 | }; | |||
16 | ||||
17 | RegisterClassNoArgs(SubclassContext)orxonox::SI_I& _SubclassContextIdentifier = (*new orxonox ::SI_I(orxonox::registerClass<SubclassContext>("SubclassContext" , new orxonox::ClassFactoryNoArgs<SubclassContext>(), true ))); | |||
18 | ||||
19 | // Fixture | |||
20 | class ContextTest : public ::testing::Test | |||
21 | { | |||
22 | public: | |||
23 | virtual void SetUp() override | |||
24 | { | |||
25 | new IdentifierManager(); | |||
| ||||
26 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); | |||
| ||||
27 | Context::setRootContext(new Context(nullptr)); | |||
28 | } | |||
29 | ||||
30 | virtual void TearDown() override | |||
31 | { | |||
32 | Context::destroyRootContext(); | |||
33 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); | |||
34 | delete &IdentifierManager::getInstance(); | |||
35 | } | |||
36 | }; | |||
37 | } | |||
38 | ||||
39 | TEST_F(ContextTest, CanCreateContext)class ContextTest_CanCreateContext_Test : public ContextTest { public: ContextTest_CanCreateContext_Test() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ContextTest_CanCreateContext_Test( ContextTest_CanCreateContext_Test const &); void operator =(ContextTest_CanCreateContext_Test const &);};::testing:: TestInfo* const ContextTest_CanCreateContext_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ContextTest" , "CanCreateContext", __null, __null, (::testing::internal::GetTypeId <ContextTest>()), ContextTest::SetUpTestCase, ContextTest ::TearDownTestCase, new ::testing::internal::TestFactoryImpl< ContextTest_CanCreateContext_Test>);void ContextTest_CanCreateContext_Test ::TestBody() | |||
40 | { | |||
41 | Context context(nullptr); | |||
42 | } | |||
43 | ||||
44 | TEST_F(ContextTest, CanCreateSubclassContext)class ContextTest_CanCreateSubclassContext_Test : public ContextTest { public: ContextTest_CanCreateSubclassContext_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ContextTest_CanCreateSubclassContext_Test (ContextTest_CanCreateSubclassContext_Test const &); void operator=(ContextTest_CanCreateSubclassContext_Test const & );};::testing::TestInfo* const ContextTest_CanCreateSubclassContext_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ContextTest", "CanCreateSubclassContext", __null, __null, ( ::testing::internal::GetTypeId<ContextTest>()), ContextTest ::SetUpTestCase, ContextTest::TearDownTestCase, new ::testing ::internal::TestFactoryImpl< ContextTest_CanCreateSubclassContext_Test >);void ContextTest_CanCreateSubclassContext_Test::TestBody () | |||
45 | { | |||
46 | SubclassContext context; | |||
47 | } | |||
48 | ||||
49 | TEST_F(ContextTest, ContextIsItsOwnContext)class ContextTest_ContextIsItsOwnContext_Test : public ContextTest { public: ContextTest_ContextIsItsOwnContext_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ContextTest_ContextIsItsOwnContext_Test (ContextTest_ContextIsItsOwnContext_Test const &); void operator =(ContextTest_ContextIsItsOwnContext_Test const &);};::testing ::TestInfo* const ContextTest_ContextIsItsOwnContext_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ContextTest" , "ContextIsItsOwnContext", __null, __null, (::testing::internal ::GetTypeId<ContextTest>()), ContextTest::SetUpTestCase , ContextTest::TearDownTestCase, new ::testing::internal::TestFactoryImpl < ContextTest_ContextIsItsOwnContext_Test>);void ContextTest_ContextIsItsOwnContext_Test ::TestBody() | |||
50 | { | |||
51 | Context context(nullptr); | |||
52 | EXPECT_EQ(&context, context.getContext())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&context)) == 1)>::Compare ("&context", "context.getContext()", &context, context .getContext()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 52, gtest_ar.failure_message()) = ::testing::Message(); | |||
53 | } | |||
54 | ||||
55 | TEST_F(ContextTest, SubclassContextIsItsOwnContext)class ContextTest_SubclassContextIsItsOwnContext_Test : public ContextTest { public: ContextTest_SubclassContextIsItsOwnContext_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); ContextTest_SubclassContextIsItsOwnContext_Test (ContextTest_SubclassContextIsItsOwnContext_Test const &) ; void operator=(ContextTest_SubclassContextIsItsOwnContext_Test const &);};::testing::TestInfo* const ContextTest_SubclassContextIsItsOwnContext_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ContextTest", "SubclassContextIsItsOwnContext", __null, __null , (::testing::internal::GetTypeId<ContextTest>()), ContextTest ::SetUpTestCase, ContextTest::TearDownTestCase, new ::testing ::internal::TestFactoryImpl< ContextTest_SubclassContextIsItsOwnContext_Test >);void ContextTest_SubclassContextIsItsOwnContext_Test::TestBody () | |||
56 | { | |||
57 | SubclassContext context; | |||
58 | EXPECT_EQ(&context, context.getContext())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&context)) == 1)>::Compare ("&context", "context.getContext()", &context, context .getContext()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 58, gtest_ar.failure_message()) = ::testing::Message(); | |||
59 | } | |||
60 | ||||
61 | TEST_F(ContextTest, SubclassAddsToItsOwnObjectList)class ContextTest_SubclassAddsToItsOwnObjectList_Test : public ContextTest { public: ContextTest_SubclassAddsToItsOwnObjectList_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); ContextTest_SubclassAddsToItsOwnObjectList_Test (ContextTest_SubclassAddsToItsOwnObjectList_Test const &) ; void operator=(ContextTest_SubclassAddsToItsOwnObjectList_Test const &);};::testing::TestInfo* const ContextTest_SubclassAddsToItsOwnObjectList_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ContextTest", "SubclassAddsToItsOwnObjectList", __null, __null , (::testing::internal::GetTypeId<ContextTest>()), ContextTest ::SetUpTestCase, ContextTest::TearDownTestCase, new ::testing ::internal::TestFactoryImpl< ContextTest_SubclassAddsToItsOwnObjectList_Test >);void ContextTest_SubclassAddsToItsOwnObjectList_Test::TestBody () | |||
62 | { | |||
63 | SubclassContext context; | |||
64 | EXPECT_EQ(&context, context.getContext())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(&context)) == 1)>::Compare ("&context", "context.getContext()", &context, context .getContext()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 64, gtest_ar.failure_message()) = ::testing::Message(); | |||
65 | EXPECT_EQ(1u, context.getObjectList<SubclassContext>()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(1u)) == 1)>::Compare("1u", "context.getObjectList<SubclassContext>()->size()", 1u, context.getObjectList<SubclassContext>()->size( )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 65, gtest_ar.failure_message()) = ::testing::Message(); | |||
66 | } | |||
67 | ||||
68 | TEST_F(ContextTest, ContextIsAddedToItsOwnObjectList)class ContextTest_ContextIsAddedToItsOwnObjectList_Test : public ContextTest { public: ContextTest_ContextIsAddedToItsOwnObjectList_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); ContextTest_ContextIsAddedToItsOwnObjectList_Test (ContextTest_ContextIsAddedToItsOwnObjectList_Test const & ); void operator=(ContextTest_ContextIsAddedToItsOwnObjectList_Test const &);};::testing::TestInfo* const ContextTest_ContextIsAddedToItsOwnObjectList_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ContextTest", "ContextIsAddedToItsOwnObjectList", __null, __null , (::testing::internal::GetTypeId<ContextTest>()), ContextTest ::SetUpTestCase, ContextTest::TearDownTestCase, new ::testing ::internal::TestFactoryImpl< ContextTest_ContextIsAddedToItsOwnObjectList_Test >);void ContextTest_ContextIsAddedToItsOwnObjectList_Test:: TestBody() | |||
69 | { | |||
70 | Context context(nullptr); | |||
71 | ASSERT_EQ(1u, context.getObjectList<Context>()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(1u)) == 1)>::Compare("1u", "context.getObjectList<Context>()->size()", 1u, context .getObjectList<Context>()->size()))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 71, gtest_ar.failure_message()) = ::testing::Message(); | |||
72 | EXPECT_TRUE(context.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&context))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(context.getObjectList <Context>()->begin()->objectBase_ == static_cast< Listable*>(&context))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 72, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "context.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&context)" , "false", "true").c_str()) = ::testing::Message(); | |||
73 | } | |||
74 | ||||
75 | TEST_F(ContextTest, ContextIsAddedToObjectListOfBaseContext)class ContextTest_ContextIsAddedToObjectListOfBaseContext_Test : public ContextTest { public: ContextTest_ContextIsAddedToObjectListOfBaseContext_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); ContextTest_ContextIsAddedToObjectListOfBaseContext_Test (ContextTest_ContextIsAddedToObjectListOfBaseContext_Test const &); void operator=(ContextTest_ContextIsAddedToObjectListOfBaseContext_Test const &);};::testing::TestInfo* const ContextTest_ContextIsAddedToObjectListOfBaseContext_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ContextTest", "ContextIsAddedToObjectListOfBaseContext", __null , __null, (::testing::internal::GetTypeId<ContextTest>( )), ContextTest::SetUpTestCase, ContextTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< ContextTest_ContextIsAddedToObjectListOfBaseContext_Test >);void ContextTest_ContextIsAddedToObjectListOfBaseContext_Test ::TestBody() | |||
76 | { | |||
77 | Context baseContext(nullptr); | |||
78 | Context subContext(&baseContext); | |||
79 | ||||
80 | ASSERT_EQ(1u, subContext.getObjectList<Context>()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(1u)) == 1)>::Compare("1u", "subContext.getObjectList<Context>()->size()", 1u, subContext .getObjectList<Context>()->size()))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 80, gtest_ar.failure_message()) = ::testing::Message(); | |||
81 | EXPECT_TRUE(subContext.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&subContext))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subContext.getObjectList <Context>()->begin()->objectBase_ == static_cast< Listable*>(&subContext))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 81, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subContext.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&subContext)" , "false", "true").c_str()) = ::testing::Message(); | |||
82 | ||||
83 | ASSERT_EQ(2u, baseContext.getObjectList<Context>()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(2u)) == 1)>::Compare("2u", "baseContext.getObjectList<Context>()->size()", 2u, baseContext.getObjectList<Context>()->size()))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 83, gtest_ar.failure_message()) = ::testing::Message(); | |||
84 | EXPECT_TRUE(baseContext.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&baseContext))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(baseContext.getObjectList <Context>()->begin()->objectBase_ == static_cast< Listable*>(&baseContext))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 84, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "baseContext.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&baseContext)" , "false", "true").c_str()) = ::testing::Message(); | |||
85 | EXPECT_TRUE(baseContext.getObjectList<Context>()->begin()->next_->objectBase_ == static_cast<Listable*>(&subContext))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(baseContext.getObjectList <Context>()->begin()->next_->objectBase_ == static_cast <Listable*>(&subContext))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/object/ContextTest.cc" , 85, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "baseContext.getObjectList<Context>()->begin()->next_->objectBase_ == static_cast<Listable*>(&subContext)" , "false", "true").c_str()) = ::testing::Message(); | |||
86 | } | |||
87 | } |