home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / glass / glass.lha / GLASS / libcvr / testprog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-09  |  1.8 KB  |  92 lines

  1. /* File: testprog.c
  2.  *
  3.  * Test of library programs.
  4.  */
  5.  
  6. /* Unix libraries */
  7. #include <stdio.h>
  8.  
  9. int flaga;
  10. int flagb;
  11.  
  12. /* the library to test */
  13. #include "cvr.h"
  14.  
  15. dbflag flagtab[] =
  16. {
  17.     'a', &flaga, "flag a",
  18.     'b', &flagb, "flag b",
  19.     '\0', 0, ""
  20. };
  21.  
  22. void bad( msg )
  23.  char *msg;
  24. {
  25.    fprintf( stderr, "check error: %s\n", msg );
  26.    exit( 1 );
  27. }
  28.  
  29. int main()
  30. {
  31.    symbol a;
  32.    symbol b;
  33.    symbol t;
  34.    symbol g1;
  35.    symbol g2;
  36.    char *m;
  37.  
  38.    initsymbol();
  39.    a = addsymbol( "a" );
  40.    b = addsymbol( "a" );
  41.    if( a != b ){
  42.        bad( "equal symbols do not compare equal" );
  43.    }
  44.    b = addsymbol( "b" );
  45.    if( a == b ){
  46.        bad( "unequal symbols compare equal" );
  47.    }
  48.    g1 = gensymbol( "base" );
  49.    if( g1 == a || g1 == b ){
  50.        bad( "gensym symbol is equal to existing symbol" );
  51.    }
  52.    t = findsymbol( "a" );
  53.    if( t == symbolNIL ){
  54.        bad( "symbol not found back" );
  55.    }
  56.    if( t != a ){
  57.        bad( "wrong symbol found" );
  58.    }
  59.    t = findsymbol( "is not there" );
  60.    if( t != symbolNIL ){
  61.        fprintf( stderr, "symbol '%s'", symbolstr( t ) );
  62.        bad( "non-existing symbol found" );
  63.    }
  64.    g2 = gensymbol( "base" );
  65.    if( g2 == a || g2 == b || g2 == g1 ){
  66.        bad( "gensym symbol is equal to existing symbol" );
  67.    }
  68.    m = ckmalloc( (unsigned int) 42 );
  69.    m = ckrealloc( m, 100 );
  70.    free( m );
  71.    m = ckcalloc( (unsigned int) 42, (unsigned int) 42 );
  72.    helpdbflags( stdout, flagtab );
  73.    setdbflags( "ab", flagtab, 0 );
  74.    if( flaga || flagb ){
  75.        bad( "one flag still set" );
  76.    }
  77.    setdbflags( "b", flagtab, 1 );
  78.    if( !flagb ){
  79.        bad( "flag not set" );
  80.    }
  81.    setdbflags( "b", flagtab, 0 );
  82.    if( flagb ){
  83.        bad( "flag not reset" );
  84.    }
  85.    setdbflags( "a", flagtab, 1 );
  86.    if( flagb ){
  87.        bad( "wrong flag set" );
  88.    }
  89.    exit( 0 );
  90.    return( 0 );
  91. }
  92.