99 dl2 = ucx_dlist_append(dl2, &v[4]); |
89 dl2 = ucx_dlist_append(dl2, &v[4]); |
100 dl2 = ucx_dlist_append(dl2, &v[0]); |
90 dl2 = ucx_dlist_append(dl2, &v[0]); |
101 dl2 = ucx_dlist_append(dl2, &v[4]); |
91 dl2 = ucx_dlist_append(dl2, &v[4]); |
102 if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) { |
92 if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) { |
103 fprintf(stderr, "ucx_dlist_equals failed (false negative)\n"); |
93 fprintf(stderr, "ucx_dlist_equals failed (false negative)\n"); |
|
94 r--; |
104 } |
95 } |
105 dl2->next->data = NULL; |
96 dl2->next->data = NULL; |
106 if (ucx_dlist_equals(dl, dl2, NULL, NULL)) { |
97 if (ucx_dlist_equals(dl, dl2, NULL, NULL)) { |
107 fprintf(stderr, "ucx_dlist_equals failed (false positive)\n"); |
98 fprintf(stderr, "ucx_dlist_equals failed (false positive)\n"); |
|
99 r--; |
108 } |
100 } |
109 dl2->next->data = &(tdata.values[1]); |
101 dl2->next->data = &(tdata.values[1]); |
110 if (!ucx_dlist_equals(dl, dl2, int_cmp, NULL)) { |
102 if (!ucx_dlist_equals(dl, dl2, int_cmp, NULL)) { |
111 fprintf(stderr, "ucx_dlist_equals failed (cmp_func false negative)\n"); |
103 fprintf(stderr, "ucx_dlist_equals failed (cmp_func false negative)\n"); |
|
104 r--; |
112 } |
105 } |
113 if (ucx_dlist_equals(dl, dl2, NULL, NULL)) { |
106 if (ucx_dlist_equals(dl, dl2, NULL, NULL)) { |
114 fprintf(stderr, "ucx_dlist_equals failed (cmp_func false positive)\n"); |
107 fprintf(stderr, "ucx_dlist_equals failed (cmp_func false positive)\n"); |
|
108 r--; |
115 } |
109 } |
116 ucx_dlist_free(dl2); |
110 ucx_dlist_free(dl2); |
117 |
111 |
118 printf(" Test ucx_dlist_clone\n"); |
112 printf(" Test ucx_dlist_clone\n"); |
119 dl2 = ucx_dlist_clone(dl, NULL, NULL); |
113 dl2 = ucx_dlist_clone(dl, NULL, NULL); |
120 if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) { |
114 if (!ucx_dlist_equals(dl, dl2, NULL, NULL)) { |
121 fprintf(stderr, "ucx_dlist_clone (without copy) failed\n"); |
115 fprintf(stderr, "ucx_dlist_clone (without copy) failed\n"); |
|
116 r--; |
122 } |
117 } |
123 ucx_dlist_free(dl2); |
118 ucx_dlist_free(dl2); |
124 |
119 |
125 printf(" TODO: test clone with copy\n"); |
120 printf(" TODO: test clone with copy\n"); |
126 |
121 |
127 return r; |
122 return r; |
128 } |
123 } |
129 |
124 |
130 int list_tests() { |
|
131 int r = 0; |
|
132 int v[8]; |
|
133 UcxList *dl = NULL; |
|
134 // build list 0,1,2,3,4,5,6,7 |
|
135 printf(" Test ucx_list_append\n"); |
|
136 fflush(stdout); |
|
137 for(int i=0;i<8;i++) { |
|
138 v[i] = i; |
|
139 dl = ucx_list_append(dl, &v[i]); |
|
140 } |
|
141 |
|
142 printf(" Test ucx_list_get\n"); |
|
143 fflush(stdout); |
|
144 for(int i=0;i<8;i++) { |
|
145 UcxList *elm = ucx_list_get(dl, i); |
|
146 if(elm == NULL) { |
|
147 fprintf(stderr, "ucx_list_get failed: element is NULL\n"); |
|
148 r--; |
|
149 } |
|
150 if(elm->data == NULL) { |
|
151 fprintf(stderr, "ucx_list_get failed: data is NULL\n"); |
|
152 r--; |
|
153 } |
|
154 int *data = (int*)elm->data; |
|
155 if(*data != i) { |
|
156 fprintf(stderr, "ucx_list_get failed with index %d\n", i); |
|
157 r--; |
|
158 } |
|
159 } |
|
160 |
|
161 printf(" Test ucx_list_free\n"); |
|
162 fflush(stdout); |
|
163 ucx_list_free(dl); |
|
164 |
|
165 dl = NULL; |
|
166 // build list 4,0,4 |
|
167 printf(" Test ucx_list_prepend\n"); |
|
168 dl = ucx_list_prepend(dl, &v[0]); |
|
169 dl = ucx_list_prepend(dl, &v[4]); |
|
170 dl = ucx_list_append(dl, &v[4]); |
|
171 |
|
172 struct test1_data tdata; |
|
173 tdata.i = 0; |
|
174 ucx_list_foreach(dl, list_tests_foreach, &tdata); |
|
175 |
|
176 if(tdata.values[0] != 4 || tdata.values[1] != 0 || tdata.values[2] != 4) { |
|
177 fprintf(stderr, "prepend/append test failed\n"); |
|
178 fprintf(stderr, "content: [%d, %d, %d]\n", |
|
179 tdata.values[0], tdata.values[1], tdata.values[2]); |
|
180 r--; |
|
181 } |
|
182 |
|
183 printf(" Test ucx_list_equals\n"); |
|
184 UcxList *dl2 = NULL; |
|
185 dl2 = ucx_list_append(dl2, &v[4]); |
|
186 dl2 = ucx_list_append(dl2, &v[0]); |
|
187 dl2 = ucx_list_append(dl2, &v[4]); |
|
188 if (!ucx_list_equals(dl, dl2, NULL, NULL)) { |
|
189 fprintf(stderr, "ucx_list_equals failed (false negative)\n"); |
|
190 } |
|
191 dl2->next->data = NULL; |
|
192 if (ucx_list_equals(dl, dl2, NULL, NULL)) { |
|
193 fprintf(stderr, "ucx_list_equals failed (false positive)\n"); |
|
194 } |
|
195 dl2->next->data = &(tdata.values[1]); |
|
196 if (!ucx_list_equals(dl, dl2, int_cmp, NULL)) { |
|
197 fprintf(stderr, "ucx_list_equals failed (cmp_func false negative)\n"); |
|
198 } |
|
199 if (ucx_list_equals(dl, dl2, NULL, NULL)) { |
|
200 fprintf(stderr, "ucx_list_equals failed (cmp_func false positive)\n"); |
|
201 } |
|
202 ucx_list_free(dl2); |
|
203 |
|
204 printf(" Test ucx_list_clone\n"); |
|
205 dl2 = ucx_list_clone(dl, NULL, NULL); |
|
206 if (!ucx_list_equals(dl, dl2, NULL, NULL)) { |
|
207 fprintf(stderr, "ucx_list_clone (without copy) failed\n"); |
|
208 } |
|
209 ucx_list_free(dl2); |
|
210 |
|
211 printf(" TODO: test clone with copy\n"); |
|
212 |
|
213 return r; |
|
214 } |
|