Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10871 was 10544, checked in by landauf, 9 years ago

fixed tests

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1#include <gtest/gtest.h>
2#include "core/singleton/ScopedSingletonIncludes.h"
3#include "core/module/ModuleInstance.h"
4#include "core/CoreIncludes.h"
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
21        ManageScopedSingleton(TestSingletonRoot, ScopeID::ROOT, false);
22        ManageScopedSingleton(TestSingletonGraphics, ScopeID::GRAPHICS, false);
23
24        // Fixture
25        class ScopeTest : public ::testing::Test
26        {
27            public:
28                virtual void SetUp()
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(NULL));
35                }
36
37                virtual void TearDown()
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)
49    {
50        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
51        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
52    }
53
54    TEST_F(ScopeTest, SingletonsDoNotExist)
55    {
56        EXPECT_FALSE(TestSingletonRoot::exists());
57        EXPECT_FALSE(TestSingletonGraphics::exists());
58    }
59
60    TEST_F(ScopeTest, RootScope)
61    {
62        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
63        {   // create root scope
64            Scope<ScopeID::ROOT> scope;
65            EXPECT_TRUE(Scope<ScopeID::ROOT>::isActive());
66        }   // destroy root scope
67        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
68    }
69
70    TEST_F(ScopeTest, DISABLED_RootAndGraphicsScope)
71    {
72        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
73        {   // create root scope
74            Scope<ScopeID::ROOT> scope;
75            EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
76            {   // create graphics scope
77                Scope<ScopeID::GRAPHICS> scope;
78                EXPECT_TRUE(Scope<ScopeID::GRAPHICS>::isActive());
79            }   // destroy graphics scope
80            EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
81        }   // destroy root scope
82        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
83    }
84
85    TEST_F(ScopeTest, RootSingleton)
86    {
87        EXPECT_FALSE(TestSingletonRoot::exists());
88        {   // create root scope
89            Scope<ScopeID::ROOT> scope;
90            EXPECT_TRUE(TestSingletonRoot::exists());
91        }   // destroy root scope
92        EXPECT_FALSE(TestSingletonRoot::exists());
93    }
94
95    TEST_F(ScopeTest, DISABLED_RootAndGraphicsSingleton)
96    {
97        EXPECT_FALSE(TestSingletonGraphics::exists());
98        {   // create root scope
99            Scope<ScopeID::ROOT> scope;
100            EXPECT_FALSE(TestSingletonGraphics::exists());
101            {   // create graphics scope
102                Scope<ScopeID::GRAPHICS> scope;
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.