X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ff021a73f0cd26b2f27ca729783aa486393f9b3a..c4e3a3e34e94ed337b089eb6339bf9b6fd5b9657:/testsuite/xbt/dynar_int.c diff --git a/testsuite/xbt/dynar_int.c b/testsuite/xbt/dynar_int.c index 51e3e989f1..8e9ba8b6e5 100644 --- a/testsuite/xbt/dynar_int.c +++ b/testsuite/xbt/dynar_int.c @@ -2,147 +2,148 @@ /* dynar_int: A test case for the dynar using integers as content */ -/* Authors: Martin Quinson */ -/* Copyright (C) 2003 the OURAGAN project. */ +/* 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. */ + * under the terms of the license (GNU LGPL) which comes with this package. */ -#include -#include +#include "gras.h" #define NB_ELEM 5000 +XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test"); int main(int argc,char *argv[]) { - gras_dynar_t *d; - gras_error_t errcode; + xbt_dynar_t d; + xbt_error_t errcode; int i,cpt,cursor; + int *iptr; - // 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_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)); + xbt_init_defaultlog(&argc,argv,"dynar.thresh=debug"); + + INFO0("==== Traverse the empty dynar"); + d=xbt_dynar_new(sizeof(int),NULL); + xbt_dynar_foreach(d,cursor,i){ + xbt_assert0(0,"Damnit, there is something in the empty dynar"); } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + INFO1("==== Push %d int, set them again 3 times, traverse them, shift them", + NB_ELEM); + d=xbt_dynar_new(sizeof(int),NULL); for (cpt=0; cpt< NB_ELEM; cpt++) { - TRYFAIL(gras_dynar_set(d,cpt,&cpt)); + xbt_dynar_push_as(d,int,cpt); + DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); } - for (cpt=0; cpt< NB_ELEM; cpt++) { - TRYFAIL(gras_dynar_set(d,cpt,&cpt)); + for (cursor=0; cursor< NB_ELEM; cursor++) { + iptr=xbt_dynar_get_ptr(d,cursor); + xbt_assert2(cursor == *iptr, + "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)); + xbt_dynar_foreach(d,cursor,cpt){ + xbt_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++) + *(int*)xbt_dynar_get_ptr(d,cpt) = cpt; + + for (cpt=0; cpt< NB_ELEM; cpt++) + *(int*)xbt_dynar_get_ptr(d,cpt) = cpt; +/* xbt_dynar_set(d,cpt,&cpt);*/ + + for (cpt=0; cpt< NB_ELEM; cpt++) + *(int*)xbt_dynar_get_ptr(d,cpt) = cpt; + cpt=0; - gras_dynar_foreach(d,cursor,i){ - if (i != cpt) { - fprintf(stderr, - "The retrieved value is not the same than the injected one (%d!=%d)\n", - i,cpt); - abort(); - } + xbt_dynar_foreach(d,cursor,i){ + xbt_assert2(i == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + i,cpt); cpt++; } - if (cpt !=NB_ELEM) { - fprintf(stderr, - "Cannot retrieve my %d values. Last got one is %d\n",NB_ELEM, - cpt); - abort(); - } + xbt_assert2(cpt == NB_ELEM, + "Cannot retrieve my %d values. Last got one is %d", + NB_ELEM, cpt); for (cpt=0; cpt< NB_ELEM; cpt++) { - gras_dynar_shift(d,&i); - if (i != cpt) { - fprintf(stderr, - "The retrieved value is not the same than the injected one (%d!=%d)\n", + xbt_dynar_shift(d,&i); + xbt_assert2(i == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", i,cpt); - abort(); - } - // fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d)); + DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); } - gras_dynar_free(d); - + xbt_dynar_free(&d); + xbt_dynar_free(&d); - fprintf(stderr,"==== Unshift/pop %d int\n",NB_ELEM); - TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); + + INFO1("==== Unshift/pop %d int",NB_ELEM); + d=xbt_dynar_new(sizeof(int),NULL); for (cpt=0; cpt< NB_ELEM; cpt++) { - TRYFAIL(gras_dynar_unshift(d,&cpt)); - // fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d)); + xbt_dynar_unshift(d,&cpt); + DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); } for (cpt=0; cpt< NB_ELEM; cpt++) { - gras_dynar_pop(d,&i); - if (i != cpt) { - fprintf(stderr, - "The retrieved value is not the same than the injected one (%d!=%d)\n", - i,cpt); - abort(); - } - // fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d)); + i=xbt_dynar_pop_as(d,int); + xbt_assert2(i == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + i,cpt); + DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); } - gras_dynar_free(d); - + xbt_dynar_free(&d); + xbt_dynar_free(&d); - - fprintf(stderr,"==== Push %d int, insert 1000 int in the middle, shift everything\n",NB_ELEM); - TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); + + INFO1("==== Push %d int, insert 1000 int in the middle, shift everything",NB_ELEM); + d=xbt_dynar_new(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)); + xbt_dynar_push_as(d,int,cpt); + DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); } for (cpt=0; cpt< 1000; cpt++) { - TRYFAIL(gras_dynar_insert_at(d,2500,&cpt)); - // fprintf (stderr,"Push %d, length=%d \n",cpt, gras_dynar_length(d)); + xbt_dynar_insert_at_as(d,2500,int,cpt); + DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); } for (cpt=0; cpt< 2500; cpt++) { - gras_dynar_shift(d,&i); - if (i != cpt) { - fprintf(stderr, - "The retrieved value is not the same than the injected one at the begining (%d!=%d)\n", + xbt_dynar_shift(d,&i); + xbt_assert2(i == cpt, + "The retrieved value is not the same than the injected one at the begining (%d!=%d)", i,cpt); - abort(); - } - // fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d)); + DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); } for (cpt=999; cpt>=0; cpt--) { - gras_dynar_shift(d,&i); - if (i != cpt) { - fprintf(stderr, - "The retrieved value is not the same than the injected one in the middle (%d!=%d)\n", + xbt_dynar_shift(d,&i); + xbt_assert2(i == cpt, + "The retrieved value is not the same than the injected one in the middle (%d!=%d)", i,cpt); - abort(); - } } for (cpt=2500; cpt< NB_ELEM; cpt++) { - gras_dynar_shift(d,&i); - if (i != cpt) { - fprintf(stderr, - "The retrieved value is not the same than the injected one at the end (%d!=%d)\n", + xbt_dynar_shift(d,&i); + xbt_assert2(i == cpt, + "The retrieved value is not the same than the injected one at the end (%d!=%d)", i,cpt); - abort(); - } } - gras_dynar_free(d); + xbt_dynar_free(&d); + xbt_dynar_free(&d); - fprintf(stderr,"==== Push %d int, remove 2000-4000. free the rest\n",NB_ELEM); - TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); - for (cpt=0; cpt< NB_ELEM; cpt++) { - TRYFAIL(gras_dynar_push(d,&cpt)); - } + INFO1("==== Push %d int, remove 2000-4000. free the rest",NB_ELEM); + d=xbt_dynar_new(sizeof(int),NULL); + for (cpt=0; cpt< NB_ELEM; cpt++) + xbt_dynar_push_as(d,int,cpt); + for (cpt=2000; cpt< 4000; cpt++) { - gras_dynar_remove_at(d,2000,&i); - if (i != cpt) { - fprintf(stderr, - "Remove a bad value. Got %d, expected %d\n", - i,cpt); - abort(); - } - // fprintf (stderr,"remove %d, length=%d \n",cpt, gras_dynar_length(d)); + xbt_dynar_remove_at(d,2000,&i); + xbt_assert2(i == cpt, + "Remove a bad value. Got %d, expected %d", + i,cpt); + DEBUG2("remove %d, length=%lu",cpt, xbt_dynar_length(d)); } - gras_dynar_free(d); + xbt_dynar_free(&d); + xbt_dynar_free(&d); + xbt_exit(); return 0; }