1 #include <ccan/list/list.h>
2 #include <ccan/tap/tap.h>
3 #include <ccan/list/list.c>
7 struct list_head children;
8 unsigned int num_children;
13 struct list_node list;
16 static LIST_HEAD(static_list);
18 int main(int argc, char *argv[])
21 struct child c1, c2, c3, *c, *n;
25 /* Test LIST_HEAD, list_empty and check_list */
26 ok1(list_empty(&static_list));
27 ok1(list_check(&static_list, NULL));
29 parent.num_children = 0;
30 list_head_init(&parent.children);
31 /* Test list_head_init */
32 ok1(list_empty(&parent.children));
33 ok1(list_check(&parent.children, NULL));
36 list_add(&parent.children, &c2.list);
37 /* Test list_add and !list_empty. */
38 ok1(!list_empty(&parent.children));
39 ok1(c2.list.next == &parent.children.n);
40 ok1(c2.list.prev == &parent.children.n);
41 ok1(parent.children.n.next == &c2.list);
42 ok1(parent.children.n.prev == &c2.list);
44 ok1(list_check(&parent.children, NULL));
47 list_add(&parent.children, &c1.list);
48 /* Test list_add and !list_empty. */
49 ok1(!list_empty(&parent.children));
50 ok1(c2.list.next == &parent.children.n);
51 ok1(c2.list.prev == &c1.list);
52 ok1(parent.children.n.next == &c1.list);
53 ok1(parent.children.n.prev == &c2.list);
54 ok1(c1.list.next == &c2.list);
55 ok1(c1.list.prev == &parent.children.n);
57 ok1(list_check(&parent.children, NULL));
60 list_add_tail(&parent.children, &c3.list);
61 /* Test list_add_tail and !list_empty. */
62 ok1(!list_empty(&parent.children));
63 ok1(parent.children.n.next == &c1.list);
64 ok1(parent.children.n.prev == &c3.list);
65 ok1(c1.list.next == &c2.list);
66 ok1(c1.list.prev == &parent.children.n);
67 ok1(c2.list.next == &c3.list);
68 ok1(c2.list.prev == &c1.list);
69 ok1(c3.list.next == &parent.children.n);
70 ok1(c3.list.prev == &c2.list);
72 ok1(list_check(&parent.children, NULL));
75 ok1(list_top(&parent.children, struct child, list) == &c1);
78 ok1(list_tail(&parent.children, struct child, list) == &c3);
80 /* Test list_for_each. */
82 list_for_each(&parent.children, c, list) {
99 /* Test list_for_each_safe and list_del. */
101 list_for_each_safe(&parent.children, c, n, list) {
114 ok1(list_check(&parent.children, NULL));
119 ok1(list_empty(&parent.children));
121 /* Test list_top/list_tail on empty list. */
122 ok1(list_top(&parent.children, struct child, list) == NULL);
123 ok1(list_tail(&parent.children, struct child, list) == NULL);
124 return exit_status();