Move headers out into their own directory (include/eruntime).
[eruntime.git] / tests / test-list.c
blob0508d6d3293c5f2455dc8e479be5bf9d50fbbc04
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "eruntime/list.h"
7 static int t_list_init (void);
8 static int t_list_create (void);
10 typedef int (*test_case_func) (void);
12 typedef struct _test_case_struct
14 const char *name;
15 const char *desc;
16 test_case_func func;
18 } test_case_t;
20 /* {{{ static test_case_t list_tests[] = { ... } */
21 static test_case_t list_tests[] =
24 "list_init",
25 "function list_init()",
26 t_list_init,
29 "list_create",
30 "function list_create()",
31 t_list_create,
34 {NULL, NULL, NULL},
36 /* }}} */
38 /* {{{ int main() */
39 int
40 main (void)
42 int i, ret;
44 for (i = 0; list_tests[i].name; ++i)
46 printf("Testing %s...\n", list_tests[i].desc);
48 ret = list_tests[i].func();
49 if (ret == EXIT_SUCCESS)
50 continue;
52 fprintf(stderr, "\n``` Test case '%s' failed.\n", list_tests[i].name);
55 return 0;
57 /* }}} */
59 /* {{{ #define LIST_INIT_IS_SANE() */
60 #define LIST_INIT_IS_SANE(list) \
61 do \
62 { \
63 list_t *__list = (list); \
65 if (__list->length) \
66 return EXIT_FAILURE; \
67 if (__list->head || __list->tail) \
68 return EXIT_FAILURE; \
69 } \
70 while (0)
71 /* }}} */
73 /* {{{ static int t_list_init() */
74 static int
75 t_list_init (void)
77 list_t list;
79 if (list_init(&list) < 0)
80 return EXIT_FAILURE;
82 LIST_INIT_IS_SANE(&list);
84 return EXIT_SUCCESS;
86 /* }}} */
88 /* {{{ static int t_list_create() */
89 static int
90 t_list_create (void)
92 list_t *list = NULL;
94 list = list_create();
95 if (!list)
96 return EXIT_FAILURE;
98 LIST_INIT_IS_SANE(list);
100 return EXIT_SUCCESS;
102 /* }}} */
105 * vim: ts=8 sw=8 noet fdm=marker tw=80