Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core6/test/core/class/SuperTest.cc @ 9601

Last change on this file since 9601 was 9601, checked in by landauf, 11 years ago

added some tests for core

  • Property svn:eol-style set to native
File size: 2.8 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(BaseObject* creator = NULL) : BaseObject(NULL), changedNameBase_(false), xmlPortBase_(false), modeBase_(XMLPort::NOP)
16                {
17                    RegisterRootObject(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(BaseObject* creator = NULL) : 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        CreateFactory(TestClass);
65        CreateFactory(TestSubclass);
66    }
67
68    TEST(SuberTest, SuperCallWithoutArguments)
69    {
70        TestSubclass test;
71        IdentifierManager::createClassHierarchy();
72
73        EXPECT_FALSE(test.changedNameBase_);
74        EXPECT_FALSE(test.changedNameSubclass_);
75
76        test.changedName();
77
78        EXPECT_TRUE(test.changedNameBase_);
79        EXPECT_TRUE(test.changedNameSubclass_);
80    }
81
82    TEST(SuberTest, SuperCallWithArguments)
83    {
84        TestSubclass test;
85        IdentifierManager::createClassHierarchy();
86
87        EXPECT_FALSE(test.xmlPortBase_);
88        EXPECT_FALSE(test.xmlPortSubclass_);
89        EXPECT_EQ(XMLPort::NOP, test.modeBase_);
90        EXPECT_EQ(XMLPort::NOP, test.modeSubclass_);
91
92        Element* element = NULL;
93        test.XMLPort(*element, XMLPort::SaveObject);
94
95        EXPECT_TRUE(test.xmlPortBase_);
96        EXPECT_TRUE(test.xmlPortSubclass_);
97        EXPECT_EQ(XMLPort::SaveObject, test.modeBase_);
98        EXPECT_EQ(XMLPort::SaveObject, test.modeSubclass_);
99    }
100}
Note: See TracBrowser for help on using the repository browser.