home *** CD-ROM | disk | FTP | other *** search
-
- /* t4pack_z.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Tests Code Base packing/zapping/writing.
-
- */
-
- #include "p4misc.h"
- #include "d4all.h"
- #include "w4.h"
- #include "u4error.h"
-
- #include <string.h>
- #include <stdlib.h>
-
- static FIELD field_list[] =
- {
- {"NUM", 'N', 11, 2, 0 },
- {"CH ", 'C', 17, 0, 0 },
- {"DT ", 'D', 7, 0, 0 },
- };
-
- static void do_test( long, long, int, int, int, int ) ;
-
- static void do_test( long num_recs, long num_delete,
- int do_pack, int i_ref, int i_ref2, int i_ref3 )
- {
- long rec_num, delete_cycle, l_count, f_ref ;
- int i, c, rc ;
- double index_date, d ;
-
- w4( w4row()+1,0, "Writing Record: " ) ;
- c = w4col() ;
-
- c4dt_julian( "19891220", &index_date ) ;
-
- for (rec_num = 1; rec_num <= num_recs; rec_num++)
- {
- w4long( w4row(),c, rec_num, 6 ) ;
-
- for ( i= 1; i <= f4num_fields(); i++ )
- {
- f_ref = f4j_ref(i) ;
-
- switch( f4type(f_ref) )
- {
- case 'N':
- d = rec_num/5.0 ;
- f4replace( f_ref, &d ) ;
- break ;
-
- case 'C':
- {
- c4ltoa( rec_num, f4ptr(f_ref), f4width(f_ref) ) ;
- break ;
- }
-
- case 'D':
- d = index_date + rec_num/3 ;
- c4dt_str( f4ptr(f_ref), &d ) ;
- break ;
- }
- }
-
- if ( d4append() < 0 )
- {
- u4error( 0, "t4pack_z: d4write", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- w4( w4row()+1,0, "Finished Writing Records") ;
-
- /* Now for the pack or zap test. */
- w4( w4row()+1,0, "Num Records: " ) ;
- w4long( w4row(),w4col(), d4reccount(), 5 ) ;
- w4( w4row()+1,0, "Checking Index File") ;
- if ( i4check(i_ref) < 0 )
- {
- u4error( 0, "t4pack_z: i4check 1", (char *) 0 ) ;
- w4exit(1) ;
- }
- if ( i4check(i_ref2) < 0 )
- {
- u4error( 0, "t4pack_z: i4check 2", (char *) 0 ) ;
- w4exit(1) ;
- }
- if ( i4check(i_ref3) < 0 )
- {
- u4error( 0, "t4pack_z: i4check 3", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- w4( w4row()+1,0, "Delete Cycle, Records" ) ;
-
- delete_cycle = 0L ;
-
- while ( d4reccount() > 0 )
- {
- if ( d4reccount() != (num_recs - delete_cycle*num_delete) )
- {
- u4error( 0, "t4pack_z: d4reccount", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- delete_cycle ++ ;
-
- w4clear(w4row()+1) ;
- w4long( w4row(),0, delete_cycle, 5 ) ;
- w4long( w4row(),w4col(), d4reccount(), 5 ) ;
-
- if ( do_pack )
- {
- for (l_count = 1; l_count <= num_delete && l_count <= d4reccount(); l_count++)
- {
- long del_rec ;
-
- if ( delete_cycle % 2L == 0L )
- del_rec = l_count ;
- else
- del_rec = d4reccount()+1-l_count ;
-
- if ( d4delete( del_rec ) < 0 )
- {
- u4error( 0, "t4pack_z: d4delete", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- if ( do_pack == 2 )
- {
- w4( w4row(),w4col(), " Extended Packing" ) ;
- rc = x4pack(0) ;
- }
- else
- {
- w4( w4row(),w4col(), " Normal Packing" ) ;
- rc = d4pack() ;
- }
-
- if ( rc < 0 )
- {
- u4error( 0, "t4pack_z: d4pack", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
- else
- {
- long start ;
-
- w4( w4row(),w4col(), " Zapping" ) ;
-
- if ( delete_cycle % 3L == 0L )
- start = 1L ;
- else
- {
- if ( delete_cycle % 3L == 1L )
- start = (num_delete+1L)/2 ;
- else
- start = d4reccount() + 1L - num_delete ;
- }
-
- if ( start+num_delete > d4reccount() )
- start = d4reccount() +1L - num_delete ;
-
- if ( start <= 0L ) start = 1L ;
-
- if ( d4zap( start, start+num_delete-1 ) < 0 )
- {
- u4error( 0, "t4pack_z: d4zap", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- w4( w4row(),w4col(), " Checking") ;
- if ( i4check(i_ref) < 0 )
- {
- u4error( 0, "t4pack_z: i4check 4", (char *) 0 ) ;
- w4exit(1) ;
- }
- if ( i4check(i_ref2) < 0 )
- {
- u4error( 0, "t4pack_z: i4check 5", (char *) 0 ) ;
- w4exit(1) ;
- }
- if ( i4check(i_ref3) < 0 )
- {
- u4error( 0, "t4pack_z: i4check 6", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
- }
-
- main( int argc, char **argv )
- {
- int i_ref, i_ref2, i_ref3, r ;
- long num_recs, num_delete ;
-
- #ifdef NO_HUGE
- #ifdef IS_386
- d4init() ;
- #else
- d4initialize( 4, 4, 20, 1000, 20000L ) ;
- #endif
- #else
- d4init() ;
- #endif
- w4clear(-1) ;
-
- r = 0 ;
-
- if ( argc < 3 )
- {
- w4( r++,0, "Pack/Zap Test" ) ;
- w4( r++,0, "t4pack_z num_records num_to_delete_at_a_time" ) ;
- w4exit(0) ;
- }
-
- num_recs = atol( argv[1] ) ;
-
- r++ ;
- w4( ++r,0, "Number of Records:" ) ;
- w4long( r,w4col(), num_recs, 6) ;
-
- num_delete = atol( argv[2] ) ;
-
- r++ ;
- w4( ++r,0, "Number to Delete at a Time:" ) ;
- w4long( r,w4col(), num_delete, 6) ;
-
- if ( d4create("t4pack",3,field_list,0) < 0 )
- {
- u4error( 0, "t4pack_z: d4create", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- x4filter( d4deleted ) ;
-
- if ( (i_ref = i4index("t4pack","CH",0,0)) < 0 )
- {
- u4error( 0, "t4pack_z: i4index 1", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( (i_ref2 = i4index("t4pack2","NUM",0,0)) < 0)
- {
- u4error( 0, "t4pack_z: i4index 2", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( (i_ref3 = i4index("t4pack3","DT",0,0)) < 0 )
- {
- u4error( 0, "t4pack_z: i4index 3", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- do_test( num_recs, num_delete, 2, i_ref, i_ref2, i_ref3 ) ;
- do_test( num_recs, num_delete, 1, i_ref, i_ref2, i_ref3 ) ;
- do_test( num_recs, num_delete, 0, i_ref, i_ref2, i_ref3 ) ;
-
- d4close_all() ;
-
-
- #ifdef H4TEST
- {
- int rc ;
- d4init_undo() ;
- rc = h4free_check(32000) ;
- d4init() ;
- if ( rc != 0 )
- {
- u4error( 0, "t4pack_z: Memory items not freed", (char *) 0 );
- w4exit(1) ;
- }
- }
- #endif
-
- w4handle(1) ;
- w4( w4row()+1,0, "t4pack_z: SUCCESS" ) ;
- w4exit(0) ;
- }
-
-