home *** CD-ROM | disk | FTP | other *** search
-
- /* t4skip.c
-
- (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Tests Code Base 'd4skip' routine.
- */
-
- #include "p4misc.h"
- #include "d4all.h"
- #include "w4.h"
- #include "u4error.h"
-
- static FIELD skip_fields[] =
- {
- {"FLD", 'N', 13, 1, 0 },
- {"CHR", 'C', 99, 0, 0 },
- };
-
-
- static void eof( int, int ) ;
-
- static void eof( int bof_cond, int eof_cond )
- {
- int rc ;
-
- rc = 0 ;
-
- if ( bof_cond )
- {
- if ( ! d4bof() ) rc = -1 ;
- }
- else
- {
- if ( d4bof() ) rc = -1 ;
- }
- if ( rc )
- {
- u4error( 0, "t4skip: d4bof()", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( eof_cond )
- {
- if ( ! d4eof() ) rc = -1 ;
- }
- else
- {
- if ( d4eof() ) rc = -1 ;
- }
- if ( rc )
- {
- u4error( 0, "t4skip: d4eof()", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- static void rec( long ) ;
- static void rec( long rec_no )
- {
- if ( d4recno() != rec_no )
- {
- u4error( 0, "t4skip: d4recno()", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- main()
- {
- long i_rec ;
-
- #ifdef NO_HUGE
- #ifdef IS_386
- d4init() ;
- #else
- d4initialize( 4, 4, 20, 1000, 20000L ) ;
- #endif
- #else
- d4init() ;
- #endif
- w4clear(-1) ;
- w4( 0,0, "t4skip Testing" ) ;
-
- if ( d4create("t4skip", 2, skip_fields, 0) < 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- /* First Execute Skips on an Empty Database */
- if ( d4bottom() != 3 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,1 ) ; rec( 1L ) ;
-
- if ( d4top() != 3 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,1 ) ; rec( 1L ) ;
-
- if ( d4skip( -1L ) != 1 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,1 ) ; rec( 1L ) ;
-
- if ( d4skip( 1L ) != 3 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,1 ) ; rec( 1L ) ;
-
- if ( i4index( "t4skip", "CHR", 0, 0 ) < 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,1 ) ; rec( 1L ) ;
-
- /* Index File Skips on an Empty Database */
- if ( d4bottom() != 3 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,1 ) ; rec( 1L ) ;
-
- if ( d4top() != 3 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,1 ) ; rec( 1L ) ;
-
- if ( d4skip(-1L ) != 1 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,1 ) ; rec( 1L ) ;
-
- if ( d4skip( 1L ) != 3 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,1 ) ; rec( 1L ) ;
-
- /* Index File Skips on a One Record Database */
- if ( d4append() != 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( 1L ) ;
-
- if ( d4skip( 1L ) != 3 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,1 ) ; rec( 2L ) ;
-
- if ( d4skip( -1L ) != 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( 1L ) ;
-
- if ( d4skip( -1L ) != 1 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,0 ) ; rec( 1L ) ;
-
- /* Database Skips on a One Record Database */
- i4unselect() ;
- if ( d4skip( 1L ) != 3 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,1 ) ; rec( 2L ) ;
-
- if ( d4skip( -1L ) != 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( 1L ) ;
-
- if ( d4skip( -1L ) != 1 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,0 ) ; rec( 1L ) ;
-
- if ( d4zap( 1L, d4reccount()) < 0) return -1 ;
- eof( 1,1 ) ; rec( 1L ) ;
-
- /* Write 100 Records */
- for ( i_rec = 1; i_rec <= 100; i_rec++ )
- {
- f4r_long( f4j_ref(2), (i_rec+1)/3 ) ;
- if ( d4append() < 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( i_rec ) ;
- }
-
- /* Skip Test Without Index File */
- if ( d4skip( -99L ) != 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( 1L ) ;
-
- if ( d4skip( -1L ) != 1 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,0 ) ; rec( 1L ) ;
-
- for ( i_rec = 2; i_rec <= 100; i_rec++ )
- {
- if ( d4skip( 1L ) != 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( i_rec ) ;
- }
-
- if ( d4skip( 1L ) != 3 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,1 ) ; rec( 101L ) ;
-
- for ( i_rec = 100; i_rec >=1; i_rec-- )
- {
- if ( d4skip( -1L ) != 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( i_rec ) ;
- }
-
- /* Skip Test With an Index File */
- i4select( i4ref("D4LEARN") ) ;
-
- if ( d4bottom() != 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( 100L ) ;
-
- if ( d4skip( -99L ) != 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( 1L ) ;
-
- if ( d4skip( -1L ) != 1 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 1,0 ) ; rec( 1L ) ;
-
- for ( i_rec = 2; i_rec <= 100; i_rec++ )
- {
- if ( d4skip( 1L ) != 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( i_rec ) ;
- }
-
- if ( d4skip( 1L ) != 3 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,1 ) ; rec( 101L ) ;
-
- for ( i_rec = 100; i_rec >=1; i_rec-- )
- {
- if ( d4skip( -1L ) != 0 )
- {
- u4error( 0, "t4skip: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- eof( 0,0 ) ; rec( i_rec ) ;
- }
-
- d4close_all() ;
-
- #ifdef H4TEST
- {
- int rc ;
- d4init_undo() ;
- rc = h4free_check(32000) ;
- d4init() ;
- if ( rc != 0 )
- {
- u4error( 0, "t4skip: Memory items not freed", (char *) 0 );
- w4exit(1) ;
- }
- }
- #endif
-
- w4handle(1) ;
- w4( w4row()+1,0, "t4skip: SUCCESS" ) ;
- w4exit(0) ;
- }
-