| 1 | #include <gtest/gtest.h> |
|---|
| 2 | #include "core/singleton/ScopedSingletonIncludes.h" |
|---|
| 3 | #include "core/module/ModuleInstance.h" |
|---|
| 4 | |
|---|
| 5 | namespace 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 | } |
|---|