From 9593fc545950782ed75f12f53238b07885559b2b Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 9 Jul 2018 22:28:25 -0700 Subject: remove ccan for now --- ccan/list/test/compile_ok-constant.c | 49 ----- ccan/list/test/helper.c | 56 ------ ccan/list/test/helper.h | 9 - ccan/list/test/run-CCAN_LIST_DEBUG.c | 60 ------ ccan/list/test/run-check-corrupt.c | 90 --------- ccan/list/test/run-check-nonconst.c | 27 --- ccan/list/test/run-list_del_from-assert.c | 36 ---- ccan/list/test/run-list_prev-list_next.c | 65 ------- ccan/list/test/run-prepend_list.c | 111 ----------- ccan/list/test/run-single-eval.c | 168 ---------------- ccan/list/test/run-with-debug.c | 3 - ccan/list/test/run.c | 305 ------------------------------ 12 files changed, 979 deletions(-) delete mode 100644 ccan/list/test/compile_ok-constant.c delete mode 100644 ccan/list/test/helper.c delete mode 100644 ccan/list/test/helper.h delete mode 100644 ccan/list/test/run-CCAN_LIST_DEBUG.c delete mode 100644 ccan/list/test/run-check-corrupt.c delete mode 100644 ccan/list/test/run-check-nonconst.c delete mode 100644 ccan/list/test/run-list_del_from-assert.c delete mode 100644 ccan/list/test/run-list_prev-list_next.c delete mode 100644 ccan/list/test/run-prepend_list.c delete mode 100644 ccan/list/test/run-single-eval.c delete mode 100644 ccan/list/test/run-with-debug.c delete mode 100644 ccan/list/test/run.c (limited to 'ccan/list/test') diff --git a/ccan/list/test/compile_ok-constant.c b/ccan/list/test/compile_ok-constant.c deleted file mode 100644 index c57cdad..0000000 --- a/ccan/list/test/compile_ok-constant.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include -#include -#include - -struct child { - const char *name; - struct list_node list; -}; - -static bool children(const struct list_head *list) -{ - return !list_empty(list); -} - -static const struct child *first_child(const struct list_head *list) -{ - return list_top(list, struct child, list); -} - -static const struct child *last_child(const struct list_head *list) -{ - return list_tail(list, struct child, list); -} - -static void check_children(const struct list_head *list) -{ - list_check(list, "bad child list"); -} - -static void print_children(const struct list_head *list) -{ - const struct child *c; - list_for_each(list, c, list) - printf("%s\n", c->name); -} - -int main(void) -{ - LIST_HEAD(h); - - children(&h); - first_child(&h); - last_child(&h); - check_children(&h); - print_children(&h); - return 0; -} diff --git a/ccan/list/test/helper.c b/ccan/list/test/helper.c deleted file mode 100644 index 4fb1c5a..0000000 --- a/ccan/list/test/helper.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include - -#include -#include "helper.h" - -#define ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING \ - (42) - -struct opaque { - struct list_node list; - size_t secret_offset; - char secret_drawer[42]; -}; - -static bool not_randomized = true; - -struct opaque *create_opaque_blob(void) -{ - struct opaque *blob = calloc(1, sizeof(struct opaque)); - - if (not_randomized) { - srandom((int)time(NULL)); - not_randomized = false; - } - - blob->secret_offset = random() % (sizeof(blob->secret_drawer)); - blob->secret_drawer[blob->secret_offset] = - ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING; - - return blob; -} - -bool if_blobs_know_the_secret(struct opaque *blob) -{ - bool answer = true; - int i; - for (i = 0; i < sizeof(blob->secret_drawer) / - sizeof(blob->secret_drawer[0]); i++) - if (i != blob->secret_offset) - answer = answer && (blob->secret_drawer[i] == 0); - else - answer = answer && - (blob->secret_drawer[blob->secret_offset] == - ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING); - - return answer; -} - -void destroy_opaque_blob(struct opaque *blob) -{ - free(blob); -} - - diff --git a/ccan/list/test/helper.h b/ccan/list/test/helper.h deleted file mode 100644 index 4b64a7d..0000000 --- a/ccan/list/test/helper.h +++ /dev/null @@ -1,9 +0,0 @@ -/* These are in a separate C file so we can test undefined structures. */ -struct opaque; -typedef struct opaque opaque_t; - -opaque_t *create_opaque_blob(void); -bool if_blobs_know_the_secret(opaque_t *blob); -void destroy_opaque_blob(opaque_t *blob); - - diff --git a/ccan/list/test/run-CCAN_LIST_DEBUG.c b/ccan/list/test/run-CCAN_LIST_DEBUG.c deleted file mode 100644 index b8e5165..0000000 --- a/ccan/list/test/run-CCAN_LIST_DEBUG.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Check that CCAN_LIST_DEBUG works */ -#include -#include -#include -#include -#include -#include - -/* We don't actually want it to exit... */ -static jmp_buf aborted; -#define abort() longjmp(aborted, 1) - -#define fprintf my_fprintf -static char printf_buffer[1000]; - -static int my_fprintf(FILE *stream, const char *format, ...) -{ - va_list ap; - int ret; - (void)stream; - va_start(ap, format); - ret = vsprintf(printf_buffer, format, ap); - va_end(ap); - return ret; -} - -#define CCAN_LIST_DEBUG 1 -#include -#include -#include - -int main(void) -{ - struct list_head list; - struct list_node n1; - char expect[100]; - - plan_tests(2); - /* Empty list. */ - list.n.next = &list.n; - list.n.prev = &list.n; - ok1(list_check(&list, NULL) == &list); - - /* Bad back ptr */ - list.n.prev = &n1; - - /* Aborting version. */ - sprintf(expect, "run-CCAN_LIST_DEBUG.c:51: prev corrupt in node %p (0) of %p\n", - &list, &list); - if (setjmp(aborted) == 0) { - assert(list_empty(&list)); - fail("list_empty on empty with bad back ptr didn't fail!"); - } else { - /* __FILE__ might give full path. */ - int prep = strlen(printf_buffer) - strlen(expect); - ok1(prep >= 0 && strcmp(printf_buffer + prep, expect) == 0); - } - - return exit_status(); -} diff --git a/ccan/list/test/run-check-corrupt.c b/ccan/list/test/run-check-corrupt.c deleted file mode 100644 index 94c2e67..0000000 --- a/ccan/list/test/run-check-corrupt.c +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/* We don't actually want it to exit... */ -static jmp_buf aborted; -#define abort() longjmp(aborted, 1) - -#define fprintf my_fprintf -static char printf_buffer[1000]; - -static int my_fprintf(FILE *stream, const char *format, ...) -{ - va_list ap; - int ret; - (void)stream; - va_start(ap, format); - ret = vsprintf(printf_buffer, format, ap); - va_end(ap); - return ret; -} - -#include -#include -#include - -int main(void) -{ - struct list_head list; - struct list_node n1; - char expect[100]; - - plan_tests(9); - /* Empty list. */ - list.n.next = &list.n; - list.n.prev = &list.n; - ok1(list_check(&list, NULL) == &list); - - /* Bad back ptr */ - list.n.prev = &n1; - /* Non-aborting version. */ - ok1(list_check(&list, NULL) == NULL); - - /* Aborting version. */ - sprintf(expect, "test message: prev corrupt in node %p (0) of %p\n", - &list, &list); - if (setjmp(aborted) == 0) { - list_check(&list, "test message"); - fail("list_check on empty with bad back ptr didn't fail!"); - } else { - ok1(strcmp(printf_buffer, expect) == 0); - } - - /* n1 in list. */ - list.n.next = &n1; - list.n.prev = &n1; - n1.prev = &list.n; - n1.next = &list.n; - ok1(list_check(&list, NULL) == &list); - ok1(list_check_node(&n1, NULL) == &n1); - - /* Bad back ptr */ - n1.prev = &n1; - ok1(list_check(&list, NULL) == NULL); - ok1(list_check_node(&n1, NULL) == NULL); - - /* Aborting version. */ - sprintf(expect, "test message: prev corrupt in node %p (1) of %p\n", - &n1, &list); - if (setjmp(aborted) == 0) { - list_check(&list, "test message"); - fail("list_check on n1 bad back ptr didn't fail!"); - } else { - ok1(strcmp(printf_buffer, expect) == 0); - } - - sprintf(expect, "test message: prev corrupt in node %p (0) of %p\n", - &n1, &n1); - if (setjmp(aborted) == 0) { - list_check_node(&n1, "test message"); - fail("list_check_node on n1 bad back ptr didn't fail!"); - } else { - ok1(strcmp(printf_buffer, expect) == 0); - } - - return exit_status(); -} diff --git a/ccan/list/test/run-check-nonconst.c b/ccan/list/test/run-check-nonconst.c deleted file mode 100644 index d3cb652..0000000 --- a/ccan/list/test/run-check-nonconst.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -#include "helper.h" - -struct child { - const char *name; - struct list_node list; -}; - -int main(void) -{ - struct child c1, c2; - struct list_head list = LIST_HEAD_INIT(list); - - plan_tests(1); - - list_add(&list, &c1.list); - list_add_tail(list_check(&list, "Bad list!"), &c2.list); - list_del_from(list_check(&list, "Bad list!"), - list_check_node(&c2.list, "Bad node!")); - list_del_from(list_check(&list, "Bad list!"), - list_check_node(&c1.list, "Bad node!")); - ok1(list_empty(list_check(&list, "Bad emptied list"))); - - return exit_status(); -} diff --git a/ccan/list/test/run-list_del_from-assert.c b/ccan/list/test/run-list_del_from-assert.c deleted file mode 100644 index 9404b71..0000000 --- a/ccan/list/test/run-list_del_from-assert.c +++ /dev/null @@ -1,36 +0,0 @@ -#define CCAN_LIST_DEBUG 1 -#include -#include -#include -#include -#include -#include -#include - -int main(void) -{ - struct list_head list1, list2; - struct list_node n1, n2, n3; - pid_t child; - int status; - - plan_tests(1); - list_head_init(&list1); - list_head_init(&list2); - list_add(&list1, &n1); - list_add(&list2, &n2); - list_add_tail(&list2, &n3); - - child = fork(); - if (child) { - wait(&status); - } else { - /* This should abort. */ - list_del_from(&list1, &n3); - exit(0); - } - - ok1(WIFSIGNALED(status) && WTERMSIG(status) == SIGABRT); - list_del_from(&list2, &n3); - return exit_status(); -} diff --git a/ccan/list/test/run-list_prev-list_next.c b/ccan/list/test/run-list_prev-list_next.c deleted file mode 100644 index cc61e03..0000000 --- a/ccan/list/test/run-list_prev-list_next.c +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include "helper.h" - -struct parent { - const char *name; - unsigned int num_children; - struct list_head children; -}; - -struct child { - const char *name; - struct list_node list; -}; - -int main(void) -{ - struct parent parent; - struct child c1, c2, c3; - const struct parent *p; - const struct child *c; - - plan_tests(20); - parent.num_children = 0; - list_head_init(&parent.children); - - c1.name = "c1"; - list_add(&parent.children, &c1.list); - - ok1(list_next(&parent.children, &c1, list) == NULL); - ok1(list_prev(&parent.children, &c1, list) == NULL); - - c2.name = "c2"; - list_add_tail(&parent.children, &c2.list); - - ok1(list_next(&parent.children, &c1, list) == &c2); - ok1(list_prev(&parent.children, &c1, list) == NULL); - ok1(list_next(&parent.children, &c2, list) == NULL); - ok1(list_prev(&parent.children, &c2, list) == &c1); - - c3.name = "c3"; - list_add_tail(&parent.children, &c3.list); - - ok1(list_next(&parent.children, &c1, list) == &c2); - ok1(list_prev(&parent.children, &c1, list) == NULL); - ok1(list_next(&parent.children, &c2, list) == &c3); - ok1(list_prev(&parent.children, &c2, list) == &c1); - ok1(list_next(&parent.children, &c3, list) == NULL); - ok1(list_prev(&parent.children, &c3, list) == &c2); - - /* Const variants */ - p = &parent; - c = &c2; - ok1(list_next(&p->children, &c1, list) == &c2); - ok1(list_prev(&p->children, &c1, list) == NULL); - ok1(list_next(&p->children, c, list) == &c3); - ok1(list_prev(&p->children, c, list) == &c1); - ok1(list_next(&parent.children, c, list) == &c3); - ok1(list_prev(&parent.children, c, list) == &c1); - ok1(list_next(&p->children, &c3, list) == NULL); - ok1(list_prev(&p->children, &c3, list) == &c2); - - return exit_status(); -} diff --git a/ccan/list/test/run-prepend_list.c b/ccan/list/test/run-prepend_list.c deleted file mode 100644 index fecd419..0000000 --- a/ccan/list/test/run-prepend_list.c +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include -#include -#include - -static bool list_expect(struct list_head *h, ...) -{ - va_list ap; - struct list_node *n = &h->n, *expected; - - va_start(ap, h); - while ((expected = va_arg(ap, struct list_node *)) != NULL) { - n = n->next; - if (n != expected) - return false; - } - return (n->next == &h->n); -} - -int main(void) -{ - struct list_head h1, h2; - struct list_node n[4]; - - plan_tests(40); - - list_head_init(&h1); - list_head_init(&h2); - - /* Append an empty list to an empty list. */ - list_append_list(&h1, &h2); - ok1(list_empty(&h1)); - ok1(list_empty(&h2)); - ok1(list_check(&h1, NULL)); - ok1(list_check(&h2, NULL)); - - /* Prepend an empty list to an empty list. */ - list_prepend_list(&h1, &h2); - ok1(list_empty(&h1)); - ok1(list_empty(&h2)); - ok1(list_check(&h1, NULL)); - ok1(list_check(&h2, NULL)); - - /* Append an empty list to a non-empty list */ - list_add(&h1, &n[0]); - list_append_list(&h1, &h2); - ok1(list_empty(&h2)); - ok1(list_check(&h1, NULL)); - ok1(list_check(&h2, NULL)); - ok1(list_expect(&h1, &n[0], NULL)); - - /* Prepend an empty list to a non-empty list */ - list_prepend_list(&h1, &h2); - ok1(list_empty(&h2)); - ok1(list_check(&h1, NULL)); - ok1(list_check(&h2, NULL)); - ok1(list_expect(&h1, &n[0], NULL)); - - /* Append a non-empty list to an empty list. */ - list_append_list(&h2, &h1); - ok1(list_empty(&h1)); - ok1(list_check(&h1, NULL)); - ok1(list_check(&h2, NULL)); - ok1(list_expect(&h2, &n[0], NULL)); - - /* Prepend a non-empty list to an empty list. */ - list_prepend_list(&h1, &h2); - ok1(list_empty(&h2)); - ok1(list_check(&h1, NULL)); - ok1(list_check(&h2, NULL)); - ok1(list_expect(&h1, &n[0], NULL)); - - /* Prepend a non-empty list to non-empty list. */ - list_add(&h2, &n[1]); - list_prepend_list(&h1, &h2); - ok1(list_empty(&h2)); - ok1(list_check(&h1, NULL)); - ok1(list_check(&h2, NULL)); - ok1(list_expect(&h1, &n[1], &n[0], NULL)); - - /* Append a non-empty list to non-empty list. */ - list_add(&h2, &n[2]); - list_append_list(&h1, &h2); - ok1(list_empty(&h2)); - ok1(list_check(&h1, NULL)); - ok1(list_check(&h2, NULL)); - ok1(list_expect(&h1, &n[1], &n[0], &n[2], NULL)); - - /* Prepend a 2-entry list to a 2-entry list. */ - list_del_from(&h1, &n[2]); - list_add(&h2, &n[2]); - list_add_tail(&h2, &n[3]); - list_prepend_list(&h1, &h2); - ok1(list_empty(&h2)); - ok1(list_check(&h1, NULL)); - ok1(list_check(&h2, NULL)); - ok1(list_expect(&h1, &n[2], &n[3], &n[1], &n[0], NULL)); - - /* Append a 2-entry list to a 2-entry list. */ - list_del_from(&h1, &n[2]); - list_del_from(&h1, &n[3]); - list_add(&h2, &n[2]); - list_add_tail(&h2, &n[3]); - list_append_list(&h1, &h2); - ok1(list_empty(&h2)); - ok1(list_check(&h1, NULL)); - ok1(list_check(&h2, NULL)); - ok1(list_expect(&h1, &n[1], &n[0], &n[2], &n[3], NULL)); - - return exit_status(); -} diff --git a/ccan/list/test/run-single-eval.c b/ccan/list/test/run-single-eval.c deleted file mode 100644 index db0bffd..0000000 --- a/ccan/list/test/run-single-eval.c +++ /dev/null @@ -1,168 +0,0 @@ -/* Make sure macros only evaluate their args once. */ -#include -#include -#include - -struct parent { - const char *name; - struct list_head children; - unsigned int num_children; - int eval_count; -}; - -struct child { - const char *name; - struct list_node list; -}; - -static LIST_HEAD(static_list); - -#define ref(obj, counter) ((counter)++, (obj)) - -int main(void) -{ - struct parent parent; - struct child c1, c2, c3, *c, *n; - unsigned int i; - unsigned int static_count = 0, parent_count = 0, list_count = 0, - node_count = 0; - struct list_head list = LIST_HEAD_INIT(list); - - plan_tests(74); - /* Test LIST_HEAD, LIST_HEAD_INIT, list_empty and check_list */ - ok1(list_empty(ref(&static_list, static_count))); - ok1(static_count == 1); - ok1(list_check(ref(&static_list, static_count), NULL)); - ok1(static_count == 2); - ok1(list_empty(ref(&list, list_count))); - ok1(list_count == 1); - ok1(list_check(ref(&list, list_count), NULL)); - ok1(list_count == 2); - - parent.num_children = 0; - list_head_init(ref(&parent.children, parent_count)); - ok1(parent_count == 1); - /* Test list_head_init */ - ok1(list_empty(ref(&parent.children, parent_count))); - ok1(parent_count == 2); - ok1(list_check(ref(&parent.children, parent_count), NULL)); - ok1(parent_count == 3); - - c2.name = "c2"; - list_add(ref(&parent.children, parent_count), &c2.list); - ok1(parent_count == 4); - /* Test list_add and !list_empty. */ - ok1(!list_empty(ref(&parent.children, parent_count))); - ok1(parent_count == 5); - ok1(c2.list.next == &parent.children.n); - ok1(c2.list.prev == &parent.children.n); - ok1(parent.children.n.next == &c2.list); - ok1(parent.children.n.prev == &c2.list); - /* Test list_check */ - ok1(list_check(ref(&parent.children, parent_count), NULL)); - ok1(parent_count == 6); - - c1.name = "c1"; - list_add(ref(&parent.children, parent_count), &c1.list); - ok1(parent_count == 7); - /* Test list_add and !list_empty. */ - ok1(!list_empty(ref(&parent.children, parent_count))); - ok1(parent_count == 8); - ok1(c2.list.next == &parent.children.n); - ok1(c2.list.prev == &c1.list); - ok1(parent.children.n.next == &c1.list); - ok1(parent.children.n.prev == &c2.list); - ok1(c1.list.next == &c2.list); - ok1(c1.list.prev == &parent.children.n); - /* Test list_check */ - ok1(list_check(ref(&parent.children, parent_count), NULL)); - ok1(parent_count == 9); - - c3.name = "c3"; - list_add_tail(ref(&parent.children, parent_count), &c3.list); - ok1(parent_count == 10); - /* Test list_add_tail and !list_empty. */ - ok1(!list_empty(ref(&parent.children, parent_count))); - ok1(parent_count == 11); - ok1(parent.children.n.next == &c1.list); - ok1(parent.children.n.prev == &c3.list); - ok1(c1.list.next == &c2.list); - ok1(c1.list.prev == &parent.children.n); - ok1(c2.list.next == &c3.list); - ok1(c2.list.prev == &c1.list); - ok1(c3.list.next == &parent.children.n); - ok1(c3.list.prev == &c2.list); - /* Test list_check */ - ok1(list_check(ref(&parent.children, parent_count), NULL)); - ok1(parent_count == 12); - - /* 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(ref(&parent.children, parent_count), struct child, list) == &c1); - ok1(parent_count == 13); - - /* Test list_tail */ - ok1(list_tail(ref(&parent.children, parent_count), struct child, list) == &c3); - ok1(parent_count == 14); - - /* Test list_for_each. */ - i = 0; - list_for_each(&parent.children, c, list) { - switch (i++) { - case 0: - ok1(c == &c1); - break; - case 1: - ok1(c == &c2); - break; - case 2: - ok1(c == &c3); - break; - } - if (i > 2) - break; - } - ok1(i == 3); - - /* 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); - list_del(ref(&c->list, node_count)); - ok1(node_count == 1); - break; - case 1: - ok1(c == &c2); - list_del_from(ref(&parent.children, parent_count), - ref(&c->list, node_count)); - ok1(node_count == 2); - break; - case 2: - ok1(c == &c3); - list_del_from(ref(&parent.children, parent_count), - ref(&c->list, node_count)); - ok1(node_count == 3); - break; - } - ok1(list_check(ref(&parent.children, parent_count), NULL)); - if (i > 2) - break; - } - ok1(i == 3); - ok1(parent_count == 19); - ok1(list_empty(ref(&parent.children, parent_count))); - ok1(parent_count == 20); - - /* Test list_top/list_tail on empty list. */ - ok1(list_top(ref(&parent.children, parent_count), struct child, list) == NULL); - ok1(parent_count == 21); - ok1(list_tail(ref(&parent.children, parent_count), struct child, list) == NULL); - ok1(parent_count == 22); - return exit_status(); -} diff --git a/ccan/list/test/run-with-debug.c b/ccan/list/test/run-with-debug.c deleted file mode 100644 index d090242..0000000 --- a/ccan/list/test/run-with-debug.c +++ /dev/null @@ -1,3 +0,0 @@ -/* Just like run.c, but with all debug checks enabled. */ -#define CCAN_LIST_DEBUG 1 -#include diff --git a/ccan/list/test/run.c b/ccan/list/test/run.c deleted file mode 100644 index 5787e45..0000000 --- a/ccan/list/test/run.c +++ /dev/null @@ -1,305 +0,0 @@ -#include -#include -#include -#include "helper.h" - -struct parent { - const char *name; - struct list_head children; - unsigned int num_children; -}; - -struct child { - const char *name; - struct list_node list; -}; - -static LIST_HEAD(static_list); - -int main(void) -{ - struct parent parent; - struct child c1, c2, c3, x1, *c, *n; - unsigned int i; - struct list_head list = LIST_HEAD_INIT(list); - opaque_t *q, *nq; - struct list_head opaque_list = LIST_HEAD_INIT(opaque_list); - LIST_HEAD(rev); - - plan_tests(92); - /* 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); - /* Test list_head_init */ - ok1(list_empty(&parent.children)); - ok1(list_check(&parent.children, NULL)); - - c2.name = "c2"; - list_add(&parent.children, &c2.list); - /* Test list_add and !list_empty. */ - ok1(!list_empty(&parent.children)); - ok1(c2.list.next == &parent.children.n); - ok1(c2.list.prev == &parent.children.n); - ok1(parent.children.n.next == &c2.list); - ok1(parent.children.n.prev == &c2.list); - /* Test list_check */ - ok1(list_check(&parent.children, NULL)); - - c1.name = "c1"; - list_add(&parent.children, &c1.list); - /* Test list_add and !list_empty. */ - ok1(!list_empty(&parent.children)); - ok1(c2.list.next == &parent.children.n); - ok1(c2.list.prev == &c1.list); - ok1(parent.children.n.next == &c1.list); - ok1(parent.children.n.prev == &c2.list); - ok1(c1.list.next == &c2.list); - ok1(c1.list.prev == &parent.children.n); - /* Test list_check */ - ok1(list_check(&parent.children, NULL)); - - c3.name = "c3"; - list_add_tail(&parent.children, &c3.list); - /* Test list_add_tail and !list_empty. */ - ok1(!list_empty(&parent.children)); - ok1(parent.children.n.next == &c1.list); - ok1(parent.children.n.prev == &c3.list); - ok1(c1.list.next == &c2.list); - ok1(c1.list.prev == &parent.children.n); - ok1(c2.list.next == &c3.list); - ok1(c2.list.prev == &c1.list); - ok1(c3.list.next == &parent.children.n); - ok1(c3.list.prev == &c2.list); - /* 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_pop */ - ok1(list_pop(&parent.children, struct child, list) == &c1); - ok1(list_top(&parent.children, struct child, list) == &c2); - list_add(&parent.children, &c1.list); - - /* 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) { - switch (i++) { - case 0: - ok1(c == &c1); - break; - case 1: - ok1(c == &c2); - break; - case 2: - ok1(c == &c3); - break; - } - if (i > 2) - break; - } - ok1(i == 3); - - /* Test list_for_each_rev. */ - i = 0; - list_for_each_rev(&parent.children, c, list) { - switch (i++) { - case 0: - ok1(c == &c3); - break; - case 1: - ok1(c == &c2); - break; - case 2: - ok1(c == &c1); - break; - } - if (i > 2) - break; - } - ok1(i == 3); - - /* 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); - 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; - } - - /* prepare for list_for_each_rev_safe test */ - list_add(&rev, &c->list); - - ok1(list_check(&parent.children, NULL)); - if (i > 2) - break; - } - ok1(i == 3); - ok1(list_empty(&parent.children)); - - /* Test list_for_each_rev_safe, list_del and list_del_from. */ - i = 0; - list_for_each_rev_safe(&rev, c, n, list) { - switch (i++) { - case 0: - ok1(c == &c1); - list_del(&c->list); - break; - case 1: - ok1(c == &c2); - list_del_from(&rev, &c->list); - break; - case 2: - ok1(c == &c3); - list_del_from(&rev, &c->list); - break; - } - ok1(list_check(&rev, NULL)); - if (i > 2) - break; - } - ok1(i == 3); - ok1(list_empty(&rev)); - - /* 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()); - list_add_tail(&opaque_list, - (struct list_node *)create_opaque_blob()); - list_add_tail(&opaque_list, - (struct list_node *)create_opaque_blob()); - - i = 0; - - list_for_each_off(&opaque_list, q, 0) { - i++; - ok1(if_blobs_know_the_secret(q)); - } - ok1(i == 3); - - /* Test list_for_each_safe_off, list_del_off and list_del_from_off. */ - i = 0; - list_for_each_safe_off(&opaque_list, q, nq, 0) { - switch (i++) { - case 0: - ok1(if_blobs_know_the_secret(q)); - list_del_off(q, 0); - destroy_opaque_blob(q); - break; - case 1: - ok1(if_blobs_know_the_secret(q)); - list_del_from_off(&opaque_list, q, 0); - destroy_opaque_blob(q); - break; - case 2: - ok1(c == &c3); - list_del_from_off(&opaque_list, q, 0); - destroy_opaque_blob(q); - break; - } - ok1(list_check(&opaque_list, NULL)); - if (i > 2) - break; - } - ok1(i == 3); - ok1(list_empty(&opaque_list)); - - /* Test list_top/list_tail/list_pop on empty list. */ - 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); - - /* test list_swap */ - list_swap(&c3.list, &x1.list); - ok1(list_check(&parent.children, "list_swap")); - i = 0; - list_for_each(&parent.children, c, list) { - switch (i++) { - case 0: - ok1(c == &c1); - break; - case 1: - ok1(c == &x1); - break; - case 2: - ok1(c == &c2); - break; - } - } - ok1(i == 3); - - return exit_status(); -} -- cgit v1.2.3