Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/test/core/object/ContextTest.cc @ 10426

Last change on this file since 10426 was 10395, checked in by landauf, 10 years ago

create and initialize Identifiers explicitly via registerClass(). registerClass() must be called before using an Identifier of this type.
(some tests will currently fail)

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