Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/test/core/singleton/ScopeTest.cc @ 11903

Last change on this file since 11903 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 4.0 KB
RevLine 
[9114]1#include <gtest/gtest.h>
[10459]2#include "core/singleton/ScopedSingletonIncludes.h"
[10460]3#include "core/module/ModuleInstance.h"
[10535]4#include "core/CoreIncludes.h"
[9114]5
6namespace 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
[10464]21        ManageScopedSingleton(TestSingletonRoot, ScopeID::ROOT, false);
22        ManageScopedSingleton(TestSingletonGraphics, ScopeID::GRAPHICS, false);
[10460]23
24        // Fixture
25        class ScopeTest : public ::testing::Test
26        {
27            public:
[11071]28                virtual void SetUp() override
[10460]29                {
[10544]30                    new IdentifierManager();
31                    new ScopeManager();
[10535]32                    ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
33                    ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::SCOPED_SINGLETON_WRAPPER);
[11071]34                    Context::setRootContext(new Context(nullptr));
[10460]35                }
36
[11071]37                virtual void TearDown() override
[10460]38                {
[10544]39                    Context::destroyRootContext();
[10535]40                    ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::SCOPED_SINGLETON_WRAPPER);
41                    ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
[10544]42                    delete &ScopeManager::getInstance();
43                    delete &IdentifierManager::getInstance();
[10460]44                }
45        };
[9114]46    }
47
[10460]48    TEST_F(ScopeTest, ScopesDoNotExist)
[9114]49    {
[10464]50        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
51        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
[9114]52    }
53
[10460]54    TEST_F(ScopeTest, SingletonsDoNotExist)
[9114]55    {
56        EXPECT_FALSE(TestSingletonRoot::exists());
57        EXPECT_FALSE(TestSingletonGraphics::exists());
58    }
59
[10460]60    TEST_F(ScopeTest, RootScope)
[9114]61    {
[10464]62        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
[9114]63        {   // create root scope
[10464]64            Scope<ScopeID::ROOT> scope;
65            EXPECT_TRUE(Scope<ScopeID::ROOT>::isActive());
[9114]66        }   // destroy root scope
[10464]67        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
[9114]68    }
69
[10460]70    TEST_F(ScopeTest, DISABLED_RootAndGraphicsScope)
[9114]71    {
[10464]72        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
[9114]73        {   // create root scope
[10464]74            Scope<ScopeID::ROOT> scope;
75            EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
[9114]76            {   // create graphics scope
[10464]77                Scope<ScopeID::GRAPHICS> scope;
78                EXPECT_TRUE(Scope<ScopeID::GRAPHICS>::isActive());
[9114]79            }   // destroy graphics scope
[10464]80            EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
[9114]81        }   // destroy root scope
[10464]82        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
[9114]83    }
84
[10460]85    TEST_F(ScopeTest, RootSingleton)
[9114]86    {
87        EXPECT_FALSE(TestSingletonRoot::exists());
88        {   // create root scope
[10464]89            Scope<ScopeID::ROOT> scope;
[9114]90            EXPECT_TRUE(TestSingletonRoot::exists());
91        }   // destroy root scope
92        EXPECT_FALSE(TestSingletonRoot::exists());
93    }
94
[10460]95    TEST_F(ScopeTest, DISABLED_RootAndGraphicsSingleton)
[9114]96    {
97        EXPECT_FALSE(TestSingletonGraphics::exists());
98        {   // create root scope
[10464]99            Scope<ScopeID::ROOT> scope;
[9114]100            EXPECT_FALSE(TestSingletonGraphics::exists());
101            {   // create graphics scope
[10464]102                Scope<ScopeID::GRAPHICS> scope;
[9114]103                EXPECT_TRUE(TestSingletonGraphics::exists());
104            }   // destroy graphics scope
105            EXPECT_FALSE(TestSingletonGraphics::exists());
106        }   // destroy root scope
107        EXPECT_FALSE(TestSingletonGraphics::exists());
108    }
109}
Note: See TracBrowser for help on using the repository browser.