The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
dcursor_typed_tests.c
Go to the documentation of this file.
1 #include <freeradius-devel/util/acutest.h>
2 
3 #include "dcursor.c"
4 
5 /*
6  * A repeat of the tests in dcursor_tests.c, but using
7  * type specific dcursors
8  */
9 
10 FR_DLIST_TYPES(test_list)
11 
12 typedef struct {
13  char const *name;
14  FR_DLIST_ENTRY(test_list) entry;
15 } test_item_t;
16 
17 FR_DLIST_FUNCS(test_list, test_item_t, entry)
18 
19 FR_DCURSOR_DLIST_TYPES(test_dcursor, test_list, test_item_t)
20 
21 FR_DCURSOR_FUNCS(test_dcursor, test_list, test_item_t)
22 
23 static test_item_t *test_iter(FR_DLIST_HEAD(test_list) *list, test_item_t *current, UNUSED void *uctx)
24 {
25  return test_list_next(list, current);
26 }
27 
28 static void test_init_null_item(void)
29 {
30  FR_DCURSOR(test_dcursor) cursor;
31  test_item_t *item_p;
32  FR_DLIST_HEAD(test_list) list;
33 
34  test_list_init(&list);
35 
36  item_p = test_dcursor_iter_init(&cursor, &list, test_iter, NULL, &cursor);
37  TEST_CHECK(!item_p);
38  TEST_CHECK((cursor.dcursor.dlist) == &list.head);
39  TEST_CHECK(!test_dcursor_current(&cursor));
40  TEST_CHECK(!test_dcursor_list_next_peek(&cursor));
41  TEST_CHECK(cursor.dcursor.iter_uctx == &cursor);
42 }
43 
44 static void test_init_1i_start(void)
45 {
46  FR_DCURSOR(test_dcursor) cursor;
47  test_item_t item1 = { "item1", { { NULL, NULL } } };
48  test_item_t *item_p;
49  FR_DLIST_HEAD(test_list) list;
50 
51  test_list_init(&list);
52  test_list_insert_tail(&list, &item1);
53 
54  item_p = test_dcursor_init(&cursor, &list);
55  TEST_CHECK(item_p == &item1);
56  TEST_CHECK((cursor.dcursor.dlist) == &list.head);
57  TEST_CHECK(test_dcursor_current(&cursor) == &item1);
58 }
59 
60 static void test_init_2i_start(void)
61 {
62  FR_DCURSOR(test_dcursor) cursor;
63  test_item_t item1 = { "item1", { { NULL, NULL } } };
64  test_item_t item2 = { "item2", { { NULL, NULL } } };
65  test_item_t *item_p;
66  FR_DLIST_HEAD(test_list) list;
67 
68  test_list_init(&list);
69  test_list_insert_tail(&list, &item1);
70  test_list_insert_tail(&list, &item2);
71 
72  item_p = test_dcursor_init(&cursor, &list);
73  TEST_CHECK(item_p == &item1);
74  TEST_CHECK(test_dcursor_current(&cursor) == &item1);
75 }
76 
77 static void test_next(void)
78 {
79  FR_DCURSOR(test_dcursor) cursor;
80  test_item_t item1 = { "item1", { { NULL, NULL } } };
81  test_item_t item2 = { "item2", { { NULL, NULL } } };
82  test_item_t *item_p;
83  FR_DLIST_HEAD(test_list) list;
84 
85  test_list_init(&list);
86  test_list_insert_tail(&list, &item1);
87  test_list_insert_tail(&list, &item2);
88 
89  test_dcursor_init(&cursor, &list);
90  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item2);
91 
92  item_p = test_dcursor_next(&cursor);
93  TEST_CHECK(item_p == &item2);
94  TEST_CHECK(test_dcursor_current(&cursor) == &item2);
95  TEST_CHECK(!test_dcursor_next_peek(&cursor));
96 }
97 
98 static void test_next_wrap(void)
99 {
100  FR_DCURSOR(test_dcursor) cursor;
101  test_item_t item1 = { "item1", { { NULL, NULL } } };
102  test_item_t item2 = { "item2", { { NULL, NULL } } };
103  test_item_t *item_p;
104  FR_DLIST_HEAD(test_list) list;
105 
106  test_list_init(&list);
107  test_list_insert_tail(&list, &item1);
108  test_list_insert_tail(&list, &item2);
109 
110  test_dcursor_init(&cursor, &list);
111  test_dcursor_next(&cursor);
112  item_p = test_dcursor_next(&cursor);
113  TEST_CHECK(!item_p);
114  TEST_CHECK(!test_dcursor_current(&cursor));
115  TEST_CHECK(!test_dcursor_next_peek(&cursor));
116 
117  item_p = test_dcursor_next(&cursor);
118  TEST_CHECK(!item_p);
119  TEST_CHECK(!test_dcursor_current(&cursor));
120  TEST_CHECK(!test_dcursor_next_peek(&cursor));
121 }
122 
124 {
125  FR_DCURSOR(test_dcursor) cursor;
126  FR_DLIST_HEAD(test_list) list;
127 
128  test_list_init(&list);
129 
130  test_dcursor_init(&cursor, &list);
131  TEST_CHECK(!test_dcursor_current(&cursor));
132  TEST_CHECK(!test_dcursor_head(&cursor));
133  TEST_CHECK(!test_dcursor_tail(&cursor));
134 }
135 
136 static void test_dcursor_test_head(void)
137 {
138  FR_DCURSOR(test_dcursor) cursor;
139  test_item_t item1 = { "item1", { { NULL, NULL } } };
140  test_item_t item2 = { "item2", { { NULL, NULL } } };
141  test_item_t item3 = { "item3", { { NULL, NULL } } };
142  test_item_t *item_p;
143  FR_DLIST_HEAD(test_list) list;
144 
145  test_list_init(&list);
146  test_list_insert_tail(&list, &item1);
147  test_list_insert_tail(&list, &item2);
148  test_list_insert_tail(&list, &item3);
149 
150  test_dcursor_init(&cursor, &list);
151  item_p = test_dcursor_head(&cursor);
152  TEST_CHECK(item_p == &item1);
153 }
154 
155 static void test_dcursor_head_reset(void)
156 {
157  FR_DCURSOR(test_dcursor) cursor;
158  test_item_t item1 = { "item1", { { NULL, NULL } } };
159  test_item_t item2 = { "item2", { { NULL, NULL } } };
160  test_item_t *item_p;
161  FR_DLIST_HEAD(test_list) list;
162 
163  test_list_init(&list);
164  test_list_insert_tail(&list, &item1);
165  test_list_insert_tail(&list, &item2);
166 
167  test_dcursor_init(&cursor, &list);
168 
169  item_p = test_dcursor_head(&cursor);
170  TEST_CHECK(item_p == &item1);
171 
172  item_p = test_dcursor_next(&cursor);
173  TEST_CHECK(item_p == &item2);
174 
175  item_p = test_dcursor_next(&cursor);
176  TEST_CHECK(item_p == NULL);
177 
178  item_p = test_dcursor_head(&cursor);
179  TEST_CHECK(item_p == &item1);
180 
181  item_p = test_dcursor_current(&cursor);
182  TEST_CHECK(item_p == &item1);
183 }
184 
186 {
187  FR_DCURSOR(test_dcursor) cursor;
188  test_item_t item1 = { "item1", { { NULL, NULL } } };
189  test_item_t item2 = { "item2", { { NULL, NULL } } };
190  test_item_t *item_p;
191  FR_DLIST_HEAD(test_list) list;
192 
193  test_list_init(&list);
194  test_list_insert_tail(&list, &item1);
195  test_list_insert_tail(&list, &item2);
196 
197  item_p = test_dcursor_iter_init(&cursor, &list, test_iter, NULL, &cursor);
198  TEST_CHECK(item_p == &item1);
199 
200  item_p = test_dcursor_next(&cursor);
201  TEST_CHECK(item_p == &item2);
202 
203  item_p = test_dcursor_next(&cursor);
204  TEST_CHECK(item_p == NULL);
205 
206  item_p = test_dcursor_head(&cursor);
207  TEST_CHECK(item_p == &item1);
208 
209  item_p = test_dcursor_current(&cursor);
210  TEST_CHECK(item_p == &item1);
211 }
212 
214 {
215  FR_DCURSOR(test_dcursor) cursor;
216  test_item_t item1 = { "item1", { { NULL, NULL } } };
217  test_item_t item2 = { "item2", { { NULL, NULL } } };
218  test_item_t item3 = { "item3", { { NULL, NULL } } };
219  test_item_t *item_p;
220  FR_DLIST_HEAD(test_list) list;
221 
222  test_list_init(&list);
223  test_list_insert_tail(&list, &item1);
224  test_list_insert_tail(&list, &item2);
225  test_list_insert_tail(&list, &item3);
226 
227  test_dcursor_init(&cursor, &list);
228  test_dcursor_next(&cursor);
229  item_p = test_dcursor_head(&cursor);
230  TEST_CHECK(item_p == &item1);
231 }
232 
233 static void test_dcursor_test_tail(void)
234 {
235  FR_DCURSOR(test_dcursor) cursor;
236  test_item_t item1 = { "item1", { { NULL, NULL } } };
237  test_item_t item2 = { "item2", { { NULL, NULL } } };
238  test_item_t item3 = { "item3", { { NULL, NULL } } };
239  test_item_t *item_p;
240  FR_DLIST_HEAD(test_list) list;
241 
242  test_list_init(&list);
243  test_list_insert_tail(&list, &item1);
244  test_list_insert_tail(&list, &item2);
245  test_list_insert_tail(&list, &item3);
246 
247  test_dcursor_init(&cursor, &list);
248  test_dcursor_next(&cursor);
249  item_p = test_dcursor_tail(&cursor);
250  TEST_CHECK(item_p == &item3);
251  item_p = test_dcursor_current(&cursor);
252  TEST_CHECK(item_p == &item3);
253 }
254 
256 {
257  FR_DCURSOR(test_dcursor) cursor;
258  test_item_t item1 = { "item1", { { NULL, NULL } } };
259  test_item_t item2 = { "item2", { { NULL, NULL } } };
260  test_item_t item3 = { "item3", { { NULL, NULL } } };
261  test_item_t *item_p;
262  FR_DLIST_HEAD(test_list) list;
263 
264  test_list_init(&list);
265  test_list_insert_tail(&list, &item1);
266  test_list_insert_tail(&list, &item2);
267  test_list_insert_tail(&list, &item3);
268 
269  test_dcursor_init(&cursor, &list);
270  test_dcursor_tail(&cursor);
271  item_p = test_dcursor_head(&cursor);
272  TEST_CHECK(item_p == &item1);
273 }
274 
276 {
277  FR_DCURSOR(test_dcursor) cursor;
278  test_item_t item1 = { "item1", { { NULL, NULL } } };
279  test_item_t item2 = { "item2", { { NULL, NULL } } };
280  test_item_t item3 = { "item3", { { NULL, NULL } } };
281  test_item_t *item_p;
282  FR_DLIST_HEAD(test_list) list;
283 
284  test_list_init(&list);
285  test_list_insert_tail(&list, &item1);
286  test_list_insert_tail(&list, &item2);
287  test_list_insert_tail(&list, &item3);
288 
289  test_dcursor_init(&cursor, &list);
290  test_dcursor_tail(&cursor);
291  item_p = test_dcursor_next(&cursor);
292  TEST_CHECK(!item_p);
293 
294  item_p = test_dcursor_next(&cursor);
295  TEST_CHECK(!item_p);
296 }
297 
298 static void test_dcursor_append_empty(void)
299 {
300  FR_DCURSOR(test_dcursor) cursor;
301  test_item_t *item_p;
302  test_item_t item1 = { "item1", { { NULL, NULL } } };
303  FR_DLIST_HEAD(test_list) list;
304 
305  test_list_init(&list);
306  test_dcursor_init(&cursor, &list);
307  test_dcursor_append(&cursor, &item1);
308 
309  item_p = test_dcursor_current(&cursor);
310  TEST_CHECK(!item_p);
311  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item1);
312 }
313 
315 {
316  FR_DCURSOR(test_dcursor) cursor;
317  test_item_t item1 = { "item1", { { NULL, NULL } } };
318  test_item_t item2 = { "item2", { { NULL, NULL } } };
319  test_item_t item3 = { "item3", { { NULL, NULL } } };
320  test_item_t *item_p;
321  FR_DLIST_HEAD(test_list) list;
322 
323  test_list_init(&list);
324 
325  test_dcursor_init(&cursor, &list);
326  test_dcursor_append(&cursor, &item1);
327  test_dcursor_append(&cursor, &item2);
328  test_dcursor_append(&cursor, &item3);
329 
330  item_p = test_dcursor_current(&cursor);
331  TEST_CHECK(!item_p);
332  TEST_CHECK(test_dcursor_next(&cursor) == &item1);
333  TEST_CHECK(test_dcursor_next(&cursor) == &item2);
334  TEST_CHECK(test_dcursor_next(&cursor) == &item3);
335 }
336 
337 static void test_dcursor_prepend_empty(void)
338 {
339  FR_DCURSOR(test_dcursor) cursor;
340  test_item_t *item_p;
341  test_item_t item1 = { "item1", { { NULL, NULL } } };
342  FR_DLIST_HEAD(test_list) list;
343 
344  test_list_init(&list);
345 
346  test_dcursor_init(&cursor, &list);
347  test_dcursor_prepend(&cursor, &item1);
348 
349  item_p = test_dcursor_current(&cursor);
350  TEST_CHECK(!item_p);
351  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item1);
352 }
353 
355 {
356  FR_DCURSOR(test_dcursor) cursor;
357  test_item_t item1 = { "item1", { { NULL, NULL } } };
358  test_item_t item2 = { "item2", { { NULL, NULL } } };
359  test_item_t item3 = { "item3", { { NULL, NULL } } };
360  test_item_t *item_p;
361  FR_DLIST_HEAD(test_list) list;
362 
363  test_list_init(&list);
364 
365  test_dcursor_init(&cursor, &list);
366  test_dcursor_prepend(&cursor, &item1);
367  test_dcursor_prepend(&cursor, &item2);
368  test_dcursor_prepend(&cursor, &item3);
369 
370  item_p = test_dcursor_current(&cursor);
371  TEST_CHECK(!item_p);
372  TEST_CHECK(test_dcursor_next(&cursor) == &item3);
373  TEST_CHECK(test_dcursor_next(&cursor) == &item2);
374  TEST_CHECK(test_dcursor_next(&cursor) == &item1);
375 }
376 
378 {
379  FR_DCURSOR(test_dcursor) cursor;
380  test_item_t *item_p;
381  test_item_t item1 = { "item1", { { NULL, NULL } } };
382  FR_DLIST_HEAD(test_list) list;
383 
384  test_list_init(&list);
385 
386  test_dcursor_init(&cursor, &list);
387  test_dcursor_insert(&cursor, &item1);
388 
389  item_p = test_dcursor_current(&cursor);
390  TEST_CHECK(!item_p);
391  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item1);
392 }
393 
395 {
396  FR_DCURSOR(test_dcursor) cursor;
397  test_item_t item1 = { "item1", { { NULL, NULL } } };
398  test_item_t item2 = { "item2", { { NULL, NULL } } };
399  test_item_t item3 = { "item3", { { NULL, NULL } } };
400  test_item_t *item_p;
401  FR_DLIST_HEAD(test_list) list;
402 
403  test_list_init(&list);
404 
405  test_dcursor_init(&cursor, &list);
406  test_dcursor_insert(&cursor, &item1);
407  test_dcursor_insert(&cursor, &item2);
408  test_dcursor_insert(&cursor, &item3);
409 
410  item_p = test_dcursor_current(&cursor);
411  TEST_CHECK(!item_p);
412  TEST_CHECK(test_dcursor_next(&cursor) == &item1);
413  TEST_CHECK(test_dcursor_next(&cursor) == &item2);
414  TEST_CHECK(test_dcursor_next(&cursor) == &item3);
415 }
416 
418 {
419  FR_DCURSOR(test_dcursor) cursor;
420  test_item_t *item_p;
421  test_item_t item1 = { "item1", { { NULL, NULL } } };
422  FR_DLIST_HEAD(test_list) list;
423 
424  test_list_init(&list);
425 
426  test_dcursor_init(&cursor, &list);
427  TEST_CHECK(!test_dcursor_replace(&cursor, &item1));
428 
429  item_p = test_dcursor_current(&cursor);
430  TEST_CHECK(!item_p);
431  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item1);
432 }
433 
435 {
436  FR_DCURSOR(test_dcursor) cursor;
437  test_item_t item1 = { "item1", { { NULL, NULL } } };
438  test_item_t item2 = { "item2", { { NULL, NULL } } };
439  test_item_t *item_p;
440  FR_DLIST_HEAD(test_list) list;
441 
442  test_list_init(&list);
443  test_list_insert_tail(&list, &item1);
444 
445  test_dcursor_init(&cursor, &list);
446  test_dcursor_prepend(&cursor, &item2);
447 
448  TEST_CHECK(test_dcursor_current(&cursor) == &item1);
449  TEST_CHECK(!test_dcursor_next_peek(&cursor));
450 
451  item_p = test_dcursor_next(&cursor);
452  TEST_CHECK(!item_p);
453 
454  item_p = test_dcursor_head(&cursor);
455  TEST_CHECK(item_p == &item2);
456  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item1);
457 
458  item_p = test_dcursor_tail(&cursor);
459  TEST_CHECK(item_p == &item1);
460 }
461 
463 {
464  FR_DCURSOR(test_dcursor) cursor;
465  test_item_t item1 = { "item1", { { NULL, NULL } } };
466  test_item_t item2 = { "item2", { { NULL, NULL } } };
467  test_item_t *item_p;
468  FR_DLIST_HEAD(test_list) list;
469 
470  test_list_init(&list);
471  test_list_insert_tail(&list, &item1);
472 
473  test_dcursor_init(&cursor, &list);
474  test_dcursor_append(&cursor, &item2);
475 
476  TEST_CHECK(test_dcursor_current(&cursor) == &item1);
477  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item2);
478 
479  item_p = test_dcursor_next(&cursor);
480  TEST_CHECK(item_p == &item2);
481 
482  item_p = test_dcursor_head(&cursor);
483  TEST_CHECK(item_p == &item1);
484 
485  item_p = test_dcursor_tail(&cursor);
486  TEST_CHECK(item_p == &item2);
487 }
488 
490 {
491  FR_DCURSOR(test_dcursor) cursor;
492  test_item_t item1 = { "item1", { { NULL, NULL } } };
493  test_item_t item2 = { "item2", { { NULL, NULL } } };
494  test_item_t *item_p;
495  FR_DLIST_HEAD(test_list) list;
496 
497  test_list_init(&list);
498  test_list_insert_tail(&list, &item1);
499 
500  test_dcursor_init(&cursor, &list);
501  test_dcursor_append(&cursor, &item2);
502 
503  TEST_CHECK(test_dcursor_current(&cursor) == &item1);
504  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item2);
505 
506  item_p = test_dcursor_next(&cursor);
507  TEST_CHECK(item_p == &item2);
508 
509  item_p = test_dcursor_head(&cursor);
510  TEST_CHECK(item_p == &item1);
511 
512  item_p = test_dcursor_tail(&cursor);
513  TEST_CHECK(item_p == &item2);
514 }
515 
517 {
518  FR_DCURSOR(test_dcursor) cursor;
519  test_item_t item1 = { "item1", { { NULL, NULL } } };
520  test_item_t item2 = { "item2", { { NULL, NULL } } };
521  test_item_t *item_p;
522  FR_DLIST_HEAD(test_list) list;
523 
524  test_list_init(&list);
525  test_list_insert_tail(&list, &item1);
526 
527  test_dcursor_init(&cursor, &list);
528  item_p = test_dcursor_replace(&cursor, &item2);
529  TEST_CHECK(item_p == &item1);
530 
531  item_p = test_dcursor_current(&cursor);
532  TEST_CHECK(item_p == &item2);
533 
534  item_p = test_dcursor_head(&cursor);
535  TEST_CHECK(item_p == &item2);
536 
537  item_p = test_dcursor_tail(&cursor);
538  TEST_CHECK(item_p == &item2);
539 }
540 
542 {
543  FR_DCURSOR(test_dcursor) cursor;
544  test_item_t item1 = { "item1", { { NULL, NULL } } };
545  test_item_t item2 = { "item2", { { NULL, NULL } } };
546  test_item_t item3 = { "item3", { { NULL, NULL } } };
547  test_item_t *item_p;
548  FR_DLIST_HEAD(test_list) list;
549 
550  test_list_init(&list);
551  test_list_insert_tail(&list, &item1);
552  test_list_insert_tail(&list, &item2);
553 
554  test_dcursor_init(&cursor, &list);
555  test_dcursor_prepend(&cursor, &item3);
556 
557  TEST_CHECK(test_dcursor_current(&cursor) == &item1);
558  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item2);
559 
560  item_p = test_dcursor_next(&cursor);
561  TEST_CHECK(item_p == &item2);
562 
563  item_p = test_dcursor_next(&cursor);
564  TEST_CHECK(!item_p);
565 
566  item_p = test_dcursor_head(&cursor);
567  TEST_CHECK(item_p == &item3);
568 
569  item_p = test_dcursor_tail(&cursor);
570  TEST_CHECK(item_p == &item2);
571 }
572 
574 {
575  FR_DCURSOR(test_dcursor) cursor;
576  test_item_t item1 = { "item1", { { NULL, NULL } } };
577  test_item_t item2 = { "item2", { { NULL, NULL } } };
578  test_item_t item3 = { "item3", { { NULL, NULL } } };
579  test_item_t *item_p;
580  FR_DLIST_HEAD(test_list) list;
581 
582  test_list_init(&list);
583  test_list_insert_tail(&list, &item1);
584  test_list_insert_tail(&list, &item2);
585 
586  test_dcursor_init(&cursor, &list);
587  test_dcursor_append(&cursor, &item3);
588 
589  TEST_CHECK(test_dcursor_current(&cursor) == &item1);
590 
591  item_p = test_dcursor_next(&cursor);
592  TEST_CHECK(item_p == &item2);
593  item_p = test_dcursor_next(&cursor);
594  TEST_CHECK(item_p == &item3);
595 
596  item_p = test_dcursor_head(&cursor);
597  TEST_CHECK(item_p == &item1);
598 
599  item_p = test_dcursor_tail(&cursor);
600  TEST_CHECK(item_p == &item3);
601 }
602 
604 {
605  FR_DCURSOR(test_dcursor) cursor;
606  test_item_t item1 = { "item1", { { NULL, NULL } } };
607  test_item_t item2 = { "item2", { { NULL, NULL } } };
608  test_item_t item3 = { "item3", { { NULL, NULL } } };
609  test_item_t *item_p;
610  FR_DLIST_HEAD(test_list) list;
611 
612  test_list_init(&list);
613  test_list_insert_tail(&list, &item1);
614  test_list_insert_tail(&list, &item2);
615 
616  test_dcursor_init(&cursor, &list);
617  test_dcursor_insert(&cursor, &item3);
618 
619  TEST_CHECK(test_dcursor_current(&cursor) == &item1);
620  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item3);
621 
622  item_p = test_dcursor_next(&cursor);
623  TEST_CHECK(item_p == &item3);
624 
625  item_p = test_dcursor_next(&cursor);
626  TEST_CHECK(item_p == &item2);
627 
628  item_p = test_dcursor_head(&cursor);
629  TEST_CHECK(item_p == &item1);
630 
631  item_p = test_dcursor_tail(&cursor);
632  TEST_CHECK(item_p == &item2);
633 }
634 
636 {
637  FR_DCURSOR(test_dcursor) cursor;
638  test_item_t item1 = { "item1", { { NULL, NULL } } };
639  test_item_t item2 = { "item2", { { NULL, NULL } } };
640  test_item_t item3 = { "item3", { { NULL, NULL } } };
641  test_item_t *item_p;
642  FR_DLIST_HEAD(test_list) list;
643 
644  test_list_init(&list);
645  test_list_insert_tail(&list, &item1);
646  test_list_insert_tail(&list, &item2);
647 
648  test_dcursor_init(&cursor, &list);
649  item_p = test_dcursor_replace(&cursor, &item3);
650  TEST_CHECK(item_p == &item1);
651 
652  item_p = test_dcursor_current(&cursor);
653  TEST_CHECK(item_p == &item3);
654 
655  item_p = test_dcursor_head(&cursor);
656  TEST_CHECK(item_p == &item3);
657 
658  item_p = test_dcursor_tail(&cursor);
659  TEST_CHECK(item_p == &item2);
660 }
661 
663 {
664  FR_DCURSOR(test_dcursor) cursor;
665  test_item_t item1 = { "item1", { { NULL, NULL } } };
666  test_item_t item2 = { "item2", { { NULL, NULL } } };
667  test_item_t item3 = { "item3", { { NULL, NULL } } };
668  test_item_t item4 = { "item4", { { NULL, NULL } } };
669  test_item_t *item_p;
670  FR_DLIST_HEAD(test_list) list;
671 
672  test_list_init(&list);
673  test_list_insert_tail(&list, &item1);
674  test_list_insert_tail(&list, &item2);
675  test_list_insert_tail(&list, &item3);
676 
677  test_dcursor_init(&cursor, &list);
678  test_dcursor_next(&cursor);
679  test_dcursor_prepend(&cursor, &item4);
680 
681  TEST_CHECK(test_dcursor_current(&cursor) == &item2);
682  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item3);
683 
684  item_p = test_dcursor_next(&cursor);
685  TEST_CHECK(item_p == &item3);
686 
687  item_p = test_dcursor_next(&cursor);
688  TEST_CHECK(!item_p);
689 
690  item_p = test_dcursor_head(&cursor);
691  TEST_CHECK(item_p == &item4);
692 
693  item_p = test_dcursor_tail(&cursor);
694  TEST_CHECK(item_p == &item3);
695 }
696 
697 static void test_dcursor_append_3i_mid(void)
698 {
699  FR_DCURSOR(test_dcursor) cursor;
700  test_item_t item1 = { "item1", { { NULL, NULL } } };
701  test_item_t item2 = { "item2", { { NULL, NULL } } };
702  test_item_t item3 = { "item3", { { NULL, NULL } } };
703  test_item_t item4 = { "item4", { { NULL, NULL } } };
704  test_item_t *item_p;
705  FR_DLIST_HEAD(test_list) list;
706 
707  test_list_init(&list);
708  test_list_insert_tail(&list, &item1);
709  test_list_insert_tail(&list, &item2);
710  test_list_insert_tail(&list, &item3);
711 
712  test_dcursor_init(&cursor, &list);
713  test_dcursor_next(&cursor);
714  test_dcursor_append(&cursor, &item4);
715 
716  TEST_CHECK(test_dcursor_current(&cursor) == &item2);
717  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item3);
718 
719  item_p = test_dcursor_next(&cursor);
720  TEST_CHECK(item_p == &item3);
721 
722  item_p = test_dcursor_head(&cursor);
723  TEST_CHECK(item_p == &item1);
724 
725  item_p = test_dcursor_tail(&cursor);
726  TEST_CHECK(item_p == &item4);
727 }
728 
729 static void test_dcursor_insert_3i_mid(void)
730 {
731  FR_DCURSOR(test_dcursor) cursor;
732  test_item_t item1 = { "item1", { { NULL, NULL } } };
733  test_item_t item2 = { "item2", { { NULL, NULL } } };
734  test_item_t item3 = { "item3", { { NULL, NULL } } };
735  test_item_t item4 = { "item4", { { NULL, NULL } } };
736  test_item_t *item_p;
737  FR_DLIST_HEAD(test_list) list;
738 
739  test_list_init(&list);
740  test_list_insert_tail(&list, &item1);
741  test_list_insert_tail(&list, &item2);
742  test_list_insert_tail(&list, &item3);
743 
744  test_dcursor_init(&cursor, &list);
745  test_dcursor_next(&cursor);
746  test_dcursor_insert(&cursor, &item4);
747 
748  TEST_CHECK(test_dcursor_current(&cursor) == &item2);
749  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item4);
750 
751  item_p = test_dcursor_next(&cursor);
752  TEST_CHECK(item_p == &item4);
753 
754  item_p = test_dcursor_next(&cursor);
755  TEST_CHECK(item_p == &item3);
756 
757  item_p = test_dcursor_head(&cursor);
758  TEST_CHECK(item_p == &item1);
759 
760  item_p = test_dcursor_tail(&cursor);
761  TEST_CHECK(item_p == &item3);
762 }
763 
765 {
766  FR_DCURSOR(test_dcursor) cursor;
767  test_item_t item1 = { "item1", { { NULL, NULL } } };
768  test_item_t item2 = { "item2", { { NULL, NULL } } };
769  test_item_t item3 = { "item3", { { NULL, NULL } } };
770  test_item_t item4 = { "item4", { { NULL, NULL } } };
771  test_item_t *item_p;
772  FR_DLIST_HEAD(test_list) list;
773 
774  test_list_init(&list);
775  test_list_insert_tail(&list, &item1);
776  test_list_insert_tail(&list, &item2);
777  test_list_insert_tail(&list, &item3);
778 
779  test_dcursor_init(&cursor, &list);
780  test_dcursor_next(&cursor);
781  item_p = test_dcursor_replace(&cursor, &item4);
782  TEST_CHECK(item_p == &item2);
783 
784  item_p = test_dcursor_current(&cursor);
785  TEST_CHECK(item_p == &item4);
786 
787  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item3);
788 
789  item_p = test_dcursor_head(&cursor);
790  TEST_CHECK(item_p == &item1);
791 
792  item_p = test_dcursor_tail(&cursor);
793  TEST_CHECK(item_p == &item3);
794 }
795 
797 {
798  FR_DCURSOR(test_dcursor) cursor;
799  test_item_t item1 = { "item1", { { NULL, NULL } } };
800  test_item_t item2 = { "item2", { { NULL, NULL } } };
801  test_item_t item3 = { "item3", { { NULL, NULL } } };
802  test_item_t item4 = { "item4", { { NULL, NULL } } };
803  test_item_t *item_p;
804  FR_DLIST_HEAD(test_list) list;
805 
806  test_list_init(&list);
807  test_list_insert_tail(&list, &item1);
808  test_list_insert_tail(&list, &item2);
809  test_list_insert_tail(&list, &item3);
810 
811  test_dcursor_init(&cursor, &list);
812  test_dcursor_next(&cursor);
813  test_dcursor_next(&cursor);
814  test_dcursor_prepend(&cursor, &item4);
815 
816  TEST_CHECK(test_dcursor_current(&cursor) == &item3);
817  TEST_CHECK(!test_dcursor_next_peek(&cursor));
818 
819  item_p = test_dcursor_next(&cursor);
820  TEST_CHECK(!item_p);
821 
822  item_p = test_dcursor_head(&cursor);
823  TEST_CHECK(item_p == &item4);
824 
825  item_p = test_dcursor_tail(&cursor);
826  TEST_CHECK(item_p == &item3);
827 }
828 
829 static void test_dcursor_append_3i_end(void)
830 {
831  FR_DCURSOR(test_dcursor) cursor;
832  test_item_t item1 = { "item1", { { NULL, NULL } } };
833  test_item_t item2 = { "item2", { { NULL, NULL } } };
834  test_item_t item3 = { "item3", { { NULL, NULL } } };
835  test_item_t item4 = { "item4", { { NULL, NULL } } };
836  test_item_t *item_p;
837  FR_DLIST_HEAD(test_list) list;
838 
839  test_list_init(&list);
840  test_list_insert_tail(&list, &item1);
841  test_list_insert_tail(&list, &item2);
842  test_list_insert_tail(&list, &item3);
843 
844  test_dcursor_init(&cursor, &list);
845  test_dcursor_next(&cursor);
846  test_dcursor_next(&cursor);
847  test_dcursor_append(&cursor, &item4);
848 
849  TEST_CHECK(test_dcursor_current(&cursor) == &item3);
850  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item4);
851 
852  item_p = test_dcursor_next(&cursor);
853  TEST_CHECK(item_p == &item4);
854 
855  item_p = test_dcursor_head(&cursor);
856  TEST_CHECK(item_p == &item1);
857 
858  item_p = test_dcursor_tail(&cursor);
859  TEST_CHECK(item_p == &item4);
860 }
861 
862 static void test_dcursor_insert_3i_end(void)
863 {
864  FR_DCURSOR(test_dcursor) cursor;
865  test_item_t item1 = { "item1", { { NULL, NULL } } };
866  test_item_t item2 = { "item2", { { NULL, NULL } } };
867  test_item_t item3 = { "item3", { { NULL, NULL } } };
868  test_item_t item4 = { "item4", { { NULL, NULL } } };
869  test_item_t *item_p;
870  FR_DLIST_HEAD(test_list) list;
871 
872  test_list_init(&list);
873  test_list_insert_tail(&list, &item1);
874  test_list_insert_tail(&list, &item2);
875  test_list_insert_tail(&list, &item3);
876 
877  test_dcursor_init(&cursor, &list);
878  test_dcursor_next(&cursor);
879  test_dcursor_next(&cursor);
880  test_dcursor_insert(&cursor, &item4);
881 
882  TEST_CHECK(test_dcursor_current(&cursor) == &item3);
883  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item4);
884 
885  item_p = test_dcursor_next(&cursor);
886  TEST_CHECK(item_p == &item4);
887 
888  item_p = test_dcursor_head(&cursor);
889  TEST_CHECK(item_p == &item1);
890 
891  item_p = test_dcursor_tail(&cursor);
892  TEST_CHECK(item_p == &item4);
893 }
894 
896 {
897  FR_DCURSOR(test_dcursor) cursor;
898  test_item_t item1 = { "item1", { { NULL, NULL } } };
899  test_item_t item2 = { "item2", { { NULL, NULL } } };
900  test_item_t item3 = { "item3", { { NULL, NULL } } };
901  test_item_t item4 = { "item4", { { NULL, NULL } } };
902  test_item_t *item_p;
903  FR_DLIST_HEAD(test_list) list;
904 
905  test_list_init(&list);
906  test_list_insert_tail(&list, &item1);
907  test_list_insert_tail(&list, &item2);
908  test_list_insert_tail(&list, &item3);
909 
910  test_dcursor_init(&cursor, &list);
911  test_dcursor_next(&cursor);
912  test_dcursor_next(&cursor);
913  item_p = test_dcursor_replace(&cursor, &item4);
914  TEST_CHECK(item_p == &item3);
915 
916  item_p = test_dcursor_current(&cursor);
917  TEST_CHECK(item_p == &item4);
918 
919  TEST_CHECK(!test_dcursor_next_peek(&cursor));
920 
921  item_p = test_dcursor_head(&cursor);
922  TEST_CHECK(item_p == &item1);
923 
924  item_p = test_dcursor_tail(&cursor);
925  TEST_CHECK(item_p == &item4);
926 }
927 
928 static void test_dcursor_remove_empty(void)
929 {
930  FR_DCURSOR(test_dcursor) cursor;
931  FR_DLIST_HEAD(test_list) list;
932 
933  test_list_init(&list);
934 
935  test_dcursor_init(&cursor, &list);
936 
937  TEST_CHECK(!test_dcursor_remove(&cursor));
938 }
939 
940 static void test_dcursor_remove_1i(void)
941 {
942  FR_DCURSOR(test_dcursor) cursor;
943  test_item_t item1 = { "item1", { { NULL, NULL } } };
944  test_item_t *item_p;
945  FR_DLIST_HEAD(test_list) list;
946 
947  test_list_init(&list);
948  test_list_insert_tail(&list, &item1);
949 
950  test_dcursor_init(&cursor, &list);
951 
952  item_p = test_dcursor_remove(&cursor);
953  TEST_CHECK(item_p == &item1);
954 
955  TEST_CHECK(!test_dcursor_current(&cursor));
956  TEST_CHECK(!test_dcursor_next(&cursor));
957  TEST_CHECK(!test_dcursor_tail(&cursor));
958  TEST_CHECK(!test_dcursor_head(&cursor));
959 }
960 
961 static void test_dcursor_remove_2i(void)
962 {
963  FR_DCURSOR(test_dcursor) cursor;
964  test_item_t item1 = { "item1", { { NULL, NULL } } };
965  test_item_t item2 = { "item2", { { NULL, NULL } } };
966  test_item_t *item_p;
967  FR_DLIST_HEAD(test_list) list;
968 
969  test_list_init(&list);
970  test_list_insert_tail(&list, &item1);
971  test_list_insert_tail(&list, &item2);
972 
973  test_dcursor_init(&cursor, &list);
974 
975  item_p = test_dcursor_remove(&cursor);
976  TEST_CHECK(item_p == &item1);
977 
978  TEST_CHECK(test_dcursor_current(&cursor) == &item2);
979  TEST_CHECK(!test_dcursor_next(&cursor));
980  TEST_CHECK(test_dcursor_tail(&cursor) == &item2);
981  TEST_CHECK(test_dcursor_head(&cursor) == &item2);
982 
983  item_p = test_dcursor_remove(&cursor);
984  TEST_CHECK(item_p == &item2);
985 
986  TEST_CHECK(!test_dcursor_current(&cursor));
987  TEST_CHECK(!test_dcursor_next(&cursor));
988  TEST_CHECK(!test_dcursor_tail(&cursor));
989  TEST_CHECK(!test_dcursor_head(&cursor));
990 }
991 
993 {
994  FR_DCURSOR(test_dcursor) cursor;
995  test_item_t item1 = { "item1", { { NULL, NULL } } };
996  test_item_t item2 = { "item2", { { NULL, NULL } } };
997  test_item_t item3 = { "item3", { { NULL, NULL } } };
998  test_item_t *item_p;
999  FR_DLIST_HEAD(test_list) list;
1000 
1001  test_list_init(&list);
1002  test_list_insert_tail(&list, &item1);
1003  test_list_insert_tail(&list, &item2);
1004  test_list_insert_tail(&list, &item3);
1005 
1006  test_dcursor_init(&cursor, &list);
1007  item_p = test_dcursor_remove(&cursor);
1008  TEST_CHECK(item_p == &item1);
1009  TEST_CHECK(test_dcursor_current(&cursor) == &item2);
1010  TEST_CHECK(test_dcursor_next_peek(&cursor) == &item3);
1011 
1012  item_p = test_dcursor_remove(&cursor);
1013  TEST_CHECK(item_p == &item2);
1014  TEST_CHECK(test_dcursor_current(&cursor) == &item3);
1015  TEST_CHECK(!test_dcursor_next_peek(&cursor));
1016 
1017  item_p = test_dcursor_remove(&cursor);
1018  TEST_CHECK(item_p == &item3);
1019 
1020  TEST_CHECK(!test_dcursor_current(&cursor));
1021  TEST_CHECK(!test_dcursor_tail(&cursor));
1022  TEST_CHECK(!test_dcursor_head(&cursor));
1023 }
1024 
1026 {
1027  FR_DCURSOR(test_dcursor) cursor;
1028  test_item_t item1 = { "item1", { { NULL, NULL } } };
1029  test_item_t item2 = { "item2", { { NULL, NULL } } };
1030  test_item_t item3 = { "item3", { { NULL, NULL } } };
1031  test_item_t *item_p;
1032  FR_DLIST_HEAD(test_list) list;
1033 
1034  test_list_init(&list);
1035  test_list_insert_tail(&list, &item1);
1036  test_list_insert_tail(&list, &item2);
1037  test_list_insert_tail(&list, &item3);
1038 
1039  test_dcursor_init(&cursor, &list);
1040  test_dcursor_next(&cursor);
1041 
1042  item_p = test_dcursor_remove(&cursor);
1043  TEST_CHECK(item_p == &item2);
1044  TEST_CHECK(test_dcursor_current(&cursor) == &item3);
1045  TEST_CHECK(!test_dcursor_next_peek(&cursor));
1046 
1047  item_p = test_dcursor_remove(&cursor);
1048  TEST_CHECK(item_p == &item3);
1049 
1050  TEST_CHECK(!test_dcursor_current(&cursor));
1051  TEST_CHECK(!test_dcursor_next_peek(&cursor));
1052 
1053  item_p = test_dcursor_remove(&cursor);
1054  TEST_CHECK(!item_p);
1055 
1056  TEST_CHECK(test_dcursor_tail(&cursor) == &item1);
1057  TEST_CHECK(test_dcursor_head(&cursor) == &item1);
1058 }
1059 
1061 {
1062  FR_DCURSOR(test_dcursor) cursor;
1063  test_item_t item1 = { "item1", { { NULL, NULL } } };
1064  test_item_t item2 = { "item2", { { NULL, NULL } } };
1065  test_item_t item3 = { "item3", { { NULL, NULL } } };
1066  test_item_t *item_p;
1067  FR_DLIST_HEAD(test_list) list;
1068 
1069  test_list_init(&list);
1070  test_list_insert_tail(&list, &item1);
1071  test_list_insert_tail(&list, &item2);
1072  test_list_insert_tail(&list, &item3);
1073 
1074  test_dcursor_init(&cursor, &list);
1075  test_dcursor_tail(&cursor);
1076 
1077  item_p = test_dcursor_remove(&cursor);
1078  TEST_CHECK(item_p == &item3);
1079  TEST_CHECK(!test_dcursor_current(&cursor));
1080  TEST_CHECK(!test_dcursor_next_peek(&cursor));
1081 
1082  item_p = test_dcursor_remove(&cursor);
1083  TEST_CHECK(!item_p);
1084 
1085  TEST_CHECK(!test_dcursor_current(&cursor));
1086  TEST_CHECK(!test_dcursor_next_peek(&cursor));
1087 
1088  TEST_CHECK(test_dcursor_tail(&cursor) == &item2);
1089  TEST_CHECK(test_dcursor_head(&cursor) == &item1);
1090 }
1091 
1093 {
1094  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1095 
1096  test_item_t item1a = { "item1a", { { NULL, NULL } } };
1097  test_item_t item2a = { "item2a", { { NULL, NULL } } };
1098  test_item_t item3a = { "item3a", { { NULL, NULL } } };
1099 
1100  test_item_t item1b = { "item1b", { { NULL, NULL } } };
1101  test_item_t item2b = { "item2b", { { NULL, NULL } } };
1102  test_item_t item3b = { "item3b", { { NULL, NULL } } };
1103 
1104  FR_DLIST_HEAD(test_list) list_a, list_b;
1105 
1106  test_list_init(&list_a);
1107  test_list_insert_tail(&list_a, &item1a);
1108  test_list_insert_tail(&list_a, &item2a);
1109  test_list_insert_tail(&list_a, &item3a);
1110 
1111  test_list_init(&list_b);
1112  test_list_insert_tail(&list_b, &item1b);
1113  test_list_insert_tail(&list_b, &item2b);
1114  test_list_insert_tail(&list_b, &item3b);
1115 
1116  test_dcursor_init(&cursor_a, &list_a);
1117  test_dcursor_init(&cursor_b, &list_b);
1118  test_dcursor_merge(&cursor_a, &cursor_b);
1119 
1120  TEST_CHECK(test_dcursor_current(&cursor_a) == &item1a);
1121  TEST_MSG("Expected %s", item1a.name);
1122  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1123 
1124  TEST_CHECK(test_dcursor_next(&cursor_a) == &item1b);
1125  TEST_MSG("Expected %s", item1b.name);
1126  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1127  TEST_CHECK(test_dcursor_next(&cursor_a) == &item2b);
1128  TEST_MSG("Expected %s", item2b.name);
1129  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1130  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3b);
1131  TEST_MSG("Expected %s", item3b.name);
1132  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1133 
1134  TEST_CHECK(test_dcursor_next(&cursor_a) == &item2a);
1135  TEST_MSG("Expected %s", item2a.name);
1136  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1137  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3a);
1138  TEST_MSG("Expected %s", item3a.name);
1139  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1140  TEST_CHECK(!test_dcursor_next(&cursor_a));
1141 
1142  TEST_CHECK(!test_dcursor_current(&cursor_b));
1143  TEST_CHECK(!test_dcursor_list_next_peek(&cursor_b));
1144 }
1145 
1146 static void test_dcursor_merge_mid_a(void)
1147 {
1148  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1149 
1150  test_item_t item1a = { "item1a", { { NULL, NULL } } };
1151  test_item_t item2a = { "item2a", { { NULL, NULL } } };
1152  test_item_t item3a = { "item3a", { { NULL, NULL } } };
1153 
1154  test_item_t item1b = { "item1b", { { NULL, NULL } } };
1155  test_item_t item2b = { "item2b", { { NULL, NULL } } };
1156  test_item_t item3b = { "item3b", { { NULL, NULL } } };
1157 
1158  FR_DLIST_HEAD(test_list) list_a, list_b;
1159 
1160  test_list_init(&list_a);
1161  test_list_insert_tail(&list_a, &item1a);
1162  test_list_insert_tail(&list_a, &item2a);
1163  test_list_insert_tail(&list_a, &item3a);
1164 
1165  test_list_init(&list_b);
1166  test_list_insert_tail(&list_b, &item1b);
1167  test_list_insert_tail(&list_b, &item2b);
1168  test_list_insert_tail(&list_b, &item3b);
1169 
1170  test_dcursor_init(&cursor_a, &list_a);
1171  test_dcursor_init(&cursor_b, &list_b);
1172  test_dcursor_next(&cursor_a);
1173  test_dcursor_merge(&cursor_a, &cursor_b);
1174 
1175  TEST_CHECK(test_dcursor_current(&cursor_a) == &item2a);
1176  TEST_MSG("Expected %s", item2a.name);
1177  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1178 
1179  TEST_CHECK(test_dcursor_next(&cursor_a) == &item1b);
1180  TEST_MSG("Expected %s", item1b.name);
1181  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1182  TEST_CHECK(test_dcursor_next(&cursor_a) == &item2b);
1183  TEST_MSG("Expected %s", item2b.name);
1184  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1185  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3b);
1186  TEST_MSG("Expected %s", item3b.name);
1187  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1188 
1189  /*
1190  * Final item should be from cursor a
1191  */
1192  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3a);
1193  TEST_MSG("Expected %s", item3a.name);
1194  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1195  TEST_CHECK(!test_dcursor_next(&cursor_a));
1196 
1197  TEST_CHECK(!test_dcursor_current(&cursor_b));
1198  TEST_CHECK(!test_dcursor_list_next_peek(&cursor_b));
1199 }
1200 
1201 static void test_dcursor_merge_end_a(void)
1202 {
1203  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1204 
1205  test_item_t item1a = { "item1a", { { NULL, NULL } } };
1206  test_item_t item2a = { "item2a", { { NULL, NULL } } };
1207  test_item_t item3a = { "item3a", { { NULL, NULL } } };
1208 
1209  test_item_t item1b = { "item1b", { { NULL, NULL } } };
1210  test_item_t item2b = { "item2b", { { NULL, NULL } } };
1211  test_item_t item3b = { "item3b", { { NULL, NULL } } };
1212 
1213  FR_DLIST_HEAD(test_list) list_a, list_b;
1214 
1215  test_list_init(&list_a);
1216  test_list_insert_tail(&list_a, &item1a);
1217  test_list_insert_tail(&list_a, &item2a);
1218  test_list_insert_tail(&list_a, &item3a);
1219 
1220  test_list_init(&list_b);
1221  test_list_insert_tail(&list_b, &item1b);
1222  test_list_insert_tail(&list_b, &item2b);
1223  test_list_insert_tail(&list_b, &item3b);
1224 
1225  test_dcursor_init(&cursor_a, &list_a);
1226  test_dcursor_init(&cursor_b, &list_b);
1227  test_dcursor_tail(&cursor_a);
1228  test_dcursor_merge(&cursor_a, &cursor_b);
1229 
1230  TEST_CHECK(test_dcursor_current(&cursor_a) == &item3a);
1231  TEST_MSG("Expected %s", item3a.name);
1232  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1233 
1234  TEST_CHECK(test_dcursor_next(&cursor_a) == &item1b);
1235  TEST_MSG("Expected %s", item1b.name);
1236  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1237  TEST_CHECK(test_dcursor_next(&cursor_a) == &item2b);
1238  TEST_MSG("Expected %s", item2b.name);
1239  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1240  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3b);
1241  TEST_MSG("Expected %s", item3b.name);
1242  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1243 
1244  TEST_CHECK(!test_dcursor_list_next_peek(&cursor_a));
1245  TEST_CHECK(!test_dcursor_current(&cursor_b));
1246  TEST_CHECK(!test_dcursor_list_next_peek(&cursor_b));
1247 }
1248 
1249 static void test_dcursor_merge_mid_b(void)
1250 {
1251  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1252 
1253  test_item_t item1a = { "item1a", { { NULL, NULL } } };
1254  test_item_t item2a = { "item2a", { { NULL, NULL } } };
1255  test_item_t item3a = { "item3a", { { NULL, NULL } } };
1256 
1257  test_item_t item1b = { "item1b", { { NULL, NULL } } };
1258  test_item_t item2b = { "item2b", { { NULL, NULL } } };
1259  test_item_t item3b = { "item3b", { { NULL, NULL } } };
1260 
1261  FR_DLIST_HEAD(test_list) list_a, list_b;
1262 
1263  test_list_init(&list_a);
1264  test_list_insert_tail(&list_a, &item1a);
1265  test_list_insert_tail(&list_a, &item2a);
1266  test_list_insert_tail(&list_a, &item3a);
1267 
1268  test_list_init(&list_b);
1269  test_list_insert_tail(&list_b, &item1b);
1270  test_list_insert_tail(&list_b, &item2b);
1271  test_list_insert_tail(&list_b, &item3b);
1272 
1273  test_dcursor_init(&cursor_a, &list_a);
1274  test_dcursor_init(&cursor_b, &list_b);
1275  test_dcursor_next(&cursor_b);
1276  test_dcursor_merge(&cursor_a, &cursor_b);
1277 
1278  TEST_CHECK(test_dcursor_current(&cursor_a) == &item1a);
1279  TEST_MSG("Expected %s", item1a.name);
1280  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1281 
1282  TEST_CHECK(test_dcursor_next(&cursor_a) == &item2b);
1283  TEST_MSG("Expected %s", item2b.name);
1284  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1285  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3b);
1286  TEST_MSG("Expected %s", item3b.name);
1287  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1288 
1289  TEST_CHECK(test_dcursor_next(&cursor_a) == &item2a);
1290  TEST_MSG("Expected %s", item2a.name);
1291  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1292  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3a);
1293  TEST_MSG("Expected %s", item3a.name);
1294  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1295  TEST_CHECK(!test_dcursor_next(&cursor_a));
1296 
1297  TEST_CHECK(!test_dcursor_current(&cursor_b));
1298  TEST_CHECK(!test_dcursor_list_next_peek(&cursor_b));
1299 }
1300 
1301 static void test_dcursor_merge_end_b(void)
1302 {
1303  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1304 
1305  test_item_t item1a = { "item1a", { { NULL, NULL } } };
1306  test_item_t item2a = { "item2a", { { NULL, NULL } } };
1307  test_item_t item3a = { "item3a", { { NULL, NULL } } };
1308 
1309  test_item_t item1b = { "item1b", { { NULL, NULL } } };
1310  test_item_t item2b = { "item2b", { { NULL, NULL } } };
1311  test_item_t item3b = { "item3b", { { NULL, NULL } } };
1312 
1313  FR_DLIST_HEAD(test_list) list_a, list_b;
1314 
1315  test_list_init(&list_a);
1316  test_list_insert_tail(&list_a, &item1a);
1317  test_list_insert_tail(&list_a, &item2a);
1318  test_list_insert_tail(&list_a, &item3a);
1319 
1320  test_list_init(&list_b);
1321  test_list_insert_tail(&list_b, &item1b);
1322  test_list_insert_tail(&list_b, &item2b);
1323  test_list_insert_tail(&list_b, &item3b);
1324 
1325  test_dcursor_init(&cursor_a, &list_a);
1326  test_dcursor_init(&cursor_b, &list_b);
1327  test_dcursor_next(&cursor_b);
1328  test_dcursor_next(&cursor_b);
1329  test_dcursor_merge(&cursor_a, &cursor_b);
1330 
1331  TEST_CHECK(test_dcursor_current(&cursor_a) == &item1a);
1332  TEST_MSG("Expected %s", item1a.name);
1333  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1334 
1335  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3b);
1336  TEST_MSG("Expected %s", item3b.name);
1337  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1338  TEST_CHECK(test_dcursor_next(&cursor_a) == &item2a);
1339  TEST_MSG("Expected %s", item2a.name);
1340  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1341  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3a);
1342  TEST_MSG("Expected %s", item3a.name);
1343  TEST_MSG("Got %s", test_dcursor_current(&cursor_a)->name);
1344  TEST_CHECK(!test_dcursor_next(&cursor_a));
1345 
1346  TEST_CHECK(!test_dcursor_current(&cursor_b));
1347  TEST_CHECK(test_dcursor_head(&cursor_b) == &item1b);
1348 }
1349 
1351 {
1352  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1353 
1354  test_item_t item1b = { "item1b", { { NULL, NULL } } };
1355  test_item_t item2b = { "item2b", { { NULL, NULL } } };
1356  test_item_t item3b = { "item3b", { { NULL, NULL } } };
1357 
1358  FR_DLIST_HEAD(test_list) list_a, list_b;
1359 
1360  test_list_init(&list_a);
1361  test_list_init(&list_b);
1362  test_list_insert_tail(&list_b, &item1b);
1363  test_list_insert_tail(&list_b, &item2b);
1364  test_list_insert_tail(&list_b, &item3b);
1365 
1366  test_dcursor_init(&cursor_a, &list_a);
1367  test_dcursor_init(&cursor_b, &list_b);
1368  test_dcursor_merge(&cursor_a, &cursor_b);
1369 
1370  TEST_CHECK(test_dcursor_head(&cursor_a) == &item1b);
1371  TEST_CHECK(test_dcursor_next(&cursor_a) == &item2b);
1372  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3b);
1373 
1374  TEST_CHECK(!test_dcursor_current(&cursor_b));
1375  TEST_CHECK(!test_dcursor_list_next_peek(&cursor_b));
1376 }
1377 
1378 static void test_dcursor_merge_empty(void)
1379 {
1380  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1381 
1382  test_item_t item1a = { "item1a", { { NULL, NULL } } };
1383  test_item_t item2a = { "item2a", { { NULL, NULL } } };
1384  test_item_t item3a = { "item3a", { { NULL, NULL } } };
1385 
1386  FR_DLIST_HEAD(test_list) list_a, list_b;
1387 
1388  test_list_init(&list_a);
1389  test_list_insert_tail(&list_a, &item1a);
1390  test_list_insert_tail(&list_a, &item2a);
1391  test_list_insert_tail(&list_a, &item3a);
1392  test_list_init(&list_b);
1393 
1394  test_dcursor_init(&cursor_a, &list_a);
1395  test_dcursor_init(&cursor_b, &list_b);
1396  test_dcursor_merge(&cursor_a, &cursor_b);
1397 
1398  TEST_CHECK(test_dcursor_head(&cursor_a) == &item1a);
1399  TEST_CHECK(test_dcursor_next(&cursor_a) == &item2a);
1400  TEST_CHECK(test_dcursor_next(&cursor_a) == &item3a);
1401 }
1402 
1403 static void test_dcursor_copy_test(void)
1404 {
1405  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1406 
1407  test_item_t item1 = { "item1", { { NULL, NULL } } };
1408  test_item_t item2 = { "item2", { { NULL, NULL } } };
1409  test_item_t item3 = { "item3", { { NULL, NULL } } };
1410 
1411  FR_DLIST_HEAD(test_list) list;
1412 
1413  test_list_init(&list);
1414  test_list_insert_tail(&list, &item1);
1415  test_list_insert_tail(&list, &item2);
1416  test_list_insert_tail(&list, &item3);
1417 
1418  test_dcursor_init(&cursor_a, &list);
1419  test_dcursor_copy(&cursor_b, &cursor_a);
1420 
1421  TEST_CHECK(test_dcursor_head(&cursor_b) == &item1);
1422  TEST_CHECK(test_dcursor_next(&cursor_b) == &item2);
1423  TEST_CHECK(test_dcursor_next(&cursor_b) == &item3);
1424 }
1425 
1426 static void test_dcursor_free_by_list(void)
1427 {
1428  test_item_t *item1, *item2, *item3;
1429  FR_DLIST_HEAD(test_list) list;
1430  FR_DCURSOR(test_dcursor) cursor;
1431 
1432  test_list_init(&list);
1433 
1434  item1 = talloc_zero(NULL, test_item_t);
1435  item2 = talloc_zero(NULL, test_item_t);
1436  item3 = talloc_zero(NULL, test_item_t);
1437 
1438  test_dcursor_init(&cursor, &list);
1439  test_dcursor_append(&cursor, item1);
1440  test_dcursor_append(&cursor, item2);
1441  test_dcursor_append(&cursor, item3);
1442 
1443  test_dcursor_head(&cursor);
1444  test_dcursor_free_list(&cursor);
1445 
1446  TEST_CHECK(test_dcursor_current(&cursor) == NULL);
1447  TEST_CHECK(!test_dcursor_tail(&cursor));
1448  TEST_CHECK(!test_dcursor_head(&cursor));
1449 }
1450 
1451 static void test_dcursor_free_by_item(void)
1452 {
1453  test_item_t *item1, *item2, *item3;
1454  FR_DLIST_HEAD(test_list) list;
1455  FR_DCURSOR(test_dcursor) cursor;
1456 
1457  test_list_init(&list);
1458 
1459  item1 = talloc_zero(NULL, test_item_t);
1460  item2 = talloc_zero(NULL, test_item_t);
1461  item3 = talloc_zero(NULL, test_item_t);
1462 
1463  test_dcursor_init(&cursor, &list);
1464  test_dcursor_append(&cursor, item1);
1465  test_dcursor_append(&cursor, item2);
1466  test_dcursor_append(&cursor, item3);
1467 
1468  test_dcursor_head(&cursor);
1469  test_dcursor_free_item(&cursor);
1470 
1471  TEST_CHECK(test_dcursor_current(&cursor) == item2);
1472  TEST_CHECK(test_dcursor_tail(&cursor) == item3);
1473  TEST_CHECK(test_dcursor_head(&cursor) == item2);
1474 
1475  test_dcursor_free_item(&cursor);
1476  test_dcursor_free_item(&cursor);
1477 
1478  TEST_CHECK(test_dcursor_current(&cursor) == NULL);
1479  TEST_CHECK(!test_dcursor_tail(&cursor));
1480  TEST_CHECK(!test_dcursor_head(&cursor));
1481 }
1482 
1483 typedef struct {
1484  int pos;
1485  char val;
1486 } item_filter;
1487 
1488 static test_item_t *iter_name_check(FR_DLIST_HEAD(test_list) *list, test_item_t *current, void *uctx)
1489 {
1490  item_filter *f = uctx;
1491 
1492  while ((current = test_list_next(list, current))) {
1493  if (current->name[f->pos] == f->val) break;
1494  }
1495 
1496  return current;
1497 }
1498 
1500 {
1501  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1502 
1503  test_item_t item1 = { "item1", { { NULL, NULL } } };
1504  test_item_t item2 = { "item2", { { NULL, NULL } } };
1505  FR_DLIST_HEAD(test_list) list_a, list_b;
1506 
1507  test_list_init(&list_a);
1508  test_list_insert_tail(&list_a, &item1);
1509  test_list_init(&list_b);
1510  test_list_insert_tail(&list_b, &item2);
1511 
1512  test_dcursor_init(&cursor_a, &list_a);
1513  test_dcursor_init(&cursor_b, &list_b);
1514 
1515  TEST_CHECK(test_dcursor_intersect_head(&cursor_a, &cursor_b) == NULL);
1516 }
1517 
1519 {
1520  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1521 
1522  test_item_t item1 = { "item1", { { NULL, NULL } } };
1523  test_item_t item2 = { "item2", { { NULL, NULL } } };
1524  test_item_t item3 = { "item3", { { NULL, NULL } } };
1525  test_item_t *item4 = NULL;
1526  FR_DLIST_HEAD(test_list) list;
1527 
1528  test_list_init(&list);
1529  test_list_insert_tail(&list, &item1);
1530  test_list_insert_tail(&list, &item2);
1531  test_list_insert_tail(&list, &item3);
1532 
1533  test_dcursor_init(&cursor_a, &list);
1534  test_dcursor_init(&cursor_b, &list);
1535 
1536  item4 = test_dcursor_intersect_head(&cursor_a, &cursor_b);
1537  TEST_CHECK(item4 == &item1);
1538  TEST_CHECK(test_dcursor_intersect_next(&cursor_a, &cursor_b) == &item2);
1539  TEST_CHECK(test_dcursor_intersect_next(&cursor_a, &cursor_b) == &item3);
1540  TEST_CHECK(test_dcursor_intersect_next(&cursor_a, &cursor_b) == NULL);
1541 }
1542 
1543 static void test_intersect_iterator_a(void)
1544 {
1545  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1546 
1547  test_item_t item1 = { "actor", { { NULL, NULL } } };
1548  test_item_t item2 = { "alter", { { NULL, NULL } } };
1549  test_item_t item3 = { "extra", { { NULL, NULL } } };
1550  test_item_t item4 = { "after", { { NULL, NULL } } };
1551  FR_DLIST_HEAD(test_list) list;
1552  item_filter filter_a = { 0, 'a' };
1553 
1554  test_list_init(&list);
1555  test_list_insert_tail(&list, &item1);
1556  test_list_insert_tail(&list, &item2);
1557  test_list_insert_tail(&list, &item3);
1558  test_list_insert_tail(&list, &item4);
1559 
1560  test_dcursor_iter_init(&cursor_a, &list, iter_name_check, NULL, &filter_a);
1561  test_dcursor_init(&cursor_b, &list);
1562 
1563  TEST_CHECK(test_dcursor_intersect_head(&cursor_a, &cursor_b) == &item1);
1564  TEST_CHECK(test_dcursor_intersect_next(&cursor_a, &cursor_b) == &item2);
1565  TEST_CHECK(test_dcursor_intersect_next(&cursor_a, &cursor_b) == &item4);
1566  TEST_CHECK(test_dcursor_intersect_next(&cursor_a, &cursor_b) == NULL);
1567 }
1568 
1569 static void test_intersect_iterator_b(void)
1570 {
1571  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1572 
1573  test_item_t item1 = { "blink", { { NULL, NULL } } };
1574  test_item_t item2 = { "alter", { { NULL, NULL } } };
1575  test_item_t item3 = { "basic", { { NULL, NULL } } };
1576  test_item_t item4 = { "bland", { { NULL, NULL } } };
1577  FR_DLIST_HEAD(test_list) list;
1578  item_filter filter_b = { 0, 'b'};
1579 
1580  test_list_init(&list);
1581  test_list_insert_tail(&list, &item1);
1582  test_list_insert_tail(&list, &item2);
1583  test_list_insert_tail(&list, &item3);
1584  test_list_insert_tail(&list, &item4);
1585 
1586  test_dcursor_init(&cursor_a, &list);
1587  test_dcursor_iter_init(&cursor_b, &list, iter_name_check, NULL, &filter_b);
1588 
1589  TEST_CHECK(test_dcursor_intersect_head(&cursor_a, &cursor_b) == &item1);
1590  TEST_CHECK(test_dcursor_intersect_next(&cursor_a, &cursor_b) == &item3);
1591  TEST_CHECK(test_dcursor_intersect_next(&cursor_a, &cursor_b) == &item4);
1592 }
1593 
1595 {
1596  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1597 
1598  test_item_t item1 = { "baits", { { NULL, NULL } } };
1599  test_item_t item2 = { "alter", { { NULL, NULL } } };
1600  test_item_t item3 = { "basic", { { NULL, NULL } } };
1601  test_item_t item4 = { "cavil", { { NULL, NULL } } };
1602  test_item_t item5 = { "bland", { { NULL, NULL } } };
1603  FR_DLIST_HEAD(test_list) list;
1604  item_filter filter_a = { 1, 'a' };
1605  item_filter filter_b = { 0, 'b' };
1606 
1607  test_list_init(&list);
1608  test_list_insert_tail(&list, &item1);
1609  test_list_insert_tail(&list, &item2);
1610  test_list_insert_tail(&list, &item3);
1611  test_list_insert_tail(&list, &item4);
1612  test_list_insert_tail(&list, &item5);
1613 
1614  test_dcursor_iter_init(&cursor_a, &list, iter_name_check, NULL, &filter_a);
1615  test_dcursor_iter_init(&cursor_b, &list, iter_name_check, NULL, &filter_b);
1616 
1617  TEST_CHECK(test_dcursor_intersect_head(&cursor_a, &cursor_b) == &item1);
1618  TEST_CHECK(test_dcursor_intersect_next(&cursor_a, &cursor_b) == &item3);
1619  TEST_MSG("Expected %s", item3.name);
1620  TEST_MSG("Current %s", test_dcursor_current(&cursor_a)->name);
1621  TEST_CHECK(test_dcursor_intersect_next(&cursor_a, &cursor_b) == NULL);
1622 }
1623 
1625 {
1626  FR_DCURSOR(test_dcursor) cursor_a, cursor_b;
1627 
1628  test_item_t item1 = { "baits", { { NULL, NULL } } };
1629  test_item_t item2 = { "alter", { { NULL, NULL } } };
1630  test_item_t item3 = { "basic", { { NULL, NULL } } };
1631  test_item_t item4 = { "cavil", { { NULL, NULL } } };
1632  test_item_t item5 = { "bland", { { NULL, NULL } } };
1633  FR_DLIST_HEAD(test_list) list;
1634  item_filter filter_a = { 0, 'a' };
1635  item_filter filter_b = { 0, 'b' };
1636 
1637  test_list_init(&list);
1638  test_list_insert_tail(&list, &item1);
1639  test_list_insert_tail(&list, &item2);
1640  test_list_insert_tail(&list, &item3);
1641  test_list_insert_tail(&list, &item4);
1642  test_list_insert_tail(&list, &item5);
1643 
1644  test_dcursor_iter_init(&cursor_a, &list, iter_name_check, NULL, &filter_a);
1645  test_dcursor_iter_init(&cursor_b, &list, iter_name_check, NULL, &filter_b);
1646 
1647  TEST_CHECK(test_dcursor_intersect_head(&cursor_a, &cursor_b) == NULL);
1648 }
1649 
1650 static bool eval_eq(test_item_t const *item, void const *uctx)
1651 {
1652  char const *s = uctx;
1653  return strcmp(item->name, s) == 0;
1654 }
1655 
1656 static void test_filter_head_next(void)
1657 {
1658  FR_DCURSOR(test_dcursor) cursor;
1659 
1660  test_item_t item1 = { "yes", { { NULL, NULL } } };
1661  test_item_t item2 = { "no", { { NULL, NULL } } };
1662  test_item_t item3 = { "yes", { { NULL, NULL } } };
1663  test_item_t item4 = { "no", { { NULL, NULL } } };
1664  test_item_t item5 = { "yes", { { NULL, NULL } } };
1665  test_item_t item6 = { "no", { { NULL, NULL } } };
1666  FR_DLIST_HEAD(test_list) list;
1667 
1668  test_list_init(&list);
1669  test_list_insert_tail(&list, &item1);
1670  test_list_insert_tail(&list, &item2);
1671  test_list_insert_tail(&list, &item3);
1672  test_list_insert_tail(&list, &item4);
1673  test_list_insert_tail(&list, &item5);
1674  test_list_insert_tail(&list, &item6);
1675 
1676  test_dcursor_init(&cursor, &list);
1677 
1678  TEST_CHECK(test_dcursor_filter_head(&cursor, eval_eq, "yes") == &item1);
1679  TEST_CHECK(test_dcursor_filter_next(&cursor, eval_eq, "yes") == &item3);
1680  TEST_CHECK(test_dcursor_filter_next(&cursor, eval_eq, "yes") == &item5);
1681  TEST_CHECK(test_dcursor_filter_next(&cursor, eval_eq, "yes") == NULL);
1682 }
1683 
1684 static void test_filter_current(void)
1685 {
1686  FR_DCURSOR(test_dcursor) cursor;
1687 
1688  test_item_t item1 = { "yes", { { NULL, NULL } } };
1689  test_item_t item2 = { "no", { { NULL, NULL } } };
1690  test_item_t item3 = { "yes", { { NULL, NULL } } };
1691  test_item_t item4 = { "no", { { NULL, NULL } } };
1692  test_item_t item5 = { "yes", { { NULL, NULL } } };
1693  test_item_t item6 = { "no", { { NULL, NULL } } };
1694  FR_DLIST_HEAD(test_list) list;
1695 
1696  test_list_init(&list);
1697  test_list_insert_tail(&list, &item1);
1698  test_list_insert_tail(&list, &item2);
1699  test_list_insert_tail(&list, &item3);
1700  test_list_insert_tail(&list, &item4);
1701  test_list_insert_tail(&list, &item5);
1702  test_list_insert_tail(&list, &item6);
1703 
1704  test_dcursor_init(&cursor, &list);
1705 
1706  TEST_CHECK(test_dcursor_filter_current(&cursor, eval_eq, "yes") == &item1);
1707  test_dcursor_next(&cursor);
1708  TEST_CHECK(test_dcursor_filter_current(&cursor, eval_eq, "yes") == &item3);
1709  test_dcursor_next(&cursor);
1710  TEST_CHECK(test_dcursor_filter_current(&cursor, eval_eq, "yes") == &item5);
1711  test_dcursor_next(&cursor);
1712  TEST_CHECK(test_dcursor_filter_current(&cursor, eval_eq, "yes") == NULL);
1713 }
1714 
1715 static void test_filter_no_match(void)
1716 {
1717  FR_DCURSOR(test_dcursor) cursor;
1718 
1719  test_item_t item1 = { "yes", { { NULL, NULL } } };
1720  test_item_t item2 = { "no", { { NULL, NULL } } };
1721  test_item_t item3 = { "yes", { { NULL, NULL } } };
1722  test_item_t item4 = { "no", { { NULL, NULL } } };
1723  test_item_t item5 = { "yes", { { NULL, NULL } } };
1724  test_item_t item6 = { "no", { { NULL, NULL } } };
1725  FR_DLIST_HEAD(test_list) list;
1726 
1727  test_list_init(&list);
1728  test_list_insert_tail(&list, &item1);
1729  test_list_insert_tail(&list, &item2);
1730  test_list_insert_tail(&list, &item3);
1731  test_list_insert_tail(&list, &item4);
1732  test_list_insert_tail(&list, &item5);
1733  test_list_insert_tail(&list, &item6);
1734 
1735  test_dcursor_init(&cursor, &list);
1736 
1737  TEST_CHECK(test_dcursor_filter_current(&cursor, eval_eq, "maybe") == NULL);
1738 }
1739 
1741  /*
1742  * Initialisation
1743  */
1744  { "init_null", test_init_null_item },
1745  { "init_one", test_init_1i_start },
1746  { "init_two", test_init_2i_start },
1747 
1748  /*
1749  * Normal iteration
1750  */
1751  { "next", test_next },
1752  { "next_wrap", test_next_wrap },
1753 
1754  /*
1755  * Jump to head/tail
1756  */
1757  { "head_tail_null", test_dcursor_head_tail_null },
1758  { "head", test_dcursor_test_head },
1759  { "head_resest", test_dcursor_head_reset },
1760  { "head_iter_reset", test_dcursor_iter_head_reset },
1761  { "head_after_next", test_dcursor_head_after_next },
1762  { "tail", test_dcursor_test_tail },
1763  { "head_after_tail", test_dcursor_head_after_tail },
1764  { "wrap_after_tail", test_dcursor_wrap_after_tail },
1765 
1766  /*
1767  * Insert with empty list
1768  */
1769  { "append_empty", test_dcursor_append_empty },
1770  { "append_empty_3", test_dcursor_append_empty_3 },
1771  { "prepend_empty", test_dcursor_prepend_empty },
1772  { "prepend_empty_3", test_dcursor_prepend_empty_3 },
1773  { "insert_empty", test_dcursor_insert_into_empty },
1774  { "insert_empty_3", test_dcursor_insert_into_empty_3 },
1775  { "replace_empty", test_dcursor_replace_in_empty },
1776 
1777  /*
1778  * Insert with one item list
1779  */
1780  { "prepend_1i_start", test_dcursor_prepend_1i_start },
1781  { "append_1i_start", test_dcursor_append_1i_start },
1782  { "insert_1i_start", test_dcursor_insert_1i_start },
1783  { "replace_li_start", test_dcursor_replace_1i_start },
1784 
1785  /*
1786  * Insert with two item list
1787  */
1788  { "prepend_2i_start", test_dcursor_prepend_2i_start },
1789  { "append_2i_start", test_dcursor_append_2i_start },
1790  { "insert_2i_start", test_dcursor_insert_2i_start },
1791  { "replace_2i_start", test_dcursor_replace_2i_start },
1792 
1793  /*
1794  * Insert with three item list (with cursor on item2)
1795  */
1796  { "prepend_3i_mid", test_dcursor_prepend_3i_mid },
1797  { "append_3i_mid", test_dcursor_append_3i_mid },
1798  { "insert_3i_mid", test_dcursor_insert_3i_mid },
1799  { "replace_3i_mid", test_dcursor_replace_3i_mid },
1800 
1801  /*
1802  * Insert with three item list (with cursor on item3)
1803  */
1804  { "prepend_3i_end", test_dcursor_prepend_3i_end },
1805  { "append_3i_end", test_dcursor_append_3i_end },
1806  { "insert_3i_end", test_dcursor_insert_3i_end },
1807  { "replace_3i_end", test_dcursor_replace_3i_end },
1808 
1809  /*
1810  * Remove
1811  */
1812  { "remove_empty", test_dcursor_remove_empty },
1813  { "remove_1i", test_dcursor_remove_1i },
1814  { "remove_2i", test_dcursor_remove_2i },
1815  { "remove_3i_start", test_dcursor_remove_3i_start },
1816  { "remove_3i_mid", test_dcursor_remove_3i_mid },
1817  { "remove_3i_end", test_dcursor_remove_3i_end },
1818 
1819  /*
1820  * Merge
1821  */
1822  { "merge_start_a_b", test_dcursor_merge_start_a_b },
1823  { "merge_mid_a", test_dcursor_merge_mid_a },
1824  { "merge_end_a", test_dcursor_merge_end_a },
1825  { "merge_mid_b", test_dcursor_merge_mid_b },
1826  { "merge_end_b", test_dcursor_merge_end_b },
1827  { "merge_with_empty", test_dcursor_merge_with_empty },
1828  { "merge_empty", test_dcursor_merge_empty },
1829 
1830  /*
1831  * Copy
1832  */
1833  { "copy", test_dcursor_copy_test },
1834 
1835  /*
1836  * Free
1837  */
1838  { "free_list", test_dcursor_free_by_list },
1839  { "free_item", test_dcursor_free_by_item },
1840 
1841  /*
1842  * Intersect
1843  */
1844  { "differing_lists", test_intersect_differing_lists },
1845  { "no_iterators", test_intersect_no_iterators },
1846  { "iterator_a", test_intersect_iterator_a },
1847  { "iterator_b", test_intersect_iterator_b },
1848  { "iterator_ab", test_intersect_iterator_ab },
1849  { "iterator_disjoint", test_intersect_iterator_disjoint },
1850 
1851  /*
1852  * Filter
1853  */
1854  { "head_next", test_filter_head_next },
1855  { "current", test_filter_current },
1856  { "no_match", test_filter_no_match },
1857 
1858  { NULL }
1859 };
#define TEST_CHECK(cond)
Definition: acutest.h:85
#define TEST_MSG(...)
Definition: acutest.h:215
#define UNUSED
Definition: build.h:313
Functions to iterate over a sets and subsets of items in dlists.
#define FR_DCURSOR_DLIST_TYPES(_name, _list_name, _element_type)
Define type specific wrapper structs for dcursors.
Definition: dcursor.h:890
#define FR_DCURSOR(_name)
Expands to the type name used for the dcursor wrapper structure.
Definition: dcursor.h:839
#define FR_DCURSOR_FUNCS(_name, _list_name, _element_type)
Define type specific wrapper functions for dcursors.
Definition: dcursor.h:907
static void test_dcursor_free_item(void)
static void test_dcursor_copy(void)
static void test_dcursor_tail(void)
static void test_dcursor_head(void)
static void test_list_init(test_item_list_t *list)
Definition: dcursor_tests.c:20
static void test_dcursor_append_3i_end(void)
static void test_intersect_iterator_b(void)
static void test_dcursor_replace_3i_mid(void)
static void test_intersect_iterator_a(void)
static void test_dcursor_merge_empty(void)
static void test_dcursor_prepend_empty(void)
static void test_dcursor_free_by_list(void)
static void test_dcursor_merge_end_b(void)
static void test_dcursor_append_empty(void)
static void test_dcursor_replace_2i_start(void)
static void test_dcursor_head_tail_null(void)
static test_item_t * test_iter(FR_DLIST_HEAD(test_list) *list, test_item_t *current, UNUSED void *uctx)
static void test_dcursor_replace_1i_start(void)
static void test_dcursor_prepend_3i_end(void)
static void test_dcursor_remove_3i_mid(void)
char const * name
Definition: dcursor_tests.c:6
static void test_dcursor_insert_2i_start(void)
static void test_dcursor_test_head(void)
static void test_init_2i_start(void)
static void test_dcursor_remove_3i_start(void)
static void test_dcursor_prepend_empty_3(void)
static void test_dcursor_merge_mid_a(void)
static void test_dcursor_wrap_after_tail(void)
static void test_dcursor_test_tail(void)
static test_item_t * iter_name_check(FR_DLIST_HEAD(test_list) *list, test_item_t *current, void *uctx)
static void test_dcursor_append_3i_mid(void)
static void test_filter_no_match(void)
static void test_dcursor_append_1i_start(void)
static void test_dcursor_copy_test(void)
static void test_dcursor_prepend_2i_start(void)
static void test_intersect_iterator_disjoint(void)
static void test_dcursor_iter_head_reset(void)
static void test_next(void)
static void test_dcursor_remove_2i(void)
static void test_dcursor_remove_empty(void)
static void test_intersect_no_iterators(void)
static void test_dcursor_replace_in_empty(void)
static void test_dcursor_insert_1i_start(void)
static void test_dcursor_head_after_next(void)
static void test_dcursor_merge_start_a_b(void)
static void test_dcursor_head_reset(void)
static void test_dcursor_merge_with_empty(void)
static void test_dcursor_append_2i_start(void)
static void test_dcursor_prepend_3i_mid(void)
static bool eval_eq(test_item_t const *item, void const *uctx)
static void test_next_wrap(void)
static void test_dcursor_merge_mid_b(void)
static void test_dcursor_replace_3i_end(void)
static void test_init_null_item(void)
static void test_dcursor_insert_into_empty_3(void)
static void test_intersect_differing_lists(void)
static void test_filter_head_next(void)
static void test_dcursor_head_after_tail(void)
static void test_dcursor_prepend_1i_start(void)
static void test_dcursor_append_empty_3(void)
static void test_dcursor_insert_into_empty(void)
static void test_dcursor_remove_1i(void)
static void test_filter_current(void)
static void test_intersect_iterator_ab(void)
static void test_dcursor_insert_3i_mid(void)
static void test_dcursor_insert_3i_end(void)
static void test_dcursor_free_by_item(void)
static void test_init_1i_start(void)
static void test_dcursor_merge_end_a(void)
static void test_dcursor_remove_3i_end(void)
#define FR_DLIST_TYPES(_name)
Define type specific wrapper structs for dlists.
Definition: dlist.h:1129
#define FR_DLIST_ENTRY(_name)
Expands to the type name used for the entry wrapper structure.
Definition: dlist.h:1115
#define FR_DLIST_FUNCS(_name, _element_type, _element_entry)
Define type specific wrapper functions for dlists.
Definition: dlist.h:1152
static void * item(fr_lst_t const *lst, fr_lst_index_t idx)
Definition: lst.c:122
typedef FR_DLIST_HEAD(map_list) map_list_t
Given these are used in so many places, it's more friendly to have a proper type.
static rc_request_t * current
Definition: radclient-ng.c:97
char const * name
Test name (as specified in the request).
Definition: radclient.h:101
static char const * name