1.1 --- a/test/list_tests.c Sat Dec 31 22:48:28 2011 +0100 1.2 +++ b/test/list_tests.c Wed Jan 04 14:51:54 2012 +0100 1.3 @@ -13,20 +13,32 @@ 1.4 int i; 1.5 }; 1.6 1.7 -int list_tests_foreach1(void *v, void *custom) { 1.8 +int int_cmp(void* e1, void *e2, void *data) { 1.9 + if (e1 == NULL || e2 == NULL) return (e1 == e2) ? 0 : -1; 1.10 + 1.11 + int *i1 = (int*)e1, *i2 = (int*)e2; 1.12 + int r = (*i1) - (*i2); 1.13 + return (r < 0) ? -1 : (r == 0 ? 0 : 1); 1.14 +} 1.15 + 1.16 +int dlist_tests_foreach(void *v, void *custom) { 1.17 UcxDlist *dl = (UcxDlist*)v; 1.18 struct test1_data *tdata = (struct test1_data*)custom; 1.19 1.20 tdata->values[tdata->i] = *(int*)dl->data; 1.21 tdata->i++; 1.22 + 1.23 + return 0; 1.24 } 1.25 1.26 -int list_tests_foreach2(void *v, void *custom) { 1.27 +int list_tests_foreach(void *v, void *custom) { 1.28 UcxList *dl = (UcxList*)v; 1.29 struct test1_data *tdata = (struct test1_data*)custom; 1.30 1.31 tdata->values[tdata->i] = *(int*)dl->data; 1.32 tdata->i++; 1.33 + 1.34 + return 0; 1.35 } 1.36 1.37 int dlist_tests() { 1.38 @@ -73,14 +85,45 @@ 1.39 1.40 struct test1_data tdata; 1.41 tdata.i = 0; 1.42 - ucx_dlist_foreach(dl, list_tests_foreach1, &tdata); 1.43 + ucx_dlist_foreach(dl, dlist_tests_foreach, &tdata); 1.44 1.45 if(tdata.values[0] != 4 || tdata.values[1] != 0 || tdata.values[2] != 4) { 1.46 fprintf(stderr, "prepend/append test failed\n"); 1.47 - fprintf(stderr, "content: [%d, %d, %d]\n", tdata.values[0], tdata.values[1], tdata.values[2]); 1.48 + fprintf(stderr, "content: [%d, %d, %d]\n", 1.49 + tdata.values[0], tdata.values[1], tdata.values[2]); 1.50 r--; 1.51 } 1.52 1.53 + printf(" Test ucx_dlist_equals\n"); 1.54 + UcxDlist *dl2 = NULL; 1.55 + dl2 = ucx_dlist_append(dl2, &v[4]); 1.56 + dl2 = ucx_dlist_append(dl2, &v[0]); 1.57 + dl2 = ucx_dlist_append(dl2, &v[4]); 1.58 + if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) { 1.59 + fprintf(stderr, "ucx_dlist_equals failed (false negative)\n"); 1.60 + } 1.61 + dl2->next->data = NULL; 1.62 + if (ucx_dlist_equals(dl, dl2, NULL, NULL)) { 1.63 + fprintf(stderr, "ucx_dlist_equals failed (false positive)\n"); 1.64 + } 1.65 + dl2->next->data = &(tdata.values[1]); 1.66 + if (!ucx_dlist_equals(dl, dl2, int_cmp, NULL)) { 1.67 + fprintf(stderr, "ucx_dlist_equals failed (cmp_func false negative)\n"); 1.68 + } 1.69 + if (ucx_dlist_equals(dl, dl2, NULL, NULL)) { 1.70 + fprintf(stderr, "ucx_dlist_equals failed (cmp_func false positive)\n"); 1.71 + } 1.72 + ucx_dlist_free(dl2); 1.73 + 1.74 + printf(" Test ucx_dlist_clone\n"); 1.75 + dl2 = ucx_dlist_clone(dl, NULL, NULL); 1.76 + if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) { 1.77 + fprintf(stderr, "ucx_dlist_clone (without copy) failed\n"); 1.78 + } 1.79 + ucx_dlist_free(dl2); 1.80 + 1.81 + printf(" TODO: test clone with copy\n"); 1.82 + 1.83 return r; 1.84 } 1.85 1.86 @@ -128,13 +171,44 @@ 1.87 1.88 struct test1_data tdata; 1.89 tdata.i = 0; 1.90 - ucx_list_foreach(dl, list_tests_foreach1, &tdata); 1.91 + ucx_list_foreach(dl, list_tests_foreach, &tdata); 1.92 1.93 if(tdata.values[0] != 4 || tdata.values[1] != 0 || tdata.values[2] != 4) { 1.94 fprintf(stderr, "prepend/append test failed\n"); 1.95 - fprintf(stderr, "content: [%d, %d, %d]\n", tdata.values[0], tdata.values[1], tdata.values[2]); 1.96 + fprintf(stderr, "content: [%d, %d, %d]\n", 1.97 + tdata.values[0], tdata.values[1], tdata.values[2]); 1.98 r--; 1.99 } 1.100 + 1.101 + printf(" Test ucx_list_equals\n"); 1.102 + UcxList *dl2 = NULL; 1.103 + dl2 = ucx_list_append(dl2, &v[4]); 1.104 + dl2 = ucx_list_append(dl2, &v[0]); 1.105 + dl2 = ucx_list_append(dl2, &v[4]); 1.106 + if (!ucx_list_equals(dl, dl2, NULL, NULL)) { 1.107 + fprintf(stderr, "ucx_list_equals failed (false negative)\n"); 1.108 + } 1.109 + dl2->next->data = NULL; 1.110 + if (ucx_list_equals(dl, dl2, NULL, NULL)) { 1.111 + fprintf(stderr, "ucx_list_equals failed (false positive)\n"); 1.112 + } 1.113 + dl2->next->data = &(tdata.values[1]); 1.114 + if (!ucx_list_equals(dl, dl2, int_cmp, NULL)) { 1.115 + fprintf(stderr, "ucx_list_equals failed (cmp_func false negative)\n"); 1.116 + } 1.117 + if (ucx_list_equals(dl, dl2, NULL, NULL)) { 1.118 + fprintf(stderr, "ucx_list_equals failed (cmp_func false positive)\n"); 1.119 + } 1.120 + ucx_list_free(dl2); 1.121 + 1.122 + printf(" Test ucx_list_clone\n"); 1.123 + dl2 = ucx_list_clone(dl, NULL, NULL); 1.124 + if (!ucx_list_equals(dl, dl2, NULL, NULL)) { 1.125 + fprintf(stderr, "ucx_list_clone (without copy) failed\n"); 1.126 + } 1.127 + ucx_list_free(dl2); 1.128 + 1.129 + printf(" TODO: test clone with copy\n"); 1.130 1.131 return r; 1.132 }