From: mquinson Date: Wed, 28 Jan 2004 19:16:57 +0000 (+0000) Subject: use iterators; try to traverse the empty dynar, just to see ;) X-Git-Tag: v3.3~5334 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/25e6bf5edb877acac0b08833a6f3eafa9039dc83 use iterators; try to traverse the empty dynar, just to see ;) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@12 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/testsuite/xbt/dynar_double.c b/testsuite/xbt/dynar_double.c index 9449e7d9b2..22590dfbf9 100644 --- a/testsuite/xbt/dynar_double.c +++ b/testsuite/xbt/dynar_double.c @@ -14,15 +14,33 @@ int main(int argc,char *argv[]) { gras_dynar_t *d; gras_error_t errcode; - int cpt; + int cpt,cursor; double d1,d2; + fprintf(stderr,"==== Traverse the empty dynar\n"); + TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); + gras_dynar_foreach(d,cursor,cpt){ + fprintf(stderr, + "Damnit, there is something in the empty dynar\n"); + abort(); + } + gras_dynar_free(d); + fprintf(stderr,"==== Push/shift 5000 doubles\n"); TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL)); for (cpt=0; cpt< 5000; cpt++) { d1=(double)cpt; TRYFAIL(gras_dynar_push(d,&d1)); } + gras_dynar_foreach(d,cursor,d2){ + d1=(double)cursor; + if (d1 != d2) { + fprintf(stderr, + "The retrieved value is not the same than the injected one (%f!=%f)\n", + d1,d2); + abort(); + } + } for (cpt=0; cpt< 5000; cpt++) { d1=(double)cpt; gras_dynar_shift(d,&d2); diff --git a/testsuite/xbt/dynar_int.c b/testsuite/xbt/dynar_int.c index 51e3e989f1..e65b29dab9 100644 --- a/testsuite/xbt/dynar_int.c +++ b/testsuite/xbt/dynar_int.c @@ -12,6 +12,7 @@ #include #define NB_ELEM 5000 +GRAS_LOG_NEW_DEFAULT_CATEGORY(test); int main(int argc,char *argv[]) { gras_dynar_t *d; @@ -19,12 +20,34 @@ int main(int argc,char *argv[]) { int i,cpt,cursor; // TRYFAIL(gras_log_control_set("root.thresh=debug dynar.thresh=info")); - TRYFAIL(gras_log_control_set("root.thresh=info")); - fprintf(stderr,"==== Push %d int, set them again 3 times, traverse them, shift them\n",NB_ELEM); + TRYFAIL(gras_log_control_set("dynar.thresh=debug root.thresh=info")); + fprintf(stderr,"==== Traverse the empty dynar\n"); + TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); + gras_dynar_foreach(d,cursor,i){ + fprintf(stderr, + "Damnit, there is something in the empty dynar\n"); + abort(); + } + gras_dynar_free(d); + + fprintf(stderr, + "==== Push %d int, set them again 3 times, traverse them, shift them\n", + NB_ELEM); TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); for (cpt=0; cpt< NB_ELEM; cpt++) { TRYFAIL(gras_dynar_push(d,&cpt)); - // fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d)); + //fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d)); + } + for (cursor=0; cursor< NB_ELEM; cursor++) { + gras_dynar_get(d,cursor,&cpt); + gras_assert2(cursor == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + cursor,cpt); + } + gras_dynar_foreach(d,cursor,cpt){ + gras_assert2(cursor == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + cursor,cpt); } for (cpt=0; cpt< NB_ELEM; cpt++) { TRYFAIL(gras_dynar_set(d,cpt,&cpt)); diff --git a/testsuite/xbt/dynar_string.c b/testsuite/xbt/dynar_string.c index 6b82126a6f..b37b6a80e4 100644 --- a/testsuite/xbt/dynar_string.c +++ b/testsuite/xbt/dynar_string.c @@ -20,10 +20,19 @@ void free_string(void *d){ int main(int argc,char *argv[]) { gras_dynar_t *d; gras_error_t errcode; - int cpt; + int cpt,i; char buf[1024]; char *s1,*s2; + fprintf(stderr,"==== Traverse the empty dynar\n"); + TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); + gras_dynar_foreach(d,cpt,i){ + fprintf(stderr, + "Damnit, there is something in the empty dynar\n"); + abort(); + } + gras_dynar_free(d); + fprintf(stderr,"==== Push 5000 strings, set them again 3 times, shift them\n"); TRYFAIL(gras_dynar_new(&d,sizeof(char*),&free_string)); for (cpt=0; cpt< 5000; cpt++) {