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,"Dynars of integers") {
19 /* Vars_decl [doxygen cruft] */
25 xbt_test_add0("==== Traverse the empty dynar");
26 d=xbt_dynar_new(sizeof(int),NULL);
27 xbt_dynar_foreach(d,cursor,i){
28 xbt_assert0(0,"Damnit, there is something in the empty dynar");
33 xbt_test_add1("==== Push %d int, set them again 3 times, traverse them, shift them",
35 /* Populate_ints [doxygen cruft] */
36 /* 1. Populate the dynar */
37 d=xbt_dynar_new(sizeof(int),NULL);
38 for (cpt=0; cpt< NB_ELEM; cpt++) {
39 xbt_dynar_push_as(d,int,cpt); /* This is faster (and possible only with scalars) */
40 /* xbt_dynar_push(d,&cpt); This would also work */
41 xbt_test_log2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
44 /* 2. Traverse manually the dynar */
45 for (cursor=0; cursor< NB_ELEM; cursor++) {
46 iptr=xbt_dynar_get_ptr(d,cursor);
47 xbt_test_assert2(cursor == *iptr,
48 "The retrieved value is not the same than the injected one (%d!=%d)",
52 /* 3. Traverse the dynar using the neat macro to that extend */
53 xbt_dynar_foreach(d,cursor,cpt){
54 xbt_test_assert2(cursor == cpt,
55 "The retrieved value is not the same than the injected one (%d!=%d)",
58 /* end_of_traversal */
60 for (cpt=0; cpt< NB_ELEM; cpt++)
61 *(int*)xbt_dynar_get_ptr(d,cpt) = cpt;
63 for (cpt=0; cpt< NB_ELEM; cpt++)
64 *(int*)xbt_dynar_get_ptr(d,cpt) = cpt;
65 /* xbt_dynar_set(d,cpt,&cpt);*/
67 for (cpt=0; cpt< NB_ELEM; cpt++)
68 *(int*)xbt_dynar_get_ptr(d,cpt) = cpt;
71 xbt_dynar_foreach(d,cursor,i){
72 xbt_test_assert2(i == cpt,
73 "The retrieved value is not the same than the injected one (%d!=%d)",
77 xbt_test_assert2(cpt == NB_ELEM,
78 "Cannot retrieve my %d values. Last got one is %d",
81 /* shifting [doxygen cruft] */
82 /* 4. Shift all the values */
83 for (cpt=0; cpt< NB_ELEM; cpt++) {
84 xbt_dynar_shift(d,&i);
85 xbt_test_assert2(i == cpt,
86 "The retrieved value is not the same than the injected one (%d!=%d)",
88 xbt_test_log2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
91 /* 5. Free the resources */
96 xbt_test_add1("==== Unshift/pop %d int",NB_ELEM);
97 d=xbt_dynar_new(sizeof(int),NULL);
98 for (cpt=0; cpt< NB_ELEM; cpt++) {
99 xbt_dynar_unshift(d,&cpt);
100 DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
102 for (cpt=0; cpt< NB_ELEM; cpt++) {
103 i=xbt_dynar_pop_as(d,int);
104 xbt_test_assert2(i == cpt,
105 "The retrieved value is not the same than the injected one (%d!=%d)",
107 xbt_test_log2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
113 xbt_test_add1("==== Push %d int, insert 1000 int in the middle, shift everything",NB_ELEM);
114 d=xbt_dynar_new(sizeof(int),NULL);
115 for (cpt=0; cpt< NB_ELEM; cpt++) {
116 xbt_dynar_push_as(d,int,cpt);
117 DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
119 for (cpt=0; cpt< 1000; cpt++) {
120 xbt_dynar_insert_at_as(d,2500,int,cpt);
121 DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d));
124 for (cpt=0; cpt< 2500; cpt++) {
125 xbt_dynar_shift(d,&i);
126 xbt_test_assert2(i == cpt,
127 "The retrieved value is not the same than the injected one at the begining (%d!=%d)",
129 DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
131 for (cpt=999; cpt>=0; cpt--) {
132 xbt_dynar_shift(d,&i);
133 xbt_test_assert2(i == cpt,
134 "The retrieved value is not the same than the injected one in the middle (%d!=%d)",
137 for (cpt=2500; cpt< NB_ELEM; cpt++) {
138 xbt_dynar_shift(d,&i);
139 xbt_test_assert2(i == cpt,
140 "The retrieved value is not the same than the injected one at the end (%d!=%d)",
147 xbt_test_add1("==== Push %d int, remove 2000-4000. free the rest",NB_ELEM);
148 d=xbt_dynar_new(sizeof(int),NULL);
149 for (cpt=0; cpt< NB_ELEM; cpt++)
150 xbt_dynar_push_as(d,int,cpt);
152 for (cpt=2000; cpt< 4000; cpt++) {
153 xbt_dynar_remove_at(d,2000,&i);
154 xbt_test_assert2(i == cpt,
155 "Remove a bad value. Got %d, expected %d",
157 DEBUG2("remove %d, length=%lu",cpt, xbt_dynar_length(d));
162 /*******************************************************************************/
163 /*******************************************************************************/
164 /*******************************************************************************/
165 XBT_TEST_UNIT("double",test_dynar_double,"Dynars of doubles") {
171 xbt_test_add0("==== Traverse the empty dynar");
172 d=xbt_dynar_new(sizeof(int),NULL);
173 xbt_dynar_foreach(d,cursor,cpt){
174 xbt_test_assert0(FALSE,
175 "Damnit, there is something in the empty dynar");
180 xbt_test_add0("==== Push/shift 5000 doubles");
181 d=xbt_dynar_new(sizeof(double),NULL);
182 for (cpt=0; cpt< 5000; cpt++) {
184 xbt_dynar_push(d,&d1);
186 xbt_dynar_foreach(d,cursor,d2){
188 xbt_test_assert2(d1 == d2,
189 "The retrieved value is not the same than the injected one (%f!=%f)",
192 for (cpt=0; cpt< 5000; cpt++) {
194 xbt_dynar_shift(d,&d2);
195 xbt_test_assert2(d1 == d2,
196 "The retrieved value is not the same than the injected one (%f!=%f)",
203 xbt_test_add0("==== Unshift/pop 5000 doubles");
204 d=xbt_dynar_new(sizeof(double),NULL);
205 for (cpt=0; cpt< 5000; cpt++) {
207 xbt_dynar_unshift(d,&d1);
209 for (cpt=0; cpt< 5000; cpt++) {
211 xbt_dynar_pop(d,&d2);
212 xbt_test_assert2 (d1 == d2,
213 "The retrieved value is not the same than the injected one (%f!=%f)",
221 xbt_test_add0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything");
222 d=xbt_dynar_new(sizeof(double),NULL);
223 for (cpt=0; cpt< 5000; cpt++) {
225 xbt_dynar_push(d,&d1);
227 for (cpt=0; cpt< 1000; cpt++) {
229 xbt_dynar_insert_at(d,2500,&d1);
232 for (cpt=0; cpt< 2500; cpt++) {
234 xbt_dynar_shift(d,&d2);
235 xbt_test_assert2(d1 == d2,
236 "The retrieved value is not the same than the injected one at the begining (%f!=%f)",
238 DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
240 for (cpt=999; cpt>=0; cpt--) {
242 xbt_dynar_shift(d,&d2);
243 xbt_test_assert2 (d1 == d2,
244 "The retrieved value is not the same than the injected one in the middle (%f!=%f)",
247 for (cpt=2500; cpt< 5000; cpt++) {
249 xbt_dynar_shift(d,&d2);
250 xbt_test_assert2 (d1 == d2,
251 "The retrieved value is not the same than the injected one at the end (%f!=%f)",
258 xbt_test_add0("==== Push 5000 double, remove 2000-4000. free the rest");
259 d=xbt_dynar_new(sizeof(double),NULL);
260 for (cpt=0; cpt< 5000; cpt++) {
262 xbt_dynar_push(d,&d1);
264 for (cpt=2000; cpt< 4000; cpt++) {
266 xbt_dynar_remove_at(d,2000,&d2);
267 xbt_test_assert2 (d1 == d2,
268 "Remove a bad value. Got %f, expected %f",
276 /* doxygen_string_cruft */
278 /*******************************************************************************/
279 /*******************************************************************************/
280 /*******************************************************************************/
281 XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") {
288 xbt_test_add0("==== Traverse the empty dynar");
289 d=xbt_dynar_new(sizeof(char *),&xbt_free_ref);
290 xbt_dynar_foreach(d,iter,s1){
291 xbt_test_assert0(FALSE,
292 "Damnit, there is something in the empty dynar");
297 xbt_test_add1("==== Push %d strings, set them again 3 times, shift them",NB_ELEM);
298 /* Populate_str [doxygen cruft] */
299 d=xbt_dynar_new(sizeof(char*),&xbt_free_ref);
300 /* 1. Populate the dynar */
301 for (cpt=0; cpt< NB_ELEM; cpt++) {
302 sprintf(buf,"%d",cpt);
304 xbt_dynar_push(d,&s1);
306 for (cpt=0; cpt< NB_ELEM; cpt++) {
307 sprintf(buf,"%d",cpt);
309 xbt_dynar_replace(d,cpt,&s1);
311 for (cpt=0; cpt< NB_ELEM; cpt++) {
312 sprintf(buf,"%d",cpt);
314 xbt_dynar_replace(d,cpt,&s1);
316 for (cpt=0; cpt< NB_ELEM; cpt++) {
317 sprintf(buf,"%d",cpt);
319 xbt_dynar_replace(d,cpt,&s1);
321 for (cpt=0; cpt< NB_ELEM; cpt++) {
322 sprintf(buf,"%d",cpt);
323 xbt_dynar_shift(d,&s2);
324 xbt_test_assert2 (!strcmp(buf,s2),
325 "The retrieved value is not the same than the injected one (%s!=%s)",
333 xbt_test_add1("==== Unshift, traverse and pop %d strings",NB_ELEM);
334 d=xbt_dynar_new(sizeof(char**),&xbt_free_ref);
335 for (cpt=0; cpt< NB_ELEM; cpt++) {
336 sprintf(buf,"%d",cpt);
338 xbt_dynar_unshift(d,&s1);
340 /* 2. Traverse the dynar with the macro */
341 xbt_dynar_foreach(d,iter,s1) {
342 sprintf(buf,"%d",NB_ELEM - iter -1);
343 xbt_test_assert2 (!strcmp(buf,s1),
344 "The retrieved value is not the same than the injected one (%s!=%s)",
347 /* 3. Traverse the dynar with the macro */
348 for (cpt=0; cpt< NB_ELEM; cpt++) {
349 sprintf(buf,"%d",cpt);
350 xbt_dynar_pop(d,&s2);
351 xbt_test_assert2 (!strcmp(buf,s2),
352 "The retrieved value is not the same than the injected one (%s!=%s)",
356 /* 4. Free the resources */
361 xbt_test_add2("==== Push %d strings, insert %d strings in the middle, shift everything",NB_ELEM,NB_ELEM/5);
362 d=xbt_dynar_new(sizeof(char*),&xbt_free_ref);
363 for (cpt=0; cpt< NB_ELEM; cpt++) {
364 sprintf(buf,"%d",cpt);
366 xbt_dynar_push(d,&s1);
368 for (cpt=0; cpt< NB_ELEM/5; cpt++) {
369 sprintf(buf,"%d",cpt);
371 xbt_dynar_insert_at(d,NB_ELEM/2,&s1);
374 for (cpt=0; cpt< NB_ELEM/2; cpt++) {
375 sprintf(buf,"%d",cpt);
376 xbt_dynar_shift(d,&s2);
377 xbt_test_assert2(!strcmp(buf,s2),
378 "The retrieved value is not the same than the injected one at the begining (%s!=%s)",
382 for (cpt=(NB_ELEM/5)-1; cpt>=0; cpt--) {
383 sprintf(buf,"%d",cpt);
384 xbt_dynar_shift(d,&s2);
385 xbt_test_assert2 (!strcmp(buf,s2),
386 "The retrieved value is not the same than the injected one in the middle (%s!=%s)",
390 for (cpt=NB_ELEM/2; cpt< NB_ELEM; cpt++) {
391 sprintf(buf,"%d",cpt);
392 xbt_dynar_shift(d,&s2);
393 xbt_test_assert2 (!strcmp(buf,s2),
394 "The retrieved value is not the same than the injected one at the end (%s!=%s)",
402 xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest",NB_ELEM,2*(NB_ELEM/5),4*(NB_ELEM/5));
403 d=xbt_dynar_new(sizeof(char*),&xbt_free_ref);
404 for (cpt=0; cpt< NB_ELEM; cpt++) {
405 sprintf(buf,"%d",cpt);
407 xbt_dynar_push(d,&s1);
409 for (cpt=2*(NB_ELEM/5); cpt< 4*(NB_ELEM/5); cpt++) {
410 sprintf(buf,"%d",cpt);
411 xbt_dynar_remove_at(d,2*(NB_ELEM/5),&s2);
412 xbt_test_assert2(!strcmp(buf,s2),
413 "Remove a bad value. Got %s, expected %s",
417 xbt_dynar_free(&d); /* end_of_doxygen */
421 /*******************************************************************************/
422 /*******************************************************************************/
423 /*******************************************************************************/
424 #include "xbt/synchro.h"
425 static void pusher_f(void *a) {
426 xbt_dynar_t d=(xbt_dynar_t)a;
428 for (i=0; i<500; i++) {
429 xbt_dynar_push(d,&i);
432 static void poper_f(void *a) {
433 xbt_dynar_t d=(xbt_dynar_t)a;
438 for (i=0; i<500; i++) {
440 xbt_dynar_pop(d,&data);
442 if (e.category == bound_error) {
453 XBT_TEST_UNIT("synchronized int",test_dynar_sync_int,"Synchronized dynars of integers") {
454 /* Vars_decl [doxygen cruft] */
456 xbt_thread_t pusher,poper;
458 xbt_test_add0("==== Have a pusher and a popper on the dynar");
459 d=xbt_dynar_new_sync(sizeof(int),NULL);
460 pusher = xbt_thread_create("pusher",pusher_f,d);
461 poper = xbt_thread_create("poper",poper_f,d);
462 xbt_thread_join(pusher);
463 xbt_thread_join(poper);
467 /*******************************/
468 /* GENERATED FILE, DO NOT EDIT */
469 /*******************************/