tests/test_list.cpp

changeset 790
42877968260c
parent 764
ccbdbd088455
child 798
7644da6e2d35
equal deleted inserted replaced
789:9b2f5661bebd 790:42877968260c
37 #include <vector> 37 #include <vector>
38 #include <unordered_set> 38 #include <unordered_set>
39 #include <algorithm> 39 #include <algorithm>
40 40
41 struct node { 41 struct node {
42 node *next = nullptr; 42 node *next = NULL;
43 node *prev = nullptr; 43 node *prev = NULL;
44 int data = 0; 44 int data = 0;
45 }; 45 };
46 46
47 const ptrdiff_t loc_prev = offsetof(struct node, prev); 47 const ptrdiff_t loc_prev = offsetof(struct node, prev);
48 const ptrdiff_t loc_next = offsetof(struct node, next); 48 const ptrdiff_t loc_next = offsetof(struct node, next);
49 const ptrdiff_t loc_data = offsetof(struct node, data); 49 const ptrdiff_t loc_data = offsetof(struct node, data);
50 50
51 struct node_test_data { 51 struct node_test_data {
52 node *begin = nullptr; 52 node *begin = NULL;
53 53
54 explicit node_test_data(node *begin) : begin(begin) { 54 explicit node_test_data(node *begin) : begin(begin) {
55 auto n = begin; 55 auto n = begin;
56 while (n != nullptr) { 56 while (n != NULL) {
57 nodes.push_back(n); 57 nodes.push_back(n);
58 n = n->next; 58 n = n->next;
59 } 59 }
60 } 60 }
61 61
70 private: 70 private:
71 std::vector<node *> nodes; 71 std::vector<node *> nodes;
72 }; 72 };
73 73
74 static node_test_data create_nodes_test_data(size_t len) { 74 static node_test_data create_nodes_test_data(size_t len) {
75 if (len == 0) return node_test_data{nullptr}; 75 if (len == 0) return node_test_data{NULL};
76 auto begin = new node; 76 auto begin = new node;
77 auto prev = begin; 77 auto prev = begin;
78 for (size_t i = 1; i < len; i++) { 78 for (size_t i = 1; i < len; i++) {
79 auto n = new node; 79 auto n = new node;
80 cx_linked_list_link(prev, n, loc_prev, loc_next); 80 cx_linked_list_link(prev, n, loc_prev, loc_next);
86 template<typename InputIter> 86 template<typename InputIter>
87 static node_test_data create_nodes_test_data( 87 static node_test_data create_nodes_test_data(
88 InputIter begin, 88 InputIter begin,
89 InputIter end 89 InputIter end
90 ) { 90 ) {
91 if (begin == end) return node_test_data{nullptr}; 91 if (begin == end) return node_test_data{NULL};
92 node *first = new node; 92 node *first = new node;
93 first->data = *begin; 93 first->data = *begin;
94 node *prev = first; 94 node *prev = first;
95 begin++; 95 begin++;
96 for (; begin != end; begin++) { 96 for (; begin != end; begin++) {
117 117
118 TEST(LinkedList_LowLevel, link_unlink) { 118 TEST(LinkedList_LowLevel, link_unlink) {
119 node a, b, c; 119 node a, b, c;
120 120
121 cx_linked_list_link(&a, &b, loc_prev, loc_next); 121 cx_linked_list_link(&a, &b, loc_prev, loc_next);
122 EXPECT_EQ(a.prev, nullptr); 122 CX_TEST_ASSERT(a.prev == NULL);
123 EXPECT_EQ(a.next, &b); 123 CX_TEST_ASSERT(a.next == &b);
124 EXPECT_EQ(b.prev, &a); 124 CX_TEST_ASSERT(b.prev == &a);
125 EXPECT_EQ(b.next, nullptr); 125 CX_TEST_ASSERT(b.next == NULL);
126 126
127 cx_linked_list_unlink(&a, &b, loc_prev, loc_next); 127 cx_linked_list_unlink(&a, &b, loc_prev, loc_next);
128 EXPECT_EQ(a.prev, nullptr); 128 CX_TEST_ASSERT(a.prev == NULL);
129 EXPECT_EQ(a.next, nullptr); 129 CX_TEST_ASSERT(a.next == NULL);
130 EXPECT_EQ(b.prev, nullptr); 130 CX_TEST_ASSERT(b.prev == NULL);
131 EXPECT_EQ(b.next, nullptr); 131 CX_TEST_ASSERT(b.next == NULL);
132 132
133 cx_linked_list_link(&b, &c, loc_prev, loc_next); 133 cx_linked_list_link(&b, &c, loc_prev, loc_next);
134 cx_linked_list_link(&a, &b, loc_prev, loc_next); 134 cx_linked_list_link(&a, &b, loc_prev, loc_next);
135 cx_linked_list_unlink(&b, &c, loc_prev, loc_next); 135 cx_linked_list_unlink(&b, &c, loc_prev, loc_next);
136 EXPECT_EQ(a.prev, nullptr); 136 CX_TEST_ASSERT(a.prev == NULL);
137 EXPECT_EQ(a.next, &b); 137 CX_TEST_ASSERT(a.next == &b);
138 EXPECT_EQ(b.prev, &a); 138 CX_TEST_ASSERT(b.prev == &a);
139 EXPECT_EQ(b.next, nullptr); 139 CX_TEST_ASSERT(b.next == NULL);
140 EXPECT_EQ(c.prev, nullptr); 140 CX_TEST_ASSERT(c.prev == NULL);
141 EXPECT_EQ(c.next, nullptr); 141 CX_TEST_ASSERT(c.next == NULL);
142 } 142 }
143 143
144 TEST(LinkedList_LowLevel, cx_linked_list_at) { 144 TEST(LinkedList_LowLevel, cx_linked_list_at) {
145 node a, b, c, d; 145 node a, b, c, d;
146 cx_linked_list_link(&a, &b, loc_prev, loc_next); 146 cx_linked_list_link(&a, &b, loc_prev, loc_next);
149 149
150 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 0), &a); 150 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 0), &a);
151 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 1), &b); 151 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 1), &b);
152 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 2), &c); 152 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 2), &c);
153 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 3), &d); 153 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 3), &d);
154 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 4), nullptr); 154 EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 4), NULL);
155 155
156 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_prev, 0), &a); 156 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_prev, 0), &a);
157 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 1), &b); 157 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 1), &b);
158 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 2), &c); 158 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 2), &c);
159 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 3), &d); 159 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 3), &d);
160 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 4), nullptr); 160 EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 4), NULL);
161 161
162 EXPECT_EQ(cx_linked_list_at(&d, 3, loc_prev, 0), &a); 162 EXPECT_EQ(cx_linked_list_at(&d, 3, loc_prev, 0), &a);
163 EXPECT_EQ(cx_linked_list_at(&d, 3, loc_prev, 1), &b); 163 EXPECT_EQ(cx_linked_list_at(&d, 3, loc_prev, 1), &b);
164 } 164 }
165 165
197 197
198 TEST(LinkedList_LowLevel, cx_linked_list_add) { 198 TEST(LinkedList_LowLevel, cx_linked_list_add) {
199 // test with begin, end / prev, next 199 // test with begin, end / prev, next
200 { 200 {
201 node nodes[4]; 201 node nodes[4];
202 void *begin = nullptr, *end = nullptr; 202 void *begin = NULL, *end = NULL;
203 203
204 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]); 204 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]);
205 EXPECT_EQ(begin, &nodes[0]); 205 CX_TEST_ASSERT(begin == &nodes[0]);
206 EXPECT_EQ(end, &nodes[0]); 206 CX_TEST_ASSERT(end == &nodes[0]);
207 EXPECT_EQ(nodes[0].prev, nullptr); 207 CX_TEST_ASSERT(nodes[0].prev == NULL);
208 EXPECT_EQ(nodes[0].next, nullptr); 208 CX_TEST_ASSERT(nodes[0].next == NULL);
209 209
210 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]); 210 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]);
211 EXPECT_EQ(begin, &nodes[0]); 211 CX_TEST_ASSERT(begin == &nodes[0]);
212 EXPECT_EQ(end, &nodes[1]); 212 CX_TEST_ASSERT(end == &nodes[1]);
213 EXPECT_EQ(nodes[0].next, &nodes[1]); 213 CX_TEST_ASSERT(nodes[0].next == &nodes[1]);
214 EXPECT_EQ(nodes[1].prev, &nodes[0]); 214 CX_TEST_ASSERT(nodes[1].prev == &nodes[0]);
215 } 215 }
216 216
217 // test with begin only / prev, next 217 // test with begin only / prev, next
218 { 218 {
219 node nodes[4]; 219 node nodes[4];
220 void *begin = nullptr; 220 void *begin = NULL;
221 221
222 cx_linked_list_add(&begin, nullptr, loc_prev, loc_next, &nodes[0]); 222 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]);
223 EXPECT_EQ(begin, &nodes[0]); 223 CX_TEST_ASSERT(begin == &nodes[0]);
224 cx_linked_list_add(&begin, nullptr, loc_prev, loc_next, &nodes[1]); 224 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]);
225 EXPECT_EQ(begin, &nodes[0]); 225 CX_TEST_ASSERT(begin == &nodes[0]);
226 EXPECT_EQ(nodes[0].next, &nodes[1]); 226 CX_TEST_ASSERT(nodes[0].next == &nodes[1]);
227 EXPECT_EQ(nodes[1].prev, &nodes[0]); 227 CX_TEST_ASSERT(nodes[1].prev == &nodes[0]);
228 228
229 cx_linked_list_add(&begin, nullptr, loc_prev, loc_next, &nodes[2]); 229 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]);
230 EXPECT_EQ(nodes[1].next, &nodes[2]); 230 CX_TEST_ASSERT(nodes[1].next == &nodes[2]);
231 EXPECT_EQ(nodes[2].prev, &nodes[1]); 231 CX_TEST_ASSERT(nodes[2].prev == &nodes[1]);
232 } 232 }
233 233
234 // test with end only / prev, next 234 // test with end only / prev, next
235 { 235 {
236 node nodes[4]; 236 node nodes[4];
237 void *end = nullptr; 237 void *end = NULL;
238 238
239 cx_linked_list_add(nullptr, &end, loc_prev, loc_next, &nodes[0]); 239 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[0]);
240 EXPECT_EQ(end, &nodes[0]); 240 CX_TEST_ASSERT(end == &nodes[0]);
241 cx_linked_list_add(nullptr, &end, loc_prev, loc_next, &nodes[1]); 241 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]);
242 EXPECT_EQ(end, &nodes[1]); 242 CX_TEST_ASSERT(end == &nodes[1]);
243 EXPECT_EQ(nodes[0].next, &nodes[1]); 243 CX_TEST_ASSERT(nodes[0].next == &nodes[1]);
244 EXPECT_EQ(nodes[1].prev, &nodes[0]); 244 CX_TEST_ASSERT(nodes[1].prev == &nodes[0]);
245 245
246 cx_linked_list_add(nullptr, &end, loc_prev, loc_next, &nodes[2]); 246 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]);
247 EXPECT_EQ(end, &nodes[2]); 247 CX_TEST_ASSERT(end == &nodes[2]);
248 EXPECT_EQ(nodes[1].next, &nodes[2]); 248 CX_TEST_ASSERT(nodes[1].next == &nodes[2]);
249 EXPECT_EQ(nodes[2].prev, &nodes[1]); 249 CX_TEST_ASSERT(nodes[2].prev == &nodes[1]);
250 } 250 }
251 251
252 // test with begin, end / next 252 // test with begin, end / next
253 { 253 {
254 node nodes[4]; 254 node nodes[4];
255 void *begin = nullptr, *end = nullptr; 255 void *begin = NULL, *end = NULL;
256 256
257 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]); 257 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]);
258 EXPECT_EQ(begin, &nodes[0]); 258 CX_TEST_ASSERT(begin == &nodes[0]);
259 EXPECT_EQ(end, &nodes[0]); 259 CX_TEST_ASSERT(end == &nodes[0]);
260 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]); 260 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]);
261 EXPECT_EQ(end, &nodes[1]); 261 CX_TEST_ASSERT(end == &nodes[1]);
262 EXPECT_EQ(nodes[0].next, &nodes[1]); 262 CX_TEST_ASSERT(nodes[0].next == &nodes[1]);
263 EXPECT_EQ(nodes[1].prev, nullptr); 263 CX_TEST_ASSERT(nodes[1].prev == NULL);
264 } 264 }
265 } 265 }
266 266
267 TEST(LinkedList_LowLevel, cx_linked_list_prepend) { 267 TEST(LinkedList_LowLevel, cx_linked_list_prepend) {
268 // test with begin, end / prev, next 268 // test with begin, end / prev, next
269 { 269 {
270 node nodes[4]; 270 node nodes[4];
271 void *begin = nullptr, *end = nullptr; 271 void *begin = NULL, *end = NULL;
272 272
273 cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[0]); 273 cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[0]);
274 EXPECT_EQ(begin, &nodes[0]); 274 CX_TEST_ASSERT(begin == &nodes[0]);
275 EXPECT_EQ(end, &nodes[0]); 275 CX_TEST_ASSERT(end == &nodes[0]);
276 EXPECT_EQ(nodes[0].prev, nullptr); 276 CX_TEST_ASSERT(nodes[0].prev == NULL);
277 EXPECT_EQ(nodes[0].next, nullptr); 277 CX_TEST_ASSERT(nodes[0].next == NULL);
278 278
279 cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[1]); 279 cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[1]);
280 EXPECT_EQ(begin, &nodes[1]); 280 CX_TEST_ASSERT(begin == &nodes[1]);
281 EXPECT_EQ(end, &nodes[0]); 281 CX_TEST_ASSERT(end == &nodes[0]);
282 EXPECT_EQ(nodes[1].next, &nodes[0]); 282 CX_TEST_ASSERT(nodes[1].next == &nodes[0]);
283 EXPECT_EQ(nodes[0].prev, &nodes[1]); 283 CX_TEST_ASSERT(nodes[0].prev == &nodes[1]);
284 } 284 }
285 285
286 // test with begin only / prev, next 286 // test with begin only / prev, next
287 { 287 {
288 node nodes[4]; 288 node nodes[4];
289 void *begin = nullptr; 289 void *begin = NULL;
290 290
291 cx_linked_list_prepend(&begin, nullptr, loc_prev, loc_next, &nodes[0]); 291 cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[0]);
292 EXPECT_EQ(begin, &nodes[0]); 292 CX_TEST_ASSERT(begin == &nodes[0]);
293 cx_linked_list_prepend(&begin, nullptr, loc_prev, loc_next, &nodes[1]); 293 cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[1]);
294 EXPECT_EQ(begin, &nodes[1]); 294 CX_TEST_ASSERT(begin == &nodes[1]);
295 EXPECT_EQ(nodes[1].next, &nodes[0]); 295 CX_TEST_ASSERT(nodes[1].next == &nodes[0]);
296 EXPECT_EQ(nodes[0].prev, &nodes[1]); 296 CX_TEST_ASSERT(nodes[0].prev == &nodes[1]);
297 297
298 cx_linked_list_prepend(&begin, nullptr, loc_prev, loc_next, &nodes[2]); 298 cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[2]);
299 EXPECT_EQ(begin, &nodes[2]); 299 CX_TEST_ASSERT(begin == &nodes[2]);
300 EXPECT_EQ(nodes[2].next, &nodes[1]); 300 CX_TEST_ASSERT(nodes[2].next == &nodes[1]);
301 EXPECT_EQ(nodes[1].prev, &nodes[2]); 301 CX_TEST_ASSERT(nodes[1].prev == &nodes[2]);
302 } 302 }
303 303
304 // test with end only / prev, next 304 // test with end only / prev, next
305 { 305 {
306 node nodes[4]; 306 node nodes[4];
307 void *end = nullptr; 307 void *end = NULL;
308 308
309 cx_linked_list_prepend(nullptr, &end, loc_prev, loc_next, &nodes[0]); 309 cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[0]);
310 EXPECT_EQ(end, &nodes[0]); 310 CX_TEST_ASSERT(end == &nodes[0]);
311 cx_linked_list_prepend(nullptr, &end, loc_prev, loc_next, &nodes[1]); 311 cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[1]);
312 EXPECT_EQ(end, &nodes[0]); 312 CX_TEST_ASSERT(end == &nodes[0]);
313 EXPECT_EQ(nodes[1].next, &nodes[0]); 313 CX_TEST_ASSERT(nodes[1].next == &nodes[0]);
314 EXPECT_EQ(nodes[0].prev, &nodes[1]); 314 CX_TEST_ASSERT(nodes[0].prev == &nodes[1]);
315 315
316 cx_linked_list_prepend(nullptr, &end, loc_prev, loc_next, &nodes[2]); 316 cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[2]);
317 EXPECT_EQ(end, &nodes[0]); 317 CX_TEST_ASSERT(end == &nodes[0]);
318 EXPECT_EQ(nodes[2].next, &nodes[1]); 318 CX_TEST_ASSERT(nodes[2].next == &nodes[1]);
319 EXPECT_EQ(nodes[1].prev, &nodes[2]); 319 CX_TEST_ASSERT(nodes[1].prev == &nodes[2]);
320 } 320 }
321 321
322 // test with begin, end / next 322 // test with begin, end / next
323 { 323 {
324 node nodes[4]; 324 node nodes[4];
325 void *begin = nullptr, *end = nullptr; 325 void *begin = NULL, *end = NULL;
326 326
327 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[0]); 327 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[0]);
328 EXPECT_EQ(begin, &nodes[0]); 328 CX_TEST_ASSERT(begin == &nodes[0]);
329 EXPECT_EQ(end, &nodes[0]); 329 CX_TEST_ASSERT(end == &nodes[0]);
330 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[1]); 330 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[1]);
331 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[2]); 331 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[2]);
332 EXPECT_EQ(begin, &nodes[2]); 332 CX_TEST_ASSERT(begin == &nodes[2]);
333 EXPECT_EQ(end, &nodes[0]); 333 CX_TEST_ASSERT(end == &nodes[0]);
334 EXPECT_EQ(nodes[1].next, &nodes[0]); 334 CX_TEST_ASSERT(nodes[1].next == &nodes[0]);
335 EXPECT_EQ(nodes[2].next, &nodes[1]); 335 CX_TEST_ASSERT(nodes[2].next == &nodes[1]);
336 EXPECT_EQ(nodes[1].prev, nullptr); 336 CX_TEST_ASSERT(nodes[1].prev == NULL);
337 EXPECT_EQ(nodes[0].prev, nullptr); 337 CX_TEST_ASSERT(nodes[0].prev == NULL);
338 } 338 }
339 } 339 }
340 340
341 TEST(LinkedList_LowLevel, cx_linked_list_insert) { 341 TEST(LinkedList_LowLevel, cx_linked_list_insert) {
342 // insert mid list 342 // insert mid list
346 346
347 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); 347 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
348 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); 348 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
349 349
350 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3]); 350 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3]);
351 EXPECT_EQ(begin, &nodes[0]); 351 CX_TEST_ASSERT(begin == &nodes[0]);
352 EXPECT_EQ(end, &nodes[2]); 352 CX_TEST_ASSERT(end == &nodes[2]);
353 EXPECT_EQ(nodes[1].next, &nodes[3]); 353 CX_TEST_ASSERT(nodes[1].next == &nodes[3]);
354 EXPECT_EQ(nodes[2].prev, &nodes[3]); 354 CX_TEST_ASSERT(nodes[2].prev == &nodes[3]);
355 EXPECT_EQ(nodes[3].prev, &nodes[1]); 355 CX_TEST_ASSERT(nodes[3].prev == &nodes[1]);
356 EXPECT_EQ(nodes[3].next, &nodes[2]); 356 CX_TEST_ASSERT(nodes[3].next == &nodes[2]);
357 } 357 }
358 358
359 // insert end 359 // insert end
360 { 360 {
361 node nodes[4]; 361 node nodes[4];
363 363
364 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); 364 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
365 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); 365 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
366 366
367 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3]); 367 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3]);
368 EXPECT_EQ(begin, &nodes[0]); 368 CX_TEST_ASSERT(begin == &nodes[0]);
369 EXPECT_EQ(end, &nodes[3]); 369 CX_TEST_ASSERT(end == &nodes[3]);
370 EXPECT_EQ(nodes[2].next, &nodes[3]); 370 CX_TEST_ASSERT(nodes[2].next == &nodes[3]);
371 EXPECT_EQ(nodes[3].prev, &nodes[2]); 371 CX_TEST_ASSERT(nodes[3].prev == &nodes[2]);
372 EXPECT_EQ(nodes[3].next, nullptr); 372 CX_TEST_ASSERT(nodes[3].next == NULL);
373 } 373 }
374 374
375 // insert begin 375 // insert begin
376 { 376 {
377 node nodes[4]; 377 node nodes[4];
378 void *begin = &nodes[0], *end = &nodes[2]; 378 void *begin = &nodes[0], *end = &nodes[2];
379 379
380 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); 380 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
381 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); 381 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
382 382
383 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, nullptr, &nodes[3]); 383 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, NULL, &nodes[3]);
384 EXPECT_EQ(begin, &nodes[3]); 384 CX_TEST_ASSERT(begin == &nodes[3]);
385 EXPECT_EQ(end, &nodes[2]); 385 CX_TEST_ASSERT(end == &nodes[2]);
386 EXPECT_EQ(nodes[0].prev, &nodes[3]); 386 CX_TEST_ASSERT(nodes[0].prev == &nodes[3]);
387 EXPECT_EQ(nodes[3].prev, nullptr); 387 CX_TEST_ASSERT(nodes[3].prev == NULL);
388 EXPECT_EQ(nodes[3].next, &nodes[0]); 388 CX_TEST_ASSERT(nodes[3].next == &nodes[0]);
389 } 389 }
390 } 390 }
391 391
392 TEST(LinkedList_LowLevel, cx_linked_list_insert_chain) { 392 TEST(LinkedList_LowLevel, cx_linked_list_insert_chain) {
393 // insert mid list 393 // insert mid list
397 397
398 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); 398 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
399 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); 399 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
400 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next); 400 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next);
401 401
402 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3], nullptr); 402 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3], NULL);
403 EXPECT_EQ(begin, &nodes[0]); 403 CX_TEST_ASSERT(begin == &nodes[0]);
404 EXPECT_EQ(end, &nodes[2]); 404 CX_TEST_ASSERT(end == &nodes[2]);
405 EXPECT_EQ(nodes[1].next, &nodes[3]); 405 CX_TEST_ASSERT(nodes[1].next == &nodes[3]);
406 EXPECT_EQ(nodes[2].prev, &nodes[4]); 406 CX_TEST_ASSERT(nodes[2].prev == &nodes[4]);
407 EXPECT_EQ(nodes[3].prev, &nodes[1]); 407 CX_TEST_ASSERT(nodes[3].prev == &nodes[1]);
408 EXPECT_EQ(nodes[4].next, &nodes[2]); 408 CX_TEST_ASSERT(nodes[4].next == &nodes[2]);
409 } 409 }
410 410
411 // insert end 411 // insert end
412 { 412 {
413 node nodes[5]; 413 node nodes[5];
415 415
416 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); 416 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
417 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); 417 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
418 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next); 418 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next);
419 419
420 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3], nullptr); 420 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3], NULL);
421 EXPECT_EQ(begin, &nodes[0]); 421 CX_TEST_ASSERT(begin == &nodes[0]);
422 EXPECT_EQ(end, &nodes[4]); 422 CX_TEST_ASSERT(end == &nodes[4]);
423 EXPECT_EQ(nodes[2].next, &nodes[3]); 423 CX_TEST_ASSERT(nodes[2].next == &nodes[3]);
424 EXPECT_EQ(nodes[3].prev, &nodes[2]); 424 CX_TEST_ASSERT(nodes[3].prev == &nodes[2]);
425 EXPECT_EQ(nodes[4].next, nullptr); 425 CX_TEST_ASSERT(nodes[4].next == NULL);
426 } 426 }
427 427
428 // insert begin 428 // insert begin
429 { 429 {
430 node nodes[5]; 430 node nodes[5];
432 432
433 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); 433 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
434 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); 434 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
435 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next); 435 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next);
436 436
437 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, nullptr, &nodes[3], nullptr); 437 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, NULL, &nodes[3], NULL);
438 EXPECT_EQ(begin, &nodes[3]); 438 CX_TEST_ASSERT(begin == &nodes[3]);
439 EXPECT_EQ(end, &nodes[2]); 439 CX_TEST_ASSERT(end == &nodes[2]);
440 EXPECT_EQ(nodes[0].prev, &nodes[4]); 440 CX_TEST_ASSERT(nodes[0].prev == &nodes[4]);
441 EXPECT_EQ(nodes[3].prev, nullptr); 441 CX_TEST_ASSERT(nodes[3].prev == NULL);
442 EXPECT_EQ(nodes[4].next, &nodes[0]); 442 CX_TEST_ASSERT(nodes[4].next == &nodes[0]);
443 } 443 }
444 } 444 }
445 445
446 TEST(LinkedList_LowLevel, cx_linked_list_first) { 446 TEST(LinkedList_LowLevel, cx_linked_list_first) {
447 auto testdata = create_nodes_test_data(3); 447 auto testdata = create_nodes_test_data(3);
461 } 461 }
462 462
463 TEST(LinkedList_LowLevel, cx_linked_list_prev) { 463 TEST(LinkedList_LowLevel, cx_linked_list_prev) {
464 auto testdata = create_nodes_test_data(3); 464 auto testdata = create_nodes_test_data(3);
465 auto begin = testdata.begin; 465 auto begin = testdata.begin;
466 EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin), nullptr); 466 EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin), NULL);
467 EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin->next), begin); 467 EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin->next), begin);
468 EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin->next->next), begin->next); 468 EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin->next->next), begin->next);
469 } 469 }
470 470
471 TEST(LinkedList_LowLevel, cx_linked_list_remove) { 471 TEST(LinkedList_LowLevel, cx_linked_list_remove) {
475 auto second = first->next; 475 auto second = first->next;
476 auto third = second->next; 476 auto third = second->next;
477 auto end = reinterpret_cast<void *>(third); 477 auto end = reinterpret_cast<void *>(third);
478 478
479 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, second); 479 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, second);
480 EXPECT_EQ(begin, first); 480 CX_TEST_ASSERT(begin == first);
481 EXPECT_EQ(end, third); 481 CX_TEST_ASSERT(end == third);
482 EXPECT_EQ(first->prev, nullptr); 482 CX_TEST_ASSERT(first->prev == NULL);
483 EXPECT_EQ(first->next, third); 483 CX_TEST_ASSERT(first->next == third);
484 EXPECT_EQ(third->prev, first); 484 CX_TEST_ASSERT(third->prev == first);
485 EXPECT_EQ(third->next, nullptr); 485 CX_TEST_ASSERT(third->next == NULL);
486 486
487 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, third); 487 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, third);
488 EXPECT_EQ(begin, first); 488 CX_TEST_ASSERT(begin == first);
489 EXPECT_EQ(end, first); 489 CX_TEST_ASSERT(end == first);
490 EXPECT_EQ(first->prev, nullptr); 490 CX_TEST_ASSERT(first->prev == NULL);
491 EXPECT_EQ(first->next, nullptr); 491 CX_TEST_ASSERT(first->next == NULL);
492 492
493 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, first); 493 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, first);
494 EXPECT_EQ(begin, nullptr); 494 CX_TEST_ASSERT(begin == NULL);
495 EXPECT_EQ(end, nullptr); 495 CX_TEST_ASSERT(end == NULL);
496 } 496 }
497 497
498 TEST(LinkedList_LowLevel, cx_linked_list_size) { 498 TEST(LinkedList_LowLevel, cx_linked_list_size) {
499 EXPECT_EQ(cx_linked_list_size(nullptr, loc_next), 0); 499 EXPECT_EQ(cx_linked_list_size(NULL, loc_next), 0);
500 500
501 { 501 {
502 auto testdata = create_nodes_test_data(5); 502 auto testdata = create_nodes_test_data(5);
503 EXPECT_EQ(cx_linked_list_size(testdata.begin, loc_next), 5); 503 EXPECT_EQ(cx_linked_list_size(testdata.begin, loc_next), 5);
504 } 504 }
508 EXPECT_EQ(cx_linked_list_size(testdata.begin, loc_next), 13); 508 EXPECT_EQ(cx_linked_list_size(testdata.begin, loc_next), 13);
509 } 509 }
510 } 510 }
511 511
512 TEST(LinkedList_LowLevel, cx_linked_list_sort_empty) { 512 TEST(LinkedList_LowLevel, cx_linked_list_sort_empty) {
513 void *begin = nullptr; 513 void *begin = NULL;
514 EXPECT_NO_FATAL_FAILURE( 514 EXPECT_NO_FATAL_FAILURE(
515 cx_linked_list_sort(&begin, nullptr, loc_prev, loc_next, loc_data, cx_cmp_int); 515 cx_linked_list_sort(&begin, NULL, loc_prev, loc_next, loc_data, cx_cmp_int);
516 ); 516 );
517 } 517 }
518 518
519 TEST(LinkedList_LowLevel, cx_linked_list_sort) { 519 TEST(LinkedList_LowLevel, cx_linked_list_sort) {
520 int_test_data<1500> testdata; 520 int_test_data<1500> testdata;
526 void *end = cx_linked_list_last(begin, loc_next); 526 void *end = cx_linked_list_last(begin, loc_next);
527 527
528 cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data, cx_cmp_int); 528 cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data, cx_cmp_int);
529 529
530 node *check = reinterpret_cast<node *>(begin); 530 node *check = reinterpret_cast<node *>(begin);
531 node *check_last = nullptr; 531 node *check_last = NULL;
532 cx_for_n (i, sorted.size()) { 532 cx_for_n (i, sorted.size()) {
533 EXPECT_EQ(check->data, sorted[i]); 533 CX_TEST_ASSERT(check->data == sorted[i]);
534 EXPECT_EQ(check->prev, check_last); 534 CX_TEST_ASSERT(check->prev == check_last);
535 if (i < sorted.size() - 1) { 535 if (i < sorted.size() - 1) {
536 ASSERT_NE(check->next, nullptr); 536 ASSERT_NE(check->next, NULL);
537 } 537 }
538 check_last = check; 538 check_last = check;
539 check = check->next; 539 check = check->next;
540 } 540 }
541 EXPECT_EQ(check, nullptr); 541 CX_TEST_ASSERT(check == NULL);
542 EXPECT_EQ(end, check_last); 542 CX_TEST_ASSERT(end == check_last);
543 } 543 }
544 544
545 TEST(LinkedList_LowLevel, cx_linked_list_reverse) { 545 TEST(LinkedList_LowLevel, cx_linked_list_reverse) {
546 auto testdata = create_nodes_test_data({2, 4, 6, 8}); 546 auto testdata = create_nodes_test_data({2, 4, 6, 8});
547 auto expected = create_nodes_test_data({8, 6, 4, 2}); 547 auto expected = create_nodes_test_data({8, 6, 4, 2});
549 auto begin = reinterpret_cast<void *>(testdata.begin); 549 auto begin = reinterpret_cast<void *>(testdata.begin);
550 auto end = cx_linked_list_last(begin, loc_next); 550 auto end = cx_linked_list_last(begin, loc_next);
551 auto orig_begin = begin, orig_end = end; 551 auto orig_begin = begin, orig_end = end;
552 552
553 cx_linked_list_reverse(&begin, &end, loc_prev, loc_next); 553 cx_linked_list_reverse(&begin, &end, loc_prev, loc_next);
554 EXPECT_EQ(end, orig_begin); 554 CX_TEST_ASSERT(end == orig_begin);
555 EXPECT_EQ(begin, orig_end); 555 CX_TEST_ASSERT(begin == orig_end);
556 EXPECT_EQ(cx_linked_list_compare(begin, expected.begin, loc_next, loc_data, cx_cmp_int), 0); 556 EXPECT_EQ(cx_linked_list_compare(begin, expected.begin, loc_next, loc_data, cx_cmp_int), 0);
557 } 557 }
558 558
559 class HighLevelTest : public ::testing::Test { 559 class HighLevelTest : public ::testing::Test {
560 mutable std::unordered_set<CxList *> lists; 560 mutable std::unordered_set<CxList *> lists;
561 protected: 561 protected:
562 CxTestingAllocator testingAllocator; 562 CxTestingAllocator testingAllocator;
563 563
564 void TearDown() override { 564 void TearDown() override {
565 for (auto &&l: lists) cxListDestroy(l); 565 for (auto &&l: lists) cxListDestroy(l);
566 EXPECT_TRUE(testingAllocator.verify()); 566 CX_TEST_ASSERT(testingAllocator.verify());
567 } 567 }
568 568
569 static constexpr size_t testdata_len = 250; 569 static constexpr size_t testdata_len = 250;
570 int_test_data<testdata_len> testdata; 570 int_test_data<testdata_len> testdata;
571 571
572 auto autofree(CxList *list) const -> CxList * { 572 auto autofree(CxList *list) const -> CxList * {
573 if (list != nullptr) lists.insert(list); 573 if (list != NULL) lists.insert(list);
574 return list; 574 return list;
575 } 575 }
576 576
577 auto linkedListFromTestData() const -> CxList * { 577 auto linkedListFromTestData() const -> CxList * {
578 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); 578 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
604 CxList *list, 604 CxList *list,
605 bool as_pointer 605 bool as_pointer
606 ) { 606 ) {
607 auto len = testdata_len; 607 auto len = testdata_len;
608 cx_for_n (i, len) EXPECT_EQ(cxListAdd(list, &testdata.data[i]), 0); 608 cx_for_n (i, len) EXPECT_EQ(cxListAdd(list, &testdata.data[i]), 0);
609 EXPECT_EQ(cxListSize(list), len); 609 CX_TEST_ASSERT(cxListSize(list) == len);
610 cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]); 610 cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]);
611 cx_for_n (i, len) ++testdata.data[i]; 611 cx_for_n (i, len) ++testdata.data[i];
612 if (as_pointer) { 612 if (as_pointer) {
613 cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]); 613 cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]);
614 } else { 614 } else {
627 EXPECT_EQ(cxListSize(list), 2); 627 EXPECT_EQ(cxListSize(list), 2);
628 EXPECT_EQ(cxListInsert(list, 1, &c), 0); 628 EXPECT_EQ(cxListInsert(list, 1, &c), 0);
629 EXPECT_EQ(cxListSize(list), 3); 629 EXPECT_EQ(cxListSize(list), 3);
630 EXPECT_EQ(cxListInsert(list, 3, &d), 0); 630 EXPECT_EQ(cxListInsert(list, 3, &d), 0);
631 631
632 ASSERT_EQ(cxListSize(list), 4); 632 CX_TEST_ASSERT(cxListSize(list) == 4);
633 633
634 EXPECT_EQ(*(int *) cxListAt(list, 0), 47); 634 EXPECT_EQ(*(int *) cxListAt(list, 0), 47);
635 EXPECT_EQ(*(int *) cxListAt(list, 1), 13); 635 EXPECT_EQ(*(int *) cxListAt(list, 1), 13);
636 EXPECT_EQ(*(int *) cxListAt(list, 2), 5); 636 EXPECT_EQ(*(int *) cxListAt(list, 2), 5);
637 EXPECT_EQ(*(int *) cxListAt(list, 3), 42); 637 EXPECT_EQ(*(int *) cxListAt(list, 3), 42);
655 if (pointers) { 655 if (pointers) {
656 inserted = cxListInsertArray(list, 0, aptr, 5); 656 inserted = cxListInsertArray(list, 0, aptr, 5);
657 } else { 657 } else {
658 inserted = cxListInsertArray(list, 0, a, 5); 658 inserted = cxListInsertArray(list, 0, a, 5);
659 } 659 }
660 EXPECT_EQ(inserted, 5); 660 CX_TEST_ASSERT(inserted == 5);
661 EXPECT_EQ(*(int *) cxListAt(list, 0), 5); 661 EXPECT_EQ(*(int *) cxListAt(list, 0), 5);
662 EXPECT_EQ(*(int *) cxListAt(list, 1), 47); 662 EXPECT_EQ(*(int *) cxListAt(list, 1), 47);
663 EXPECT_EQ(*(int *) cxListAt(list, 2), 11); 663 EXPECT_EQ(*(int *) cxListAt(list, 2), 11);
664 EXPECT_EQ(*(int *) cxListAt(list, 3), 13); 664 EXPECT_EQ(*(int *) cxListAt(list, 3), 13);
665 EXPECT_EQ(*(int *) cxListAt(list, 4), 42); 665 EXPECT_EQ(*(int *) cxListAt(list, 4), 42);
666 if (pointers) { 666 if (pointers) {
667 inserted = cxListInsertArray(list, 3, bptr, 5); 667 inserted = cxListInsertArray(list, 3, bptr, 5);
668 } else { 668 } else {
669 inserted = cxListInsertArray(list, 3, b, 5); 669 inserted = cxListInsertArray(list, 3, b, 5);
670 } 670 }
671 EXPECT_EQ(inserted, 5); 671 CX_TEST_ASSERT(inserted == 5);
672 EXPECT_EQ(*(int *) cxListAt(list, 0), 5); 672 EXPECT_EQ(*(int *) cxListAt(list, 0), 5);
673 EXPECT_EQ(*(int *) cxListAt(list, 1), 47); 673 EXPECT_EQ(*(int *) cxListAt(list, 1), 47);
674 EXPECT_EQ(*(int *) cxListAt(list, 2), 11); 674 EXPECT_EQ(*(int *) cxListAt(list, 2), 11);
675 EXPECT_EQ(*(int *) cxListAt(list, 3), 9); 675 EXPECT_EQ(*(int *) cxListAt(list, 3), 9);
676 EXPECT_EQ(*(int *) cxListAt(list, 4), 18); 676 EXPECT_EQ(*(int *) cxListAt(list, 4), 18);
792 list->advanced_destructor = advanced_destr_test_fun; 792 list->advanced_destructor = advanced_destr_test_fun;
793 verifyAnyDestructor(list); 793 verifyAnyDestructor(list);
794 } 794 }
795 795
796 static void verifySwap(CxList *list) { 796 static void verifySwap(CxList *list) {
797 ASSERT_EQ(cxListSize(list), 0); 797 CX_TEST_ASSERT(cxListSize(list) == 0);
798 798
799 int original[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 799 int original[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
800 int swapped[16] = {8, 4, 14, 3, 1, 5, 9, 12, 0, 6, 11, 10, 7, 15, 2, 13}; 800 int swapped[16] = {8, 4, 14, 3, 1, 5, 9, 12, 0, 6, 11, 10, 7, 15, 2, 13};
801 801
802 // we have to add the items one by one, because it could be a pointer list 802 // we have to add the items one by one, because it could be a pointer list
823 EXPECT_EQ(0, result); 823 EXPECT_EQ(0, result);
824 result = cxListSwap(list, 13, 15); 824 result = cxListSwap(list, 13, 15);
825 EXPECT_EQ(0, result); 825 EXPECT_EQ(0, result);
826 826
827 result = cxListSwap(list, 5, 16); 827 result = cxListSwap(list, 5, 16);
828 EXPECT_NE(0, result); 828 CX_TEST_ASSERT(0 != result);
829 result = cxListSwap(list, 16, 6); 829 result = cxListSwap(list, 16, 6);
830 EXPECT_NE(0, result); 830 CX_TEST_ASSERT(0 != result);
831 result = cxListSwap(list, 16, 17); 831 result = cxListSwap(list, 16, 17);
832 EXPECT_NE(0, result); 832 CX_TEST_ASSERT(0 != result);
833 833
834 auto iter = cxListIterator(list); 834 auto iter = cxListIterator(list);
835 cx_foreach(int*, e, iter) { 835 cx_foreach(int*, e, iter) {
836 EXPECT_EQ(*e, swapped[iter.index]); 836 EXPECT_EQ(*e, swapped[iter.index]);
837 } 837 }
845 auto len = testdata_len; 845 auto len = testdata_len;
846 EXPECT_EQ(cxListSize(list), len); 846 EXPECT_EQ(cxListSize(list), len);
847 cx_for_n (i, len) { 847 cx_for_n (i, len) {
848 EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]); 848 EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]);
849 } 849 }
850 EXPECT_EQ(cxListAt(list, cxListSize(list)), nullptr); 850 EXPECT_EQ(cxListAt(list, cxListSize(list)), NULL);
851 } 851 }
852 852
853 void verifyFind(CxList *list) const { 853 void verifyFind(CxList *list) const {
854 cx_for_n (attempt, 25) { 854 cx_for_n (attempt, 25) {
855 size_t exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp) 855 size_t exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp)
870 870
871 void verifySort(CxList *list) const { 871 void verifySort(CxList *list) const {
872 std::array<int, testdata_len> expected{}; 872 std::array<int, testdata_len> expected{};
873 std::partial_sort_copy(testdata.data.begin(), testdata.data.end(), expected.begin(), expected.end()); 873 std::partial_sort_copy(testdata.data.begin(), testdata.data.end(), expected.begin(), expected.end());
874 cxListSort(list); 874 cxListSort(list);
875 cx_for_n (i, testdata_len) ASSERT_EQ(*(int *) cxListAt(list, i), expected[i]); 875 cx_for_n (i, testdata_len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]);
876 } 876 }
877 877
878 void verifyIterator(CxList *list) const { 878 void verifyIterator(CxList *list) const {
879 auto iter = cxListIterator(list); 879 auto iter = cxListIterator(list);
880 size_t i = 0; 880 size_t i = 0;
881 cx_foreach(int*, x, iter) { 881 cx_foreach(int*, x, iter) {
882 ASSERT_EQ(i, iter.index); 882 CX_TEST_ASSERT(i == iter.index);
883 EXPECT_EQ(*x, testdata.data[iter.index]); 883 EXPECT_EQ(*x, testdata.data[iter.index]);
884 i++; 884 i++;
885 } 885 }
886 ASSERT_EQ(i, cxListSize(list)); 886 CX_TEST_ASSERT(i == cxListSize(list));
887 iter = cxListBackwardsIterator(list); 887 iter = cxListBackwardsIterator(list);
888 cx_foreach(int*, x, iter) { 888 cx_foreach(int*, x, iter) {
889 ASSERT_EQ(i - 1, iter.index); 889 CX_TEST_ASSERT(i - 1 == iter.index);
890 EXPECT_EQ(*x, testdata.data[iter.index]); 890 EXPECT_EQ(*x, testdata.data[iter.index]);
891 i--; 891 i--;
892 } 892 }
893 ASSERT_EQ(i, 0); 893 CX_TEST_ASSERT(i == 0);
894 auto len = testdata_len; 894 auto len = testdata_len;
895 i = len / 2; 895 i = len / 2;
896 auto mut_iter = cxListMutIteratorAt(list, i); 896 auto mut_iter = cxListMutIteratorAt(list, i);
897 size_t j = 0; 897 size_t j = 0;
898 cx_foreach(int*, x, mut_iter) { 898 cx_foreach(int*, x, mut_iter) {
899 ASSERT_EQ(mut_iter.index, len / 2 + j / 2); 899 CX_TEST_ASSERT(mut_iter.index == len / 2 + j / 2);
900 ASSERT_EQ(*x, testdata.data[i]); 900 CX_TEST_ASSERT(*x == testdata.data[i]);
901 if (i % 2 == 1) cxIteratorFlagRemoval(mut_iter); 901 if (i % 2 == 1) cxIteratorFlagRemoval(mut_iter);
902 i++; 902 i++;
903 j++; 903 j++;
904 } 904 }
905 ASSERT_EQ(i, len); 905 CX_TEST_ASSERT(i == len);
906 i = len / 2; 906 i = len / 2;
907 j = 0; 907 j = 0;
908 mut_iter = cxListMutBackwardsIteratorAt(list, i - 1); 908 mut_iter = cxListMutBackwardsIteratorAt(list, i - 1);
909 cx_foreach(int*, x, mut_iter) { 909 cx_foreach(int*, x, mut_iter) {
910 ASSERT_EQ(mut_iter.index, len / 2 - 1 - j); 910 CX_TEST_ASSERT(mut_iter.index == len / 2 - 1 - j);
911 ASSERT_EQ(*x, testdata.data[i - 1]); 911 CX_TEST_ASSERT(*x == testdata.data[i - 1]);
912 if (i % 2 == 0) cxIteratorFlagRemoval(mut_iter); 912 if (i % 2 == 0) cxIteratorFlagRemoval(mut_iter);
913 i--; 913 i--;
914 j++; 914 j++;
915 } 915 }
916 ASSERT_EQ(i, 0); 916 CX_TEST_ASSERT(i == 0);
917 ASSERT_EQ(cxListSize(list), len / 2); 917 CX_TEST_ASSERT(cxListSize(list) == len / 2);
918 cx_for_n(j, len / 2) ASSERT_EQ(*(int *) cxListAt(list, j), testdata.data[j * 2]); 918 cx_for_n(j, len / 2) ASSERT_EQ(*(int *) cxListAt(list, j), testdata.data[j * 2]);
919 } 919 }
920 920
921 static void verifyInsertViaIterator(CxList *list) { 921 static void verifyInsertViaIterator(CxList *list) {
922 int newdata[] = {10, 20, 30, 40, 50}; 922 int newdata[] = {10, 20, 30, 40, 50};
923 923
924 auto iter = cxListMutIteratorAt(list, 2); 924 auto iter = cxListMutIteratorAt(list, 2);
925 EXPECT_TRUE(cxIteratorValid(iter)); 925 CX_TEST_ASSERT(cxIteratorValid(iter));
926 EXPECT_EQ(iter.index, 2); 926 EXPECT_EQ(iter.index, 2);
927 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); 927 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
928 cxListInsertAfter(&iter, &newdata[0]); 928 cxListInsertAfter(&iter, &newdata[0]);
929 EXPECT_TRUE(cxIteratorValid(iter)); 929 CX_TEST_ASSERT(cxIteratorValid(iter));
930 EXPECT_EQ(iter.index, 2); 930 EXPECT_EQ(iter.index, 2);
931 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); 931 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
932 cxListInsertBefore(&iter, &newdata[1]); 932 cxListInsertBefore(&iter, &newdata[1]);
933 EXPECT_TRUE(cxIteratorValid(iter)); 933 CX_TEST_ASSERT(cxIteratorValid(iter));
934 EXPECT_EQ(iter.index, 3); 934 EXPECT_EQ(iter.index, 3);
935 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); 935 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
936 936
937 iter = cxListMutIterator(list); 937 iter = cxListMutIterator(list);
938 cxListInsertBefore(&iter, &newdata[2]); 938 cxListInsertBefore(&iter, &newdata[2]);
939 EXPECT_TRUE(cxIteratorValid(iter)); 939 CX_TEST_ASSERT(cxIteratorValid(iter));
940 EXPECT_EQ(iter.index, 1); 940 EXPECT_EQ(iter.index, 1);
941 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 0); 941 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 0);
942 iter = cxListMutIteratorAt(list, cxListSize(list)); 942 iter = cxListMutIteratorAt(list, cxListSize(list));
943 cxListInsertBefore(&iter, &newdata[3]); 943 cxListInsertBefore(&iter, &newdata[3]);
944 EXPECT_FALSE(cxIteratorValid(iter)); 944 CX_TEST_ASSERT(!cxIteratorValid(iter));
945 EXPECT_EQ(iter.index, 9); 945 EXPECT_EQ(iter.index, 9);
946 iter = cxListMutIteratorAt(list, cxListSize(list)); 946 iter = cxListMutIteratorAt(list, cxListSize(list));
947 cxListInsertAfter(&iter, &newdata[4]); 947 cxListInsertAfter(&iter, &newdata[4]);
948 EXPECT_FALSE(cxIteratorValid(iter)); 948 CX_TEST_ASSERT(!cxIteratorValid(iter));
949 EXPECT_EQ(iter.index, 10); 949 EXPECT_EQ(iter.index, 10);
950 950
951 int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50}; 951 int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50};
952 cx_for_n (j, 10) EXPECT_EQ(*(int *) cxListAt(list, j), expdata[j]); 952 cx_for_n (j, 10) EXPECT_EQ(*(int *) cxListAt(list, j), expdata[j]);
953 } 953 }
968 cxListAdd(left, &x); 968 cxListAdd(left, &x);
969 ASSERT_GT(cxListSize(left), cxListSize(right)); 969 ASSERT_GT(cxListSize(left), cxListSize(right));
970 EXPECT_GT(cxListCompare(left, right), 0); 970 EXPECT_GT(cxListCompare(left, right), 0);
971 EXPECT_LT(cxListCompare(right, left), 0); 971 EXPECT_LT(cxListCompare(right, left), 0);
972 cxListAdd(right, &x); 972 cxListAdd(right, &x);
973 ASSERT_EQ(cxListSize(left), cxListSize(right)); 973 CX_TEST_ASSERT(cxListSize(left) == cxListSize(right));
974 EXPECT_EQ(cxListCompare(left, right), 0); 974 EXPECT_EQ(cxListCompare(left, right), 0);
975 int a = 5, b = 10; 975 int a = 5, b = 10;
976 cxListInsert(left, 15, &a); 976 cxListInsert(left, 15, &a);
977 cxListInsert(right, 15, &b); 977 cxListInsert(right, 15, &b);
978 ASSERT_EQ(cxListSize(left), cxListSize(right)); 978 CX_TEST_ASSERT(cxListSize(left) == cxListSize(right));
979 EXPECT_LT(cxListCompare(left, right), 0); 979 EXPECT_LT(cxListCompare(left, right), 0);
980 EXPECT_GT(cxListCompare(right, left), 0); 980 EXPECT_GT(cxListCompare(right, left), 0);
981 *(int *) cxListAt(left, 15) = 10; 981 *(int *) cxListAt(left, 15) = 10;
982 EXPECT_EQ(cxListCompare(left, right), 0); 982 EXPECT_EQ(cxListCompare(left, right), 0);
983 } 983 }
998 class PointerArrayList : public HighLevelTest { 998 class PointerArrayList : public HighLevelTest {
999 }; 999 };
1000 1000
1001 TEST_F(PointerLinkedList, cxListStorePointers) { 1001 TEST_F(PointerLinkedList, cxListStorePointers) {
1002 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, 47)); 1002 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, 47));
1003 EXPECT_FALSE(cxListIsStoringPointers(list)); 1003 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
1004 cxListStorePointers(list); 1004 cxListStorePointers(list);
1005 EXPECT_EQ(list->item_size, sizeof(void *)); 1005 EXPECT_EQ(list->item_size, sizeof(void *));
1006 EXPECT_NE(list->cl, nullptr); 1006 CX_TEST_ASSERT(list->cl != NULL);
1007 EXPECT_NE(list->climpl, nullptr); 1007 CX_TEST_ASSERT(list->climpl != NULL);
1008 EXPECT_TRUE(cxListIsStoringPointers(list)); 1008 CX_TEST_ASSERT(cxListIsStoringPointers(list));
1009 cxListStoreObjects(list); 1009 cxListStoreObjects(list);
1010 EXPECT_NE(list->cl, nullptr); 1010 CX_TEST_ASSERT(list->cl != NULL);
1011 EXPECT_EQ(list->climpl, nullptr); 1011 EXPECT_EQ(list->climpl, NULL);
1012 EXPECT_FALSE(cxListIsStoringPointers(list)); 1012 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
1013 } 1013 }
1014 1014
1015 TEST_F(LinkedList, cxLinkedListCreate) { 1015 TEST_F(LinkedList, cxLinkedListCreate) {
1016 CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); 1016 CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
1017 ASSERT_NE(list, nullptr); 1017 ASSERT_NE(list, NULL);
1018 EXPECT_EQ(list->item_size, sizeof(int)); 1018 EXPECT_EQ(list->item_size, sizeof(int));
1019 EXPECT_EQ(list->simple_destructor, nullptr); 1019 EXPECT_EQ(list->simple_destructor, NULL);
1020 EXPECT_EQ(list->advanced_destructor, nullptr); 1020 EXPECT_EQ(list->advanced_destructor, NULL);
1021 EXPECT_EQ(list->destructor_data, nullptr); 1021 EXPECT_EQ(list->destructor_data, NULL);
1022 EXPECT_EQ(cxListSize(list), 0); 1022 EXPECT_EQ(cxListSize(list), 0);
1023 EXPECT_EQ(list->allocator, &testingAllocator); 1023 EXPECT_EQ(list->allocator, &testingAllocator);
1024 EXPECT_EQ(list->cmpfunc, cx_cmp_int); 1024 EXPECT_EQ(list->cmpfunc, cx_cmp_int);
1025 EXPECT_FALSE(cxListIsStoringPointers(list)); 1025 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
1026 } 1026 }
1027 1027
1028 TEST_F(LinkedList, cxLinkedListCreateSimple) { 1028 TEST_F(LinkedList, cxLinkedListCreateSimple) {
1029 CxList *list = autofree(cxLinkedListCreateSimple(sizeof(int))); 1029 CxList *list = autofree(cxLinkedListCreateSimple(sizeof(int)));
1030 ASSERT_NE(list, nullptr); 1030 ASSERT_NE(list, NULL);
1031 EXPECT_EQ(list->item_size, sizeof(int)); 1031 EXPECT_EQ(list->item_size, sizeof(int));
1032 EXPECT_EQ(list->cmpfunc, nullptr); 1032 EXPECT_EQ(list->cmpfunc, NULL);
1033 EXPECT_EQ(list->allocator, cxDefaultAllocator); 1033 EXPECT_EQ(list->allocator, cxDefaultAllocator);
1034 EXPECT_EQ(list->simple_destructor, nullptr); 1034 EXPECT_EQ(list->simple_destructor, NULL);
1035 EXPECT_EQ(list->advanced_destructor, nullptr); 1035 EXPECT_EQ(list->advanced_destructor, NULL);
1036 EXPECT_EQ(list->destructor_data, nullptr); 1036 EXPECT_EQ(list->destructor_data, NULL);
1037 EXPECT_EQ(cxListSize(list), 0); 1037 EXPECT_EQ(cxListSize(list), 0);
1038 EXPECT_FALSE(cxListIsStoringPointers(list)); 1038 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
1039 } 1039 }
1040 1040
1041 TEST_F(PointerLinkedList, cxLinkedListCreateSimpleForPointers) { 1041 TEST_F(PointerLinkedList, cxLinkedListCreateSimpleForPointers) {
1042 CxList *list = autofree(cxLinkedListCreateSimple(CX_STORE_POINTERS)); 1042 CxList *list = autofree(cxLinkedListCreateSimple(CX_STORE_POINTERS));
1043 ASSERT_NE(list, nullptr); 1043 ASSERT_NE(list, NULL);
1044 EXPECT_EQ(list->item_size, sizeof(void *)); 1044 EXPECT_EQ(list->item_size, sizeof(void *));
1045 EXPECT_EQ(list->cmpfunc, cx_cmp_ptr); 1045 EXPECT_EQ(list->cmpfunc, cx_cmp_ptr);
1046 EXPECT_EQ(list->allocator, cxDefaultAllocator); 1046 EXPECT_EQ(list->allocator, cxDefaultAllocator);
1047 EXPECT_EQ(list->simple_destructor, nullptr); 1047 EXPECT_EQ(list->simple_destructor, NULL);
1048 EXPECT_EQ(list->advanced_destructor, nullptr); 1048 EXPECT_EQ(list->advanced_destructor, NULL);
1049 EXPECT_EQ(list->destructor_data, nullptr); 1049 EXPECT_EQ(list->destructor_data, NULL);
1050 EXPECT_EQ(cxListSize(list), 0); 1050 EXPECT_EQ(cxListSize(list), 0);
1051 EXPECT_TRUE(cxListIsStoringPointers(list)); 1051 CX_TEST_ASSERT(cxListIsStoringPointers(list));
1052 } 1052 }
1053 1053
1054 TEST_F(ArrayList, cxArrayListCreate) { 1054 TEST_F(ArrayList, cxArrayListCreate) {
1055 CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8)); 1055 CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8));
1056 ASSERT_NE(list, nullptr); 1056 ASSERT_NE(list, NULL);
1057 EXPECT_EQ(list->item_size, sizeof(int)); 1057 EXPECT_EQ(list->item_size, sizeof(int));
1058 EXPECT_EQ(list->simple_destructor, nullptr); 1058 EXPECT_EQ(list->simple_destructor, NULL);
1059 EXPECT_EQ(list->advanced_destructor, nullptr); 1059 EXPECT_EQ(list->advanced_destructor, NULL);
1060 EXPECT_EQ(list->destructor_data, nullptr); 1060 EXPECT_EQ(list->destructor_data, NULL);
1061 EXPECT_EQ(cxListSize(list), 0); 1061 EXPECT_EQ(cxListSize(list), 0);
1062 EXPECT_EQ(list->allocator, &testingAllocator); 1062 EXPECT_EQ(list->allocator, &testingAllocator);
1063 EXPECT_EQ(list->cmpfunc, cx_cmp_int); 1063 EXPECT_EQ(list->cmpfunc, cx_cmp_int);
1064 EXPECT_FALSE(cxListIsStoringPointers(list)); 1064 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
1065 } 1065 }
1066 1066
1067 TEST_F(ArrayList, cxArrayListCreateSimple) { 1067 TEST_F(ArrayList, cxArrayListCreateSimple) {
1068 CxList *list = autofree(cxArrayListCreateSimple(sizeof(int), 8)); 1068 CxList *list = autofree(cxArrayListCreateSimple(sizeof(int), 8));
1069 ASSERT_NE(list, nullptr); 1069 ASSERT_NE(list, NULL);
1070 EXPECT_EQ(list->cmpfunc, nullptr); 1070 EXPECT_EQ(list->cmpfunc, NULL);
1071 EXPECT_EQ(list->allocator, cxDefaultAllocator); 1071 EXPECT_EQ(list->allocator, cxDefaultAllocator);
1072 EXPECT_EQ(list->item_size, sizeof(int)); 1072 EXPECT_EQ(list->item_size, sizeof(int));
1073 EXPECT_EQ(list->simple_destructor, nullptr); 1073 EXPECT_EQ(list->simple_destructor, NULL);
1074 EXPECT_EQ(list->advanced_destructor, nullptr); 1074 EXPECT_EQ(list->advanced_destructor, NULL);
1075 EXPECT_EQ(list->destructor_data, nullptr); 1075 EXPECT_EQ(list->destructor_data, NULL);
1076 EXPECT_EQ(cxListSize(list), 0); 1076 EXPECT_EQ(cxListSize(list), 0);
1077 EXPECT_FALSE(cxListIsStoringPointers(list)); 1077 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
1078 } 1078 }
1079 1079
1080 TEST_F(PointerArrayList, cxArrayListCreateSimpleForPointers) { 1080 TEST_F(PointerArrayList, cxArrayListCreateSimpleForPointers) {
1081 CxList *list = autofree(cxArrayListCreateSimple(CX_STORE_POINTERS, 8)); 1081 CxList *list = autofree(cxArrayListCreateSimple(CX_STORE_POINTERS, 8));
1082 ASSERT_NE(list, nullptr); 1082 ASSERT_NE(list, NULL);
1083 EXPECT_EQ(list->cmpfunc, cx_cmp_ptr); 1083 EXPECT_EQ(list->cmpfunc, cx_cmp_ptr);
1084 EXPECT_EQ(list->allocator, cxDefaultAllocator); 1084 EXPECT_EQ(list->allocator, cxDefaultAllocator);
1085 EXPECT_EQ(list->item_size, sizeof(void *)); 1085 EXPECT_EQ(list->item_size, sizeof(void *));
1086 EXPECT_TRUE(cxListIsStoringPointers(list)); 1086 CX_TEST_ASSERT(cxListIsStoringPointers(list));
1087 } 1087 }
1088 1088
1089 TEST_F(LinkedList, cxListAdd) { 1089 TEST_F(LinkedList, cxListAdd) {
1090 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); 1090 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
1091 verifyAdd(list, false); 1091 verifyAdd(list, false);
1454 1454
1455 TEST_F(PointerLinkedList, DestroyNoDestructor) { 1455 TEST_F(PointerLinkedList, DestroyNoDestructor) {
1456 void *item = cxMalloc(&testingAllocator, sizeof(int)); 1456 void *item = cxMalloc(&testingAllocator, sizeof(int));
1457 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); 1457 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS);
1458 cxListAdd(list, item); 1458 cxListAdd(list, item);
1459 ASSERT_FALSE(testingAllocator.verify()); 1459 CX_TEST_ASSERT(!testingAllocator.verify());
1460 cxListDestroy(list); 1460 cxListDestroy(list);
1461 EXPECT_FALSE(testingAllocator.verify()); 1461 CX_TEST_ASSERT(!testingAllocator.verify());
1462 cxFree(&testingAllocator, item); 1462 cxFree(&testingAllocator, item);
1463 EXPECT_TRUE(testingAllocator.verify()); 1463 CX_TEST_ASSERT(testingAllocator.verify());
1464 } 1464 }
1465 1465
1466 TEST_F(PointerLinkedList, DestroySimpleDestructor) { 1466 TEST_F(PointerLinkedList, DestroySimpleDestructor) {
1467 int item = 0; 1467 int item = 0;
1468 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); 1468 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS);
1476 void *item = cxMalloc(&testingAllocator, sizeof(int)); 1476 void *item = cxMalloc(&testingAllocator, sizeof(int));
1477 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); 1477 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS);
1478 list->destructor_data = &testingAllocator; 1478 list->destructor_data = &testingAllocator;
1479 list->advanced_destructor = (cx_destructor_func2) cxFree; 1479 list->advanced_destructor = (cx_destructor_func2) cxFree;
1480 cxListAdd(list, item); 1480 cxListAdd(list, item);
1481 ASSERT_FALSE(testingAllocator.verify()); 1481 CX_TEST_ASSERT(!testingAllocator.verify());
1482 cxListDestroy(list); 1482 cxListDestroy(list);
1483 EXPECT_TRUE(testingAllocator.verify()); 1483 CX_TEST_ASSERT(testingAllocator.verify());
1484 } 1484 }
1485 1485
1486 TEST_F(PointerArrayList, DestroyNoDestructor) { 1486 TEST_F(PointerArrayList, DestroyNoDestructor) {
1487 void *item = cxMalloc(&testingAllocator, sizeof(int)); 1487 void *item = cxMalloc(&testingAllocator, sizeof(int));
1488 auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4); 1488 auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4);
1489 cxListAdd(list, item); 1489 cxListAdd(list, item);
1490 ASSERT_FALSE(testingAllocator.verify()); 1490 CX_TEST_ASSERT(!testingAllocator.verify());
1491 cxListDestroy(list); 1491 cxListDestroy(list);
1492 EXPECT_FALSE(testingAllocator.verify()); 1492 CX_TEST_ASSERT(!testingAllocator.verify());
1493 cxFree(&testingAllocator, item); 1493 cxFree(&testingAllocator, item);
1494 EXPECT_TRUE(testingAllocator.verify()); 1494 CX_TEST_ASSERT(testingAllocator.verify());
1495 } 1495 }
1496 1496
1497 TEST_F(PointerArrayList, DestroySimpleDestructor) { 1497 TEST_F(PointerArrayList, DestroySimpleDestructor) {
1498 int item = 0; 1498 int item = 0;
1499 auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4); 1499 auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4);
1507 void *item = cxMalloc(&testingAllocator, sizeof(int)); 1507 void *item = cxMalloc(&testingAllocator, sizeof(int));
1508 auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4); 1508 auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4);
1509 list->destructor_data = &testingAllocator; 1509 list->destructor_data = &testingAllocator;
1510 list->advanced_destructor = (cx_destructor_func2) cxFree; 1510 list->advanced_destructor = (cx_destructor_func2) cxFree;
1511 cxListAdd(list, item); 1511 cxListAdd(list, item);
1512 ASSERT_FALSE(testingAllocator.verify()); 1512 CX_TEST_ASSERT(!testingAllocator.verify());
1513 cxListDestroy(list); 1513 cxListDestroy(list);
1514 EXPECT_TRUE(testingAllocator.verify()); 1514 CX_TEST_ASSERT(testingAllocator.verify());
1515 } 1515 }
1516 1516
1517 TEST(EmptyList, Size) { 1517 TEST(EmptyList, Size) {
1518 auto list = cxEmptyList; 1518 auto list = cxEmptyList;
1519 1519
1527 auto it1 = cxListIterator(list); 1527 auto it1 = cxListIterator(list);
1528 auto it2 = cxListBackwardsIterator(list); 1528 auto it2 = cxListBackwardsIterator(list);
1529 auto it3 = cxListMutIterator(list); 1529 auto it3 = cxListMutIterator(list);
1530 auto it4 = cxListMutBackwardsIterator(list); 1530 auto it4 = cxListMutBackwardsIterator(list);
1531 1531
1532 EXPECT_FALSE(cxIteratorValid(it1)); 1532 CX_TEST_ASSERT(!cxIteratorValid(it1));
1533 EXPECT_FALSE(cxIteratorValid(it2)); 1533 CX_TEST_ASSERT(!cxIteratorValid(it2));
1534 EXPECT_FALSE(cxIteratorValid(it3)); 1534 CX_TEST_ASSERT(!cxIteratorValid(it3));
1535 EXPECT_FALSE(cxIteratorValid(it4)); 1535 CX_TEST_ASSERT(!cxIteratorValid(it4));
1536 1536
1537 int c = 0; 1537 int c = 0;
1538 cx_foreach(void*, data, it1) c++; 1538 cx_foreach(void*, data, it1) c++;
1539 cx_foreach(void*, data, it2) c++; 1539 cx_foreach(void*, data, it2) c++;
1540 cx_foreach(void*, data, it3) c++; 1540 cx_foreach(void*, data, it3) c++;
1551 } 1551 }
1552 1552
1553 TEST(EmptyList, At) { 1553 TEST(EmptyList, At) {
1554 auto list = cxEmptyList; 1554 auto list = cxEmptyList;
1555 1555
1556 EXPECT_EQ(cxListAt(list, 0), nullptr); 1556 EXPECT_EQ(cxListAt(list, 0), NULL);
1557 EXPECT_EQ(cxListAt(list, 1), nullptr); 1557 EXPECT_EQ(cxListAt(list, 1), NULL);
1558 } 1558 }
1559 1559
1560 TEST(EmptyList, Find) { 1560 TEST(EmptyList, Find) {
1561 auto list = cxEmptyList; 1561 auto list = cxEmptyList;
1562 1562

mercurial