test/list_tests.c

Fri, 18 Nov 2016 15:17:04 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 18 Nov 2016 15:17:04 +0100
changeset 228
9f385abc72fb
parent 225
a1a068c2c4ef
child 229
9db71925eaa8
permissions
-rw-r--r--

adds ucx_list_append_once() and ucx_list_prepend_once()

olaf@9 1 /*
universe@103 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@103 3 *
universe@225 4 * Copyright 2016 Olaf Wintermann. All rights reserved.
universe@103 5 *
universe@103 6 * Redistribution and use in source and binary forms, with or without
universe@103 7 * modification, are permitted provided that the following conditions are met:
universe@103 8 *
universe@103 9 * 1. Redistributions of source code must retain the above copyright
universe@103 10 * notice, this list of conditions and the following disclaimer.
universe@103 11 *
universe@103 12 * 2. Redistributions in binary form must reproduce the above copyright
universe@103 13 * notice, this list of conditions and the following disclaimer in the
universe@103 14 * documentation and/or other materials provided with the distribution.
universe@103 15 *
universe@103 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@103 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@103 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@103 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@103 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@103 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@103 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@103 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@103 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@103 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@103 26 * POSSIBILITY OF SUCH DAMAGE.
olaf@9 27 */
olaf@9 28
universe@122 29 #include "list_tests.h"
universe@94 30 #include "ucx/utils.h"
olaf@9 31
universe@134 32 UCX_TEST(test_ucx_list_append) {
universe@172 33 UcxList *list, *first;
universe@172 34 list = first = ucx_list_append(NULL, (void*)"Hello");
universe@33 35 UCX_TEST_BEGIN
universe@27 36
universe@69 37 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
universe@69 38 "failed");
universe@27 39
universe@122 40 list = ucx_list_append(list, (void*)" World!");
universe@27 41
universe@172 42 UCX_TEST_ASSERT(list == first, "does not return first element");
universe@69 43 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
universe@69 44 "failed");
universe@172 45 UCX_TEST_ASSERT(list->next->prev == list, "failed");
universe@40 46 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
universe@33 47 UCX_TEST_END
universe@27 48
universe@122 49 ucx_list_free(list);
universe@24 50 }
universe@24 51
universe@134 52 UCX_TEST(test_ucx_list_prepend) {
universe@172 53 UcxList *list, *last;
universe@172 54 list = last = ucx_list_prepend(NULL, (void*)" World!");
universe@33 55 UCX_TEST_BEGIN
universe@33 56
universe@122 57 list = ucx_list_prepend(list, (void*)"Hello");
universe@27 58
universe@69 59 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
universe@69 60 "failed");
universe@69 61 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
universe@69 62 "failed");
universe@172 63 UCX_TEST_ASSERT(list == last->prev, "does not return first element");
universe@40 64 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
universe@172 65 UCX_TEST_ASSERT(list->prev == NULL, "failed");
universe@27 66
universe@33 67 UCX_TEST_END
universe@122 68 ucx_list_free(list);
universe@18 69 }
universe@18 70
universe@228 71 UCX_TEST(test_ucx_list_append_once) {
universe@228 72 UcxList *list, *first;
universe@228 73 list = first = ucx_list_append_once(NULL, (void*)"Hello", ucx_strcmp, NULL);
universe@228 74 UCX_TEST_BEGIN
universe@228 75
universe@228 76 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
universe@228 77 "failed");
universe@228 78
universe@228 79 list = ucx_list_append_once(list, (void*)"Hello", ucx_strcmp, NULL);
universe@228 80 list = ucx_list_append_once(list, (void*)" World!", ucx_strcmp, NULL);
universe@228 81
universe@228 82 UCX_TEST_ASSERT(list == first, "does not return first element");
universe@228 83 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
universe@228 84 "'Hello' was not inserted _once_");
universe@228 85 UCX_TEST_ASSERT(list->next->prev == list, "failed");
universe@228 86 UCX_TEST_ASSERT(list->next->next == NULL, "right not terminated");
universe@228 87 UCX_TEST_END
universe@228 88
universe@228 89 ucx_list_free(list);
universe@228 90 }
universe@228 91
universe@228 92 UCX_TEST(test_ucx_list_prepend_once) {
universe@228 93 UcxList *list, *last, *first;
universe@228 94 list = last = ucx_list_prepend_once(NULL, (void*)" World!",
universe@228 95 ucx_strcmp, NULL);
universe@228 96 UCX_TEST_BEGIN
universe@228 97
universe@228 98 list = ucx_list_prepend_once(list, (void*)"Hello", ucx_strcmp, NULL);
universe@228 99 first = ucx_list_prepend_once(list, (void*)"Hello", ucx_strcmp, NULL);
universe@228 100
universe@228 101 UCX_TEST_ASSERT(list == first, "'Hello' was not prepended _once_");
universe@228 102 UCX_TEST_ASSERT(first == last->prev, "does not return first element");
universe@228 103 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
universe@228 104 "failed");
universe@228 105 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
universe@228 106 "failed");
universe@228 107 UCX_TEST_ASSERT(list->next->next == NULL, "right not terminated");
universe@228 108 UCX_TEST_ASSERT(list->prev == NULL, "left not terminated");
universe@228 109
universe@228 110 UCX_TEST_END
universe@228 111 ucx_list_free(list);
universe@228 112 }
universe@228 113
universe@134 114 UCX_TEST(test_ucx_list_equals) {
universe@172 115 const char *hello = "Hello";
universe@172 116 const char *world = " World!";
universe@172 117 UcxList *list = ucx_list_append(NULL, (void*)hello);
universe@172 118 list = ucx_list_append(list, (void*)world);
universe@172 119 UcxList *list2 = ucx_list_prepend(NULL, (void*)world);
universe@172 120 list2 = ucx_list_prepend(list2, (void*)hello);
universe@122 121 UcxList *list3 = ucx_list_prepend(NULL, (void*)" Welt!");
universe@122 122 list3 = ucx_list_prepend(list3, (void*)"Hallo");
universe@172 123 UcxList *list4 = ucx_list_prepend(NULL, (void*)" World!");
universe@172 124 list4 = ucx_list_prepend(list4, (void*)"Hello");
universe@33 125 UCX_TEST_BEGIN
universe@27 126
universe@172 127 UCX_TEST_ASSERT(ucx_list_equals(list, list4, ucx_strcmp, NULL), "failed");
universe@122 128 UCX_TEST_ASSERT(!ucx_list_equals(list, list3, ucx_strcmp, NULL), "failed");
universe@172 129 UCX_TEST_ASSERT(ucx_list_equals(list, list2, NULL, NULL), "failed");
universe@27 130
universe@33 131 UCX_TEST_END
universe@172 132 ucx_list_free(list4);
universe@122 133 ucx_list_free(list3);
universe@122 134 ucx_list_free(list2);
universe@122 135 ucx_list_free(list);
universe@24 136 }
universe@24 137
universe@134 138 UCX_TEST(test_ucx_list_concat) {
universe@122 139 UcxList *list = ucx_list_append(NULL, (void*)"Hello");
universe@172 140 list = ucx_list_append(list, (void*)" my ");
universe@122 141 UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!");
universe@172 142 list2 = ucx_list_prepend(list2, (void*)" sweet ");
universe@33 143 UCX_TEST_BEGIN
universe@27 144
universe@122 145 list = ucx_list_concat(list, list2);
universe@172 146 list = ucx_list_concat(list, NULL);
universe@172 147 list = ucx_list_concat(NULL, list);
universe@27 148
universe@172 149 UCX_TEST_ASSERT(!strncmp((const char*)list->data, "Hello", 5),
universe@69 150 "failed");
universe@172 151 UCX_TEST_ASSERT(!strncmp((const char*)list->next->data, " my ", 4),
universe@69 152 "failed");
universe@172 153 UCX_TEST_ASSERT(!strncmp((const char*)list->next->next->data, " sweet ", 7),
universe@172 154 "failed");
universe@172 155 UCX_TEST_ASSERT(!strncmp((const char*)ucx_list_last(list)->data,
universe@172 156 " World!", 7), "failed");
universe@172 157
universe@172 158 UCX_TEST_ASSERT(list->prev == NULL, "failed");
universe@27 159
universe@33 160 UCX_TEST_END
universe@172 161 // don't free list2, as it is freed by freeing list;
universe@122 162 ucx_list_free(list);
olaf@9 163 }
olaf@9 164
universe@134 165 UCX_TEST(test_ucx_list_size) {
universe@122 166 UcxList *list = ucx_list_append(NULL, (void*)"This ");
universe@122 167 list = ucx_list_append(list, (void*)"list ");
universe@122 168 list = ucx_list_append(list, (void*)"has ");
universe@122 169 list = ucx_list_append(list, (void*)"size ");
universe@122 170 list = ucx_list_append(list, (void*)"5!");
universe@27 171
universe@123 172 UCX_TEST_BEGIN
universe@123 173
universe@122 174 UCX_TEST_ASSERT(ucx_list_size(list) == 5, "failed");
universe@172 175 list = ucx_list_remove(list, ucx_list_get(list, 2));
universe@172 176 UCX_TEST_ASSERT(ucx_list_size(list) == 4, "failed after removal");
universe@27 177
universe@33 178 UCX_TEST_END
universe@122 179 ucx_list_free(list);
olaf@9 180 }
olaf@11 181
universe@134 182 UCX_TEST(test_ucx_list_first) {
universe@122 183 UcxList *list = ucx_list_append(NULL, (void*)"Find ");
universe@122 184 list = ucx_list_append(list, (void*)"the ");
universe@122 185 list = ucx_list_append(list, (void*)"first!");
universe@27 186
universe@123 187 UCX_TEST_BEGIN
universe@123 188
universe@122 189 const char* first = (const char*) (ucx_list_first(list)->data);
universe@27 190
universe@27 191 UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed");
universe@172 192 UCX_TEST_ASSERT(ucx_list_first(list->next->next) == list, "failed");
universe@172 193 UCX_TEST_ASSERT(!ucx_list_first(NULL),
universe@172 194 "does not return NULL on an empty list");
universe@27 195
universe@33 196 UCX_TEST_END
universe@122 197 ucx_list_free(list);
universe@27 198 }
universe@27 199
universe@134 200 UCX_TEST(test_ucx_list_last) {
universe@122 201 UcxList *list = ucx_list_append(NULL, (void*)"Find ");
universe@122 202 list = ucx_list_append(list, (void*)"the ");
universe@122 203 list = ucx_list_append(list, (void*)"last!");
universe@27 204
universe@123 205 UCX_TEST_BEGIN
universe@123 206
universe@172 207 const char* last = (const char*) (ucx_list_last(list->next->next)->data);
universe@27 208
universe@27 209 UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed");
universe@172 210 UCX_TEST_ASSERT(ucx_list_last(list) == list->next->next, "failed");
universe@172 211 UCX_TEST_ASSERT(!ucx_list_last(NULL),
universe@172 212 "does not return NULL on an empty list");
universe@27 213
universe@33 214 UCX_TEST_END
universe@122 215 ucx_list_free(list);
universe@27 216 }
universe@27 217
universe@134 218 UCX_TEST(test_ucx_list_get) {
universe@122 219 UcxList *list = ucx_list_append(NULL, (void*)"Find ");
universe@122 220 list = ucx_list_append(list, (void*)"the ");
universe@122 221 list = ucx_list_append(list, (void*)"mid!");
universe@27 222
universe@123 223 UCX_TEST_BEGIN
universe@123 224
universe@172 225 const char* first = (const char*) (ucx_list_get(list, 0)->data);
universe@122 226 const char* mid = (const char*) (ucx_list_get(list, 1)->data);
universe@172 227 const char* last = (const char*) (ucx_list_get(list, 2)->data);
universe@27 228
universe@172 229 UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed");
universe@27 230 UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed");
universe@172 231 UCX_TEST_ASSERT(strncmp(last, "mid!", 4) == 0, "failed");
universe@172 232 UCX_TEST_ASSERT(!ucx_list_get(list, -1), "out of bounds (neg)");
universe@172 233 UCX_TEST_ASSERT(!ucx_list_get(list, 3), "out of bounds");
universe@172 234 UCX_TEST_ASSERT(!ucx_list_get(NULL, 0), "empty list");
universe@27 235
universe@33 236 UCX_TEST_END
universe@122 237 ucx_list_free(list);
universe@27 238 }
universe@27 239
universe@134 240 UCX_TEST(test_ucx_list_indexof) {
universe@123 241 UcxList *list = ucx_list_append(NULL, (void*)"Find ");
universe@123 242 list = ucx_list_append(list, (void*)"the ");
universe@123 243 list = ucx_list_append(list, (void*)"mid!");
universe@123 244
universe@123 245 UCX_TEST_BEGIN
universe@123 246
universe@123 247 UCX_TEST_ASSERT(ucx_list_indexof(list, list) == 0, "failed");
universe@123 248 UCX_TEST_ASSERT(ucx_list_indexof(list, list->next) == 1, "failed");
universe@123 249 UCX_TEST_ASSERT(ucx_list_indexof(list, ucx_list_get(list, 2)) == 2,
universe@123 250 "failed");
universe@123 251
universe@172 252 UcxList *otherlist = ucx_list_append(NULL, (void*) "the ");
universe@123 253 UCX_TEST_ASSERT(ucx_list_indexof(list, otherlist) == -1, "failed");
universe@172 254 UCX_TEST_ASSERT(ucx_list_indexof(NULL, otherlist) == -1, "empty list");
universe@172 255
universe@123 256 ucx_list_free(otherlist);
universe@123 257
universe@123 258 UCX_TEST_END
universe@123 259 ucx_list_free(list);
universe@123 260 }
universe@123 261
universe@134 262 UCX_TEST(test_ucx_list_find) {
universe@172 263 const char* teststr = "string!";
universe@123 264 UcxList *l = ucx_list_append(NULL, (void*)"find ");
universe@123 265 l = ucx_list_append(l, (void*)"some ");
universe@172 266 l = ucx_list_append(l, (void*)teststr);
universe@123 267
universe@123 268 UCX_TEST_BEGIN
universe@123 269
universe@123 270 UCX_TEST_ASSERT(ucx_list_find(l,(void*)"some ",ucx_strcmp,NULL) == 1,
universe@123 271 "doesn't find string");
universe@123 272 UCX_TEST_ASSERT(ucx_list_find(l,(void*)"a",ucx_strcmp,NULL) == -1,
universe@123 273 "finds non-existing string");
universe@123 274
universe@172 275 UCX_TEST_ASSERT(ucx_list_find(l,(void*)teststr,NULL,NULL) == 2,
universe@172 276 "doesn't find integer without cmp_func");
universe@172 277
universe@172 278 UCX_TEST_ASSERT(ucx_list_find(NULL, (void*)"some ",ucx_strcmp,NULL) == -1,
universe@172 279 "empty list");
universe@172 280
universe@123 281 UCX_TEST_END
universe@123 282 ucx_list_free(l);
universe@123 283 }
universe@123 284
universe@134 285 UCX_TEST(test_ucx_list_contains) {
universe@122 286 UcxList *l = ucx_list_append(NULL, (void*)"Contains ");
universe@122 287 l = ucx_list_append(l, (void*)"a ");
universe@122 288 l = ucx_list_append(l, (void*)"string!");
universe@90 289
universe@123 290 UCX_TEST_BEGIN
universe@123 291
universe@123 292 UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_strcmp,NULL),
universe@123 293 "false negative");
universe@123 294 UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_strcmp,NULL),
universe@123 295 "false positive");
universe@90 296
universe@90 297 UCX_TEST_END
universe@122 298 ucx_list_free(l);
universe@90 299 }
universe@90 300
universe@134 301 UCX_TEST(test_ucx_list_remove) {
universe@122 302 UcxList *list = ucx_list_append(NULL, (void*)"Hello");
olaf@162 303 list = ucx_list_append(list, (void*)"fucking");
olaf@162 304 list = ucx_list_append(list, (void*)"World!");
olaf@162 305
olaf@162 306 UcxList *list2 = ucx_list_append(NULL, (void*)"A");
olaf@162 307 list2 = ucx_list_append(list2, (void*)"B");
olaf@162 308 list2 = ucx_list_append(list2, (void*)"C");
olaf@162 309 list2 = ucx_list_append(list2, (void*)"D");
olaf@162 310 list2 = ucx_list_append(list2, (void*)"E");
olaf@162 311 list2 = ucx_list_append(list2, (void*)"F");
olaf@162 312 list2 = ucx_list_append(list2, (void*)"G");
universe@27 313
universe@123 314 UCX_TEST_BEGIN
universe@123 315
universe@122 316 list = ucx_list_remove(list, ucx_list_get(list, 1));
universe@27 317
universe@69 318 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
universe@69 319 "failed");
olaf@162 320 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, "World!", 7) == 0,
universe@69 321 "failed");
universe@40 322 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
universe@27 323
olaf@162 324 // remove first element: B, C, D, E, F, G
olaf@162 325 list2 = ucx_list_remove(list2, list2);
olaf@162 326
olaf@162 327 UCX_TEST_ASSERT(ucx_list_size(list2) == 6, "list2 has wrong size");
olaf@162 328 UCX_TEST_ASSERT(strncmp((const char*)list2->data, "B", 1) == 0,
olaf@162 329 "wrong first element");
olaf@162 330 UCX_TEST_ASSERT(strncmp((const char*)ucx_list_get(list2, 5)->data, "G", 1)
olaf@162 331 == 0, "wrong last element");
olaf@162 332
olaf@162 333 // remove second element: B, D, E, F, G
olaf@162 334 list2 = ucx_list_remove(list2, list2->next);
olaf@162 335
olaf@162 336 UCX_TEST_ASSERT(ucx_list_size(list2) == 5, "list2 has wrong size");
olaf@162 337 UCX_TEST_ASSERT(strncmp((const char*)list2->next->data, "D", 1) == 0,
olaf@162 338 "wrong second element");
olaf@162 339
olaf@162 340 UcxList *last = ucx_list_get(list2, 4);
olaf@162 341 list2 = ucx_list_remove(list2, last->prev);
olaf@162 342
olaf@162 343 UCX_TEST_ASSERT(ucx_list_size(list2) == 4, "list2 has wrong size");
olaf@162 344 UCX_TEST_ASSERT(strncmp((const char*)last->prev->data, "E", 1) == 0,
olaf@162 345 "wrong element");
olaf@162 346
olaf@162 347 // remove last element: B, D, E, F
olaf@162 348 list2 = ucx_list_remove(list2, last);
olaf@162 349 UCX_TEST_ASSERT(ucx_list_size(list2) == 3, "list2 has wrong size");
olaf@162 350 UCX_TEST_ASSERT(strncmp((const char*)ucx_list_get(list2, 2)->data, "E", 1)
olaf@162 351 == 0, "wrong last element");
olaf@162 352
olaf@162 353 UCX_TEST_ASSERT(strncmp((const char*)list2->data, "B", 1) == 0,
olaf@162 354 "wrong element");
olaf@162 355
olaf@162 356 list2 = ucx_list_remove(list2, list2);
olaf@162 357 UCX_TEST_ASSERT(ucx_list_size(list2) == 2, "list2 has wrong size");
olaf@162 358 list2 = ucx_list_remove(list2, list2);
olaf@162 359 UCX_TEST_ASSERT(ucx_list_size(list2) == 1, "list2 has wrong size");
olaf@162 360 list2 = ucx_list_remove(list2, list2);
olaf@162 361 UCX_TEST_ASSERT(list2 == NULL, "list2 is not null");
olaf@162 362
universe@33 363 UCX_TEST_END
universe@122 364 ucx_list_free(list);
universe@27 365 }
universe@27 366
universe@134 367 UCX_TEST(test_ucx_list_clone) {
universe@27 368
universe@27 369 char *hello = (char*)malloc(6);
universe@27 370 char *world = (char*)malloc(8);
universe@27 371
universe@27 372 memcpy(hello, "Hello", 6);
universe@27 373 memcpy(world, " World!", 8);
universe@27 374
universe@122 375 UcxList *list = ucx_list_append(NULL, hello);
universe@122 376 list = ucx_list_append(list, world);
universe@27 377
universe@122 378 UcxList *copy = ucx_list_clone(list, ucx_strcpy, NULL);
universe@33 379 UCX_TEST_BEGIN
universe@27 380
universe@122 381 UCX_TEST_ASSERT(ucx_list_equals(list, copy, ucx_strcmp, NULL), "failed");
universe@40 382 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy");
universe@40 383 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy");
universe@27 384
universe@33 385 UCX_TEST_END
universe@211 386
universe@212 387 ucx_list_free_content(copy, free);
universe@27 388
universe@27 389 free(world);
universe@27 390 free(hello);
universe@122 391 ucx_list_free(list);
universe@122 392 ucx_list_free(copy);
universe@27 393 }
universe@35 394
universe@134 395 UCX_TEST(test_ucx_list_sort) {
universe@122 396 UcxList *list = ucx_list_append(NULL, (void*)"this");
universe@122 397 list = ucx_list_append(list, (void*)"is");
universe@122 398 list = ucx_list_append(list, (void*)"a");
universe@122 399 list = ucx_list_append(list, (void*)"test");
universe@122 400 list = ucx_list_append(list, (void*)"for");
universe@122 401 list = ucx_list_append(list, (void*)"partial");
universe@122 402 list = ucx_list_append(list, (void*)"correctness");
universe@172 403 list = ucx_list_append(list, (void*)"of");
universe@172 404 list = ucx_list_append(list, (void*)"the");
universe@172 405 list = ucx_list_append(list, (void*)"sort");
universe@172 406 list = ucx_list_append(list, (void*)"function");
universe@172 407 list = ucx_list_append(list, (void*)"that");
universe@172 408 list = ucx_list_append(list, (void*)"shall");
universe@172 409 list = ucx_list_append(list, (void*)"pass");
universe@172 410 list = ucx_list_append(list, (void*)"this");
universe@172 411 list = ucx_list_append(list, (void*)"test");
universe@35 412
universe@122 413 UcxList *expected = ucx_list_append(NULL, (void*)"a");
universe@122 414 expected = ucx_list_append(expected, (void*)"correctness");
universe@122 415 expected = ucx_list_append(expected, (void*)"for");
universe@172 416 expected = ucx_list_append(expected, (void*)"function");
universe@122 417 expected = ucx_list_append(expected, (void*)"is");
universe@172 418 expected = ucx_list_append(expected, (void*)"of");
universe@122 419 expected = ucx_list_append(expected, (void*)"partial");
universe@172 420 expected = ucx_list_append(expected, (void*)"pass");
universe@172 421 expected = ucx_list_append(expected, (void*)"shall");
universe@172 422 expected = ucx_list_append(expected, (void*)"sort");
universe@122 423 expected = ucx_list_append(expected, (void*)"test");
universe@172 424 expected = ucx_list_append(expected, (void*)"test");
universe@172 425 expected = ucx_list_append(expected, (void*)"that");
universe@172 426 expected = ucx_list_append(expected, (void*)"the");
universe@172 427 expected = ucx_list_append(expected, (void*)"this");
universe@122 428 expected = ucx_list_append(expected, (void*)"this");
universe@35 429
universe@122 430 list = ucx_list_sort(list, ucx_strcmp, NULL);
universe@35 431
universe@35 432 UCX_TEST_BEGIN
universe@35 433 UCX_TEST_ASSERT(
universe@122 434 ucx_list_equals(list, expected, ucx_strcmp, NULL), "failed");
universe@172 435 UCX_TEST_ASSERT(ucx_list_size(list) == 16, "list has now a wrong size");
universe@122 436 UcxList *l = list;
universe@35 437 UCX_TEST_ASSERT(l->prev == NULL, "prev field of first entry is not null");
universe@35 438 while (l->next != NULL) {
universe@172 439 UCX_TEST_ASSERT(l->next->prev == l, "next or prev pointer corrupted");
universe@35 440 l = l->next;
universe@35 441 }
universe@172 442 UCX_TEST_ASSERT(!ucx_list_sort(NULL, ucx_strcmp, NULL),
universe@172 443 "failed to sort empty list");
universe@35 444 UCX_TEST_END
universe@35 445
universe@122 446 ucx_list_free(expected);
universe@122 447 ucx_list_free(list);
universe@35 448 }

mercurial