home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_10 / 1010050a < prev    next >
Text File  |  1992-08-12  |  1KB  |  47 lines

  1. /* Listing 3
  2.  
  3.     Defines macros for accessing test versions of
  4.     calloc and malloc and for collecting and reporting
  5.     errors.
  6. */
  7. #if defined( TEST )
  8.   #include <stddef.h>
  9.  
  10.   /* macro to print error message */
  11.   #define ErrorMsg(testNumber,msg) \
  12.      (fprintf(stderr,"\n\t\a%d)%s",testNumber,msg),\
  13.      ++errors)
  14.  
  15.   /* macro to initialize error counter and display
  16.      start message*/
  17.   #define StartTest(list) \
  18.      int  errors = 0; \
  19.      fprintf(stderr,"\nTesting %s...\n",list)
  20.  
  21.   /* macro to report results */
  22.      #define EndTest \
  23.         {  \
  24.            if(errors) \
  25.               fprintf(stderr, \
  26.                       "\n%d errors detected\n"); \
  27.            else \
  28.               fprintf(stderr,"Success\n"); \
  29.            return errors; \
  30.         }
  31.  
  32.     /* re-direct calloc and malloc to test versions */
  33.     #define calloc(x,y) testCalloc(x,y)
  34.     #define malloc(x)   testMalloc(x)
  35.  
  36.     /* prototype calloc and malloc shell functions */
  37.     void    *testCalloc( size_t numElems,
  38.                          size_t elemSize );
  39.     void    *testMalloc( size_t numElems );
  40.  
  41.     /* prototypes to set the number of times calloc
  42.        and malloc will work before failing */
  43.     void    SetCalloc( int passes );
  44.     void    SetMalloc( int passes );
  45.  
  46. #endif
  47.