Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/invaders/test/util/ScopeTest.cc @ 10150

Last change on this file since 10150 was 9114, checked in by landauf, 13 years ago

added tests for several classes and functions in util

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1#include <gtest/gtest.h>
2#include "util/ScopedSingletonManager.h"
3
4namespace orxonox
5{
6    namespace
7    {
8        class TestSingletonRoot : public Singleton<TestSingletonRoot>
9        {
10            friend class Singleton<TestSingletonRoot>;
11            static TestSingletonRoot* singletonPtr_s;
12        };
13        class TestSingletonGraphics : public Singleton<TestSingletonGraphics>
14        {
15            friend class Singleton<TestSingletonGraphics>;
16            static TestSingletonGraphics* singletonPtr_s;
17        };
18
19        ManageScopedSingleton(TestSingletonRoot, ScopeID::Root, false);
20        ManageScopedSingleton(TestSingletonGraphics, ScopeID::Graphics, false);
21    }
22
23    TEST(Scope, ScopesDoNotExist)
24    {
25        EXPECT_FALSE(Scope<ScopeID::Root>::isActive());
26        EXPECT_FALSE(Scope<ScopeID::Graphics>::isActive());
27    }
28
29    TEST(Scope, SingletonsDoNotExist)
30    {
31        EXPECT_FALSE(TestSingletonRoot::exists());
32        EXPECT_FALSE(TestSingletonGraphics::exists());
33    }
34
35    TEST(Scope, RootScope)
36    {
37        EXPECT_FALSE(Scope<ScopeID::Root>::isActive());
38        {   // create root scope
39            Scope<ScopeID::Root> scope;
40            EXPECT_TRUE(Scope<ScopeID::Root>::isActive());
41        }   // destroy root scope
42        EXPECT_FALSE(Scope<ScopeID::Root>::isActive());
43    }
44
45    TEST(Scope, RootAndGraphicsScope)
46    {
47        EXPECT_FALSE(Scope<ScopeID::Graphics>::isActive());
48        {   // create root scope
49            Scope<ScopeID::Root> scope;
50            EXPECT_FALSE(Scope<ScopeID::Graphics>::isActive());
51            {   // create graphics scope
52                Scope<ScopeID::Graphics> scope;
53                EXPECT_TRUE(Scope<ScopeID::Graphics>::isActive());
54            }   // destroy graphics scope
55            EXPECT_FALSE(Scope<ScopeID::Graphics>::isActive());
56        }   // destroy root scope
57        EXPECT_FALSE(Scope<ScopeID::Graphics>::isActive());
58    }
59
60    TEST(Scope, RootSingleton)
61    {
62        EXPECT_FALSE(TestSingletonRoot::exists());
63        {   // create root scope
64            Scope<ScopeID::Root> scope;
65            EXPECT_TRUE(TestSingletonRoot::exists());
66        }   // destroy root scope
67        EXPECT_FALSE(TestSingletonRoot::exists());
68    }
69
70    TEST(Scope, RootAndGraphicsSingleton)
71    {
72        EXPECT_FALSE(TestSingletonGraphics::exists());
73        {   // create root scope
74            Scope<ScopeID::Root> scope;
75            EXPECT_FALSE(TestSingletonGraphics::exists());
76            {   // create graphics scope
77                Scope<ScopeID::Graphics> scope;
78                EXPECT_TRUE(TestSingletonGraphics::exists());
79            }   // destroy graphics scope
80            EXPECT_FALSE(TestSingletonGraphics::exists());
81        }   // destroy root scope
82        EXPECT_FALSE(TestSingletonGraphics::exists());
83    }
84}
Note: See TracBrowser for help on using the repository browser.