home *** CD-ROM | disk | FTP | other *** search
-
- /* t4memo.c
-
- (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Tests Code Base memo routines.
- */
-
- #include "p4misc.h"
- #include "d4all.h"
- #include "w4.h"
- #include "u4error.h"
-
- #include <string.h>
- #include <stdlib.h>
-
- #ifdef TURBO
- extern unsigned _stklen = 28000 ;
- #endif
-
- static FIELD fields[]=
- {
- {"MEMO_DAT", 'M', 0,0,0},
- } ;
-
- #define RW_SIZE 12000
-
- main()
- {
- char *write_data ;
- char *read_data ;
- long binary_out[260], binary_read[262] ;
- long f_ref ;
- long *data ;
- int rc, i, len ;
-
- #ifdef NO_HUGE
- #ifdef IS_386
- d4init() ;
- #else
- d4initialize( 4, 4, 20, 1000, 5000L ) ;
- #endif
- #else
- d4init() ;
- #endif
-
- write_data = h4alloc( RW_SIZE ) ;
- read_data = h4alloc( RW_SIZE ) ;
-
- w4clear(-1) ;
-
- /* First the > 64K Test */
- d4create( "t4memo", 1, fields, 0) ;
- if ( (f_ref = f4ref("MEMO_DAT")) < 0L )
- {
- u4error( 0, "t4memo: 10", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- /* Test the reading and writing of Binary Data. */
- for ( i=0; i< 260; i++ )
- binary_out[i] = 256-i ;
-
- m4write( f_ref, 1L, (char *) binary_out, sizeof(binary_out) ) ;
-
- memset( (char *) binary_read, 0, sizeof(binary_read) ) ;
- rc = m4read( f_ref, 1L, (char *) binary_read, sizeof(binary_read) ) ;
- if ( rc != sizeof(binary_out) )
- {
- u4error( 0, "t4memo: 15", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- for ( i=0; i<260; i++ )
- if ( binary_read[i] != 256-i )
- {
- u4error( 0, "t4memo: 17", (char *) 0 ) ;
- w4exit(1) ;
- }
-
-
- for ( i=1; i< 200; i++ )
- {
- len = i/20 + 2 ;
- c4ltoa( (long) i, write_data, len) ;
- write_data[len] = '\0' ;
-
- if ( m4write( f_ref, (long) i, write_data, strlen(write_data)) !=
- strlen(write_data) )
- {
- u4error( 0, "t4memo: 20", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- data = m4check( f_ref ) ;
- if ( data == (long *) 0 )
- {
- u4error( 0, "t4memo: 30", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- for ( i=0; i< 3; i++ )
- if ( data[i] != 0L )
- {
- u4error( 0, "t4memo: 40", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- for ( i=1; i< 200; i++ )
- {
- len = i/20 + 2 ;
- c4ltoa( (long) i, write_data, len) ;
- write_data[len] = '\0' ;
- if ( m4read( f_ref, (long) i, read_data, 1000) !=
- strlen(write_data) )
- {
- u4error( 0, "t4memo: 50", (char *) 0 ) ;
- w4exit(1) ;
- }
- if ( i != atoi(read_data) )
- {
- u4error( 0, "t4memo: 60", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- /* First the Write/Read test */
- d4create( "t4memo2", 1, fields, 0) ;
- f_ref = f4ref("MEMO_DAT") ;
-
- memset( write_data, (int) '1', RW_SIZE ) ;
-
- rc = m4read( f_ref, 1L, read_data, 100 ) ;
- if ( rc != 0 )
- {
- u4error( 0, "t4memo: 70", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( m4write( f_ref, 1L, write_data, 10000 ) != 10000 )
- {
- u4error( 0, "t4memo: 80", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- data = m4check( f_ref ) ;
- if ( data == (long *) 0 )
- {
- u4error( 0, "t4memo: 90", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- for ( i=0; i< 3; i++ )
- if ( data[i] != 0L )
- {
- u4error( 0, "t4memo: 100", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- w4( 0,0, "Read Loop") ;
-
- for ( i=9998; i< 10000; i++)
- {
- if ( i > 100 && i< 9000 ) i+= 100 ;
- if ( i > 9000 && i< 9980 ) i+= 10 ;
- w4int( 1,0, i, 5 ) ;
- if ( m4read( f_ref, 1L, read_data, i+1) != i)
- {
- u4error( 0, "t4memo: 110", (char *) 0 ) ;
- w4exit(1) ;
- }
- if ( strlen(read_data) != i )
- {
- u4error( 0, "t4memo: 120", (char *) 0 ) ;
- w4exit(1) ;
- }
- if ( memcmp(read_data, write_data, i ) != 0)
- {
- u4error( 0, "t4memo: 130", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- if ( m4read( f_ref, 1L, read_data, 10001) != 10000)
- {
- u4error( 0, "t4memo: 140", (char *) 0 ) ;
- w4exit(1) ;
- }
- if ( strlen(read_data) != 10000 )
- {
- u4error( 0, "t4memo: 150", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- w4( 0,0, "Write Loop") ;
-
- for ( i=10000; i>0; i-- )
- {
- int chr ;
- w4int( 1,0, i, 5 ) ;
- if ( i > 50 && i< 9990 ) i-= 40 ;
- chr = (int) 'A' + i % 26 ;
- memset( write_data, chr, i) ;
-
- if ( m4write( f_ref, 1L, write_data, i ) != i )
- {
- u4error( 0, "t4memo: 160", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( m4read( f_ref, 1L, read_data, 11000 ) != i )
- {
- u4error( 0, "t4memo: 170", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( memcmp(read_data, write_data, i ) != 0)
- {
- u4error( 0, "t4memo: 180", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
-
- data = m4check( f_ref ) ;
- if ( data == (long *) 0 )
- {
- u4error( 0, "t4memo: 190", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( data[3] != 0L )
- {
- u4error( 0, "t4memo: 200", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- d4close_all() ;
-
- h4free_memory( read_data ) ;
- h4free_memory( write_data ) ;
-
- #ifdef H4TEST
- {
- int rc ;
- d4init_undo() ;
- rc = h4free_check(32000) ;
- d4init() ;
- if ( rc != 0 )
- {
- u4error( 0, "t4memo: Memory items not freed", (char *) 0 );
- w4exit(1) ;
- }
- }
- #endif
-
- w4handle(1) ;
- w4( w4row()+1,0, "t4memo: SUCCESS" ) ;
- w4exit(0) ;
- }
-
-