disable warning C5250: _BitScanReverse: intrinsic function not declared
[liba.git] / test / slist.h
bloba8daa58232ac37902e8b376f8a94aec11fd4914a
1 #define MAIN_(x) A_CAST_2(x, _slist)
2 #include "test.h"
3 #include "a/slist.h"
5 static a_size a_slist_len(a_slist const *ctx)
7 a_size count = 0;
8 a_slist_foreach(it, ctx) { ++count; }
9 return count;
12 static void test(void)
14 typedef struct
16 a_slist_node node;
17 a_cast data;
18 } data;
19 a_slist *list1 = a_new(a_slist, A_NULL, 1);
20 a_slist_ctor(list1);
21 for (int i = 0; i != 10; ++i)
23 data *node = a_new(data, A_NULL, 1);
24 node->data.i = i;
25 a_slist_add_tail(list1, &node->node);
27 a_slist *list2 = a_new(a_slist, A_NULL, 1);
28 a_slist_ctor(list2);
29 for (int i = 14; i != 9; --i)
31 data *node = a_new(data, A_NULL, 1);
32 node->data.i = i;
33 a_slist_add_head(list2, &node->node);
35 a_slist *list3 = a_new(a_slist, A_NULL, 1);
36 a_slist_ctor(list3);
37 for (int i = 15; i != 20; ++i)
39 data *node = a_new(data, A_NULL, 1);
40 node->data.i = i;
41 a_slist_add(list3, list3->tail, &node->node);
43 a_slist_rot(list1);
44 a_slist_mov(list2, list3, &list3->head);
45 a_slist_dtor(list2);
46 a_slist_mov(list3, list1, list1->tail);
47 a_slist_dtor(list3);
48 a_slist_foreach(it, list1)
50 data *node = a_slist_entry(it, data, node); // NOLINT(performance-no-int-to-ptr)
51 printf("%i ", node->data.i);
53 printf("%" PRIz "u", a_slist_len(list1));
54 for (int i = 0; i != 10; ++i)
56 data *node = a_slist_entry_next(&list1->head, data, node); // NOLINT(performance-no-int-to-ptr)
57 a_slist_del_head(list1);
58 a_die(node);
60 a_slist_forsafe(it, at, list1)
62 data *node = a_slist_entry(it, data, node); // NOLINT(performance-no-int-to-ptr)
63 a_slist_del(list1, at);
64 a_die(node);
65 it = A_NULL;
67 if (list1->head.next == &list1->head &&
68 list2->head.next == &list2->head &&
69 list3->head.next == &list3->head)
71 printf(" ok");
73 putchar('\n');
74 a_die(list3);
75 a_die(list2);
76 a_die(list1);
79 static void null(void)
81 static a_slist_node node1 = A_SLIST_NODE;
82 static a_slist_node node2 = A_SLIST_NODE;
83 static a_slist list1 = A_SLIST_INIT(list1);
84 static a_slist list2 = A_SLIST_INIT(list2);
86 a_slist_rot(&list1);
87 a_slist_rot(&list1);
88 a_slist_mov(&list2, &list1, &list1.head);
89 a_slist_mov(&list2, &list1, list1.tail);
90 a_slist_del(&list1, &list1.head);
91 a_slist_del(&list1, list1.tail);
92 a_slist_del_head(&list2);
93 a_slist_del_head(&list2);
95 a_slist_init(&list1);
96 a_slist_init(&list2);
97 a_slist_add(&list1, &list1.head, &node1);
98 a_slist_add(&list1, &list1.head, &node1);
99 a_slist_del(&list1, &node1);
100 a_slist_add(&list1, list1.tail, &node1);
101 a_slist_add(&list1, &node1, &node1);
102 a_slist_add_head(&list1, &node1);
103 a_slist_add_tail(&list2, &node2);
104 a_slist_mov(&list2, &list1, &list1.head);
105 a_slist_mov(&list2, &list1, list1.tail);
108 int MAIN(int argc, char *argv[]) // NOLINT(misc-definitions-in-headers)
110 (void)(argc);
111 (void)(argv);
112 printf("%s\n", A_FUNC);
113 test();
114 null();
115 return 0;