From e7bc1ed0bacd2274ee55ccab916271f7fffe09f2 Mon Sep 17 00:00:00 2001 From: Elfyn McBratney Date: Fri, 9 Feb 2007 00:52:36 +0000 Subject: [PATCH] Add/update tests. --- tests/test-list.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/tests/test-list.c b/tests/test-list.c index 0508d6d..a0ef80d 100644 --- a/tests/test-list.c +++ b/tests/test-list.c @@ -6,6 +6,9 @@ static int t_list_init (void); static int t_list_create (void); +static int t_list_append (void); +static int t_list_prepend (void); +static int t_list_apply (void); typedef int (*test_case_func) (void); @@ -30,6 +33,16 @@ static test_case_t list_tests[] = "function list_create()", t_list_create, }, + { + "list_append", + "function list_append()", + t_list_append, + }, + { + "list_prepend", + "function list_prepend()", + t_list_prepend, + }, {NULL, NULL, NULL}, }; @@ -43,9 +56,10 @@ main (void) for (i = 0; list_tests[i].name; ++i) { - printf("Testing %s...\n", list_tests[i].desc); + printf("Testing %s...", list_tests[i].desc); ret = list_tests[i].func(); + printf(" %s\n", ret == EXIT_SUCCESS ? "success" : "failure"); if (ret == EXIT_SUCCESS) continue; @@ -96,11 +110,88 @@ t_list_create (void) return EXIT_FAILURE; LIST_INIT_IS_SANE(list); + list_destroy(list); return EXIT_SUCCESS; } /* }}} */ +/* {{{ static int t_list_append() */ +static int +t_list_append (void) +{ + list_t *list = NULL; + list_node_t *cur = NULL; + char *strings[] = {"afoo", "bfoo", "cfoo", NULL}; + int i, c; + + list = list_create(); + if (!list) + return EXIT_FAILURE; + + LIST_INIT_IS_SANE(list); + + for (i = 0; strings[i]; ++i) + { + if (list_append(list, strings[i]) < 0) + { + list_destroy(list); + return EXIT_FAILURE; + } + } + + i = c = 0; + LIST_FOREACH (list, cur) + { + if (cur->data == strings[i]) + ++c; + ++i; + } + + list_destroy(list); + + return c == 3 ? EXIT_SUCCESS : EXIT_FAILURE; +} +/* }}} */ + +/* {{{ static int t_list_prepend() */ +static int +t_list_prepend (void) +{ + list_t *list = NULL; + list_node_t *cur = NULL; + char *strings[] = {"cfoo", "bfoo", "afoo", NULL}; + int i, c; + + list = list_create(); + if (!list) + return EXIT_FAILURE; + + LIST_INIT_IS_SANE(list); + + for (i = 0; strings[i]; ++i) + { + if (list_prepend(list, strings[i]) < 0) + { + list_destroy(list); + return EXIT_FAILURE; + } + } + + i = 2, c = 0; + LIST_FOREACH (list, cur) + { + if (cur->data == strings[i]) + ++c; + --i; + } + + list_destroy(list); + + return c == 3 ? EXIT_SUCCESS : EXIT_FAILURE; +} +/* }}} */ + /* * vim: ts=8 sw=8 noet fdm=marker tw=80 */ -- 2.11.4.GIT