X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ff021a73f0cd26b2f27ca729783aa486393f9b3a..0447db21f56b3586a6b8f004c2bfbdb71d0d90a0:/testsuite/xbt/dynar_double.c diff --git a/testsuite/xbt/dynar_double.c b/testsuite/xbt/dynar_double.c index 9449e7d9b2..09c295d75e 100644 --- a/testsuite/xbt/dynar_double.c +++ b/testsuite/xbt/dynar_double.c @@ -11,113 +11,114 @@ #include #include +GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test"); + int main(int argc,char *argv[]) { gras_dynar_t *d; gras_error_t errcode; - int cpt; + int cpt,cursor; double d1,d2; - fprintf(stderr,"==== Push/shift 5000 doubles\n"); - TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL)); + gras_init_defaultlog(&argc,argv,"dynar.thresh=debug"); + + INFO0("==== Traverse the empty dynar"); + d=gras_dynar_new(sizeof(int),NULL); + gras_dynar_foreach(d,cursor,cpt){ + gras_assert0(FALSE, + "Damnit, there is something in the empty dynar"); + } + gras_dynar_free(d); + + INFO0("==== Push/shift 5000 doubles"); + d=gras_dynar_new(sizeof(double),NULL); for (cpt=0; cpt< 5000; cpt++) { d1=(double)cpt; - TRYFAIL(gras_dynar_push(d,&d1)); + gras_dynar_push(d,&d1); + } + gras_dynar_foreach(d,cursor,d2){ + d1=(double)cursor; + gras_assert2(d1 == d2, + "The retrieved value is not the same than the injected one (%f!=%f)", + d1,d2); } for (cpt=0; cpt< 5000; cpt++) { d1=(double)cpt; gras_dynar_shift(d,&d2); - if (d1 != d2) { - fprintf(stderr, - "The retrieved value is not the same than the injected one (%f!=%f)\n", - d1,d2); - abort(); - } + gras_assert2(d1 == d2, + "The retrieved value is not the same than the injected one (%f!=%f)", + d1,d2); } gras_dynar_free(d); - fprintf(stderr,"==== Unshift/pop 5000 doubles\n"); - TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL)); + INFO0("==== Unshift/pop 5000 doubles"); + d=gras_dynar_new(sizeof(double),NULL); for (cpt=0; cpt< 5000; cpt++) { d1=(double)cpt; - TRYFAIL(gras_dynar_unshift(d,&d1)); + gras_dynar_unshift(d,&d1); } for (cpt=0; cpt< 5000; cpt++) { d1=(double)cpt; gras_dynar_pop(d,&d2); - if (d1 != d2) { - fprintf(stderr, - "The retrieved value is not the same than the injected one (%f!=%f)\n", - d1,d2); - abort(); - } + gras_assert2 (d1 == d2, + "The retrieved value is not the same than the injected one (%f!=%f)", + d1,d2); } gras_dynar_free(d); - fprintf(stderr,"==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything\n"); - TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL)); + INFO0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything"); + d=gras_dynar_new(sizeof(double),NULL); for (cpt=0; cpt< 5000; cpt++) { d1=(double)cpt; - TRYFAIL(gras_dynar_push(d,&d1)); + gras_dynar_push(d,&d1); } for (cpt=0; cpt< 1000; cpt++) { d1=(double)cpt; - TRYFAIL(gras_dynar_insert_at(d,2500,&d1)); + gras_dynar_insert_at(d,2500,&d1); } for (cpt=0; cpt< 2500; cpt++) { d1=(double)cpt; gras_dynar_shift(d,&d2); - if (d1 != d2) { - fprintf(stderr, - "The retrieved value is not the same than the injected one at the begining (%f!=%f)\n", - d1,d2); - abort(); - } - // fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d)); + gras_assert2(d1 == d2, + "The retrieved value is not the same than the injected one at the begining (%f!=%f)", + d1,d2); + DEBUG2("Pop %d, length=%lu",cpt, gras_dynar_length(d)); } for (cpt=999; cpt>=0; cpt--) { d1=(double)cpt; gras_dynar_shift(d,&d2); - if (d1 != d2) { - fprintf(stderr, - "The retrieved value is not the same than the injected one in the middle (%f!=%f)\n", - d1,d2); - abort(); - } + gras_assert2 (d1 == d2, + "The retrieved value is not the same than the injected one in the middle (%f!=%f)", + d1,d2); } for (cpt=2500; cpt< 5000; cpt++) { d1=(double)cpt; gras_dynar_shift(d,&d2); - if (d1 != d2) { - fprintf(stderr, - "The retrieved value is not the same than the injected one at the end (%f!=%f)\n", - d1,d2); - abort(); - } + gras_assert2 (d1 == d2, + "The retrieved value is not the same than the injected one at the end (%f!=%f)", + d1,d2); } gras_dynar_free(d); - fprintf(stderr,"==== Push 5000 double, remove 2000-4000. free the rest\n"); - TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL)); + INFO0("==== Push 5000 double, remove 2000-4000. free the rest"); + d=gras_dynar_new(sizeof(double),NULL); for (cpt=0; cpt< 5000; cpt++) { d1=(double)cpt; - TRYFAIL(gras_dynar_push(d,&d1)); + gras_dynar_push(d,&d1); } for (cpt=2000; cpt< 4000; cpt++) { d1=(double)cpt; gras_dynar_remove_at(d,2000,&d2); - if (d1 != d2) { - fprintf(stderr, - "Remove a bad value. Got %f, expected %f\n", + gras_assert2 (d1 == d2, + "Remove a bad value. Got %f, expected %f", d2,d1); - abort(); - } } gras_dynar_free(d); + gras_exit(); return 0; }