1 #include <ccan/list/list.h>
2 #include <ccan/tap/tap.h>
3 #include <ccan/list/list.c>
8 unsigned int num_children;
9 struct list_head children;
14 struct list_node list;
17 int main(int argc, char *argv[])
20 struct child c1, c2, c3;
21 const struct parent *p;
22 const struct child *c;
25 parent.num_children = 0;
26 list_head_init(&parent.children);
29 list_add(&parent.children, &c1.list);
31 ok1(list_next(&parent.children, &c1, list) == NULL);
32 ok1(list_prev(&parent.children, &c1, list) == NULL);
35 list_add_tail(&parent.children, &c2.list);
37 ok1(list_next(&parent.children, &c1, list) == &c2);
38 ok1(list_prev(&parent.children, &c1, list) == NULL);
39 ok1(list_next(&parent.children, &c2, list) == NULL);
40 ok1(list_prev(&parent.children, &c2, list) == &c1);
43 list_add_tail(&parent.children, &c3.list);
45 ok1(list_next(&parent.children, &c1, list) == &c2);
46 ok1(list_prev(&parent.children, &c1, list) == NULL);
47 ok1(list_next(&parent.children, &c2, list) == &c3);
48 ok1(list_prev(&parent.children, &c2, list) == &c1);
49 ok1(list_next(&parent.children, &c3, list) == NULL);
50 ok1(list_prev(&parent.children, &c3, list) == &c2);
55 ok1(list_next(&p->children, &c1, list) == &c2);
56 ok1(list_prev(&p->children, &c1, list) == NULL);
57 ok1(list_next(&p->children, c, list) == &c3);
58 ok1(list_prev(&p->children, c, list) == &c1);
59 ok1(list_next(&parent.children, c, list) == &c3);
60 ok1(list_prev(&parent.children, c, list) == &c1);
61 ok1(list_next(&p->children, &c3, list) == NULL);
62 ok1(list_prev(&p->children, &c3, list) == &c2);