From: Jeremy Kerr Date: Wed, 1 May 2013 05:11:17 +0000 (+0800) Subject: test/lib: Add empty list test X-Git-Tag: v1.0.0~683 X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=commitdiff_plain;h=5399335e509f1866d071f03f6163b86ae608d9c5;ds=sidebyside 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 --- 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; }