]> git.ozlabs.org Git - petitboot/blobdiff - test/lib/list-test.c
lib/process: Add add_stderr flag to process module
[petitboot] / test / lib / list-test.c
index de629eede7da6d80ae45f6ac72f9c6ce7efdca79..144613da7d06a1da673091bba1c9ae27cebe649b 100644 (file)
 #include "config.h"
 #endif
 
-#define _GNU_SOURCE
-
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <list/list.h>
+#include <talloc/talloc.h>
 
 
 int main(void)
@@ -36,10 +35,13 @@ int main(void)
        STATIC_LIST(tester);
        struct item *item;
        struct item *tmp;
+       void *ctx;
        int i;
 
+       ctx = talloc_new(NULL);
+
        for (i = 0; i < 5; i++) {
-               struct item *item = malloc(sizeof(struct item));
+               struct item *item = talloc(ctx, struct item);
 
                item->value = i;
 
@@ -60,12 +62,31 @@ 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");
+
+       talloc_free(ctx);
+
        return EXIT_SUCCESS;
 }