1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
7 /*******************************/
8 /* GENERATED FILE, DO NOT EDIT */
9 /*******************************/
11 #line 730 "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",
155 d = xbt_dynar_new(sizeof(int), NULL);
156 for (cpt = 0; cpt < NB_ELEM; cpt++)
157 xbt_dynar_push_as(d, int, cpt);
159 for (cpt = 2000; cpt < 4000; cpt++) {
160 xbt_dynar_remove_at(d, 2000, &i);
161 xbt_test_assert2(i == cpt,
162 "Remove a bad value. Got %d, expected %d", i, cpt);
163 DEBUG2("remove %d, length=%lu", cpt, xbt_dynar_length(d));
165 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
166 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
167 /* in your code is naturally the way to go outside a regression test */
170 /*******************************************************************************/
171 /*******************************************************************************/
172 /*******************************************************************************/
173 XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles")
180 xbt_test_add0("==== Traverse the empty dynar");
181 d = xbt_dynar_new(sizeof(int), NULL);
182 xbt_dynar_foreach(d, cursor, cpt) {
183 xbt_test_assert0(FALSE,
184 "Damnit, there is something in the empty dynar");
186 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
187 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
188 /* in your code is naturally the way to go outside a regression test */
190 xbt_test_add0("==== Push/shift 5000 doubles");
191 d = xbt_dynar_new(sizeof(double), NULL);
192 for (cpt = 0; cpt < 5000; cpt++) {
194 xbt_dynar_push(d, &d1);
196 xbt_dynar_foreach(d, cursor, d2) {
197 d1 = (double) cursor;
198 xbt_test_assert2(d1 == d2,
199 "The retrieved value is not the same than the injected one (%f!=%f)",
202 for (cpt = 0; cpt < 5000; cpt++) {
204 xbt_dynar_shift(d, &d2);
205 xbt_test_assert2(d1 == d2,
206 "The retrieved value is not the same than the injected one (%f!=%f)",
209 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
210 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
211 /* in your code is naturally the way to go outside a regression test */
213 xbt_test_add0("==== Unshift/pop 5000 doubles");
214 d = xbt_dynar_new(sizeof(double), NULL);
215 for (cpt = 0; cpt < 5000; cpt++) {
217 xbt_dynar_unshift(d, &d1);
219 for (cpt = 0; cpt < 5000; cpt++) {
221 xbt_dynar_pop(d, &d2);
222 xbt_test_assert2(d1 == d2,
223 "The retrieved value is not the same than the injected one (%f!=%f)",
226 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
227 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
228 /* in your code is naturally the way to go outside a regression test */
233 ("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything");
234 d = xbt_dynar_new(sizeof(double), NULL);
235 for (cpt = 0; cpt < 5000; cpt++) {
237 xbt_dynar_push(d, &d1);
239 for (cpt = 0; cpt < 1000; cpt++) {
241 xbt_dynar_insert_at(d, 2500, &d1);
244 for (cpt = 0; cpt < 2500; cpt++) {
246 xbt_dynar_shift(d, &d2);
247 xbt_test_assert2(d1 == d2,
248 "The retrieved value is not the same than the injected one at the begining (%f!=%f)",
250 DEBUG2("Pop %d, length=%lu", cpt, xbt_dynar_length(d));
252 for (cpt = 999; cpt >= 0; cpt--) {
254 xbt_dynar_shift(d, &d2);
255 xbt_test_assert2(d1 == d2,
256 "The retrieved value is not the same than the injected one in the middle (%f!=%f)",
259 for (cpt = 2500; cpt < 5000; cpt++) {
261 xbt_dynar_shift(d, &d2);
262 xbt_test_assert2(d1 == d2,
263 "The retrieved value is not the same than the injected one at the end (%f!=%f)",
266 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
267 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
268 /* in your code is naturally the way to go outside a regression test */
271 xbt_test_add0("==== Push 5000 double, remove 2000-4000. free the rest");
272 d = xbt_dynar_new(sizeof(double), NULL);
273 for (cpt = 0; cpt < 5000; cpt++) {
275 xbt_dynar_push(d, &d1);
277 for (cpt = 2000; cpt < 4000; cpt++) {
279 xbt_dynar_remove_at(d, 2000, &d2);
280 xbt_test_assert2(d1 == d2,
281 "Remove a bad value. Got %f, expected %f", d2, d1);
283 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
284 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
285 /* in your code is naturally the way to go outside a regression test */
289 /* doxygen_string_cruft */
291 /*******************************************************************************/
292 /*******************************************************************************/
293 /*******************************************************************************/
294 XBT_TEST_UNIT("string", test_dynar_string, "Dynars of strings")
302 xbt_test_add0("==== Traverse the empty dynar");
303 d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
304 xbt_dynar_foreach(d, iter, s1) {
305 xbt_test_assert0(FALSE,
306 "Damnit, there is something in the empty dynar");
308 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
309 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
310 /* in your code is naturally the way to go outside a regression test */
312 xbt_test_add1("==== Push %d strings, set them again 3 times, shift them",
314 /* Populate_str [doxygen cruft] */
315 d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
316 /* 1. Populate the dynar */
317 for (cpt = 0; cpt < NB_ELEM; cpt++) {
318 sprintf(buf, "%d", cpt);
320 xbt_dynar_push(d, &s1);
322 for (cpt = 0; cpt < NB_ELEM; cpt++) {
323 sprintf(buf, "%d", cpt);
325 xbt_dynar_replace(d, cpt, &s1);
327 for (cpt = 0; cpt < NB_ELEM; cpt++) {
328 sprintf(buf, "%d", cpt);
330 xbt_dynar_replace(d, cpt, &s1);
332 for (cpt = 0; cpt < NB_ELEM; cpt++) {
333 sprintf(buf, "%d", cpt);
335 xbt_dynar_replace(d, cpt, &s1);
337 for (cpt = 0; cpt < NB_ELEM; cpt++) {
338 sprintf(buf, "%d", cpt);
339 xbt_dynar_shift(d, &s2);
340 xbt_test_assert2(!strcmp(buf, s2),
341 "The retrieved value is not the same than the injected one (%s!=%s)",
345 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
346 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
347 /* in your code is naturally the way to go outside a regression test */
349 xbt_test_add1("==== Unshift, traverse and pop %d strings", NB_ELEM);
350 d = xbt_dynar_new(sizeof(char **), &xbt_free_ref);
351 for (cpt = 0; cpt < NB_ELEM; cpt++) {
352 sprintf(buf, "%d", cpt);
354 xbt_dynar_unshift(d, &s1);
356 /* 2. Traverse the dynar with the macro */
357 xbt_dynar_foreach(d, iter, s1) {
358 sprintf(buf, "%d", NB_ELEM - iter - 1);
359 xbt_test_assert2(!strcmp(buf, s1),
360 "The retrieved value is not the same than the injected one (%s!=%s)",
363 /* 3. Traverse the dynar with the macro */
364 for (cpt = 0; cpt < NB_ELEM; cpt++) {
365 sprintf(buf, "%d", cpt);
366 xbt_dynar_pop(d, &s2);
367 xbt_test_assert2(!strcmp(buf, s2),
368 "The retrieved value is not the same than the injected one (%s!=%s)",
372 /* 4. Free the resources */
373 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
374 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
375 /* in your code is naturally the way to go outside a regression test */
379 ("==== Push %d strings, insert %d strings in the middle, shift everything",
380 NB_ELEM, NB_ELEM / 5);
381 d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
382 for (cpt = 0; cpt < NB_ELEM; cpt++) {
383 sprintf(buf, "%d", cpt);
385 xbt_dynar_push(d, &s1);
387 for (cpt = 0; cpt < NB_ELEM / 5; cpt++) {
388 sprintf(buf, "%d", cpt);
390 xbt_dynar_insert_at(d, NB_ELEM / 2, &s1);
393 for (cpt = 0; cpt < NB_ELEM / 2; cpt++) {
394 sprintf(buf, "%d", cpt);
395 xbt_dynar_shift(d, &s2);
396 xbt_test_assert2(!strcmp(buf, s2),
397 "The retrieved value is not the same than the injected one at the begining (%s!=%s)",
401 for (cpt = (NB_ELEM / 5) - 1; cpt >= 0; cpt--) {
402 sprintf(buf, "%d", cpt);
403 xbt_dynar_shift(d, &s2);
404 xbt_test_assert2(!strcmp(buf, s2),
405 "The retrieved value is not the same than the injected one in the middle (%s!=%s)",
409 for (cpt = NB_ELEM / 2; cpt < NB_ELEM; cpt++) {
410 sprintf(buf, "%d", cpt);
411 xbt_dynar_shift(d, &s2);
412 xbt_test_assert2(!strcmp(buf, s2),
413 "The retrieved value is not the same than the injected one at the end (%s!=%s)",
417 xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
418 xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
419 /* in your code is naturally the way to go outside a regression test */
422 xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest",
423 NB_ELEM, 2 * (NB_ELEM / 5), 4 * (NB_ELEM / 5));
424 d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
425 for (cpt = 0; cpt < NB_ELEM; cpt++) {
426 sprintf(buf, "%d", cpt);
428 xbt_dynar_push(d, &s1);
430 for (cpt = 2 * (NB_ELEM / 5); cpt < 4 * (NB_ELEM / 5); cpt++) {
431 sprintf(buf, "%d", cpt);
432 xbt_dynar_remove_at(d, 2 * (NB_ELEM / 5), &s2);
433 xbt_test_assert2(!strcmp(buf, s2),
434 "Remove a bad value. Got %s, expected %s", s2, buf);
437 xbt_dynar_free(&d); /* end_of_doxygen */
441 /*******************************************************************************/
442 /*******************************************************************************/
443 /*******************************************************************************/
444 #include "xbt/synchro.h"
445 static void pusher_f(void *a)
447 xbt_dynar_t d = (xbt_dynar_t) a;
449 for (i = 0; i < 500; i++) {
450 xbt_dynar_push(d, &i);
454 static void poper_f(void *a)
456 xbt_dynar_t d = (xbt_dynar_t) a;
461 for (i = 0; i < 500; i++) {
463 xbt_dynar_pop(d, &data);
466 if (e.category == bound_error) {
477 XBT_TEST_UNIT("synchronized int", test_dynar_sync_int, "Synchronized dynars of integers")
479 /* Vars_decl [doxygen cruft] */
481 xbt_thread_t pusher, poper;
483 xbt_test_add0("==== Have a pusher and a popper on the dynar");
484 d = xbt_dynar_new_sync(sizeof(int), NULL);
485 pusher = xbt_thread_create("pusher", pusher_f, d, 0 /*not joinable */ );
486 poper = xbt_thread_create("poper", poper_f, d, 0 /*not joinable */ );
487 xbt_thread_join(pusher);
488 xbt_thread_join(poper);
492 /*******************************/
493 /* GENERATED FILE, DO NOT EDIT */
494 /*******************************/