home *** CD-ROM | disk | FTP | other *** search
-
- /* t4multi.c
-
- (c)Copyright Sequiter Software Inc., 1987, 1988, 1989. All rights reserved.
-
- Tests Code Base 4 multi-user capabilities.
-
- 1. Erase both 't4multi.dbf' and 't4multi.ndx' (t4multi.ntx).
- 2. Run 't4multi' on one station.
- 3. Run 't4multi' on a second station.
- */
-
- #include "p4misc.h"
- #include "d4base.h"
- #include "w4.h"
- #include "u4error.h"
-
- #include <string.h>
- #include <stdlib.h>
-
- static FIELD fields[]=
- {
- { "TEST", 'C', 10, 0, 0 },
- } ;
-
-
- main( int argc, char **argv)
- {
- int r, width, i_ref, c, did_create, c2 ;
- long n, i_rec ;
- char *ptr ;
-
- d4init() ;
- w4clear(-1) ;
-
- r = 0 ;
-
- if ( argc < 2 )
- {
- w4( r++,0, "Multi-user Test" ) ;
- w4( r++,0, "t4multi num_records" ) ;
- w4exit(0) ;
- }
-
- n = atol( argv[1] ) ;
- r++ ;
- w4( ++r,0, "Number of Records:" ) ;
- w4long( r,w4col(), n, 6) ;
- r++ ;
-
- did_create = 1 ;
- if ( d4create( "t4multi", 1, fields, 1 ) >= 0 )
- {
- if ( (i_ref = i4index( "t4multi", "TEST", 0, 0) ) < 0 )
- {
- u4error( 0, "t4multi: Creating Database.", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
- else
- {
- did_create = 0 ;
-
- w4( ++r,0, "Could not Create, Opening Instead." ) ;
- if ( d4use( "t4multi" ) < 0 )
- {
- u4error( 0, "t4multi: Opening database.", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- /* Wait for the index file to be created. */
- if ( d4lock(-1L, 1) < 0 )
- {
- u4error( 0, "t4multi: Locking database.", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( (i_ref = i4open( "t4multi")) < 0 )
- {
- u4error( 0, "t4multi: Opening Index File.", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- d4unlock( -1L ) ;
-
- ptr = f4ptr( f4ref( "TEST") ) ;
- width = f4width( f4ref( "TEST") ) ;
-
- w4( w4row()+1,0, "Record Number:" ) ;
- c = w4col() ;
- w4( w4row(),c, " New Record Value:" ) ;
- c2 = w4col() ;
-
- for ( i_rec = 1L; i_rec <= n; i_rec++ )
- {
- w4long( w4row(),c, i_rec, 6 ) ;
-
- if ( did_create )
- {
- w4long( w4row(),c2, i_rec, 6 ) ;
- c4ltoa( i_rec, ptr, width ) ;
- }
- else
- {
- w4long( w4row(),c2, n-i_rec, 6 ) ;
- c4ltoa( n-i_rec, ptr, width ) ;
- }
- if ( d4append() < 0 )
- {
- u4error( 0, "t4multi: d4append", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( d4unlock(-1L) < 0 )
- {
- u4error( 0, "t4multi: d4unlock", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- w4( w4row()+1,0, "Checking Index File" ) ;
- if ( i4check( i_ref ) != 0 )
- {
- u4error( 0, "t4multi: i4check", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- d4close_all() ;
-
- w4handle(1) ;
- w4( w4row()+1, 0, "t4multi: SUCCESS" ) ;
-
- w4exit(0) ;
- }
-