1 #define MAIN(x) list##x
5 static a_size
a_list_len(a_list
const *ctx
)
9 else if (ctx
!= ctx
->next
)
12 A_LIST_FOREACH_NEXT(it
, ctx
)
16 printf("\nwarning endless loop!\n");
22 else if (ctx
!= ctx
->prev
)
25 A_LIST_FOREACH_PREV(it
, ctx
)
29 printf("\nwarning endless loop!\n");
44 static void test_next(void)
47 a_list
*list1
, *list2
;
48 a_list
*it
, *at
, *next
;
49 list1
= a_new(a_list
, A_NULL
, 1);
51 for (i
= 0; i
!= 10; ++i
)
53 data
*node
= a_new(data
, A_NULL
, 1);
55 a_list_add_prev(list1
, &node
->node
);
57 a_list_rot_prev(list1
);
58 list2
= a_new(a_list
, A_NULL
, 1);
60 for (i
= 10; i
!= 21; ++i
)
62 data
*node
= a_new(data
, A_NULL
, 1);
64 a_list_add_prev(list2
, &node
->node
);
67 data
*node
= a_list_entry_prev(list2
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
68 a_list_del_prev(list2
);
72 a_list_mov_prev(list1
, list2
);
73 A_LIST_FOREACH_NEXT(it
, list1
)
75 data
*node
= a_list_entry(it
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
76 printf("%i ", node
->data
.i
);
78 printf("%" PRIz
"u", a_list_len(list1
));
79 A_LIST_FORSAFE_NEXT(it
, at
, list1
)
81 data
*node
= a_list_entry(it
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
82 a_list_del_node(&node
->node
);
85 if (list1
->next
== list1
&& list2
->next
== next
)
94 static void test_prev(void)
97 a_list
*list1
, *list2
;
98 a_list
*it
, *at
, *prev
;
99 list1
= a_new(a_list
, A_NULL
, 1);
101 for (i
= 0; i
!= 10; ++i
)
103 data
*node
= a_new(data
, A_NULL
, 1);
105 a_list_add_next(list1
, &node
->node
);
107 a_list_rot_next(list1
);
108 list2
= a_new(a_list
, A_NULL
, 1);
110 for (i
= 10; i
!= 21; ++i
)
112 data
*node
= a_new(data
, A_NULL
, 1);
114 a_list_add_next(list2
, &node
->node
);
117 data
*node
= a_list_entry_next(list2
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
118 a_list_del_next(list2
);
122 a_list_mov_next(list1
, list2
);
123 A_LIST_FOREACH_PREV(it
, list1
)
125 data
*node
= a_list_entry(it
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
126 printf("%i ", node
->data
.i
);
128 printf("%" PRIz
"u", a_list_len(list1
));
129 A_LIST_FORSAFE_PREV(it
, at
, list1
)
131 data
*node
= a_list_entry(it
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
132 a_list_del_node(&node
->node
);
135 if (list1
->prev
== list1
&& list2
->prev
== prev
)
144 static void test_func(void)
149 a_list
*list1
, *list2
;
150 list1
= a_new(a_list
, A_NULL
, 1);
152 for (i
= 0; i
!= 10; ++i
)
154 data
*node
= a_new(data
, A_NULL
, 1);
156 a_list_add_prev(list1
, &node
->node
);
158 list2
= a_new(a_list
, A_NULL
, 1);
160 for (i
= 10; i
!= 20; ++i
)
162 data
*node
= a_new(data
, A_NULL
, 1);
164 a_list_add_prev(list2
, &node
->node
);
166 ctx
= a_new(data
, A_NULL
, 1);
169 a_list
*ptr
= list2
->prev
;
170 a_list_set_node(ptr
, &ctx
->node
);
171 ctx
= a_list_entry(ptr
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
173 a_list_swap_node(list2
->prev
, list2
->next
);
174 A_LIST_FOREACH_NEXT(it
, list1
)
176 data
*node
= a_list_entry(it
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
177 printf("%i ", node
->data
.i
);
179 A_LIST_FOREACH_NEXT(it
, list2
)
181 data
*node
= a_list_entry(it
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
182 printf("%i ", node
->data
.i
);
184 printf("%" PRIz
"u", a_list_len(list1
) + a_list_len(list2
));
185 A_LIST_FORSAFE_NEXT(it
, at
, list1
)
187 data
*node
= a_list_entry(it
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
188 a_list_del_node(&node
->node
);
191 A_LIST_FORSAFE_NEXT(it
, at
, list2
)
193 data
*node
= a_list_entry(it
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
194 a_list_del_node(&node
->node
);
197 if (list1
->next
== list1
&& list2
->next
== list2
)
207 static void test_null(void)
209 static a_list list1
= A_LIST_INIT(list1
);
210 static a_list list2
= A_LIST_INIT(list2
);
211 a_size len
= a_list_len(&list1
) + a_list_len(&list2
);
213 a_list_add_next(&list1
, &list1
);
214 len
= a_list_len(&list1
) + a_list_len(&list2
);
217 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
220 a_list_add_prev(&list1
, &list1
);
221 len
= a_list_len(&list1
) + a_list_len(&list2
);
224 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
227 a_list_add_next(&list1
, &list2
);
228 len
= a_list_len(&list1
) + a_list_len(&list2
);
231 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
234 a_list_add_prev(&list1
, &list2
);
235 len
= a_list_len(&list1
) + a_list_len(&list2
);
238 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
241 a_list_del_node(&list1
);
242 a_list_del_node(&list1
);
243 a_list_del_next(&list1
);
244 a_list_del_prev(&list1
);
246 len
= a_list_len(&list1
) + a_list_len(&list2
);
249 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
252 a_list_rot_next(&list1
);
253 a_list_rot_prev(&list1
);
254 len
= a_list_len(&list1
) + a_list_len(&list2
);
257 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
260 a_list_link(&list1
, &list2
);
261 a_list_loop(&list1
, &list2
);
262 len
= a_list_len(&list1
) + a_list_len(&list2
);
265 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
268 a_list_rot_next(&list1
);
269 a_list_rot_prev(&list1
);
270 a_list_rot_prev(&list1
);
271 len
= a_list_len(&list1
) + a_list_len(&list2
);
274 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
277 a_list_swap_node(&list1
, &list1
);
278 a_list_swap_node(&list2
, &list2
);
279 len
= a_list_len(&list1
) + a_list_len(&list2
);
282 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
285 a_list_swap_node(&list1
, &list2
);
286 len
= a_list_len(&list1
) + a_list_len(&list2
);
289 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
292 a_list_swap_node(&list2
, &list1
);
293 len
= a_list_len(&list1
) + a_list_len(&list2
);
296 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
299 a_list_set_node(&list1
, &list1
);
300 a_list_set_node(&list2
, &list2
);
301 len
= a_list_len(&list1
) + a_list_len(&list2
);
304 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
307 a_list_set_node(&list2
, &list1
);
309 len
= a_list_len(&list1
) + a_list_len(&list2
);
312 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
316 int main(int argc
, char *argv
[]) /* NOLINT(misc-definitions-in-headers) */