X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Flist%2Ftest%2Frun.c;h=2f1acc78a0605e959fbc94a21cd7eae2a5595018;hp=dad308282f7c14aa77bb2ecd54277770618b0ed5;hb=e4046df7898c233437c3ac9857371d6b1da97512;hpb=8216fa0be7d9bf39774a192d52fef955f6bd7cd8 diff --git a/ccan/list/test/run.c b/ccan/list/test/run.c index dad30828..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(68); + 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)); @@ -155,6 +155,19 @@ int main(int argc, char *argv[]) ok1(i == 3); ok1(list_empty(&parent.children)); + /* Test list_node_init: safe to list_del after this. */ + list_node_init(&c->list); + list_del(&c->list); + + /* Test list_del_init */ + list_add(&parent.children, &c->list); + ok1(!list_empty(&parent.children)); + list_del_init(&c->list); + ok1(list_empty(&parent.children)); + /* We can call this as many times as we like. */ + list_del_init(&c->list); + list_del_init(&c->list); + /* Test list_for_each_off. */ list_add_tail(&opaque_list, (struct list_node *)create_opaque_blob()); @@ -202,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(); }