1 #define CCAN_LIST_DEBUG 1
2 #include <ccan/tlist2/tlist2.h>
3 #include <ccan/tap/tap.h>
12 TLIST2(struct child, list) children;
13 unsigned int num_children;
16 int main(int argc, char *argv[])
19 struct child c1, c2, c3, *c, *n;
21 TLIST2(struct child, list) tlist = TLIST2_INIT(tlist);
24 /* Test TLIST2_INIT, and tlist2_empty */
25 ok1(tlist2_empty(&tlist));
26 ok1(tlist2_check(&tlist, NULL));
28 parent.num_children = 0;
29 tlist2_init(&parent.children);
30 /* Test tlist2_init */
31 ok1(tlist2_empty(&parent.children));
32 ok1(tlist2_check(&parent.children, NULL));
35 tlist2_add(&parent.children, &c2);
36 /* Test tlist2_add and !tlist2_empty. */
37 ok1(!tlist2_empty(&parent.children));
38 ok1(c2.list.next == &tlist2_unwrap(&parent.children)->n);
39 ok1(c2.list.prev == &tlist2_unwrap(&parent.children)->n);
40 ok1(tlist2_unwrap(&parent.children)->n.next == &c2.list);
41 ok1(tlist2_unwrap(&parent.children)->n.prev == &c2.list);
42 /* Test tlist2_check */
43 ok1(tlist2_check(&parent.children, NULL));
46 tlist2_add(&parent.children, &c1);
47 /* Test list_add and !list_empty. */
48 ok1(!tlist2_empty(&parent.children));
49 ok1(c2.list.next == &tlist2_unwrap(&parent.children)->n);
50 ok1(c2.list.prev == &c1.list);
51 ok1(tlist2_unwrap(&parent.children)->n.next == &c1.list);
52 ok1(tlist2_unwrap(&parent.children)->n.prev == &c2.list);
53 ok1(c1.list.next == &c2.list);
54 ok1(c1.list.prev == &tlist2_unwrap(&parent.children)->n);
55 /* Test tlist2_check */
56 ok1(tlist2_check(&parent.children, NULL));
59 tlist2_add_tail(&parent.children, &c3);
60 /* Test list_add_tail and !list_empty. */
61 ok1(!tlist2_empty(&parent.children));
62 ok1(tlist2_unwrap(&parent.children)->n.next == &c1.list);
63 ok1(tlist2_unwrap(&parent.children)->n.prev == &c3.list);
64 ok1(c1.list.next == &c2.list);
65 ok1(c1.list.prev == &tlist2_unwrap(&parent.children)->n);
66 ok1(c2.list.next == &c3.list);
67 ok1(c2.list.prev == &c1.list);
68 ok1(c3.list.next == &tlist2_unwrap(&parent.children)->n);
69 ok1(c3.list.prev == &c2.list);
70 /* Test tlist2_check */
71 ok1(tlist2_check(&parent.children, NULL));
74 ok1(tlist2_top(&parent.children) == &c1);
77 ok1(tlist2_tail(&parent.children) == &c3);
79 /* Test tlist2_for_each. */
81 tlist2_for_each(&parent.children, c) {
98 /* Test tlist2_for_each_rev. */
100 tlist2_for_each_rev(&parent.children, c) {
117 /* Test tlist2_for_each_safe, tlist2_del and tlist2_del_from. */
119 tlist2_for_each_safe(&parent.children, c, n) {
123 tlist2_del_from(&parent.children, c);
127 tlist2_del_from(&parent.children, c);
131 tlist2_del_from(&parent.children, c);
134 ok1(tlist2_check(&parent.children, NULL));
139 ok1(tlist2_empty(&parent.children));
141 /* Test list_top/list_tail on empty list. */
142 ok1(tlist2_top(&parent.children) == (struct child *)NULL);
143 ok1(tlist2_tail(&parent.children) == (struct child *)NULL);
144 return exit_status();