diff -r 2e7050c3a18e -r 69636f81db31 test/list_tests.c --- a/test/list_tests.c Sat Dec 31 22:48:28 2011 +0100 +++ b/test/list_tests.c Wed Jan 04 14:51:54 2012 +0100 @@ -13,20 +13,32 @@ int i; }; -int list_tests_foreach1(void *v, void *custom) { +int int_cmp(void* e1, void *e2, void *data) { + if (e1 == NULL || e2 == NULL) return (e1 == e2) ? 0 : -1; + + int *i1 = (int*)e1, *i2 = (int*)e2; + int r = (*i1) - (*i2); + return (r < 0) ? -1 : (r == 0 ? 0 : 1); +} + +int dlist_tests_foreach(void *v, void *custom) { UcxDlist *dl = (UcxDlist*)v; struct test1_data *tdata = (struct test1_data*)custom; tdata->values[tdata->i] = *(int*)dl->data; tdata->i++; + + return 0; } -int list_tests_foreach2(void *v, void *custom) { +int list_tests_foreach(void *v, void *custom) { UcxList *dl = (UcxList*)v; struct test1_data *tdata = (struct test1_data*)custom; tdata->values[tdata->i] = *(int*)dl->data; tdata->i++; + + return 0; } int dlist_tests() { @@ -73,14 +85,45 @@ struct test1_data tdata; tdata.i = 0; - ucx_dlist_foreach(dl, list_tests_foreach1, &tdata); + ucx_dlist_foreach(dl, dlist_tests_foreach, &tdata); if(tdata.values[0] != 4 || tdata.values[1] != 0 || tdata.values[2] != 4) { fprintf(stderr, "prepend/append test failed\n"); - fprintf(stderr, "content: [%d, %d, %d]\n", tdata.values[0], tdata.values[1], tdata.values[2]); + fprintf(stderr, "content: [%d, %d, %d]\n", + tdata.values[0], tdata.values[1], tdata.values[2]); r--; } + printf(" Test ucx_dlist_equals\n"); + UcxDlist *dl2 = NULL; + dl2 = ucx_dlist_append(dl2, &v[4]); + dl2 = ucx_dlist_append(dl2, &v[0]); + dl2 = ucx_dlist_append(dl2, &v[4]); + if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) { + fprintf(stderr, "ucx_dlist_equals failed (false negative)\n"); + } + dl2->next->data = NULL; + if (ucx_dlist_equals(dl, dl2, NULL, NULL)) { + fprintf(stderr, "ucx_dlist_equals failed (false positive)\n"); + } + dl2->next->data = &(tdata.values[1]); + if (!ucx_dlist_equals(dl, dl2, int_cmp, NULL)) { + fprintf(stderr, "ucx_dlist_equals failed (cmp_func false negative)\n"); + } + if (ucx_dlist_equals(dl, dl2, NULL, NULL)) { + fprintf(stderr, "ucx_dlist_equals failed (cmp_func false positive)\n"); + } + ucx_dlist_free(dl2); + + printf(" Test ucx_dlist_clone\n"); + dl2 = ucx_dlist_clone(dl, NULL, NULL); + if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) { + fprintf(stderr, "ucx_dlist_clone (without copy) failed\n"); + } + ucx_dlist_free(dl2); + + printf(" TODO: test clone with copy\n"); + return r; } @@ -128,13 +171,44 @@ struct test1_data tdata; tdata.i = 0; - ucx_list_foreach(dl, list_tests_foreach1, &tdata); + ucx_list_foreach(dl, list_tests_foreach, &tdata); if(tdata.values[0] != 4 || tdata.values[1] != 0 || tdata.values[2] != 4) { fprintf(stderr, "prepend/append test failed\n"); - fprintf(stderr, "content: [%d, %d, %d]\n", tdata.values[0], tdata.values[1], tdata.values[2]); + fprintf(stderr, "content: [%d, %d, %d]\n", + tdata.values[0], tdata.values[1], tdata.values[2]); r--; } + + printf(" Test ucx_list_equals\n"); + UcxList *dl2 = NULL; + dl2 = ucx_list_append(dl2, &v[4]); + dl2 = ucx_list_append(dl2, &v[0]); + dl2 = ucx_list_append(dl2, &v[4]); + if (!ucx_list_equals(dl, dl2, NULL, NULL)) { + fprintf(stderr, "ucx_list_equals failed (false negative)\n"); + } + dl2->next->data = NULL; + if (ucx_list_equals(dl, dl2, NULL, NULL)) { + fprintf(stderr, "ucx_list_equals failed (false positive)\n"); + } + dl2->next->data = &(tdata.values[1]); + if (!ucx_list_equals(dl, dl2, int_cmp, NULL)) { + fprintf(stderr, "ucx_list_equals failed (cmp_func false negative)\n"); + } + if (ucx_list_equals(dl, dl2, NULL, NULL)) { + fprintf(stderr, "ucx_list_equals failed (cmp_func false positive)\n"); + } + ucx_list_free(dl2); + + printf(" Test ucx_list_clone\n"); + dl2 = ucx_list_clone(dl, NULL, NULL); + if (!ucx_list_equals(dl, dl2, NULL, NULL)) { + fprintf(stderr, "ucx_list_clone (without copy) failed\n"); + } + ucx_list_free(dl2); + + printf(" TODO: test clone with copy\n"); return r; }