5 #include "eruntime/list.h"
7 static int t_list_init (void);
8 static int t_list_create (void);
9 static int t_list_append (void);
10 static int t_list_prepend (void);
11 static int t_list_apply (void);
13 typedef int (*test_case_func
) (void);
15 typedef struct _test_case_struct
23 /* {{{ static test_case_t list_tests[] = { ... } */
24 static test_case_t list_tests
[] =
28 "function list_init()",
33 "function list_create()",
38 "function list_append()",
43 "function list_prepend()",
57 for (i
= 0; list_tests
[i
].name
; ++i
)
59 printf("Testing %s...", list_tests
[i
].desc
);
61 ret
= list_tests
[i
].func();
62 printf(" %s\n", ret
== EXIT_SUCCESS
? "success" : "failure");
63 if (ret
== EXIT_SUCCESS
)
66 fprintf(stderr
, "\n``` Test case '%s' failed.\n", list_tests
[i
].name
);
73 /* {{{ #define LIST_INIT_IS_SANE() */
74 #define LIST_INIT_IS_SANE(list) \
77 list_t *__list = (list); \
80 return EXIT_FAILURE; \
81 if (__list->head || __list->tail) \
82 return EXIT_FAILURE; \
87 /* {{{ static int t_list_init() */
93 if (list_init(&list
) < 0)
96 LIST_INIT_IS_SANE(&list
);
102 /* {{{ static int t_list_create() */
108 list
= list_create();
112 LIST_INIT_IS_SANE(list
);
119 /* {{{ static int t_list_append() */
124 list_node_t
*cur
= NULL
;
125 char *strings
[] = {"afoo", "bfoo", "cfoo", NULL
};
128 list
= list_create();
132 LIST_INIT_IS_SANE(list
);
134 for (i
= 0; strings
[i
]; ++i
)
136 if (list_append(list
, strings
[i
]) < 0)
144 LIST_FOREACH (list
, cur
)
146 if (cur
->data
== strings
[i
])
153 return c
== 3 ? EXIT_SUCCESS
: EXIT_FAILURE
;
157 /* {{{ static int t_list_prepend() */
159 t_list_prepend (void)
162 list_node_t
*cur
= NULL
;
163 char *strings
[] = {"cfoo", "bfoo", "afoo", NULL
};
166 list
= list_create();
170 LIST_INIT_IS_SANE(list
);
172 for (i
= 0; strings
[i
]; ++i
)
174 if (list_prepend(list
, strings
[i
]) < 0)
182 LIST_FOREACH (list
, cur
)
184 if (cur
->data
== strings
[i
])
191 return c
== 3 ? EXIT_SUCCESS
: EXIT_FAILURE
;
196 * vim: ts=8 sw=8 noet fdm=marker tw=80