home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / TEST / T4MUL2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-22  |  2.9 KB  |  136 lines

  1.  
  2. /* t4multi.c
  3.  
  4.    (c)Copyright Sequiter Software Inc., 1987, 1988, 1989. All rights reserved.
  5.  
  6.    Tests Code Base 4 multi-user capabilities.
  7.  
  8.       1.  Erase both 't4multi.dbf' and 't4multi.ndx' (t4multi.ntx).
  9.       2.  Run 't4multi' on one station.
  10.       3.  Run 't4multi' on a second station.
  11. */
  12.  
  13. #include  "p4misc.h"
  14. #include  "d4base.h"
  15. #include  "w4.h"
  16. #include  "u4error.h"
  17.  
  18. #include <string.h>
  19. #include <stdlib.h>
  20.  
  21. static FIELD  fields[]=
  22. {
  23.    { "TEST", 'C', 10, 0, 0 },
  24. } ;
  25.  
  26.  
  27. main( int argc, char **argv)
  28. {
  29.    int  r, width, i_ref, c, did_create, c2 ;
  30.    long n, i_rec ;
  31.    char *ptr ;
  32.  
  33.    d4init() ;
  34.    w4clear(-1) ;
  35.  
  36.    r = 0 ;
  37.  
  38.    if ( argc < 2 )
  39.    {
  40.       w4( r++,0, "Multi-user Test" ) ;
  41.       w4( r++,0, "t4multi   num_records" ) ;
  42.       w4exit(0) ;
  43.    }
  44.  
  45.    n =  atol( argv[1] ) ;
  46.    r++ ;
  47.    w4(   ++r,0, "Number of Records:" ) ;
  48.    w4long( r,w4col(), n, 6)  ;
  49.    r++ ;
  50.  
  51.    did_create =  1 ;
  52.    if ( d4create( "t4multi", 1, fields, 1 )  >= 0 )
  53.    {
  54.       if ( (i_ref =  i4index( "t4multi", "TEST", 0, 0) )  < 0 )
  55.       {
  56.          u4error( 0, "t4multi:  Creating Database.", (char *) 0 ) ;
  57.          w4exit(1) ;
  58.       }
  59.    }
  60.    else
  61.    {
  62.       did_create =  0 ;
  63.  
  64.       w4( ++r,0, "Could not Create, Opening Instead." ) ;
  65.       if ( d4use( "t4multi" ) < 0 )
  66.       {
  67.      u4error( 0, "t4multi:  Opening database.", (char *) 0 ) ;
  68.          w4exit(1) ;
  69.       }
  70.  
  71.       /* Wait for the index file to be created. */
  72.       if ( d4lock(-1L, 1) < 0 )
  73.       {
  74.          u4error( 0, "t4multi:  Locking database.", (char *) 0 ) ;
  75.          w4exit(1) ;
  76.       }
  77.  
  78.       if ( (i_ref = i4open( "t4multi")) < 0 )
  79.       {
  80.          u4error( 0, "t4multi:  Opening Index File.", (char *) 0 ) ;
  81.          w4exit(1) ;
  82.       }
  83.    }
  84.  
  85.    d4unlock( -1L ) ;
  86.  
  87.    ptr   =  f4ptr(   f4ref( "TEST") ) ;
  88.    width =  f4width( f4ref( "TEST") ) ;
  89.  
  90.    w4( w4row()+1,0, "Record Number:" ) ;
  91.    c  =  w4col() ;
  92.    w4( w4row(),c, "            New Record Value:" ) ;
  93.    c2 =  w4col() ;
  94.  
  95.    for ( i_rec = 1L; i_rec <= n; i_rec++ )
  96.    {
  97.       w4long( w4row(),c, i_rec, 6 ) ;
  98.  
  99.       if ( did_create )
  100.       {
  101.          w4long( w4row(),c2, i_rec, 6 ) ;
  102.          c4ltoa( i_rec, ptr, width ) ;
  103.       }
  104.       else
  105.       {
  106.          w4long( w4row(),c2, n-i_rec, 6 ) ;
  107.          c4ltoa( n-i_rec, ptr, width ) ;
  108.       }
  109.       if ( d4append() < 0 )
  110.       {
  111.          u4error( 0, "t4multi:  d4append", (char *) 0 ) ;
  112.          w4exit(1) ;
  113.       }
  114.  
  115.       if ( d4unlock(-1L) < 0 )
  116.       {
  117.          u4error( 0, "t4multi:  d4unlock", (char *) 0 ) ;
  118.          w4exit(1) ;
  119.       }
  120.    }
  121.  
  122.    w4( w4row()+1,0, "Checking Index File" ) ;
  123.    if ( i4check( i_ref ) != 0 )
  124.    {
  125.       u4error( 0, "t4multi:  i4check", (char *) 0 ) ;
  126.       w4exit(1) ;
  127.    }
  128.  
  129.    d4close_all() ;
  130.  
  131.    w4handle(1) ;
  132.    w4( w4row()+1, 0, "t4multi:  SUCCESS" ) ;
  133.  
  134.    w4exit(0) ;
  135. }
  136.