Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

statically initialized instances are now registered with a type. CoreStaticInitializationHandler initializes all instances in core, NetworkStaticInitializationHandler initializes all instances in network.

  • Property svn:eol-style set to native
File size: 3.7 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                    ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
31                    ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::SCOPED_SINGLETON_WRAPPER);
32                }
33
34                virtual void TearDown()
35                {
36                    ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::SCOPED_SINGLETON_WRAPPER);
37                    ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
38                }
39        };
40    }
41
42    TEST_F(ScopeTest, ScopesDoNotExist)
43    {
44        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
45        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
46    }
47
48    TEST_F(ScopeTest, SingletonsDoNotExist)
49    {
50        EXPECT_FALSE(TestSingletonRoot::exists());
51        EXPECT_FALSE(TestSingletonGraphics::exists());
52    }
53
54    TEST_F(ScopeTest, RootScope)
55    {
56        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
57        {   // create root scope
58            Scope<ScopeID::ROOT> scope;
59            EXPECT_TRUE(Scope<ScopeID::ROOT>::isActive());
60        }   // destroy root scope
61        EXPECT_FALSE(Scope<ScopeID::ROOT>::isActive());
62    }
63
64    TEST_F(ScopeTest, DISABLED_RootAndGraphicsScope)
65    {
66        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
67        {   // create root scope
68            Scope<ScopeID::ROOT> scope;
69            EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
70            {   // create graphics scope
71                Scope<ScopeID::GRAPHICS> scope;
72                EXPECT_TRUE(Scope<ScopeID::GRAPHICS>::isActive());
73            }   // destroy graphics scope
74            EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
75        }   // destroy root scope
76        EXPECT_FALSE(Scope<ScopeID::GRAPHICS>::isActive());
77    }
78
79    TEST_F(ScopeTest, RootSingleton)
80    {
81        EXPECT_FALSE(TestSingletonRoot::exists());
82        {   // create root scope
83            Scope<ScopeID::ROOT> scope;
84            EXPECT_TRUE(TestSingletonRoot::exists());
85        }   // destroy root scope
86        EXPECT_FALSE(TestSingletonRoot::exists());
87    }
88
89    TEST_F(ScopeTest, DISABLED_RootAndGraphicsSingleton)
90    {
91        EXPECT_FALSE(TestSingletonGraphics::exists());
92        {   // create root scope
93            Scope<ScopeID::ROOT> scope;
94            EXPECT_FALSE(TestSingletonGraphics::exists());
95            {   // create graphics scope
96                Scope<ScopeID::GRAPHICS> scope;
97                EXPECT_TRUE(TestSingletonGraphics::exists());
98            }   // destroy graphics scope
99            EXPECT_FALSE(TestSingletonGraphics::exists());
100        }   // destroy root scope
101        EXPECT_FALSE(TestSingletonGraphics::exists());
102    }
103}
Note: See TracBrowser for help on using the repository browser.