From 5399335e509f1866d071f03f6163b86ae608d9c5 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 1 May 2013 13:11:17 +0800 Subject: [PATCH] test/lib: Add empty list test Check that the list iterators work on empty lists too. Signed-off-by: Jeremy Kerr Signed-off-by: Geoff Levand --- test/lib/list-test.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/lib/list-test.c b/test/lib/list-test.c index de629ee..c532282 100644 --- a/test/lib/list-test.c +++ b/test/lib/list-test.c @@ -60,12 +60,28 @@ int main(void) list_remove(&item->list); } + /* we should see that the list is empty */ i = 0; - fprintf(stderr, "-- list_for_each_entry --\n"); + fprintf(stderr, "-- list_for_each_entry(empty) --\n"); list_for_each_entry(&tester, item, list) { fprintf(stderr, "%d: %d: %p -> %p\n", i++, item->value, item, item->list.next); } + if (i) { + fprintf(stderr, "Error: list should be empty\n"); + return EXIT_FAILURE; + } + + i = 0; + fprintf(stderr, "-- list_for_each_entry_safe(empty) --\n"); + list_for_each_entry_safe(&tester, item, tmp, list) { + fprintf(stderr, "%d: %d: %p -> %p\n", i++, item->value, item, item->list.next); + } + + if (i) { + fprintf(stderr, "Error: list should be empty\n"); + return EXIT_FAILURE; + } fprintf(stderr, "-- done --\n"); return EXIT_SUCCESS; } -- 2.39.2