Fix a typo in doxygen specification
[hostap-gosc2009.git] / tests / test-list.c
blob930ce4165fe418a98478a2697793fd179c364541
1 /*
2 * Doubly-linked list - test program
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
16 #include "utils/os.h"
17 #include "utils/list.h"
19 struct test {
20 struct dl_list list;
21 int value;
24 static void dump_list(struct dl_list *head)
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" : "");
34 int main(int argc, char *argv[])
36 struct dl_list head;
37 struct test *t, *tmp;
38 int i;
40 dl_list_init(&head);
41 dump_list(&head);
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);
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);
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);
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);
77 return 0;