Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Compile pas avec les warnings, sinon
[simgrid.git] / testsuite / xbt / dynar_double.c
index 1acaeb0..bfd0641 100644 (file)
 
 /* dynar_double: A test case for the dynar using doubles 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 <stdio.h>
-#include <gras.h>
+#include "gras.h"
+
+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 cpt,cursor;
    double d1,d2;
    
-   gras_init_defaultlog(argc,argv,"dynar.thresh=debug");
-
-   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();
+   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,cpt){
+     xbt_assert0(FALSE,
+            "Damnit, there is something in the empty dynar");
    }
-   gras_dynar_free(d);
+   xbt_dynar_free(&d);
+   xbt_dynar_free(&d);
 
-   fprintf(stderr,"==== Push/shift 5000 doubles\n");
-   TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
+   INFO0("==== Push/shift 5000 doubles");
+   d=xbt_dynar_new(sizeof(double),NULL);
    for (cpt=0; cpt< 5000; cpt++) {
      d1=(double)cpt;
-     TRYFAIL(gras_dynar_push(d,&d1));
+     xbt_dynar_push(d,&d1);
    }
-   gras_dynar_foreach(d,cursor,d2){
+   xbt_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();
-     }
+     xbt_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();
-     }
+     xbt_dynar_shift(d,&d2);
+     xbt_assert2(d1 == d2,
+           "The retrieved value is not the same than the injected one (%f!=%f)",
+                 d1,d2);
    }
-   gras_dynar_free(d);
+   xbt_dynar_free(&d);
+   xbt_dynar_free(&d);
 
 
-   fprintf(stderr,"==== Unshift/pop 5000 doubles\n");
-   TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
+   INFO0("==== Unshift/pop 5000 doubles");
+   d=xbt_dynar_new(sizeof(double),NULL);
    for (cpt=0; cpt< 5000; cpt++) {
      d1=(double)cpt;
-     TRYFAIL(gras_dynar_unshift(d,&d1));
+     xbt_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();
-     }
+     xbt_dynar_pop(d,&d2);
+     xbt_assert2 (d1 == d2,
+           "The retrieved value is not the same than the injected one (%f!=%f)",
+                  d1,d2);
    }
-   gras_dynar_free(d);
+   xbt_dynar_free(&d);
+   xbt_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=xbt_dynar_new(sizeof(double),NULL);
    for (cpt=0; cpt< 5000; cpt++) {
      d1=(double)cpt;
-     TRYFAIL(gras_dynar_push(d,&d1));
+     xbt_dynar_push(d,&d1);
    }
    for (cpt=0; cpt< 1000; cpt++) {
      d1=(double)cpt;
-     TRYFAIL(gras_dynar_insert_at(d,2500,&d1));
+     xbt_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));
+     xbt_dynar_shift(d,&d2);
+     xbt_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, xbt_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();
-     }
+     xbt_dynar_shift(d,&d2);
+     xbt_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();
-     }
+     xbt_dynar_shift(d,&d2);
+     xbt_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);
+   xbt_dynar_free(&d);
+   xbt_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=xbt_dynar_new(sizeof(double),NULL);
    for (cpt=0; cpt< 5000; cpt++) {
      d1=(double)cpt;
-     TRYFAIL(gras_dynar_push(d,&d1));
+     xbt_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",
+     xbt_dynar_remove_at(d,2000,&d2);
+     xbt_assert2 (d1 == d2,
+           "Remove a bad value. Got %f, expected %f",
               d2,d1);
-       abort();
-     }
    }
-   gras_dynar_free(d);
+   xbt_dynar_free(&d);
+   xbt_dynar_free(&d);
 
-   gras_exit();
+   xbt_exit();
    return 0;
 }