home *** CD-ROM | disk | FTP | other *** search
-
- /* t4write2.c
-
- (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Tests Code Base 'd4seek' and 'd4write' routines.
-
- 1. Create databases 'd4learn.dbf' and 'd4learn.ndx'.
-
- 2. Write 'n' records with even values
- 2*reccount - 2*n
- Ex. For 5 records 8, 6, 4, 2, 0
-
-
- 3. Seek for a record which has not yet been searched for.
- Write corresponding Odd Value. 2*n-1
- Ex. For 5 records 1, 3, 5, 7, 9
-
- 4. Check the index file.
- */
-
- #include "p4misc.h"
- #include "d4all.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, rc, c ;
- long n, i_rec, odd_rec ;
- char *ptr ;
- char buf[1000] ;
-
- #ifdef NO_HUGE
- #ifdef IS_386
- d4init() ;
- #else
- d4initialize( 4, 4, 20, 1000, 20000L ) ;
- #endif
- #else
- d4init() ;
- #endif
- w4clear(-1) ;
-
- r = 0 ;
-
- if ( argc < 2 )
- {
- w4( r++,0, "Write/Seek Test" ) ;
- w4( r++,0, "t4write2 num_records" ) ;
- w4exit(0) ;
- }
-
- n = atol( argv[1] ) ;
- r++ ;
- w4( ++r,0, "Number of Records:" ) ;
- w4long( r,w4col(), n, 6) ;
- r++ ;
-
- d4create( "t4write2", 1, fields, 0 ) ;
- ptr = f4ptr( f4ref( "TEST") ) ;
- width = f4width( f4ref( "TEST") ) ;
-
- w4( w4row()+1,0, "Writing Rec:" ) ;
- c = w4col() ;
-
- for ( i_rec = 1L; i_rec <= n; i_rec++ )
- {
- w4long( w4row(),c, i_rec, 6 ) ;
- c4ltoa( 2*n - 2*i_rec, ptr, width ) ;
- d4write(0L) ;
- }
-
- i_ref = i4index( "t4write2", "TEST", 0, 0 ) ;
-
- /* Ex. 5 records: 2,3,1,4,0 (ignored),5;
- Ex. 4 records: 2,3,1,4
- */
- if ( n & 1L )
- odd_rec = n ;
- else
- odd_rec = n+1 ;
-
- w4( w4row()+1,0, "Seeking Rec:" ) ;
- c = w4col() ;
-
- for ( i_rec = n/2; i_rec >= 0; )
- {
- if ( i_rec > 0 && i_rec <= n )
- {
- w4long( w4row(),c, i_rec, 6 ) ;
-
- c4ltoa( 2*n - 2*i_rec, buf, width ) ;
- if ( d4seek( buf ) != 0 )
- {
- u4error( 0, "t4write2: d4seek", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- c4ltoa( 2*i_rec-1, ptr, width ) ;
- d4write( d4recno() ) ;
- }
-
- if ( i_rec <= n/2 )
- i_rec = odd_rec-i_rec ;
- else
- {
- i_rec = odd_rec-i_rec ;
- i_rec -- ;
- }
- }
-
- w4( w4row()+1,0, "Checking Index File" ) ;
- i4check( i_ref ) ;
-
- w4( w4row()+1,0, "Checking Record:" ) ;
- c = w4col() ;
-
- for ( i_rec = 1L, rc = d4top(); rc != 3; i_rec++, rc = d4skip(1L) )
- {
- w4long( w4row(),c, i_rec, 6 ) ;
-
- if ( d4recno() != i_rec )
- {
- u4error( 0, "t4write2: Seek/Write Test Fail, Final Check", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- c4ltoa( 2*i_rec-1, buf, width ) ;
- if ( memcmp( ptr, buf, width ) != 0 )
- {
- u4error( 0, "t4write2: Seek/Write Test Fail, Final Check", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- d4close_all() ;
-
-
- #ifdef H4TEST
- {
- int rc ;
- d4init_undo() ;
- rc = h4free_check(32000) ;
- d4init() ;
- if ( rc != 0 )
- {
- u4error( 0, "t4write2: Memory items not freed", (char *) 0 );
- w4exit(1) ;
- }
- }
- #endif
-
- w4handle(1) ;
- w4( w4row()+1,0, "t4write2: SUCCESS" ) ;
- w4exit(0) ;
- }
-