test/lib: Add empty list test
authorJeremy Kerr <jk@ozlabs.org>
Wed, 1 May 2013 05:11:17 +0000 (13:11 +0800)
committerGeoff Levand <geoff@infradead.org>
Fri, 3 May 2013 23:21:11 +0000 (16:21 -0700)
Check that the list iterators work on empty lists too.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Geoff Levand <geoff@infradead.org>
test/lib/list-test.c

index de629eede7da6d80ae45f6ac72f9c6ce7efdca79..c532282aadbd5c3d886c9a0838761c1b35bea13b 100644 (file)
@@ -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;
 }