X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Flist%2Ftest%2Frun.c;h=f80e364a276c1dd466737a80186db60f99cc57f3;hb=9a83a074ce88154bc96e871868ed481cb1c31fe7;hp=66b9630db514610ac9d78c76212492e39b6465ca;hpb=650c775ff00cccd03fc84e7789a03c51d9839004;p=ccan diff --git a/ccan/list/test/run.c b/ccan/list/test/run.c index 66b9630d..f80e364a 100644 --- a/ccan/list/test/run.c +++ b/ccan/list/test/run.c @@ -1,6 +1,6 @@ -#include "list/list.h" -#include "tap/tap.h" -#include "list/list.c" +#include +#include +#include struct parent { const char *name; @@ -20,11 +20,14 @@ int main(int argc, char *argv[]) struct parent parent; struct child c1, c2, c3, *c, *n; unsigned int i; + struct list_head list = LIST_HEAD_INIT(list); - plan_tests(41); - /* Test LIST_HEAD, list_empty and check_list */ + plan_tests(49); + /* Test LIST_HEAD, LIST_HEAD_INIT, list_empty and check_list */ ok1(list_empty(&static_list)); ok1(list_check(&static_list, NULL)); + ok1(list_empty(&list)); + ok1(list_check(&list, NULL)); parent.num_children = 0; list_head_init(&parent.children); @@ -71,9 +74,17 @@ int main(int argc, char *argv[]) /* Test list_check */ ok1(list_check(&parent.children, NULL)); + /* Test list_check_node */ + ok1(list_check_node(&c1.list, NULL)); + ok1(list_check_node(&c2.list, NULL)); + ok1(list_check_node(&c3.list, NULL)); + /* Test list_top */ ok1(list_top(&parent.children, struct child, list) == &c1); + /* Test list_tail */ + ok1(list_tail(&parent.children, struct child, list) == &c3); + /* Test list_for_each. */ i = 0; list_for_each(&parent.children, c, list) { @@ -93,26 +104,32 @@ int main(int argc, char *argv[]) } ok1(i == 3); - /* Test list_for_each_safe and list_del. */ + /* Test list_for_each_safe, list_del and list_del_from. */ i = 0; list_for_each_safe(&parent.children, c, n, list) { switch (i++) { case 0: - ok1(c == &c1); + ok1(c == &c1); + list_del(&c->list); break; case 1: ok1(c == &c2); + list_del_from(&parent.children, &c->list); break; case 2: ok1(c == &c3); + list_del_from(&parent.children, &c->list); break; } - list_del(&c->list); ok1(list_check(&parent.children, NULL)); if (i > 2) break; } ok1(i == 3); ok1(list_empty(&parent.children)); + + /* Test list_top/list_tail on empty list. */ + ok1(list_top(&parent.children, struct child, list) == NULL); + ok1(list_tail(&parent.children, struct child, list) == NULL); return exit_status(); }