X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8c354c48ec90c997cc7213ce96ca97d882934166..3aee10984d32855971ee5a687856099e914effbc:/testsuite/xbt/dynar_string.c diff --git a/testsuite/xbt/dynar_string.c b/testsuite/xbt/dynar_string.c index 44090239de..645ce5b5f2 100644 --- a/testsuite/xbt/dynar_string.c +++ b/testsuite/xbt/dynar_string.c @@ -2,32 +2,32 @@ /* dynar_string: A test case for the dynar using strings as content */ -/* Copyright (c) 2004 Martin Quinson. All rights reserved. */ +/* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include -#include +#include /* sprintf */ +#include "gras.h" /* NB_ELEM HAS to be a multiple of 5 */ #define NB_ELEM 5000 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test"); -void free_string(void *d); +/* doxygen_first_cruft*/ -void free_string(void *d){ +/* The function we will use to free the data */ +static void free_string(void *d){ free(*(void**)d); } int main(int argc,char *argv[]) { xbt_dynar_t d; - xbt_error_t errcode; int cpt; char buf[1024]; char *s1,*s2; - xbt_init_defaultlog(&argc,argv,"dynar.thresh=debug"); + xbt_init(&argc,argv); INFO0("==== Traverse the empty dynar"); d=xbt_dynar_new(sizeof(char *),&free_string); @@ -40,6 +40,8 @@ int main(int argc,char *argv[]) { INFO1("==== Push %d strings, set them again 3 times, shift them",NB_ELEM); d=xbt_dynar_new(sizeof(char*),&free_string); + /* Populate_str [doxygen cruft] */ + /* 1. Populate the dynar */ for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); @@ -79,12 +81,14 @@ int main(int argc,char *argv[]) { s1=strdup(buf); xbt_dynar_unshift(d,&s1); } + /* 2. Traverse the dynar with the macro */ xbt_dynar_foreach(d,cpt,s1) { sprintf(buf,"%d",NB_ELEM - cpt -1); xbt_assert2 (!strcmp(buf,s1), "The retrieved value is not the same than the injected one (%s!=%s)", buf,s1); } + /* 3. Traverse the dynar with the macro */ for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); xbt_dynar_pop(d,&s2); @@ -93,6 +97,7 @@ int main(int argc,char *argv[]) { buf,s2); free(s2); } + /* 4. Free the resources */ xbt_dynar_free(&d); xbt_dynar_free(&d);