Mercurial > dovecot > core-2.2
annotate src/lib/test-llist.c @ 22664:fea53c2725c0
director: Fix director_max_parallel_moves/kicks type
Should be uint, not time.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 09 Nov 2017 12:24:16 +0200 |
parents | 2e2563132d5f |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
19552
diff
changeset
|
1 /* Copyright (c) 2009-2017 Dovecot authors, see the included COPYING file */ |
10262
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "test-lib.h" |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "llist.h" |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 struct dllist { |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 struct dllist *prev, *next; |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 }; |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 static void test_dllist(void) |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 { |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 struct dllist *head = NULL, *l4, *l3, *l2, *l1; |
17577
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
14 struct dllist empty = { NULL, NULL }; |
10262
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 l4 = t_new(struct dllist, 1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 l3 = t_new(struct dllist, 1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 l2 = t_new(struct dllist, 1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 l1 = t_new(struct dllist, 1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 test_begin("dllist"); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 DLLIST_PREPEND(&head, l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 test_assert(head == l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 test_assert(l4->prev == NULL && l4->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 DLLIST_PREPEND(&head, l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 test_assert(head == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 test_assert(l3->prev == NULL && l3->next == l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 test_assert(l4->prev == l3 && l4->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 DLLIST_PREPEND(&head, l2); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 DLLIST_PREPEND(&head, l1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 /* remove from middle */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 DLLIST_REMOVE(&head, l2); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 test_assert(l2->prev == NULL && l2->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 test_assert(head == l1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 test_assert(l1->prev == NULL && l1->next == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 test_assert(l3->prev == l1 && l3->next == l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 test_assert(l4->prev == l3 && l4->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 /* remove from head */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 DLLIST_REMOVE(&head, l1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 test_assert(l1->prev == NULL && l1->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 test_assert(head == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 test_assert(l3->prev == NULL && l3->next == l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 test_assert(l4->prev == l3 && l4->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 /* remove from tail */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 DLLIST_PREPEND(&head, l1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 DLLIST_REMOVE(&head, l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 test_assert(l4->prev == NULL && l4->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 test_assert(head == l1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 test_assert(l1->prev == NULL && l1->next == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 test_assert(l3->prev == l1 && l3->next == NULL); |
17577
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
51 /* removal of an entry not in the list shouldn't cause the list to break */ |
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
52 DLLIST_REMOVE(&head, &empty); |
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
53 test_assert(head == l1); |
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
54 test_assert(l1->prev == NULL && l1->next == l3); |
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
55 test_assert(l3->prev == l1 && l3->next == NULL); |
10262
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 /* remove last two */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 DLLIST_REMOVE(&head, l1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 DLLIST_REMOVE(&head, l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 test_assert(l3->prev == NULL && l3->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 test_assert(head == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 test_end(); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 } |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 static void test_dllist2(void) |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 { |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 struct dllist *head = NULL, *tail = NULL, *l4, *l3, *l2, *l1; |
17577
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
67 struct dllist empty = { NULL, NULL }; |
10262
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 l4 = t_new(struct dllist, 1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 l3 = t_new(struct dllist, 1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 l2 = t_new(struct dllist, 1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 l1 = t_new(struct dllist, 1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 test_begin("dllist"); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 /* prepend to empty */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 DLLIST2_PREPEND(&head, &tail, l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 test_assert(head == l3 && tail == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 test_assert(l3->next == NULL && l3->prev == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 /* remove last */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 DLLIST2_REMOVE(&head, &tail, l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 test_assert(head == NULL && tail == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 test_assert(l3->next == NULL && l3->prev == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 /* append to empty */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 DLLIST2_APPEND(&head, &tail, l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 test_assert(head == l3 && tail == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 test_assert(l3->next == NULL && l3->prev == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 /* prepend */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 DLLIST2_PREPEND(&head, &tail, l2); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 test_assert(head == l2 && tail == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 test_assert(l2->prev == NULL && l2->next == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 test_assert(l3->prev == l2 && l3->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 /* append */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 DLLIST2_APPEND(&head, &tail, l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 test_assert(head == l2 && tail == l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 test_assert(l2->prev == NULL && l2->next == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 test_assert(l3->prev == l2 && l3->next == l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 test_assert(l4->prev == l3 && l4->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 DLLIST2_PREPEND(&head, &tail, l1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 /* remove from middle */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 DLLIST2_REMOVE(&head, &tail, l2); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 test_assert(l2->prev == NULL && l2->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 test_assert(head == l1 && tail == l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 test_assert(l1->prev == NULL && l1->next == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 test_assert(l3->prev == l1 && l3->next == l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 test_assert(l4->prev == l3 && l4->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 /* remove from head */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 DLLIST2_REMOVE(&head, &tail, l1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 test_assert(l1->prev == NULL && l1->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 test_assert(head == l3 && tail == l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 test_assert(l3->prev == NULL && l3->next == l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 test_assert(l4->prev == l3 && l4->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 /* remove from tail */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
114 DLLIST2_PREPEND(&head, &tail, l1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 DLLIST2_REMOVE(&head, &tail, l4); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
116 test_assert(l4->prev == NULL && l4->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 test_assert(head == l1 && tail == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 test_assert(l1->prev == NULL && l1->next == l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 test_assert(l3->prev == l1 && l3->next == NULL); |
17577
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
120 /* removal of an entry not in the list shouldn't cause the list to break */ |
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
121 DLLIST2_REMOVE(&head, &tail, &empty); |
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
122 test_assert(head == l1); |
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
123 test_assert(head == l1 && tail == l3); |
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
124 test_assert(l1->prev == NULL && l1->next == l3); |
46e47e4082d8
lib: DLLIST*_REMOVE*() no longer breaks the linked list if we try to remove item that doesn't exist there.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
125 test_assert(l3->prev == l1 && l3->next == NULL); |
10262
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 /* remove last two */ |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 DLLIST2_REMOVE(&head, &tail, l1); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 DLLIST2_REMOVE(&head, &tail, l3); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 test_assert(l3->prev == NULL && l3->next == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 test_assert(head == NULL && tail == NULL); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 test_end(); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 } |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 void test_llist(void) |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 { |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 test_dllist(); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 test_dllist2(); |
07e0e2b4abe1
Added DLLIST2_*() functions for doubly linked list with head and tail.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 } |