Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/test/core/object/ContextTest.cc @ 11360

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

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 2.8 KB
RevLine 
[9629]1#include <gtest/gtest.h>
2#include "core/object/Context.h"
3#include "core/class/OrxonoxClass.h"
4#include "core/CoreIncludes.h"
[10624]5#include "core/module/ModuleInstance.h"
[9629]6
7namespace orxonox
8{
9    namespace
10    {
11        class SubclassContext : public OrxonoxClass, public Context
12        {
13            public:
[11071]14                SubclassContext() : Context(nullptr) { RegisterObject(SubclassContext); }
[9629]15        };
[9649]16
[10624]17        RegisterClassNoArgs(SubclassContext);
18
[9649]19        // Fixture
20        class ContextTest : public ::testing::Test
21        {
22            public:
[11071]23                virtual void SetUp() override
[9649]24                {
[10624]25                    new IdentifierManager();
26                    ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
[11071]27                    Context::setRootContext(new Context(nullptr));
[9649]28                }
29
[11071]30                virtual void TearDown() override
[9649]31                {
[10624]32                    Context::destroyRootContext();
33                    ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
34                    delete &IdentifierManager::getInstance();
[9649]35                }
36        };
[9629]37    }
38
[9649]39    TEST_F(ContextTest, CanCreateContext)
[9629]40    {
[11071]41        Context context(nullptr);
[9629]42    }
43
[9649]44    TEST_F(ContextTest, CanCreateSubclassContext)
[9629]45    {
46        SubclassContext context;
47    }
48
[9649]49    TEST_F(ContextTest, ContextIsItsOwnContext)
[9629]50    {
[11071]51        Context context(nullptr);
[9629]52        EXPECT_EQ(&context, context.getContext());
53    }
54
[9649]55    TEST_F(ContextTest, SubclassContextIsItsOwnContext)
[9629]56    {
57        SubclassContext context;
58        EXPECT_EQ(&context, context.getContext());
59    }
60
[9649]61    TEST_F(ContextTest, SubclassAddsToItsOwnObjectList)
[9629]62    {
63        SubclassContext context;
64        EXPECT_EQ(&context, context.getContext());
65        EXPECT_EQ(1u, context.getObjectList<SubclassContext>()->size());
66    }
[9650]67
68    TEST_F(ContextTest, ContextIsAddedToItsOwnObjectList)
69    {
[11071]70        Context context(nullptr);
[9650]71        ASSERT_EQ(1u, context.getObjectList<Context>()->size());
72        EXPECT_TRUE(context.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&context));
73    }
74
75    TEST_F(ContextTest, ContextIsAddedToObjectListOfBaseContext)
76    {
[11071]77        Context baseContext(nullptr);
[9650]78        Context subContext(&baseContext);
79
80        ASSERT_EQ(1u, subContext.getObjectList<Context>()->size());
81        EXPECT_TRUE(subContext.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&subContext));
82
83        ASSERT_EQ(2u, baseContext.getObjectList<Context>()->size());
84        EXPECT_TRUE(baseContext.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&baseContext));
85        EXPECT_TRUE(baseContext.getObjectList<Context>()->begin()->next_->objectBase_ == static_cast<Listable*>(&subContext));
86    }
[9629]87}
Note: See TracBrowser for help on using the repository browser.