1 #define MAIN(x) list##x
5 static a_size
a_list_len(a_list
const *ctx
)
9 else if (ctx
!= ctx
->next
)
11 a_list_foreach_next(it
, ctx
)
15 printf("\nwarning endless loop!\n");
21 else if (ctx
!= ctx
->prev
)
23 a_list_foreach_prev(it
, ctx
)
27 printf("\nwarning endless loop!\n");
42 static void test_next(void)
44 a_list
*list1
= a_new(a_list
, A_NULL
, 1);
46 for (int i
= 0; i
!= 10; ++i
)
48 data
*node
= a_new(data
, A_NULL
, 1);
50 a_list_add_prev(list1
, &node
->node
);
52 a_list_rot_prev(list1
);
53 a_list
*list2
= a_new(a_list
, A_NULL
, 1);
55 for (int i
= 10; i
!= 21; ++i
)
57 data
*node
= a_new(data
, A_NULL
, 1);
59 a_list_add_prev(list2
, &node
->node
);
62 data
*node
= a_list_entry_prev(list2
, data
, node
); // NOLINT(performance-no-int-to-ptr)
63 a_list_del_prev(list2
);
66 a_list
*next
= list2
->next
;
67 a_list_mov_prev(list1
, list2
);
68 a_list_foreach_next(it
, list1
)
70 data
*node
= a_list_entry(it
, data
, node
); // NOLINT(performance-no-int-to-ptr)
71 printf("%i ", node
->data
.i
);
73 printf("%" PRIz
"u", a_list_len(list1
));
74 a_list_forsafe_next(it
, pre
, list1
)
76 data
*node
= a_list_entry(it
, data
, node
); // NOLINT(performance-no-int-to-ptr)
77 a_list_del_node(&node
->node
);
80 if (list1
->next
== list1
&& list2
->next
== next
)
89 static void test_prev(void)
91 a_list
*list1
= a_new(a_list
, A_NULL
, 1);
93 for (int i
= 0; i
!= 10; ++i
)
95 data
*node
= a_new(data
, A_NULL
, 1);
97 a_list_add_next(list1
, &node
->node
);
99 a_list_rot_next(list1
);
100 a_list
*list2
= a_new(a_list
, A_NULL
, 1);
102 for (int i
= 10; i
!= 21; ++i
)
104 data
*node
= a_new(data
, A_NULL
, 1);
106 a_list_add_next(list2
, &node
->node
);
109 data
*node
= a_list_entry_next(list2
, data
, node
); // NOLINT(performance-no-int-to-ptr)
110 a_list_del_next(list2
);
113 a_list
*prev
= list2
->prev
;
114 a_list_mov_next(list1
, list2
);
115 a_list_foreach_prev(it
, list1
)
117 data
*node
= a_list_entry(it
, data
, node
); // NOLINT(performance-no-int-to-ptr)
118 printf("%i ", node
->data
.i
);
120 printf("%" PRIz
"u", a_list_len(list1
));
121 a_list_forsafe_prev(it
, pre
, list1
)
123 data
*node
= a_list_entry(it
, data
, node
); // NOLINT(performance-no-int-to-ptr)
124 a_list_del_node(&node
->node
);
127 if (list1
->prev
== list1
&& list2
->prev
== prev
)
136 static void test_func(void)
138 a_list
*list1
= a_new(a_list
, A_NULL
, 1);
140 for (int i
= 0; i
!= 10; ++i
)
142 data
*node
= a_new(data
, A_NULL
, 1);
144 a_list_add_prev(list1
, &node
->node
);
146 a_list
*list2
= a_new(a_list
, A_NULL
, 1);
148 for (int i
= 10; i
!= 20; ++i
)
150 data
*node
= a_new(data
, A_NULL
, 1);
152 a_list_add_prev(list2
, &node
->node
);
154 data
*ctx
= a_new(data
, A_NULL
, 1);
157 a_list
*ptr
= list2
->prev
;
158 a_list_set_node(ptr
, &ctx
->node
);
159 ctx
= a_list_entry(ptr
, data
, node
); // NOLINT(performance-no-int-to-ptr)
161 a_list_swap_node(list2
->prev
, list2
->next
);
162 a_list_foreach_next(it
, list1
)
164 data
*node
= a_list_entry(it
, data
, node
); // NOLINT(performance-no-int-to-ptr)
165 printf("%i ", node
->data
.i
);
167 a_list_foreach_next(it
, list2
)
169 data
*node
= a_list_entry(it
, data
, node
); // NOLINT(performance-no-int-to-ptr)
170 printf("%i ", node
->data
.i
);
172 printf("%" PRIz
"u", a_list_len(list1
) + a_list_len(list2
));
173 a_list_forsafe_next(it
, at
, list1
)
175 data
*node
= a_list_entry(it
, data
, node
); // NOLINT(performance-no-int-to-ptr)
176 a_list_del_node(&node
->node
);
179 a_list_forsafe_next(it
, at
, list2
)
181 data
*node
= a_list_entry(it
, data
, node
); // NOLINT(performance-no-int-to-ptr)
182 a_list_del_node(&node
->node
);
185 if (list1
->next
== list1
&& list2
->next
== list2
)
195 static void test_null(void)
197 static a_list list1
= A_LIST_INIT(list1
);
198 static a_list list2
= A_LIST_INIT(list2
);
199 a_size len
= a_list_len(&list1
) + a_list_len(&list2
);
201 a_list_add_next(&list1
, &list1
);
202 len
= a_list_len(&list1
) + a_list_len(&list2
);
205 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
208 a_list_add_prev(&list1
, &list1
);
209 len
= a_list_len(&list1
) + a_list_len(&list2
);
212 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
215 a_list_add_next(&list1
, &list2
);
216 len
= a_list_len(&list1
) + a_list_len(&list2
);
219 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
222 a_list_add_prev(&list1
, &list2
);
223 len
= a_list_len(&list1
) + a_list_len(&list2
);
226 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
229 a_list_del_node(&list1
);
230 a_list_del_node(&list1
);
231 a_list_del_next(&list1
);
232 a_list_del_prev(&list1
);
234 len
= a_list_len(&list1
) + a_list_len(&list2
);
237 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
240 a_list_rot_next(&list1
);
241 a_list_rot_prev(&list1
);
242 len
= a_list_len(&list1
) + a_list_len(&list2
);
245 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
248 a_list_link(&list1
, &list2
);
249 a_list_loop(&list1
, &list2
);
250 len
= a_list_len(&list1
) + a_list_len(&list2
);
253 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
256 a_list_rot_next(&list1
);
257 a_list_rot_prev(&list1
);
258 a_list_rot_prev(&list1
);
259 len
= a_list_len(&list1
) + a_list_len(&list2
);
262 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
265 a_list_swap_node(&list1
, &list1
);
266 a_list_swap_node(&list2
, &list2
);
267 len
= a_list_len(&list1
) + a_list_len(&list2
);
270 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
273 a_list_swap_node(&list1
, &list2
);
274 len
= a_list_len(&list1
) + a_list_len(&list2
);
277 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
280 a_list_swap_node(&list2
, &list1
);
281 len
= a_list_len(&list1
) + a_list_len(&list2
);
284 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
287 a_list_set_node(&list1
, &list1
);
288 a_list_set_node(&list2
, &list2
);
289 len
= a_list_len(&list1
) + a_list_len(&list2
);
292 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
295 a_list_set_node(&list2
, &list1
);
297 len
= a_list_len(&list1
) + a_list_len(&list2
);
300 printf("failure in %s %i %" PRIz
"u\n", __FILE__
, __LINE__
, len
);
304 int main(int argc
, char *argv
[]) // NOLINT(misc-definitions-in-headers)
308 printf("%s\n", A_FUNC
);