X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ff021a73f0cd26b2f27ca729783aa486393f9b3a..0447db21f56b3586a6b8f004c2bfbdb71d0d90a0:/testsuite/xbt/dynar_string.c diff --git a/testsuite/xbt/dynar_string.c b/testsuite/xbt/dynar_string.c index 6b82126a6f..3c5b8afa9a 100644 --- a/testsuite/xbt/dynar_string.c +++ b/testsuite/xbt/dynar_string.c @@ -11,10 +11,14 @@ #include #include +/* NB_ELEM HAS to be a multiple of 5 */ +#define NB_ELEM 5000 +GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test"); + void free_string(void *d); void free_string(void *d){ - free(*(void**)d); + gras_free(*(void**)d); } int main(int argc,char *argv[]) { @@ -24,132 +28,130 @@ int main(int argc,char *argv[]) { char buf[1024]; char *s1,*s2; - 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++) { + gras_init_defaultlog(&argc,argv,"dynar.thresh=debug"); + + INFO0("==== Traverse the empty dynar"); + d=gras_dynar_new(sizeof(char *),&free_string); + gras_dynar_foreach(d,cpt,s1){ + gras_assert0(FALSE, + "Damnit, there is something in the empty dynar"); + } + gras_dynar_free(d); + + INFO1("==== Push %d strings, set them again 3 times, shift them",NB_ELEM); + d=gras_dynar_new(sizeof(char*),&free_string); + for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); - TRYFAIL(gras_dynar_push(d,&s1)); + gras_dynar_push(d,&s1); } - for (cpt=0; cpt< 5000; cpt++) { + for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); - TRYFAIL(gras_dynar_remplace(d,cpt,&s1)); + gras_dynar_replace(d,cpt,&s1); } - for (cpt=0; cpt< 5000; cpt++) { + for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); - TRYFAIL(gras_dynar_remplace(d,cpt,&s1)); + gras_dynar_replace(d,cpt,&s1); } - for (cpt=0; cpt< 5000; cpt++) { + for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); - TRYFAIL(gras_dynar_remplace(d,cpt,&s1)); + gras_dynar_replace(d,cpt,&s1); } - for (cpt=0; cpt< 5000; cpt++) { + for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); gras_dynar_shift(d,&s2); - if (strcmp(buf,s2)) { - fprintf(stderr, - "The retrieved value is not the same than the injected one (%s!=%s)\n", - buf,s2); - abort(); - } - free(s2); + gras_assert2 (!strcmp(buf,s2), + "The retrieved value is not the same than the injected one (%s!=%s)", + buf,s2); + gras_free(s2); } gras_dynar_free(d); - fprintf(stderr,"==== Unshift/pop 5000 strings\n"); - TRYFAIL(gras_dynar_new(&d,sizeof(char**),&free_string)); - for (cpt=0; cpt< 5000; cpt++) { + INFO1("==== Unshift, traverse and pop %d strings",NB_ELEM); + d=gras_dynar_new(sizeof(char**),&free_string); + for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); - TRYFAIL(gras_dynar_unshift(d,&s1)); + gras_dynar_unshift(d,&s1); } - for (cpt=0; cpt< 5000; cpt++) { + gras_dynar_foreach(d,cpt,s1) { + sprintf(buf,"%d",NB_ELEM - cpt -1); + gras_assert2 (!strcmp(buf,s1), + "The retrieved value is not the same than the injected one (%s!=%s)", + buf,s1); + } + for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); gras_dynar_pop(d,&s2); - if (strcmp(buf,s2)) { - fprintf(stderr, - "The retrieved value is not the same than the injected one (%s!=%s)\n", + gras_assert2 (!strcmp(buf,s2), + "The retrieved value is not the same than the injected one (%s!=%s)", buf,s2); - abort(); - } - free(s2); + gras_free(s2); } gras_dynar_free(d); - - fprintf(stderr,"==== Push 5000 strings, insert 1000 strings in the middle, shift everything\n"); - TRYFAIL(gras_dynar_new(&d,sizeof(char*),&free_string)); - for (cpt=0; cpt< 5000; cpt++) { + INFO2("==== Push %d strings, insert %d strings in the middle, shift everything",NB_ELEM,NB_ELEM/5); + d=gras_dynar_new(sizeof(char*),&free_string); + for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); - TRYFAIL(gras_dynar_push(d,&s1)); + gras_dynar_push(d,&s1); } - for (cpt=0; cpt< 1000; cpt++) { + for (cpt=0; cpt< NB_ELEM/5; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); - TRYFAIL(gras_dynar_insert_at(d,2500,&s1)); + gras_dynar_insert_at(d,NB_ELEM/2,&s1); } - for (cpt=0; cpt< 2500; cpt++) { + for (cpt=0; cpt< NB_ELEM/2; cpt++) { sprintf(buf,"%d",cpt); gras_dynar_shift(d,&s2); - if (strcmp(buf,s2)) { - fprintf(stderr, - "The retrieved value is not the same than the injected one at the begining (%s!=%s)\n", + gras_assert2(!strcmp(buf,s2), + "The retrieved value is not the same than the injected one at the begining (%s!=%s)", buf,s2); - abort(); - } - free(s2); + gras_free(s2); } - for (cpt=999; cpt>=0; cpt--) { + for (cpt=(NB_ELEM/5)-1; cpt>=0; cpt--) { sprintf(buf,"%d",cpt); gras_dynar_shift(d,&s2); - if (strcmp(buf,s2)) { - fprintf(stderr, - "The retrieved value is not the same than the injected one in the middle (%s!=%s)\n", + gras_assert2 (!strcmp(buf,s2), + "The retrieved value is not the same than the injected one in the middle (%s!=%s)", buf,s2); - abort(); - } - free(s2); + gras_free(s2); } - for (cpt=2500; cpt< 5000; cpt++) { + for (cpt=NB_ELEM/2; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); gras_dynar_shift(d,&s2); - if (strcmp(buf,s2)) { - fprintf(stderr, - "The retrieved value is not the same than the injected one at the end (%s!=%s)\n", + gras_assert2 (!strcmp(buf,s2), + "The retrieved value is not the same than the injected one at the end (%s!=%s)", buf,s2); - abort(); - } - free(s2); + gras_free(s2); } gras_dynar_free(d); - fprintf(stderr,"==== Push 5000 strings, remove 2000-4000. free the rest\n"); - TRYFAIL(gras_dynar_new(&d,sizeof(char*),&free_string)); - for (cpt=0; cpt< 5000; cpt++) { + INFO3("==== Push %d strings, remove %d-%d. free the rest",NB_ELEM,2*(NB_ELEM/5),4*(NB_ELEM/5)); + d=gras_dynar_new(sizeof(char*),&free_string); + for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); - TRYFAIL(gras_dynar_push(d,&s1)); + gras_dynar_push(d,&s1); } - for (cpt=2000; cpt< 4000; cpt++) { + for (cpt=2*(NB_ELEM/5); cpt< 4*(NB_ELEM/5); cpt++) { sprintf(buf,"%d",cpt); - gras_dynar_remove_at(d,2000,&s2); - if (strcmp(buf,s2)) { - fprintf(stderr, - "Remove a bad value. Got %s, expected %s\n", - s2,buf); - abort(); - } - free(s2); + gras_dynar_remove_at(d,2*(NB_ELEM/5),&s2); + gras_assert2(!strcmp(buf,s2), + "Remove a bad value. Got %s, expected %s", + s2,buf); + gras_free(s2); } gras_dynar_free(d); + gras_exit(); return 0; }