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 | |
---|
8 | namespace 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 | 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(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 | // Fixture |
---|
65 | class SuperTest : public ::testing::Test |
---|
66 | { |
---|
67 | public: |
---|
68 | virtual void SetUp() |
---|
69 | { |
---|
70 | registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>()); |
---|
71 | registerClass("BaseObject", new ClassFactoryWithContext<BaseObject>()); |
---|
72 | registerClass("TestClass", new ClassFactoryWithContext<TestClass>()); |
---|
73 | registerClass("TestSubclass", new ClassFactoryWithContext<TestSubclass>()); |
---|
74 | |
---|
75 | IdentifierManager::getInstance().createClassHierarchy(); |
---|
76 | } |
---|
77 | |
---|
78 | virtual void TearDown() |
---|
79 | { |
---|
80 | IdentifierManager::getInstance().destroyAllIdentifiers(); |
---|
81 | } |
---|
82 | }; |
---|
83 | } |
---|
84 | |
---|
85 | TEST_F(SuperTest, SuperCallWithoutArguments) |
---|
86 | { |
---|
87 | TestSubclass test; |
---|
88 | |
---|
89 | EXPECT_FALSE(test.changedNameBase_); |
---|
90 | EXPECT_FALSE(test.changedNameSubclass_); |
---|
91 | |
---|
92 | test.changedName(); |
---|
93 | |
---|
94 | EXPECT_TRUE(test.changedNameBase_); |
---|
95 | EXPECT_TRUE(test.changedNameSubclass_); |
---|
96 | } |
---|
97 | |
---|
98 | TEST_F(SuperTest, SuperCallWithArguments) |
---|
99 | { |
---|
100 | TestSubclass test; |
---|
101 | |
---|
102 | EXPECT_FALSE(test.xmlPortBase_); |
---|
103 | EXPECT_FALSE(test.xmlPortSubclass_); |
---|
104 | EXPECT_EQ(XMLPort::NOP, test.modeBase_); |
---|
105 | EXPECT_EQ(XMLPort::NOP, test.modeSubclass_); |
---|
106 | |
---|
107 | Element* element = NULL; |
---|
108 | test.XMLPort(*element, XMLPort::SaveObject); |
---|
109 | |
---|
110 | EXPECT_TRUE(test.xmlPortBase_); |
---|
111 | EXPECT_TRUE(test.xmlPortSubclass_); |
---|
112 | EXPECT_EQ(XMLPort::SaveObject, test.modeBase_); |
---|
113 | EXPECT_EQ(XMLPort::SaveObject, test.modeSubclass_); |
---|
114 | } |
---|
115 | } |
---|