remove @EAP_LDFLAGS@, no longer exists
[mech_eap.orig] / libeap / tests / test-list.c
1 /*
2  * Doubly-linked list - test program
3  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include "utils/includes.h"
16 #include "utils/os.h"
17 #include "utils/list.h"
18
19 struct test {
20         struct dl_list list;
21         int value;
22 };
23
24 static void dump_list(struct dl_list *head)
25 {
26         struct test *t;
27         printf("dump:");
28         dl_list_for_each(t, head, struct test, list)
29                 printf(" %d", t->value);
30         printf(" (len=%d%s)\n", dl_list_len(head),
31                dl_list_empty(head) ? " empty" : "");
32 }
33
34 int main(int argc, char *argv[])
35 {
36         struct dl_list head;
37         struct test *t, *tmp;
38         int i;
39
40         dl_list_init(&head);
41         dump_list(&head);
42
43         for (i = 0; i < 5; i++) {
44                 t = os_zalloc(sizeof(*t));
45                 if (t == NULL)
46                         return -1;
47                 t->value = i;
48                 dl_list_add(&head, &t->list);
49                 dump_list(&head);
50         }
51
52         for (i = 10; i > 5; i--) {
53                 t = os_zalloc(sizeof(*t));
54                 if (t == NULL)
55                         return -1;
56                 t->value = i;
57                 dl_list_add_tail(&head, &t->list);
58                 dump_list(&head);
59         }
60
61         i = 0;
62         dl_list_for_each(t, &head, struct test, list)
63                 if (++i == 5)
64                         break;
65         printf("move: %d\n", t->value);
66         dl_list_del(&t->list);
67         dl_list_add(&head, &t->list);
68         dump_list(&head);
69
70         dl_list_for_each_safe(t, tmp, &head, struct test, list) {
71                 printf("delete: %d\n", t->value);
72                 dl_list_del(&t->list);
73                 os_free(t);
74                 dump_list(&head);
75         }
76
77         return 0;
78 }