1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
7 /*******************************/
8 /* GENERATED FILE, DO NOT EDIT */
9 /*******************************/
11 #line 716 "xbt/dynar.c"
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")
20 /* Vars_decl [doxygen cruft] */
26 xbt_test_add0("==== Traverse the empty dynar");
27 d = xbt_dynar_new(sizeof(int), NULL);
28 xbt_dynar_foreach(d, cursor, i) {
29 xbt_assert0(0, "Damnit, there is something in the empty dynar");
31 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
32 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
33 /* in your code is naturally the way to go outside a regression test */
36 ("==== Push %d int, set them again 3 times, traverse them, shift them",
38 /* Populate_ints [doxygen cruft] */
39 /* 1. Populate the dynar */
40 d = xbt_dynar_new(sizeof(int), NULL);
41 for (cpt = 0; cpt < NB_ELEM; cpt++) {
42 xbt_dynar_push_as(d, int, cpt); /* This is faster (and possible only with scalars) */
43 /* xbt_dynar_push(d,&cpt); This would also work */
44 xbt_test_log2("Push %d, length=%lu", cpt, xbt_dynar_length(d));
47 /* 2. Traverse manually the dynar */
48 for (cursor = 0; cursor < NB_ELEM; cursor++) {
49 iptr = xbt_dynar_get_ptr(d, cursor);
50 xbt_test_assert2(cursor == *iptr,
51 "The retrieved value is not the same than the injected one (%d!=%d)",
55 /* 3. Traverse the dynar using the neat macro to that extend */
56 xbt_dynar_foreach(d, cursor, cpt) {
57 xbt_test_assert2(cursor == cpt,
58 "The retrieved value is not the same than the injected one (%d!=%d)",
61 /* end_of_traversal */
63 for (cpt = 0; cpt < NB_ELEM; cpt++)
64 *(int *) xbt_dynar_get_ptr(d, cpt) = cpt;
66 for (cpt = 0; cpt < NB_ELEM; cpt++)
67 *(int *) xbt_dynar_get_ptr(d, cpt) = cpt;
68 /* xbt_dynar_set(d,cpt,&cpt); */
70 for (cpt = 0; cpt < NB_ELEM; cpt++)
71 *(int *) xbt_dynar_get_ptr(d, cpt) = cpt;
74 xbt_dynar_foreach(d, cursor, i) {
75 xbt_test_assert2(i == cpt,
76 "The retrieved value is not the same than the injected one (%d!=%d)",
80 xbt_test_assert2(cpt == NB_ELEM,
81 "Cannot retrieve my %d values. Last got one is %d",
84 /* shifting [doxygen cruft] */
85 /* 4. Shift all the values */
86 for (cpt = 0; cpt < NB_ELEM; cpt++) {
87 xbt_dynar_shift(d, &i);
88 xbt_test_assert2(i == cpt,
89 "The retrieved value is not the same than the injected one (%d!=%d)",
91 xbt_test_log2("Pop %d, length=%lu", cpt, xbt_dynar_length(d));
94 /* 5. Free the resources */
95 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
96 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
97 /* in your code is naturally the way to go outside a regression test */
99 xbt_test_add1("==== Unshift/pop %d int", NB_ELEM);
100 d = xbt_dynar_new(sizeof(int), NULL);
101 for (cpt = 0; cpt < NB_ELEM; cpt++) {
102 xbt_dynar_unshift(d, &cpt);
103 DEBUG2("Push %d, length=%lu", cpt, xbt_dynar_length(d));
105 for (cpt = 0; cpt < NB_ELEM; cpt++) {
106 i = xbt_dynar_pop_as(d, int);
107 xbt_test_assert2(i == cpt,
108 "The retrieved value is not the same than the injected one (%d!=%d)",
110 xbt_test_log2("Pop %d, length=%lu", cpt, xbt_dynar_length(d));
112 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
113 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
114 /* in your code is naturally the way to go outside a regression test */
118 ("==== Push %d int, insert 1000 int in the middle, shift everything",
120 d = xbt_dynar_new(sizeof(int), NULL);
121 for (cpt = 0; cpt < NB_ELEM; cpt++) {
122 xbt_dynar_push_as(d, int, cpt);
123 DEBUG2("Push %d, length=%lu", cpt, xbt_dynar_length(d));
125 for (cpt = 0; cpt < 1000; cpt++) {
126 xbt_dynar_insert_at_as(d, 2500, int, cpt);
127 DEBUG2("Push %d, length=%lu", cpt, xbt_dynar_length(d));
130 for (cpt = 0; cpt < 2500; 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 at the begining (%d!=%d)",
135 DEBUG2("Pop %d, length=%lu", cpt, xbt_dynar_length(d));
137 for (cpt = 999; cpt >= 0; 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 in the middle (%d!=%d)",
143 for (cpt = 2500; cpt < NB_ELEM; cpt++) {
144 xbt_dynar_shift(d, &i);
145 xbt_test_assert2(i == cpt,
146 "The retrieved value is not the same than the injected one at the end (%d!=%d)",
149 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
150 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
151 /* in your code is naturally the way to go outside a regression test */
153 xbt_test_add1("==== Push %d int, remove 2000-4000. free the rest", NB_ELEM);
154 d = xbt_dynar_new(sizeof(int), NULL);
155 for (cpt = 0; cpt < NB_ELEM; cpt++)
156 xbt_dynar_push_as(d, int, cpt);
158 for (cpt = 2000; cpt < 4000; cpt++) {
159 xbt_dynar_remove_at(d, 2000, &i);
160 xbt_test_assert2(i == cpt,
161 "Remove a bad value. Got %d, expected %d", i, cpt);
162 DEBUG2("remove %d, length=%lu", cpt, xbt_dynar_length(d));
164 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
165 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
166 /* in your code is naturally the way to go outside a regression test */
169 /*******************************************************************************/
170 /*******************************************************************************/
171 /*******************************************************************************/
172 XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles")
179 xbt_test_add0("==== Traverse the empty dynar");
180 d = xbt_dynar_new(sizeof(int), NULL);
181 xbt_dynar_foreach(d, cursor, cpt) {
182 xbt_test_assert0(FALSE, "Damnit, there is something in the empty dynar");
184 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
185 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
186 /* in your code is naturally the way to go outside a regression test */
188 xbt_test_add0("==== Push/shift 5000 doubles");
189 d = xbt_dynar_new(sizeof(double), NULL);
190 for (cpt = 0; cpt < 5000; cpt++) {
192 xbt_dynar_push(d, &d1);
194 xbt_dynar_foreach(d, cursor, d2) {
195 d1 = (double) cursor;
196 xbt_test_assert2(d1 == d2,
197 "The retrieved value is not the same than the injected one (%f!=%f)",
200 for (cpt = 0; cpt < 5000; cpt++) {
202 xbt_dynar_shift(d, &d2);
203 xbt_test_assert2(d1 == d2,
204 "The retrieved value is not the same than the injected one (%f!=%f)",
207 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
208 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
209 /* in your code is naturally the way to go outside a regression test */
211 xbt_test_add0("==== Unshift/pop 5000 doubles");
212 d = xbt_dynar_new(sizeof(double), NULL);
213 for (cpt = 0; cpt < 5000; cpt++) {
215 xbt_dynar_unshift(d, &d1);
217 for (cpt = 0; cpt < 5000; cpt++) {
219 xbt_dynar_pop(d, &d2);
220 xbt_test_assert2(d1 == d2,
221 "The retrieved value is not the same than the injected one (%f!=%f)",
224 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
225 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
226 /* in your code is naturally the way to go outside a regression test */
231 ("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything");
232 d = xbt_dynar_new(sizeof(double), NULL);
233 for (cpt = 0; cpt < 5000; cpt++) {
235 xbt_dynar_push(d, &d1);
237 for (cpt = 0; cpt < 1000; cpt++) {
239 xbt_dynar_insert_at(d, 2500, &d1);
242 for (cpt = 0; cpt < 2500; 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 begining (%f!=%f)",
248 DEBUG2("Pop %d, length=%lu", cpt, xbt_dynar_length(d));
250 for (cpt = 999; cpt >= 0; cpt--) {
252 xbt_dynar_shift(d, &d2);
253 xbt_test_assert2(d1 == d2,
254 "The retrieved value is not the same than the injected one in the middle (%f!=%f)",
257 for (cpt = 2500; cpt < 5000; cpt++) {
259 xbt_dynar_shift(d, &d2);
260 xbt_test_assert2(d1 == d2,
261 "The retrieved value is not the same than the injected one at the end (%f!=%f)",
264 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
265 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
266 /* in your code is naturally the way to go outside a regression test */
269 xbt_test_add0("==== Push 5000 double, remove 2000-4000. free the rest");
270 d = xbt_dynar_new(sizeof(double), NULL);
271 for (cpt = 0; cpt < 5000; cpt++) {
273 xbt_dynar_push(d, &d1);
275 for (cpt = 2000; cpt < 4000; cpt++) {
277 xbt_dynar_remove_at(d, 2000, &d2);
278 xbt_test_assert2(d1 == d2,
279 "Remove a bad value. Got %f, expected %f", d2, d1);
281 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
282 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
283 /* in your code is naturally the way to go outside a regression test */
287 /* doxygen_string_cruft */
289 /*******************************************************************************/
290 /*******************************************************************************/
291 /*******************************************************************************/
292 XBT_TEST_UNIT("string", test_dynar_string, "Dynars of strings")
300 xbt_test_add0("==== Traverse the empty dynar");
301 d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
302 xbt_dynar_foreach(d, iter, s1) {
303 xbt_test_assert0(FALSE, "Damnit, there is something in the empty dynar");
305 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
306 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
307 /* in your code is naturally the way to go outside a regression test */
309 xbt_test_add1("==== Push %d strings, set them again 3 times, shift them",
311 /* Populate_str [doxygen cruft] */
312 d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
313 /* 1. Populate the dynar */
314 for (cpt = 0; cpt < NB_ELEM; cpt++) {
315 sprintf(buf, "%d", cpt);
317 xbt_dynar_push(d, &s1);
319 for (cpt = 0; cpt < NB_ELEM; cpt++) {
320 sprintf(buf, "%d", cpt);
322 xbt_dynar_replace(d, cpt, &s1);
324 for (cpt = 0; cpt < NB_ELEM; cpt++) {
325 sprintf(buf, "%d", cpt);
327 xbt_dynar_replace(d, cpt, &s1);
329 for (cpt = 0; cpt < NB_ELEM; cpt++) {
330 sprintf(buf, "%d", cpt);
332 xbt_dynar_replace(d, cpt, &s1);
334 for (cpt = 0; cpt < NB_ELEM; cpt++) {
335 sprintf(buf, "%d", cpt);
336 xbt_dynar_shift(d, &s2);
337 xbt_test_assert2(!strcmp(buf, s2),
338 "The retrieved value is not the same than the injected one (%s!=%s)",
342 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
343 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
344 /* in your code is naturally the way to go outside a regression test */
346 xbt_test_add1("==== Unshift, traverse and pop %d strings", NB_ELEM);
347 d = xbt_dynar_new(sizeof(char **), &xbt_free_ref);
348 for (cpt = 0; cpt < NB_ELEM; cpt++) {
349 sprintf(buf, "%d", cpt);
351 xbt_dynar_unshift(d, &s1);
353 /* 2. Traverse the dynar with the macro */
354 xbt_dynar_foreach(d, iter, s1) {
355 sprintf(buf, "%d", NB_ELEM - iter - 1);
356 xbt_test_assert2(!strcmp(buf, s1),
357 "The retrieved value is not the same than the injected one (%s!=%s)",
360 /* 3. Traverse the dynar with the macro */
361 for (cpt = 0; cpt < NB_ELEM; cpt++) {
362 sprintf(buf, "%d", cpt);
363 xbt_dynar_pop(d, &s2);
364 xbt_test_assert2(!strcmp(buf, s2),
365 "The retrieved value is not the same than the injected one (%s!=%s)",
369 /* 4. Free the resources */
370 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
371 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
372 /* in your code is naturally the way to go outside a regression test */
376 ("==== Push %d strings, insert %d strings in the middle, shift everything",
377 NB_ELEM, NB_ELEM / 5);
378 d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
379 for (cpt = 0; cpt < NB_ELEM; cpt++) {
380 sprintf(buf, "%d", cpt);
382 xbt_dynar_push(d, &s1);
384 for (cpt = 0; cpt < NB_ELEM / 5; cpt++) {
385 sprintf(buf, "%d", cpt);
387 xbt_dynar_insert_at(d, NB_ELEM / 2, &s1);
390 for (cpt = 0; cpt < NB_ELEM / 2; 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 begining (%s!=%s)",
398 for (cpt = (NB_ELEM / 5) - 1; cpt >= 0; cpt--) {
399 sprintf(buf, "%d", cpt);
400 xbt_dynar_shift(d, &s2);
401 xbt_test_assert2(!strcmp(buf, s2),
402 "The retrieved value is not the same than the injected one in the middle (%s!=%s)",
406 for (cpt = NB_ELEM / 2; cpt < NB_ELEM; cpt++) {
407 sprintf(buf, "%d", cpt);
408 xbt_dynar_shift(d, &s2);
409 xbt_test_assert2(!strcmp(buf, s2),
410 "The retrieved value is not the same than the injected one at the end (%s!=%s)",
414 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
415 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
416 /* in your code is naturally the way to go outside a regression test */
419 xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest", NB_ELEM,
420 2 * (NB_ELEM / 5), 4 * (NB_ELEM / 5));
421 d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
422 for (cpt = 0; cpt < NB_ELEM; cpt++) {
423 sprintf(buf, "%d", cpt);
425 xbt_dynar_push(d, &s1);
427 for (cpt = 2 * (NB_ELEM / 5); cpt < 4 * (NB_ELEM / 5); cpt++) {
428 sprintf(buf, "%d", cpt);
429 xbt_dynar_remove_at(d, 2 * (NB_ELEM / 5), &s2);
430 xbt_test_assert2(!strcmp(buf, s2),
431 "Remove a bad value. Got %s, expected %s", s2, buf);
434 xbt_dynar_free(&d); /* end_of_doxygen */
438 /*******************************************************************************/
439 /*******************************************************************************/
440 /*******************************************************************************/
441 #include "xbt/synchro.h"
442 static void pusher_f(void *a)
444 xbt_dynar_t d = (xbt_dynar_t) a;
446 for (i = 0; i < 500; i++) {
447 xbt_dynar_push(d, &i);
451 static void poper_f(void *a)
453 xbt_dynar_t d = (xbt_dynar_t) a;
458 for (i = 0; i < 500; i++) {
460 xbt_dynar_pop(d, &data);
463 if (e.category == bound_error) {
474 XBT_TEST_UNIT("synchronized int", test_dynar_sync_int,"Synchronized dynars of integers")
476 /* Vars_decl [doxygen cruft] */
478 xbt_thread_t pusher, poper;
480 xbt_test_add0("==== Have a pusher and a popper on the dynar");
481 d = xbt_dynar_new_sync(sizeof(int), NULL);
482 pusher = xbt_thread_create("pusher", pusher_f, d,0/*not joinable*/);
483 poper = xbt_thread_create("poper", poper_f, d,0/*not joinable*/);
484 xbt_thread_join(pusher);
485 xbt_thread_join(poper);
489 /*******************************/
490 /* GENERATED FILE, DO NOT EDIT */
491 /*******************************/