[9605] | 1 | #include <gtest/gtest.h> |
---|
| 2 | #include <gmock/gmock.h> |
---|
| 3 | #include "core/object/ObjectListBase.h" |
---|
[9608] | 4 | #include "core/class/Identifier.h" |
---|
[9605] | 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; |
---|
[11071] | 26 | ObjectListBaseElement* element = new ObjectListElement<Listable>(nullptr); |
---|
[9605] | 27 | list.addElement(element); |
---|
| 28 | EXPECT_EQ(1u, list.size()); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | TEST(ObjectListBaseTest, CanRemoveElement) |
---|
| 32 | { |
---|
| 33 | ObjectListBase list; |
---|
[11071] | 34 | ObjectListBaseElement* element = new ObjectListElement<Listable>(nullptr); |
---|
[9605] | 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; |
---|
[11071] | 45 | list.addElement(new ObjectListElement<Listable>(nullptr)); |
---|
[9605] | 46 | EXPECT_EQ(1u, list.size()); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | TEST(ObjectListBaseTest, HasCorrectSize) |
---|
| 50 | { |
---|
| 51 | ObjectListBase list; |
---|
| 52 | EXPECT_EQ(0u, list.size()); |
---|
| 53 | { |
---|
[11071] | 54 | ObjectListElement<Listable> element1(nullptr); |
---|
[9605] | 55 | list.addElement(&element1); |
---|
| 56 | EXPECT_EQ(1u, list.size()); |
---|
| 57 | { |
---|
[11071] | 58 | ObjectListElement<Listable> element1(nullptr); |
---|
[9605] | 59 | list.addElement(&element1); |
---|
| 60 | EXPECT_EQ(2u, list.size()); |
---|
| 61 | { |
---|
[11071] | 62 | ObjectListElement<Listable> element1(nullptr); |
---|
[9605] | 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); |
---|
[11071] | 78 | ObjectListBaseElement* element = new ObjectListElement<Listable>(nullptr); |
---|
[9605] | 79 | list.addElement(element); |
---|
| 80 | EXPECT_CALL(listener, removedElement(element)); |
---|
| 81 | list.removeElement(element); |
---|
| 82 | delete element; |
---|
| 83 | } |
---|
| 84 | } |
---|