Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/test/core/singleton/ScopeTest.cc @ 10502

Last change on this file since 10502 was 10464, checked in by landauf, 10 years ago

define ScopeID as integer constants instead of an enum. this allows to extend it and add new scopes outside of core.

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1#include <gtest/gtest.h>
2#include "core/singleton/ScopedSingletonIncludes.h"
3#include "core/module/ModuleInstance.h"
4
5namespace orxonox
6{
7    namespace
8    {
9        class TestSingletonRoot : public Singleton<TestSingletonRoot>
10        {
11            friend class Singleton<TestSingletonRoot>;
12            static TestSingletonRoot* singletonPtr_s;
13        };
14        class TestSingletonGraphics : public Singleton<TestSingletonGraphics>
15        {
16            friend class Singleton<TestSingletonGraphics>;
17            static TestSingletonGraphics* singletonPtr_s;
18        };
19
20        ManageScopedSingleton(TestSingletonRoot, ScopeID::ROOT, false);
21        ManageScopedSingleton(TestSingletonGraphics, ScopeID::GRAPHICS, false);
22
23        // Fixture
24        class ScopeTest : public ::testing::Test
25        {
26            public:
27                virtual void SetUp()
28                {
29                    ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances();
30                }
31
32                virtual void TearDown()
33                {
34                    ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances();
35                }
36        };
37    }
38
39    TEST_F(ScopeTest, ScopesDoNotExist)
40    {
41        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
42        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
43    }
44
45    TEST_F(ScopeTest, SingletonsDoNotExist)
46    {
47        EXPECT_FALSE(TestSingletonRoot::exists());
48        EXPECT_FALSE(TestSingletonGraphics::exists());
49    }
50
51    TEST_F(ScopeTest, RootScope)
52    {
53        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
54        {   // create root scope
55            Scope<ScopeID::ROOT> scope;
56            EXPECT_TRUE(Scope<ScopeID::ROOT>::isActive());
57        }   // destroy root scope
58        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
59    }
60
61    TEST_F(ScopeTest, DISABLED_RootAndGraphicsScope)
62    {
63        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
64        {   // create root scope
65            Scope<ScopeID::ROOT> scope;
66            EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
67            {   // create graphics scope
68                Scope<ScopeID::GRAPHICS> scope;
69                EXPECT_TRUE(Scope<ScopeID::GRAPHICS>::isActive());
70            }   // destroy graphics scope
71            EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
72        }   // destroy root scope
73        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
74    }
75
76    TEST_F(ScopeTest, RootSingleton)
77    {
78        EXPECT_FALSE(TestSingletonRoot::exists());
79        {   // create root scope
80            Scope<ScopeID::ROOT> scope;
81            EXPECT_TRUE(TestSingletonRoot::exists());
82        }   // destroy root scope
83        EXPECT_FALSE(TestSingletonRoot::exists());
84    }
85
86    TEST_F(ScopeTest, DISABLED_RootAndGraphicsSingleton)
87    {
88        EXPECT_FALSE(TestSingletonGraphics::exists());
89        {   // create root scope
90            Scope<ScopeID::ROOT> scope;
91            EXPECT_FALSE(TestSingletonGraphics::exists());
92            {   // create graphics scope
93                Scope<ScopeID::GRAPHICS> scope;
94                EXPECT_TRUE(TestSingletonGraphics::exists());
95            }   // destroy graphics scope
96            EXPECT_FALSE(TestSingletonGraphics::exists());
97        }   // destroy root scope
98        EXPECT_FALSE(TestSingletonGraphics::exists());
99    }
100}
Note: See TracBrowser for help on using the repository browser.