X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Flist%2Ftest%2Frun.c;h=2f1acc78a0605e959fbc94a21cd7eae2a5595018;hb=e4046df7898c233437c3ac9857371d6b1da97512;hp=88c3835b4070b63949f002c44a4416bdef9cada0;hpb=c1bace5e7359b63a6fe5beab5e8c8faf9de794b6;p=ccan diff --git a/ccan/list/test/run.c b/ccan/list/test/run.c index 88c3835b..2f1acc78 100644 --- a/ccan/list/test/run.c +++ b/ccan/list/test/run.c @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) opaque_t *q, *nq; struct list_head opaque_list = LIST_HEAD_INIT(opaque_list); - plan_tests(70); + plan_tests(79); /* Test LIST_HEAD, LIST_HEAD_INIT, list_empty and check_list */ ok1(list_empty(&static_list)); ok1(list_check(&static_list, NULL)); @@ -215,5 +215,43 @@ int main(int argc, char *argv[]) ok1(list_top(&parent.children, struct child, list) == NULL); ok1(list_tail(&parent.children, struct child, list) == NULL); ok1(list_pop(&parent.children, struct child, list) == NULL); + + /* Test list_add_before and list_add_after */ + list_add(&parent.children, &c1.list); + list_add_after(&parent.children, &c1.list, &c2.list); + ok1(list_check(&parent.children, "list_add_after")); + + i = 0; + list_for_each(&parent.children, c, list) { + switch (i++) { + case 0: + ok1(c == &c1); + break; + case 1: + ok1(c == &c2); + break; + } + } + ok1(i == 2); + + list_add_before(&parent.children, &c2.list, &c3.list); + ok1(list_check(&parent.children, "list_add_before")); + + i = 0; + list_for_each(&parent.children, c, list) { + switch (i++) { + case 0: + ok1(c == &c1); + break; + case 1: + ok1(c == &c3); + break; + case 2: + ok1(c == &c2); + break; + } + } + ok1(i == 3); + return exit_status(); }