1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
7 /*******************************/
8 /* GENERATED FILE, DO NOT EDIT */
9 /*******************************/
15 XBT_LOG_EXTERNAL_CATEGORY(xbt_dyn);
16 XBT_LOG_DEFAULT_CATEGORY(xbt_dyn);
18 XBT_TEST_UNIT("int",test_dynar_int,"Dyars of integers") {
19 /* Vars_decl [doxygen cruft] */
24 xbt_test_add0("==== Traverse the empty dynar");
25 d=xbt_dynar_new(sizeof(int),NULL);
26 xbt_dynar_foreach(d,cursor,i){
27 xbt_assert0(0,"Damnit, there is something in the empty dynar");
32 xbt_test_add1("==== Push %d int, set them again 3 times, traverse them, shift them",
34 /* Populate_ints [doxygen cruft] */
35 /* 1. Populate the dynar */
36 d=xbt_dynar_new(sizeof(int),NULL);
37 for (cpt=0; cpt< NB_ELEM; cpt++) {
38 xbt_dynar_push_as(d,int,cpt); /* This is faster (and possible only with scalars) */
39 /* xbt_dynar_push(d,&cpt); This would also work */
40 xbt_test_log2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
43 /* 2. Traverse manually the dynar */
44 for (cursor=0; cursor< NB_ELEM; cursor++) {
45 iptr=xbt_dynar_get_ptr(d,cursor);
46 xbt_test_assert2(cursor == *iptr,
47 "The retrieved value is not the same than the injected one (%d!=%d)",
51 /* 3. Traverse the dynar using the neat macro to that extend */
52 xbt_dynar_foreach(d,cursor,cpt){
53 xbt_test_assert2(cursor == cpt,
54 "The retrieved value is not the same than the injected one (%d!=%d)",
57 /* end_of_traversal */
59 for (cpt=0; cpt< NB_ELEM; cpt++)
60 *(int*)xbt_dynar_get_ptr(d,cpt) = cpt;
62 for (cpt=0; cpt< NB_ELEM; cpt++)
63 *(int*)xbt_dynar_get_ptr(d,cpt) = cpt;
64 /* xbt_dynar_set(d,cpt,&cpt);*/
66 for (cpt=0; cpt< NB_ELEM; cpt++)
67 *(int*)xbt_dynar_get_ptr(d,cpt) = cpt;
70 xbt_dynar_foreach(d,cursor,i){
71 xbt_test_assert2(i == cpt,
72 "The retrieved value is not the same than the injected one (%d!=%d)",
76 xbt_test_assert2(cpt == NB_ELEM,
77 "Cannot retrieve my %d values. Last got one is %d",
80 /* shifting [doxygen cruft] */
81 /* 4. Shift all the values */
82 for (cpt=0; cpt< NB_ELEM; cpt++) {
83 xbt_dynar_shift(d,&i);
84 xbt_test_assert2(i == cpt,
85 "The retrieved value is not the same than the injected one (%d!=%d)",
87 xbt_test_log2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
90 /* 5. Free the resources */
95 xbt_test_add1("==== Unshift/pop %d int",NB_ELEM);
96 d=xbt_dynar_new(sizeof(int),NULL);
97 for (cpt=0; cpt< NB_ELEM; cpt++) {
98 xbt_dynar_unshift(d,&cpt);
99 DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
101 for (cpt=0; cpt< NB_ELEM; cpt++) {
102 i=xbt_dynar_pop_as(d,int);
103 xbt_test_assert2(i == cpt,
104 "The retrieved value is not the same than the injected one (%d!=%d)",
106 xbt_test_log2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
112 xbt_test_add1("==== Push %d int, insert 1000 int in the middle, shift everything",NB_ELEM);
113 d=xbt_dynar_new(sizeof(int),NULL);
114 for (cpt=0; cpt< NB_ELEM; cpt++) {
115 xbt_dynar_push_as(d,int,cpt);
116 DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
118 for (cpt=0; cpt< 1000; cpt++) {
119 xbt_dynar_insert_at_as(d,2500,int,cpt);
120 DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
123 for (cpt=0; cpt< 2500; cpt++) {
124 xbt_dynar_shift(d,&i);
125 xbt_test_assert2(i == cpt,
126 "The retrieved value is not the same than the injected one at the begining (%d!=%d)",
128 DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
130 for (cpt=999; cpt>=0; cpt--) {
131 xbt_dynar_shift(d,&i);
132 xbt_test_assert2(i == cpt,
133 "The retrieved value is not the same than the injected one in the middle (%d!=%d)",
136 for (cpt=2500; cpt< NB_ELEM; cpt++) {
137 xbt_dynar_shift(d,&i);
138 xbt_test_assert2(i == cpt,
139 "The retrieved value is not the same than the injected one at the end (%d!=%d)",
146 xbt_test_add1("==== Push %d int, remove 2000-4000. free the rest",NB_ELEM);
147 d=xbt_dynar_new(sizeof(int),NULL);
148 for (cpt=0; cpt< NB_ELEM; cpt++)
149 xbt_dynar_push_as(d,int,cpt);
151 for (cpt=2000; cpt< 4000; cpt++) {
152 xbt_dynar_remove_at(d,2000,&i);
153 xbt_test_assert2(i == cpt,
154 "Remove a bad value. Got %d, expected %d",
156 DEBUG2("remove %d, length=%lu",cpt, xbt_dynar_length(d));
162 XBT_TEST_UNIT("double",test_dynar_double,"Dyars of doubles") {
167 xbt_test_add0("==== Traverse the empty dynar");
168 d=xbt_dynar_new(sizeof(int),NULL);
169 xbt_dynar_foreach(d,cursor,cpt){
170 xbt_test_assert0(FALSE,
171 "Damnit, there is something in the empty dynar");
176 xbt_test_add0("==== Push/shift 5000 doubles");
177 d=xbt_dynar_new(sizeof(double),NULL);
178 for (cpt=0; cpt< 5000; cpt++) {
180 xbt_dynar_push(d,&d1);
182 xbt_dynar_foreach(d,cursor,d2){
184 xbt_test_assert2(d1 == d2,
185 "The retrieved value is not the same than the injected one (%f!=%f)",
188 for (cpt=0; cpt< 5000; cpt++) {
190 xbt_dynar_shift(d,&d2);
191 xbt_test_assert2(d1 == d2,
192 "The retrieved value is not the same than the injected one (%f!=%f)",
199 xbt_test_add0("==== Unshift/pop 5000 doubles");
200 d=xbt_dynar_new(sizeof(double),NULL);
201 for (cpt=0; cpt< 5000; cpt++) {
203 xbt_dynar_unshift(d,&d1);
205 for (cpt=0; cpt< 5000; cpt++) {
207 xbt_dynar_pop(d,&d2);
208 xbt_test_assert2 (d1 == d2,
209 "The retrieved value is not the same than the injected one (%f!=%f)",
217 xbt_test_add0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything");
218 d=xbt_dynar_new(sizeof(double),NULL);
219 for (cpt=0; cpt< 5000; cpt++) {
221 xbt_dynar_push(d,&d1);
223 for (cpt=0; cpt< 1000; cpt++) {
225 xbt_dynar_insert_at(d,2500,&d1);
228 for (cpt=0; cpt< 2500; cpt++) {
230 xbt_dynar_shift(d,&d2);
231 xbt_test_assert2(d1 == d2,
232 "The retrieved value is not the same than the injected one at the begining (%f!=%f)",
234 DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
236 for (cpt=999; cpt>=0; cpt--) {
238 xbt_dynar_shift(d,&d2);
239 xbt_test_assert2 (d1 == d2,
240 "The retrieved value is not the same than the injected one in the middle (%f!=%f)",
243 for (cpt=2500; cpt< 5000; cpt++) {
245 xbt_dynar_shift(d,&d2);
246 xbt_test_assert2 (d1 == d2,
247 "The retrieved value is not the same than the injected one at the end (%f!=%f)",
254 xbt_test_add0("==== Push 5000 double, remove 2000-4000. free the rest");
255 d=xbt_dynar_new(sizeof(double),NULL);
256 for (cpt=0; cpt< 5000; cpt++) {
258 xbt_dynar_push(d,&d1);
260 for (cpt=2000; cpt< 4000; cpt++) {
262 xbt_dynar_remove_at(d,2000,&d2);
263 xbt_test_assert2 (d1 == d2,
264 "Remove a bad value. Got %f, expected %f",
272 /* doxygen_string_cruft */
274 /* The function we will use to free the data */
275 static void free_string(void *d){
279 XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") {
285 xbt_test_add0("==== Traverse the empty dynar");
286 d=xbt_dynar_new(sizeof(char *),&free_string);
287 xbt_dynar_foreach(d,cpt,s1){
288 xbt_test_assert0(FALSE,
289 "Damnit, there is something in the empty dynar");
294 xbt_test_add1("==== Push %d strings, set them again 3 times, shift them",NB_ELEM);
295 /* Populate_str [doxygen cruft] */
296 d=xbt_dynar_new(sizeof(char*),&free_string);
297 /* 1. Populate the dynar */
298 for (cpt=0; cpt< NB_ELEM; cpt++) {
299 sprintf(buf,"%d",cpt);
301 xbt_dynar_push(d,&s1);
303 for (cpt=0; cpt< NB_ELEM; cpt++) {
304 sprintf(buf,"%d",cpt);
306 xbt_dynar_replace(d,cpt,&s1);
308 for (cpt=0; cpt< NB_ELEM; cpt++) {
309 sprintf(buf,"%d",cpt);
311 xbt_dynar_replace(d,cpt,&s1);
313 for (cpt=0; cpt< NB_ELEM; cpt++) {
314 sprintf(buf,"%d",cpt);
316 xbt_dynar_replace(d,cpt,&s1);
318 for (cpt=0; cpt< NB_ELEM; cpt++) {
319 sprintf(buf,"%d",cpt);
320 xbt_dynar_shift(d,&s2);
321 xbt_test_assert2 (!strcmp(buf,s2),
322 "The retrieved value is not the same than the injected one (%s!=%s)",
330 xbt_test_add1("==== Unshift, traverse and pop %d strings",NB_ELEM);
331 d=xbt_dynar_new(sizeof(char**),&free_string);
332 for (cpt=0; cpt< NB_ELEM; cpt++) {
333 sprintf(buf,"%d",cpt);
335 xbt_dynar_unshift(d,&s1);
337 /* 2. Traverse the dynar with the macro */
338 xbt_dynar_foreach(d,cpt,s1) {
339 sprintf(buf,"%d",NB_ELEM - cpt -1);
340 xbt_test_assert2 (!strcmp(buf,s1),
341 "The retrieved value is not the same than the injected one (%s!=%s)",
344 /* 3. Traverse the dynar with the macro */
345 for (cpt=0; cpt< NB_ELEM; cpt++) {
346 sprintf(buf,"%d",cpt);
347 xbt_dynar_pop(d,&s2);
348 xbt_test_assert2 (!strcmp(buf,s2),
349 "The retrieved value is not the same than the injected one (%s!=%s)",
353 /* 4. Free the resources */
358 xbt_test_add2("==== Push %d strings, insert %d strings in the middle, shift everything",NB_ELEM,NB_ELEM/5);
359 d=xbt_dynar_new(sizeof(char*),&free_string);
360 for (cpt=0; cpt< NB_ELEM; cpt++) {
361 sprintf(buf,"%d",cpt);
363 xbt_dynar_push(d,&s1);
365 for (cpt=0; cpt< NB_ELEM/5; cpt++) {
366 sprintf(buf,"%d",cpt);
368 xbt_dynar_insert_at(d,NB_ELEM/2,&s1);
371 for (cpt=0; cpt< NB_ELEM/2; cpt++) {
372 sprintf(buf,"%d",cpt);
373 xbt_dynar_shift(d,&s2);
374 xbt_test_assert2(!strcmp(buf,s2),
375 "The retrieved value is not the same than the injected one at the begining (%s!=%s)",
379 for (cpt=(NB_ELEM/5)-1; cpt>=0; cpt--) {
380 sprintf(buf,"%d",cpt);
381 xbt_dynar_shift(d,&s2);
382 xbt_test_assert2 (!strcmp(buf,s2),
383 "The retrieved value is not the same than the injected one in the middle (%s!=%s)",
387 for (cpt=NB_ELEM/2; cpt< NB_ELEM; cpt++) {
388 sprintf(buf,"%d",cpt);
389 xbt_dynar_shift(d,&s2);
390 xbt_test_assert2 (!strcmp(buf,s2),
391 "The retrieved value is not the same than the injected one at the end (%s!=%s)",
399 xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest",NB_ELEM,2*(NB_ELEM/5),4*(NB_ELEM/5));
400 d=xbt_dynar_new(sizeof(char*),&free_string);
401 for (cpt=0; cpt< NB_ELEM; cpt++) {
402 sprintf(buf,"%d",cpt);
404 xbt_dynar_push(d,&s1);
406 for (cpt=2*(NB_ELEM/5); cpt< 4*(NB_ELEM/5); cpt++) {
407 sprintf(buf,"%d",cpt);
408 xbt_dynar_remove_at(d,2*(NB_ELEM/5),&s2);
409 xbt_test_assert2(!strcmp(buf,s2),
410 "Remove a bad value. Got %s, expected %s",
414 xbt_dynar_free(&d); /* end_of_doxygen */
416 /*******************************/
417 /* GENERATED FILE, DO NOT EDIT */
418 /*******************************/