1 #include <ccan/list/list.h>
2 #include <ccan/tap/tap.h>
3 #include <ccan/list/list.c>
6 static bool list_expect(struct list_head *h, ...)
9 struct list_node *n = &h->n, *expected;
12 while ((expected = va_arg(ap, struct list_node *)) != NULL) {
17 return (n->next == &h->n);
22 struct list_head h1, h2;
23 struct list_node n[4];
30 /* Append an empty list to an empty list. */
31 list_append_list(&h1, &h2);
34 ok1(list_check(&h1, NULL));
35 ok1(list_check(&h2, NULL));
37 /* Prepend an empty list to an empty list. */
38 list_prepend_list(&h1, &h2);
41 ok1(list_check(&h1, NULL));
42 ok1(list_check(&h2, NULL));
44 /* Append an empty list to a non-empty list */
46 list_append_list(&h1, &h2);
48 ok1(list_check(&h1, NULL));
49 ok1(list_check(&h2, NULL));
50 ok1(list_expect(&h1, &n[0], NULL));
52 /* Prepend an empty list to a non-empty list */
53 list_prepend_list(&h1, &h2);
55 ok1(list_check(&h1, NULL));
56 ok1(list_check(&h2, NULL));
57 ok1(list_expect(&h1, &n[0], NULL));
59 /* Append a non-empty list to an empty list. */
60 list_append_list(&h2, &h1);
62 ok1(list_check(&h1, NULL));
63 ok1(list_check(&h2, NULL));
64 ok1(list_expect(&h2, &n[0], NULL));
66 /* Prepend a non-empty list to an empty list. */
67 list_prepend_list(&h1, &h2);
69 ok1(list_check(&h1, NULL));
70 ok1(list_check(&h2, NULL));
71 ok1(list_expect(&h1, &n[0], NULL));
73 /* Prepend a non-empty list to non-empty list. */
75 list_prepend_list(&h1, &h2);
77 ok1(list_check(&h1, NULL));
78 ok1(list_check(&h2, NULL));
79 ok1(list_expect(&h1, &n[1], &n[0], NULL));
81 /* Append a non-empty list to non-empty list. */
83 list_append_list(&h1, &h2);
85 ok1(list_check(&h1, NULL));
86 ok1(list_check(&h2, NULL));
87 ok1(list_expect(&h1, &n[1], &n[0], &n[2], NULL));
89 /* Prepend a 2-entry list to a 2-entry list. */
90 list_del_from(&h1, &n[2]);
92 list_add_tail(&h2, &n[3]);
93 list_prepend_list(&h1, &h2);
95 ok1(list_check(&h1, NULL));
96 ok1(list_check(&h2, NULL));
97 ok1(list_expect(&h1, &n[2], &n[3], &n[1], &n[0], NULL));
99 /* Append a 2-entry list to a 2-entry list. */
100 list_del_from(&h1, &n[2]);
101 list_del_from(&h1, &n[3]);
102 list_add(&h2, &n[2]);
103 list_add_tail(&h2, &n[3]);
104 list_append_list(&h1, &h2);
105 ok1(list_empty(&h2));
106 ok1(list_check(&h1, NULL));
107 ok1(list_check(&h2, NULL));
108 ok1(list_expect(&h1, &n[1], &n[0], &n[2], &n[3], NULL));
110 return exit_status();