summaryrefslogtreecommitdiffstats
path: root/test/src/object-test.cpp
blob: 83e90b2ece075509e310dcc4c0977674fac46f62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "gtest/gtest.h"
#include "object.h"

class ObjectTest: public testing::Test {
public:
    ObjectTest() {
        object = new Object("parent");
        childOfChild = new Object("childOfChild");
        child = new Object("child");
        child2 = new Object("child2");
        object2 = new Object("object2");
        child3 = new Object("child3");
    }
    ~ObjectTest() {
        delete child3;
        delete child2;
        delete childOfChild;
        delete child;
        delete object2;
        delete object;
    }
    Object* object;
    Object* object2;
    Object* child;
    Object* childOfChild;
    Object* child2;
    Object* child3;
};

TEST_F(ObjectTest, AddChild) {
    EXPECT_EQ(0, object->getChildren().size());
    object->addChild(child);
    EXPECT_EQ(1, object->getChildren().size());
    EXPECT_EQ(child, &(object->getChildren().front()));
    EXPECT_EQ(object, child->getParent());
}

TEST_F(ObjectTest, IsDescendantOf) {
    object->addChild(child);
    child->addChild(childOfChild);
    object->addChild(child2);
    object2->addChild(child3);
    EXPECT_TRUE(child->isDescendantOf(object));
    EXPECT_TRUE(childOfChild->isDescendantOf(child));
    EXPECT_TRUE(childOfChild->isDescendantOf(object));
    EXPECT_TRUE(child2->isDescendantOf(object));
    EXPECT_TRUE(child3->isDescendantOf(object2));
    EXPECT_FALSE(child->isDescendantOf(child2));
    EXPECT_FALSE(child2->isDescendantOf(child));
    EXPECT_FALSE(object->isDescendantOf(childOfChild));
    EXPECT_FALSE(object->isDescendantOf(child));
    EXPECT_FALSE(object->isDescendantOf(object2));
    EXPECT_FALSE(object2->isDescendantOf(object));
    EXPECT_FALSE(child2->isDescendantOf(child3));
    EXPECT_FALSE(child3->isDescendantOf(child2));
}