Skip to content
Snippets Groups Projects
Unverified Commit 64bc06f2 authored by Gaëtan Harter's avatar Gaëtan Harter
Browse files

tests/unittests: add empty list clist_foreach case

Add clist_foreach empty list test case which should:

* not call `func`
* return `NULL`
parent 56c2b6a0
No related branches found
No related tags found
No related merge requests found
...@@ -237,13 +237,19 @@ static int _foreach_test_trampoline(clist_node_t *node, void *arg) ...@@ -237,13 +237,19 @@ static int _foreach_test_trampoline(clist_node_t *node, void *arg)
static void test_clist_foreach(void) static void test_clist_foreach(void)
{ {
void *res;
list_node_t *list = &test_clist; list_node_t *list = &test_clist;
_foreach_called = 0;
res = clist_foreach(list, _foreach_test_trampoline, NULL);
TEST_ASSERT(_foreach_called == 0);
TEST_ASSERT(res == NULL);
for (int i = 0; i < TEST_CLIST_LEN; i++) { for (int i = 0; i < TEST_CLIST_LEN; i++) {
clist_rpush(list, &tests_clist_buf[i]); clist_rpush(list, &tests_clist_buf[i]);
} }
void *res = clist_foreach(list, _foreach_test_trampoline, NULL); res = clist_foreach(list, _foreach_test_trampoline, NULL);
TEST_ASSERT(_foreach_called == _foreach_abort_after); TEST_ASSERT(_foreach_called == _foreach_abort_after);
TEST_ASSERT(res == &tests_clist_buf[_foreach_abort_after-1]); TEST_ASSERT(res == &tests_clist_buf[_foreach_abort_after-1]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment