1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
6 /*******************************/
7 /* GENERATED FILE, DO NOT EDIT */
8 /*******************************/
14 XBT_LOG_EXTERNAL_CATEGORY(xbt_dyn);
15 XBT_LOG_DEFAULT_CATEGORY(xbt_dyn);
17 XBT_TEST_UNIT("int",test_dynar_int,"Dyars of integers") {
18 /* Vars_decl [doxygen cruft] */
23 xbt_test_add0("==== Traverse the empty dynar");
24 d=xbt_dynar_new(sizeof(int),NULL);
25 xbt_dynar_foreach(d,cursor,i){
26 xbt_assert0(0,"Damnit, there is something in the empty dynar");
31 xbt_test_add1("==== Push %d int, set them again 3 times, traverse them, shift them",
33 /* Populate_ints [doxygen cruft] */
34 /* 1. Populate the dynar */
35 d=xbt_dynar_new(sizeof(int),NULL);
36 for (cpt=0; cpt< NB_ELEM; cpt++) {
37 xbt_dynar_push_as(d,int,cpt); /* This is faster (and possible only with scalars) */
38 /* xbt_dynar_push(d,&cpt); This would also work */
39 xbt_test_log2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
42 /* 2. Traverse manually the dynar */
43 for (cursor=0; cursor< NB_ELEM; cursor++) {
44 iptr=xbt_dynar_get_ptr(d,cursor);
45 xbt_test_assert2(cursor == *iptr,
46 "The retrieved value is not the same than the injected one (%d!=%d)",
50 /* 3. Traverse the dynar using the neat macro to that extend */
51 xbt_dynar_foreach(d,cursor,cpt){
52 xbt_test_assert2(cursor == cpt,
53 "The retrieved value is not the same than the injected one (%d!=%d)",
56 /* end_of_traversal */
58 for (cpt=0; cpt< NB_ELEM; cpt++)
59 *(int*)xbt_dynar_get_ptr(d,cpt) = cpt;
61 for (cpt=0; cpt< NB_ELEM; cpt++)
62 *(int*)xbt_dynar_get_ptr(d,cpt) = cpt;
63 /* xbt_dynar_set(d,cpt,&cpt);*/
65 for (cpt=0; cpt< NB_ELEM; cpt++)
66 *(int*)xbt_dynar_get_ptr(d,cpt) = cpt;
69 xbt_dynar_foreach(d,cursor,i){
70 xbt_test_assert2(i == cpt,
71 "The retrieved value is not the same than the injected one (%d!=%d)",
75 xbt_test_assert2(cpt == NB_ELEM,
76 "Cannot retrieve my %d values. Last got one is %d",
79 /* shifting [doxygen cruft] */
80 /* 4. Shift all the values */
81 for (cpt=0; cpt< NB_ELEM; cpt++) {
82 xbt_dynar_shift(d,&i);
83 xbt_test_assert2(i == cpt,
84 "The retrieved value is not the same than the injected one (%d!=%d)",
86 xbt_test_log2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
89 /* 5. Free the resources */
94 xbt_test_add1("==== Unshift/pop %d int",NB_ELEM);
95 d=xbt_dynar_new(sizeof(int),NULL);
96 for (cpt=0; cpt< NB_ELEM; cpt++) {
97 xbt_dynar_unshift(d,&cpt);
98 DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
100 for (cpt=0; cpt< NB_ELEM; cpt++) {
101 i=xbt_dynar_pop_as(d,int);
102 xbt_test_assert2(i == cpt,
103 "The retrieved value is not the same than the injected one (%d!=%d)",
105 xbt_test_log2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
111 xbt_test_add1("==== Push %d int, insert 1000 int in the middle, shift everything",NB_ELEM);
112 d=xbt_dynar_new(sizeof(int),NULL);
113 for (cpt=0; cpt< NB_ELEM; cpt++) {
114 xbt_dynar_push_as(d,int,cpt);
115 DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
117 for (cpt=0; cpt< 1000; cpt++) {
118 xbt_dynar_insert_at_as(d,2500,int,cpt);
119 DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
122 for (cpt=0; cpt< 2500; cpt++) {
123 xbt_dynar_shift(d,&i);
124 xbt_test_assert2(i == cpt,
125 "The retrieved value is not the same than the injected one at the begining (%d!=%d)",
127 DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
129 for (cpt=999; cpt>=0; cpt--) {
130 xbt_dynar_shift(d,&i);
131 xbt_test_assert2(i == cpt,
132 "The retrieved value is not the same than the injected one in the middle (%d!=%d)",
135 for (cpt=2500; cpt< NB_ELEM; cpt++) {
136 xbt_dynar_shift(d,&i);
137 xbt_test_assert2(i == cpt,
138 "The retrieved value is not the same than the injected one at the end (%d!=%d)",
145 xbt_test_add1("==== Push %d int, remove 2000-4000. free the rest",NB_ELEM);
146 d=xbt_dynar_new(sizeof(int),NULL);
147 for (cpt=0; cpt< NB_ELEM; cpt++)
148 xbt_dynar_push_as(d,int,cpt);
150 for (cpt=2000; cpt< 4000; cpt++) {
151 xbt_dynar_remove_at(d,2000,&i);
152 xbt_test_assert2(i == cpt,
153 "Remove a bad value. Got %d, expected %d",
155 DEBUG2("remove %d, length=%lu",cpt, xbt_dynar_length(d));
161 XBT_TEST_UNIT("double",test_dynar_double,"Dyars of doubles") {
166 xbt_test_add0("==== Traverse the empty dynar");
167 d=xbt_dynar_new(sizeof(int),NULL);
168 xbt_dynar_foreach(d,cursor,cpt){
169 xbt_test_assert0(FALSE,
170 "Damnit, there is something in the empty dynar");
175 xbt_test_add0("==== Push/shift 5000 doubles");
176 d=xbt_dynar_new(sizeof(double),NULL);
177 for (cpt=0; cpt< 5000; cpt++) {
179 xbt_dynar_push(d,&d1);
181 xbt_dynar_foreach(d,cursor,d2){
183 xbt_test_assert2(d1 == d2,
184 "The retrieved value is not the same than the injected one (%f!=%f)",
187 for (cpt=0; cpt< 5000; cpt++) {
189 xbt_dynar_shift(d,&d2);
190 xbt_test_assert2(d1 == d2,
191 "The retrieved value is not the same than the injected one (%f!=%f)",
198 xbt_test_add0("==== Unshift/pop 5000 doubles");
199 d=xbt_dynar_new(sizeof(double),NULL);
200 for (cpt=0; cpt< 5000; cpt++) {
202 xbt_dynar_unshift(d,&d1);
204 for (cpt=0; cpt< 5000; cpt++) {
206 xbt_dynar_pop(d,&d2);
207 xbt_test_assert2 (d1 == d2,
208 "The retrieved value is not the same than the injected one (%f!=%f)",
216 xbt_test_add0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything");
217 d=xbt_dynar_new(sizeof(double),NULL);
218 for (cpt=0; cpt< 5000; cpt++) {
220 xbt_dynar_push(d,&d1);
222 for (cpt=0; cpt< 1000; cpt++) {
224 xbt_dynar_insert_at(d,2500,&d1);
227 for (cpt=0; cpt< 2500; cpt++) {
229 xbt_dynar_shift(d,&d2);
230 xbt_test_assert2(d1 == d2,
231 "The retrieved value is not the same than the injected one at the begining (%f!=%f)",
233 DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
235 for (cpt=999; cpt>=0; cpt--) {
237 xbt_dynar_shift(d,&d2);
238 xbt_test_assert2 (d1 == d2,
239 "The retrieved value is not the same than the injected one in the middle (%f!=%f)",
242 for (cpt=2500; cpt< 5000; cpt++) {
244 xbt_dynar_shift(d,&d2);
245 xbt_test_assert2 (d1 == d2,
246 "The retrieved value is not the same than the injected one at the end (%f!=%f)",
253 xbt_test_add0("==== Push 5000 double, remove 2000-4000. free the rest");
254 d=xbt_dynar_new(sizeof(double),NULL);
255 for (cpt=0; cpt< 5000; cpt++) {
257 xbt_dynar_push(d,&d1);
259 for (cpt=2000; cpt< 4000; cpt++) {
261 xbt_dynar_remove_at(d,2000,&d2);
262 xbt_test_assert2 (d1 == d2,
263 "Remove a bad value. Got %f, expected %f",
271 /* doxygen_string_cruft */
273 /* The function we will use to free the data */
274 static void free_string(void *d){
278 XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") {
284 xbt_test_add0("==== Traverse the empty dynar");
285 d=xbt_dynar_new(sizeof(char *),&free_string);
286 xbt_dynar_foreach(d,cpt,s1){
287 xbt_test_assert0(FALSE,
288 "Damnit, there is something in the empty dynar");
293 xbt_test_add1("==== Push %d strings, set them again 3 times, shift them",NB_ELEM);
294 /* Populate_str [doxygen cruft] */
295 d=xbt_dynar_new(sizeof(char*),&free_string);
296 /* 1. Populate the dynar */
297 for (cpt=0; cpt< NB_ELEM; cpt++) {
298 sprintf(buf,"%d",cpt);
300 xbt_dynar_push(d,&s1);
302 for (cpt=0; cpt< NB_ELEM; cpt++) {
303 sprintf(buf,"%d",cpt);
305 xbt_dynar_replace(d,cpt,&s1);
307 for (cpt=0; cpt< NB_ELEM; cpt++) {
308 sprintf(buf,"%d",cpt);
310 xbt_dynar_replace(d,cpt,&s1);
312 for (cpt=0; cpt< NB_ELEM; cpt++) {
313 sprintf(buf,"%d",cpt);
315 xbt_dynar_replace(d,cpt,&s1);
317 for (cpt=0; cpt< NB_ELEM; cpt++) {
318 sprintf(buf,"%d",cpt);
319 xbt_dynar_shift(d,&s2);
320 xbt_test_assert2 (!strcmp(buf,s2),
321 "The retrieved value is not the same than the injected one (%s!=%s)",
329 xbt_test_add1("==== Unshift, traverse and pop %d strings",NB_ELEM);
330 d=xbt_dynar_new(sizeof(char**),&free_string);
331 for (cpt=0; cpt< NB_ELEM; cpt++) {
332 sprintf(buf,"%d",cpt);
334 xbt_dynar_unshift(d,&s1);
336 /* 2. Traverse the dynar with the macro */
337 xbt_dynar_foreach(d,cpt,s1) {
338 sprintf(buf,"%d",NB_ELEM - cpt -1);
339 xbt_test_assert2 (!strcmp(buf,s1),
340 "The retrieved value is not the same than the injected one (%s!=%s)",
343 /* 3. Traverse the dynar with the macro */
344 for (cpt=0; cpt< NB_ELEM; cpt++) {
345 sprintf(buf,"%d",cpt);
346 xbt_dynar_pop(d,&s2);
347 xbt_test_assert2 (!strcmp(buf,s2),
348 "The retrieved value is not the same than the injected one (%s!=%s)",
352 /* 4. Free the resources */
357 xbt_test_add2("==== Push %d strings, insert %d strings in the middle, shift everything",NB_ELEM,NB_ELEM/5);
358 d=xbt_dynar_new(sizeof(char*),&free_string);
359 for (cpt=0; cpt< NB_ELEM; cpt++) {
360 sprintf(buf,"%d",cpt);
362 xbt_dynar_push(d,&s1);
364 for (cpt=0; cpt< NB_ELEM/5; cpt++) {
365 sprintf(buf,"%d",cpt);
367 xbt_dynar_insert_at(d,NB_ELEM/2,&s1);
370 for (cpt=0; cpt< NB_ELEM/2; cpt++) {
371 sprintf(buf,"%d",cpt);
372 xbt_dynar_shift(d,&s2);
373 xbt_test_assert2(!strcmp(buf,s2),
374 "The retrieved value is not the same than the injected one at the begining (%s!=%s)",
378 for (cpt=(NB_ELEM/5)-1; cpt>=0; cpt--) {
379 sprintf(buf,"%d",cpt);
380 xbt_dynar_shift(d,&s2);
381 xbt_test_assert2 (!strcmp(buf,s2),
382 "The retrieved value is not the same than the injected one in the middle (%s!=%s)",
386 for (cpt=NB_ELEM/2; cpt< NB_ELEM; cpt++) {
387 sprintf(buf,"%d",cpt);
388 xbt_dynar_shift(d,&s2);
389 xbt_test_assert2 (!strcmp(buf,s2),
390 "The retrieved value is not the same than the injected one at the end (%s!=%s)",
398 xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest",NB_ELEM,2*(NB_ELEM/5),4*(NB_ELEM/5));
399 d=xbt_dynar_new(sizeof(char*),&free_string);
400 for (cpt=0; cpt< NB_ELEM; cpt++) {
401 sprintf(buf,"%d",cpt);
403 xbt_dynar_push(d,&s1);
405 for (cpt=2*(NB_ELEM/5); cpt< 4*(NB_ELEM/5); cpt++) {
406 sprintf(buf,"%d",cpt);
407 xbt_dynar_remove_at(d,2*(NB_ELEM/5),&s2);
408 xbt_test_assert2(!strcmp(buf,s2),
409 "Remove a bad value. Got %s, expected %s",
413 xbt_dynar_free(&d); /* end_of_doxygen */
415 /*******************************/
416 /* GENERATED FILE, DO NOT EDIT */
417 /*******************************/