Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/test/core/class/SuperTest.cc @ 10400

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

fixed tests. however there are some open issues:

  • the class-hierarchy must be built exactly 1 times in core_test. this is currently done in CommandTest.cc because that's the first test to run in core_test which actually needs the class hierarchy. the order of tests is not guaranteed though, so this should be solved more generic
  • during creation of class hierarchy, config values are used. this fails in the tests, so it had to be disabled with a static flag in Identifier. this should be solved in a cleaner way.
  • because the class hierarchy is now statically generated for all tests in core_test in CommandTest.cc, there is no way to test identifiers in an uninitialized state. because of this, three tests had to be disabled (*_NoFixture tests)

⇒ make the creation of the class hierarchy more modular and fix these issues

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1#include <gtest/gtest.h>
2#include <tinyxml/tinyxml.h>
3
4#include "core/CoreIncludes.h"
5#include "core/BaseObject.h"
6#include "core/class/Super.h"
7
8namespace orxonox
9{
10    namespace
11    {
12        class TestClass : public BaseObject
13        {
14            public:
15                TestClass(Context* context = NULL) : BaseObject(context), changedNameBase_(false), xmlPortBase_(false), modeBase_(XMLPort::NOP)
16                {
17                    RegisterObject(TestClass);
18                }
19
20                virtual void changedName()
21                {
22                    this->changedNameBase_ = true;
23                }
24
25                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode)
26                {
27                    this->xmlPortBase_ = true;
28                    this->modeBase_ = mode;
29                }
30
31                bool changedNameBase_;
32                bool xmlPortBase_;
33                XMLPort::Mode modeBase_;
34        };
35
36        class TestSubclass : public TestClass
37        {
38            public:
39                TestSubclass(Context* context = NULL) : TestClass(context), changedNameSubclass_(false), xmlPortSubclass_(false), modeSubclass_(XMLPort::NOP)
40                {
41                    RegisterObject(TestSubclass);
42                }
43
44                virtual void changedName()
45                {
46                    this->changedNameSubclass_ = true;
47
48                    SUPER(TestSubclass, changedName);
49                }
50
51                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode)
52                {
53                    this->xmlPortSubclass_ = true;
54                    this->modeSubclass_ = mode;
55
56                    SUPER(TestSubclass, XMLPort, xmlelement, mode);
57                }
58
59                bool changedNameSubclass_;
60                bool xmlPortSubclass_;
61                XMLPort::Mode modeSubclass_;
62        };
63
64        RegisterClass(TestClass);
65        RegisterClass(TestSubclass);
66
67       // Fixture
68        class SuperTest : public ::testing::Test
69        {
70            public:
71                virtual void SetUp()
72                {
73                    Context::setRootContext(new Context(NULL));
74                }
75
76                virtual void TearDown()
77                {
78                    Context::setRootContext(NULL);
79                }
80        };
81    }
82
83    TEST_F(SuperTest, ClassHierarchyIsCorrect)
84    {
85        {
86            Identifier* identifier = Class(TestSubclass);
87
88            EXPECT_EQ(0u, identifier->getDirectChildren().size());
89
90            EXPECT_EQ(1u, identifier->getDirectParents().size());
91            EXPECT_TRUE(std::find(identifier->getDirectParents().begin(), identifier->getDirectParents().end(), Class(TestClass)) != identifier->getDirectParents().end());
92        }
93        {
94            Identifier* identifier = Class(TestClass);
95
96            EXPECT_EQ(1u, identifier->getDirectChildren().size());
97            EXPECT_TRUE(identifier->getDirectChildren().find(Class(TestSubclass)) != identifier->getDirectChildren().end());
98
99            EXPECT_EQ(1u, identifier->getDirectParents().size());
100            EXPECT_TRUE(std::find(identifier->getDirectParents().begin(), identifier->getDirectParents().end(), Class(BaseObject)) != identifier->getDirectParents().end());
101        }
102    }
103
104    TEST_F(SuperTest, SuperCallWithoutArguments)
105    {
106        TestSubclass test;
107
108        EXPECT_FALSE(test.changedNameBase_);
109        EXPECT_FALSE(test.changedNameSubclass_);
110
111        test.changedName();
112
113        EXPECT_TRUE(test.changedNameBase_);
114        EXPECT_TRUE(test.changedNameSubclass_);
115    }
116
117    TEST_F(SuperTest, SuperCallWithArguments)
118    {
119        TestSubclass test;
120
121        EXPECT_FALSE(test.xmlPortBase_);
122        EXPECT_FALSE(test.xmlPortSubclass_);
123        EXPECT_EQ(XMLPort::NOP, test.modeBase_);
124        EXPECT_EQ(XMLPort::NOP, test.modeSubclass_);
125
126        Element* element = NULL;
127        test.XMLPort(*element, XMLPort::SaveObject);
128
129        EXPECT_TRUE(test.xmlPortBase_);
130        EXPECT_TRUE(test.xmlPortSubclass_);
131        EXPECT_EQ(XMLPort::SaveObject, test.modeBase_);
132        EXPECT_EQ(XMLPort::SaveObject, test.modeSubclass_);
133    }
134}
Note: See TracBrowser for help on using the repository browser.