1 | #include <gtest/gtest.h> |
---|
2 | #include <gmock/gmock.h> |
---|
3 | #include "core/object/ObjectListBase.h" |
---|
4 | #include "core/class/Identifier.h" |
---|
5 | |
---|
6 | namespace orxonox |
---|
7 | { |
---|
8 | namespace |
---|
9 | { |
---|
10 | class ObjectListElementRemovalListenerMock : public ObjectListElementRemovalListener |
---|
11 | { |
---|
12 | public: |
---|
13 | MOCK_METHOD1(removedElement, void(ObjectListBaseElement*)); |
---|
14 | }; |
---|
15 | } |
---|
16 | |
---|
17 | TEST(ObjectListBaseTest, EmptyListHasSizeZero) |
---|
18 | { |
---|
19 | ObjectListBase list; |
---|
20 | EXPECT_EQ(0u, list.size()); |
---|
21 | } |
---|
22 | |
---|
23 | TEST(ObjectListBaseTest, CanAddElement) |
---|
24 | { |
---|
25 | ObjectListBase list; |
---|
26 | ObjectListBaseElement* element = new ObjectListElement<Listable>(nullptr); |
---|
27 | list.addElement(element); |
---|
28 | EXPECT_EQ(1u, list.size()); |
---|
29 | } |
---|
30 | |
---|
31 | TEST(ObjectListBaseTest, CanRemoveElement) |
---|
32 | { |
---|
33 | ObjectListBase list; |
---|
34 | ObjectListBaseElement* element = new ObjectListElement<Listable>(nullptr); |
---|
35 | list.addElement(element); |
---|
36 | EXPECT_EQ(1u, list.size()); |
---|
37 | list.removeElement(element); |
---|
38 | EXPECT_EQ(0u, list.size()); |
---|
39 | delete element; |
---|
40 | } |
---|
41 | |
---|
42 | TEST(ObjectListBaseTest, CanAddObject) |
---|
43 | { |
---|
44 | ObjectListBase list; |
---|
45 | list.addElement(new ObjectListElement<Listable>(nullptr)); |
---|
46 | EXPECT_EQ(1u, list.size()); |
---|
47 | } |
---|
48 | |
---|
49 | TEST(ObjectListBaseTest, HasCorrectSize) |
---|
50 | { |
---|
51 | ObjectListBase list; |
---|
52 | EXPECT_EQ(0u, list.size()); |
---|
53 | { |
---|
54 | ObjectListElement<Listable> element1(nullptr); |
---|
55 | list.addElement(&element1); |
---|
56 | EXPECT_EQ(1u, list.size()); |
---|
57 | { |
---|
58 | ObjectListElement<Listable> element1(nullptr); |
---|
59 | list.addElement(&element1); |
---|
60 | EXPECT_EQ(2u, list.size()); |
---|
61 | { |
---|
62 | ObjectListElement<Listable> element1(nullptr); |
---|
63 | list.addElement(&element1); |
---|
64 | EXPECT_EQ(3u, list.size()); |
---|
65 | } |
---|
66 | EXPECT_EQ(2u, list.size()); |
---|
67 | } |
---|
68 | EXPECT_EQ(1u, list.size()); |
---|
69 | } |
---|
70 | EXPECT_EQ(0u, list.size()); |
---|
71 | } |
---|
72 | |
---|
73 | TEST(ObjectListBaseTest, CallsListenerOnRemoval) |
---|
74 | { |
---|
75 | ObjectListBase list; |
---|
76 | ObjectListElementRemovalListenerMock listener; |
---|
77 | list.registerRemovalListener(&listener); |
---|
78 | ObjectListBaseElement* element = new ObjectListElement<Listable>(nullptr); |
---|
79 | list.addElement(element); |
---|
80 | EXPECT_CALL(listener, removedElement(element)); |
---|
81 | list.removeElement(element); |
---|
82 | delete element; |
---|
83 | } |
---|
84 | } |
---|