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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#include <gtest/gtest.h>
#include "../sched.hpp"
struct DebugQueue : public Queue<Task> {
public:
void
expect_ordered() const
{
int id = 1;
for (auto *it = head; it != nullptr; it = it->next) {
// std::cout << it->node->name << std::endl;
EXPECT_EQ(it->node->id, id++);
}
}
};
TEST(taskqueue, insert)
{
DebugQueue queue;
auto *p1 = new Task{"P1", 1, 1, 10};
queue.insert(p1);
queue.insert(new Task{"P2", 2, 1, 10});
queue.insert(new Task{"P3", 3, 1, 10});
auto *p4 = new Task{"P4", 4, 1, 10};
queue.insert(p4);
queue.expect_ordered();
EXPECT_EQ(queue.head->node, p1);
EXPECT_EQ(queue.tail->node, p4);
}
TEST(taskqueue, removeHead)
{
DebugQueue queue;
auto *p0 = new Task{"P0", 0, 1, 10};
queue.insert(p0);
auto *p1 = new Task{"P1", 1, 1, 10};
queue.insert(p1);
queue.insert(new Task{"P2", 2, 1, 10});
queue.insert(new Task{"P3", 3, 1, 10});
auto *p4 = new Task{"P4", 4, 1, 10};
queue.insert(p4);
queue.remove(p0);
delete p0;
EXPECT_EQ(queue.head->node, p1);
EXPECT_EQ(queue.tail->node, p4);
queue.expect_ordered();
}
TEST(taskqueue, removeTail)
{
DebugQueue queue;
auto *p1 = new Task{"P1", 1, 1, 10};
queue.insert(p1);
queue.insert(new Task{"P2", 2, 1, 10});
queue.insert(new Task{"P3", 3, 1, 10});
auto *p4 = new Task{"P4", 4, 1, 10};
queue.insert(p4);
auto *p5 = new Task{"P5", 5, 1, 10};
queue.insert(p5);
EXPECT_EQ(queue.head->node, p1);
EXPECT_EQ(queue.tail->node, p5);
queue.remove(p5);
delete p5;
EXPECT_EQ(queue.head->node, p1);
EXPECT_EQ(queue.tail->node, p4);
queue.expect_ordered();
}
TEST(taskqueue, removeLast)
{
DebugQueue queue;
auto *p0 = new Task{"P0", 0, 1, 10};
queue.insert(p0);
EXPECT_EQ(queue.head->node, p0);
EXPECT_EQ(queue.tail->node, p0);
queue.remove(p0);
delete p0;
EXPECT_EQ(queue.head, nullptr);
EXPECT_EQ(queue.tail, nullptr);
}
TEST(taskqueue, removeNullptr)
{
DebugQueue queue;
queue.insert(new Task{"P1", 1, 1, 10});
queue.insert(new Task{"P2", 2, 1, 10});
queue.insert(new Task{"P3", 3, 1, 10});
queue.insert(new Task{"P4", 4, 1, 10});
queue.remove(nullptr);
queue.expect_ordered();
}
TEST(taskqueue, remove)
{
DebugQueue queue;
auto *p1 = new Task{"P1", 1, 1, 10};
queue.insert(p1);
queue.insert(new Task{"P2", 2, 1, 10});
auto *p0 = new Task{"P0", 0, 1, 10};
queue.insert(p0);
queue.insert(new Task{"P3", 3, 1, 10});
auto *p4 = new Task{"P4", 4, 1, 10};
queue.insert(p4);
EXPECT_EQ(queue.head->node, p1);
EXPECT_EQ(queue.tail->node, p4);
queue.remove(p0);
delete p0;
EXPECT_EQ(queue.head->node, p1);
EXPECT_EQ(queue.tail->node, p4);
queue.expect_ordered();
}
|