-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathutil.cc
More file actions
58 lines (47 loc) · 1.28 KB
/
util.cc
File metadata and controls
58 lines (47 loc) · 1.28 KB
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
#include "util.h"
#include "util-inl.h"
#include "gtest/gtest.h"
TEST(UtilTest, ListHead) {
struct Item { node::ListNode<Item> node_; };
typedef node::ListHead<Item, &Item::node_> List;
List list;
EXPECT_TRUE(list.IsEmpty());
Item one;
EXPECT_TRUE(one.node_.IsEmpty());
list.PushBack(&one);
EXPECT_FALSE(list.IsEmpty());
EXPECT_FALSE(one.node_.IsEmpty());
{
List::Iterator it = list.begin();
EXPECT_NE(list.end(), it);
EXPECT_EQ(&one, *it);
++it;
EXPECT_FALSE(it != list.end()); // Iterator only implements != operator.
}
Item two;
list.PushBack(&two);
{
List::Iterator it = list.begin();
EXPECT_NE(list.end(), it);
EXPECT_EQ(&one, *it);
++it;
EXPECT_NE(list.end(), it);
EXPECT_EQ(&two, *it);
++it;
EXPECT_FALSE(it != list.end()); // Iterator only implements != operator.
}
EXPECT_EQ(&one, list.PopFront());
EXPECT_TRUE(one.node_.IsEmpty());
EXPECT_FALSE(list.IsEmpty());
{
List::Iterator it = list.begin();
EXPECT_NE(list.end(), it);
EXPECT_EQ(&two, *it);
++it;
EXPECT_FALSE(it != list.end()); // Iterator only implements != operator.
}
EXPECT_EQ(&two, list.PopFront());
EXPECT_TRUE(two.node_.IsEmpty());
EXPECT_TRUE(list.IsEmpty());
EXPECT_FALSE(list.begin() != list.end());
}