test/test_list.c

changeset 476
60ff4561dc04
parent 475
31bf97fdbf71
child 478
599770bb6314
equal deleted inserted replaced
475:31bf97fdbf71 476:60ff4561dc04
286 ptrdiff_t loc = offsetof(struct node, next); 286 ptrdiff_t loc = offsetof(struct node, next);
287 ptrdiff_t ploc = offsetof(struct dnode, prev); 287 ptrdiff_t ploc = offsetof(struct dnode, prev);
288 288
289 void *begin; 289 void *begin;
290 void *end; 290 void *end;
291 void *result;
292 291
293 // single linked list 292 // single linked list
294 struct node third = {NULL}; 293 struct node third = {NULL};
295 struct node second = {&third}; 294 struct node second = {&third};
296 struct node first = {&second}; 295 struct node first = {&second};
297 begin = &first; 296 begin = &first;
298 297
299 result = cx_linked_list_remove(&begin, NULL, -1, loc, &second); 298 cx_linked_list_remove(&begin, NULL, -1, loc, &second);
300 CU_ASSERT_PTR_EQUAL(result, &first)
301 CU_ASSERT_PTR_EQUAL(begin, &first) 299 CU_ASSERT_PTR_EQUAL(begin, &first)
302 CU_ASSERT_PTR_EQUAL(first.next, &third) 300 CU_ASSERT_PTR_EQUAL(first.next, &third)
303 CU_ASSERT_PTR_NULL(second.next)
304 CU_ASSERT_PTR_NULL(third.next) 301 CU_ASSERT_PTR_NULL(third.next)
305 302
306 result = cx_linked_list_remove(&begin, NULL, -1, loc, &first); 303 cx_linked_list_remove(&begin, NULL, -1, loc, &first);
307 CU_ASSERT_PTR_EQUAL(result, &third)
308 CU_ASSERT_PTR_EQUAL(begin, &third) 304 CU_ASSERT_PTR_EQUAL(begin, &third)
309 CU_ASSERT_PTR_NULL(first.next)
310 CU_ASSERT_PTR_NULL(third.next) 305 CU_ASSERT_PTR_NULL(third.next)
311 306
312 result = cx_linked_list_remove(&begin, NULL, -1, loc, &third); 307 cx_linked_list_remove(&begin, NULL, -1, loc, &third);
313 CU_ASSERT_PTR_NULL(result)
314 CU_ASSERT_PTR_NULL(begin) 308 CU_ASSERT_PTR_NULL(begin)
315 CU_ASSERT_PTR_NULL(third.next)
316 309
317 // doubly linked list 310 // doubly linked list
318 struct dnode dthird = {NULL , NULL}; 311 struct dnode dthird = {NULL , NULL};
319 struct dnode dsecond = {&dthird, NULL}; 312 struct dnode dsecond = {&dthird, NULL};
320 struct dnode dfirst = {&dsecond, NULL}; 313 struct dnode dfirst = {&dsecond, NULL};
321 dthird.prev = &dsecond; 314 dthird.prev = &dsecond;
322 dsecond.prev = &dfirst; 315 dsecond.prev = &dfirst;
323 begin = &dfirst; 316 begin = &dfirst;
324 end = &dthird; 317 end = &dthird;
325 318
326 result = cx_linked_list_remove(&begin, &end, ploc, loc, &dsecond); 319 cx_linked_list_remove(&begin, &end, ploc, loc, &dsecond);
327 CU_ASSERT_PTR_EQUAL(result, &dfirst)
328 CU_ASSERT_PTR_EQUAL(begin, &dfirst) 320 CU_ASSERT_PTR_EQUAL(begin, &dfirst)
329 CU_ASSERT_PTR_EQUAL(end, &dthird) 321 CU_ASSERT_PTR_EQUAL(end, &dthird)
330 CU_ASSERT_PTR_NULL(dfirst.prev) 322 CU_ASSERT_PTR_NULL(dfirst.prev)
331 CU_ASSERT_PTR_EQUAL(dfirst.next, &dthird) 323 CU_ASSERT_PTR_EQUAL(dfirst.next, &dthird)
332 CU_ASSERT_PTR_NULL(dsecond.prev)
333 CU_ASSERT_PTR_NULL(dsecond.next)
334 CU_ASSERT_PTR_EQUAL(dthird.prev, &dfirst) 324 CU_ASSERT_PTR_EQUAL(dthird.prev, &dfirst)
335 CU_ASSERT_PTR_NULL(dthird.next) 325 CU_ASSERT_PTR_NULL(dthird.next)
336 326
337 result = cx_linked_list_remove(&begin, &end, ploc, loc, &dthird); 327 cx_linked_list_remove(&begin, &end, ploc, loc, &dthird);
338 CU_ASSERT_PTR_EQUAL(result, &dfirst)
339 CU_ASSERT_PTR_EQUAL(begin, &dfirst) 328 CU_ASSERT_PTR_EQUAL(begin, &dfirst)
340 CU_ASSERT_PTR_EQUAL(end, &dfirst) 329 CU_ASSERT_PTR_EQUAL(end, &dfirst)
341 CU_ASSERT_PTR_NULL(dfirst.prev) 330 CU_ASSERT_PTR_NULL(dfirst.prev)
342 CU_ASSERT_PTR_NULL(dfirst.next) 331 CU_ASSERT_PTR_NULL(dfirst.next)
343 CU_ASSERT_PTR_NULL(dthird.prev) 332
344 CU_ASSERT_PTR_NULL(dthird.next) 333 cx_linked_list_remove(&begin, &end, ploc, loc, &dfirst);
345
346 result = cx_linked_list_remove(&begin, &end, ploc, loc, &dfirst);
347 CU_ASSERT_PTR_NULL(result)
348 CU_ASSERT_PTR_NULL(begin) 334 CU_ASSERT_PTR_NULL(begin)
349 CU_ASSERT_PTR_NULL(end) 335 CU_ASSERT_PTR_NULL(end)
350 CU_ASSERT_PTR_NULL(dfirst.next)
351 CU_ASSERT_PTR_NULL(dfirst.prev)
352 } 336 }
353 337
354 void test_linked_list_size(void) { 338 void test_linked_list_size(void) {
355 struct node { 339 struct node {
356 void *next; 340 void *next;

mercurial