File: | core/singleton/ScopeTest.cc |
Location: | line 32, column 21 |
Description: | Potential memory leak |
1 | #include <gtest/gtest.h> | |||
2 | #include "core/singleton/ScopedSingletonIncludes.h" | |||
3 | #include "core/module/ModuleInstance.h" | |||
4 | #include "core/CoreIncludes.h" | |||
5 | ||||
6 | namespace orxonox | |||
7 | { | |||
8 | namespace | |||
9 | { | |||
10 | class TestSingletonRoot : public Singleton<TestSingletonRoot> | |||
11 | { | |||
12 | friend class Singleton<TestSingletonRoot>; | |||
13 | static TestSingletonRoot* singletonPtr_s; | |||
14 | }; | |||
15 | class TestSingletonGraphics : public Singleton<TestSingletonGraphics> | |||
16 | { | |||
17 | friend class Singleton<TestSingletonGraphics>; | |||
18 | static TestSingletonGraphics* singletonPtr_s; | |||
19 | }; | |||
20 | ||||
21 | ManageScopedSingleton(TestSingletonRoot, ScopeID::ROOT, false)TestSingletonRoot* TestSingletonRoot::singletonPtr_s = nullptr ; static ScopedSingletonWrapper& TestSingletonRootScopedSingletonWrapper = (new orxonox::SI_SSW(new ClassScopedSingletonWrapper<TestSingletonRoot , false>("TestSingletonRoot"), ScopeID::ROOT))->getWrapper (); | |||
22 | ManageScopedSingleton(TestSingletonGraphics, ScopeID::GRAPHICS, false)TestSingletonGraphics* TestSingletonGraphics::singletonPtr_s = nullptr; static ScopedSingletonWrapper& TestSingletonGraphicsScopedSingletonWrapper = (new orxonox::SI_SSW(new ClassScopedSingletonWrapper<TestSingletonGraphics , false>("TestSingletonGraphics"), ScopeID::GRAPHICS))-> getWrapper(); | |||
23 | ||||
24 | // Fixture | |||
25 | class ScopeTest : public ::testing::Test | |||
26 | { | |||
27 | public: | |||
28 | virtual void SetUp() override | |||
29 | { | |||
30 | new IdentifierManager(); | |||
31 | new ScopeManager(); | |||
| ||||
32 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); | |||
| ||||
33 | ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::SCOPED_SINGLETON_WRAPPER); | |||
34 | Context::setRootContext(new Context(nullptr)); | |||
35 | } | |||
36 | ||||
37 | virtual void TearDown() override | |||
38 | { | |||
39 | Context::destroyRootContext(); | |||
40 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::SCOPED_SINGLETON_WRAPPER); | |||
41 | ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); | |||
42 | delete &ScopeManager::getInstance(); | |||
43 | delete &IdentifierManager::getInstance(); | |||
44 | } | |||
45 | }; | |||
46 | } | |||
47 | ||||
48 | TEST_F(ScopeTest, ScopesDoNotExist)class ScopeTest_ScopesDoNotExist_Test : public ScopeTest { public : ScopeTest_ScopesDoNotExist_Test() {} private: virtual void TestBody (); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ScopeTest_ScopesDoNotExist_Test(ScopeTest_ScopesDoNotExist_Test const &); void operator=(ScopeTest_ScopesDoNotExist_Test const &);};::testing::TestInfo* const ScopeTest_ScopesDoNotExist_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ScopeTest", "ScopesDoNotExist", __null, __null, (::testing:: internal::GetTypeId<ScopeTest>()), ScopeTest::SetUpTestCase , ScopeTest::TearDownTestCase, new ::testing::internal::TestFactoryImpl < ScopeTest_ScopesDoNotExist_Test>);void ScopeTest_ScopesDoNotExist_Test ::TestBody() | |||
49 | { | |||
50 | EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(Scope<ScopeID::ROOT >::isActive()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 50, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "Scope<ScopeID::ROOT>::isActive()", "true", "false"). c_str()) = ::testing::Message(); | |||
51 | EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(Scope<ScopeID::GRAPHICS >::isActive()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 51, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "Scope<ScopeID::GRAPHICS>::isActive()", "true", "false" ).c_str()) = ::testing::Message(); | |||
52 | } | |||
53 | ||||
54 | TEST_F(ScopeTest, SingletonsDoNotExist)class ScopeTest_SingletonsDoNotExist_Test : public ScopeTest { public: ScopeTest_SingletonsDoNotExist_Test() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ScopeTest_SingletonsDoNotExist_Test (ScopeTest_SingletonsDoNotExist_Test const &); void operator =(ScopeTest_SingletonsDoNotExist_Test const &);};::testing ::TestInfo* const ScopeTest_SingletonsDoNotExist_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ScopeTest", "SingletonsDoNotExist", __null, __null, (::testing::internal ::GetTypeId<ScopeTest>()), ScopeTest::SetUpTestCase, ScopeTest ::TearDownTestCase, new ::testing::internal::TestFactoryImpl< ScopeTest_SingletonsDoNotExist_Test>);void ScopeTest_SingletonsDoNotExist_Test ::TestBody() | |||
55 | { | |||
56 | EXPECT_FALSE(TestSingletonRoot::exists())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(TestSingletonRoot:: exists()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 56, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestSingletonRoot::exists()", "true", "false").c_str()) = :: testing::Message(); | |||
57 | EXPECT_FALSE(TestSingletonGraphics::exists())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(TestSingletonGraphics ::exists()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 57, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestSingletonGraphics::exists()", "true", "false").c_str() ) = ::testing::Message(); | |||
58 | } | |||
59 | ||||
60 | TEST_F(ScopeTest, RootScope)class ScopeTest_RootScope_Test : public ScopeTest { public: ScopeTest_RootScope_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); ScopeTest_RootScope_Test (ScopeTest_RootScope_Test const &); void operator=(ScopeTest_RootScope_Test const &);};::testing::TestInfo* const ScopeTest_RootScope_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ScopeTest", "RootScope", __null, __null, (::testing::internal ::GetTypeId<ScopeTest>()), ScopeTest::SetUpTestCase, ScopeTest ::TearDownTestCase, new ::testing::internal::TestFactoryImpl< ScopeTest_RootScope_Test>);void ScopeTest_RootScope_Test:: TestBody() | |||
61 | { | |||
62 | EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(Scope<ScopeID::ROOT >::isActive()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 62, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "Scope<ScopeID::ROOT>::isActive()", "true", "false"). c_str()) = ::testing::Message(); | |||
63 | { // create root scope | |||
64 | Scope<ScopeID::ROOT> scope; | |||
65 | EXPECT_TRUE(Scope<ScopeID::ROOT>::isActive())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(Scope<ScopeID::ROOT >::isActive())) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 65, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "Scope<ScopeID::ROOT>::isActive()", "false", "true"). c_str()) = ::testing::Message(); | |||
66 | } // destroy root scope | |||
67 | EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(Scope<ScopeID::ROOT >::isActive()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 67, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "Scope<ScopeID::ROOT>::isActive()", "true", "false"). c_str()) = ::testing::Message(); | |||
68 | } | |||
69 | ||||
70 | TEST_F(ScopeTest, DISABLED_RootAndGraphicsScope)class ScopeTest_DISABLED_RootAndGraphicsScope_Test : public ScopeTest { public: ScopeTest_DISABLED_RootAndGraphicsScope_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ScopeTest_DISABLED_RootAndGraphicsScope_Test (ScopeTest_DISABLED_RootAndGraphicsScope_Test const &); void operator=(ScopeTest_DISABLED_RootAndGraphicsScope_Test const &);};::testing::TestInfo* const ScopeTest_DISABLED_RootAndGraphicsScope_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ScopeTest", "DISABLED_RootAndGraphicsScope", __null, __null , (::testing::internal::GetTypeId<ScopeTest>()), ScopeTest ::SetUpTestCase, ScopeTest::TearDownTestCase, new ::testing:: internal::TestFactoryImpl< ScopeTest_DISABLED_RootAndGraphicsScope_Test >);void ScopeTest_DISABLED_RootAndGraphicsScope_Test::TestBody () | |||
71 | { | |||
72 | EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(Scope<ScopeID::GRAPHICS >::isActive()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 72, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "Scope<ScopeID::GRAPHICS>::isActive()", "true", "false" ).c_str()) = ::testing::Message(); | |||
73 | { // create root scope | |||
74 | Scope<ScopeID::ROOT> scope; | |||
75 | EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(Scope<ScopeID::GRAPHICS >::isActive()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 75, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "Scope<ScopeID::GRAPHICS>::isActive()", "true", "false" ).c_str()) = ::testing::Message(); | |||
76 | { // create graphics scope | |||
77 | Scope<ScopeID::GRAPHICS> scope; | |||
78 | EXPECT_TRUE(Scope<ScopeID::GRAPHICS>::isActive())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(Scope<ScopeID::GRAPHICS >::isActive())) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 78, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "Scope<ScopeID::GRAPHICS>::isActive()", "false", "true" ).c_str()) = ::testing::Message(); | |||
79 | } // destroy graphics scope | |||
80 | EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(Scope<ScopeID::GRAPHICS >::isActive()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 80, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "Scope<ScopeID::GRAPHICS>::isActive()", "true", "false" ).c_str()) = ::testing::Message(); | |||
81 | } // destroy root scope | |||
82 | EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(Scope<ScopeID::GRAPHICS >::isActive()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 82, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "Scope<ScopeID::GRAPHICS>::isActive()", "true", "false" ).c_str()) = ::testing::Message(); | |||
83 | } | |||
84 | ||||
85 | TEST_F(ScopeTest, RootSingleton)class ScopeTest_RootSingleton_Test : public ScopeTest { public : ScopeTest_RootSingleton_Test() {} private: virtual void TestBody (); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); ScopeTest_RootSingleton_Test(ScopeTest_RootSingleton_Test const &); void operator=(ScopeTest_RootSingleton_Test const &);};::testing::TestInfo* const ScopeTest_RootSingleton_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ScopeTest", "RootSingleton", __null, __null, (::testing::internal ::GetTypeId<ScopeTest>()), ScopeTest::SetUpTestCase, ScopeTest ::TearDownTestCase, new ::testing::internal::TestFactoryImpl< ScopeTest_RootSingleton_Test>);void ScopeTest_RootSingleton_Test ::TestBody() | |||
86 | { | |||
87 | EXPECT_FALSE(TestSingletonRoot::exists())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(TestSingletonRoot:: exists()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 87, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestSingletonRoot::exists()", "true", "false").c_str()) = :: testing::Message(); | |||
88 | { // create root scope | |||
89 | Scope<ScopeID::ROOT> scope; | |||
90 | EXPECT_TRUE(TestSingletonRoot::exists())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(TestSingletonRoot::exists ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 90, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestSingletonRoot::exists()", "false", "true").c_str()) = :: testing::Message(); | |||
91 | } // destroy root scope | |||
92 | EXPECT_FALSE(TestSingletonRoot::exists())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(TestSingletonRoot:: exists()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 92, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestSingletonRoot::exists()", "true", "false").c_str()) = :: testing::Message(); | |||
93 | } | |||
94 | ||||
95 | TEST_F(ScopeTest, DISABLED_RootAndGraphicsSingleton)class ScopeTest_DISABLED_RootAndGraphicsSingleton_Test : public ScopeTest { public: ScopeTest_DISABLED_RootAndGraphicsSingleton_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); ScopeTest_DISABLED_RootAndGraphicsSingleton_Test (ScopeTest_DISABLED_RootAndGraphicsSingleton_Test const & ); void operator=(ScopeTest_DISABLED_RootAndGraphicsSingleton_Test const &);};::testing::TestInfo* const ScopeTest_DISABLED_RootAndGraphicsSingleton_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "ScopeTest", "DISABLED_RootAndGraphicsSingleton", __null, __null , (::testing::internal::GetTypeId<ScopeTest>()), ScopeTest ::SetUpTestCase, ScopeTest::TearDownTestCase, new ::testing:: internal::TestFactoryImpl< ScopeTest_DISABLED_RootAndGraphicsSingleton_Test >);void ScopeTest_DISABLED_RootAndGraphicsSingleton_Test:: TestBody() | |||
96 | { | |||
97 | EXPECT_FALSE(TestSingletonGraphics::exists())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(TestSingletonGraphics ::exists()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 97, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestSingletonGraphics::exists()", "true", "false").c_str() ) = ::testing::Message(); | |||
98 | { // create root scope | |||
99 | Scope<ScopeID::ROOT> scope; | |||
100 | EXPECT_FALSE(TestSingletonGraphics::exists())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(TestSingletonGraphics ::exists()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 100, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestSingletonGraphics::exists()", "true", "false").c_str() ) = ::testing::Message(); | |||
101 | { // create graphics scope | |||
102 | Scope<ScopeID::GRAPHICS> scope; | |||
103 | EXPECT_TRUE(TestSingletonGraphics::exists())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(TestSingletonGraphics ::exists())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 103, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestSingletonGraphics::exists()", "false", "true").c_str() ) = ::testing::Message(); | |||
104 | } // destroy graphics scope | |||
105 | EXPECT_FALSE(TestSingletonGraphics::exists())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(TestSingletonGraphics ::exists()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 105, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestSingletonGraphics::exists()", "true", "false").c_str() ) = ::testing::Message(); | |||
106 | } // destroy root scope | |||
107 | EXPECT_FALSE(TestSingletonGraphics::exists())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(TestSingletonGraphics ::exists()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/singleton/ScopeTest.cc" , 107, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestSingletonGraphics::exists()", "true", "false").c_str() ) = ::testing::Message(); | |||
108 | } | |||
109 | } |