From 64bc06f2b65d21223cd9406cefb377d41229c55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 15 May 2018 15:26:45 +0200 Subject: [PATCH] tests/unittests: add empty list clist_foreach case Add clist_foreach empty list test case which should: * not call `func` * return `NULL` --- tests/unittests/tests-core/tests-core-clist.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/unittests/tests-core/tests-core-clist.c b/tests/unittests/tests-core/tests-core-clist.c index b873acbfeb..bbf5acd9cc 100644 --- a/tests/unittests/tests-core/tests-core-clist.c +++ b/tests/unittests/tests-core/tests-core-clist.c @@ -237,13 +237,19 @@ static int _foreach_test_trampoline(clist_node_t *node, void *arg) static void test_clist_foreach(void) { + void *res; 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++) { 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(res == &tests_clist_buf[_foreach_abort_after-1]);