home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / TEST / T4LARGE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-22  |  2.5 KB  |  130 lines

  1.  
  2. /*  t4large.c
  3.  
  4.    (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
  5.  
  6.    Tests Creating a large database.
  7. */
  8.  
  9. #include "p4misc.h"
  10. #include "d4all.h"
  11. #include "w4.h"
  12. #include "u4error.h"
  13.  
  14. #include <string.h>
  15.  
  16. FIELD  fields[] =
  17. {
  18.    { "C", 'C', 25, 0, 0 },
  19.    { "N", 'N',  5, 0, 0 },
  20. } ;
  21.  
  22. static long  middle_rec =  0x10010L ;
  23. static long  end_rec    =  0x10200L ;
  24.  
  25.  
  26. static int  add(long,long,long,int) ;
  27.  
  28. static int  add( long f_ref, long start_rec, long end_rec, int c )
  29. {
  30.    long  i_rec ;
  31.  
  32.    for ( i_rec = start_rec; i_rec <= end_rec; i_rec++)
  33.    {
  34.       char  buf[80] ;
  35.  
  36.       w4long( w4row(),c, i_rec, 6 ) ;
  37.  
  38.       c4ltoa( i_rec, buf, f4width(f_ref) ) ;
  39.       f4replace( f_ref, buf ) ;
  40.       if ( d4write( 0L ) != 0 )
  41.       {
  42.          u4error( 0, "t4large:  d4write", (char *) 0 ) ;
  43.          w4exit(1) ;
  44.       }
  45.    }
  46.  
  47.    return 0 ;
  48. }
  49.  
  50.  
  51. main()
  52. {
  53.    int   i_ref, c ;
  54.    long  i_rec, f_ref ;
  55.  
  56.    #ifdef NO_HUGE
  57.       #ifdef IS_386
  58.          d4init() ;
  59.       #else
  60.          d4initialize( 4, 4, 20, 1000, 20000L ) ;
  61.       #endif
  62.    #else
  63.       d4init() ;
  64.    #endif
  65.    w4clear(-1) ;
  66.  
  67.    if ( d4create( "t4large", 2, fields, 0 ) != 0 )
  68.    {
  69.       u4error( 0, "t4large:  d4create", (char *) 0 ) ;
  70.       w4exit(1) ;
  71.    }
  72.  
  73.    f_ref =  f4ref( "C" ) ;
  74.  
  75.    w4(0,0, "Adding Record:" ) ;
  76.    c =  w4col() ;
  77.  
  78.    /* Add most without an index file so that the test does not take too long. */
  79.    add( f_ref, 1L, middle_rec, c ) ;
  80.  
  81.    w4(w4row()+1,0, "Indexing Database" ) ;
  82.    i_ref =  i4index( "t4large", "C", 0, 0 ) ;
  83.  
  84.    w4(w4row()+1,0, "Adding Record:" ) ;
  85.    add( f_ref, middle_rec+1, end_rec, c ) ;  /* Add the rest with an index file. */
  86.  
  87.    if ( i4check(i_ref) != 0 )
  88.    {
  89.       u4error( 0, "t4large:  i4check", (char *) 0 ) ;
  90.       w4exit(1) ;
  91.    }
  92.  
  93.    d4bottom() ;
  94.  
  95.    for ( i_rec = end_rec; i_rec >= 1L; i_rec-- )
  96.    {
  97.       char  buf[80] ;
  98.  
  99.       c4ltoa( i_rec, buf, f4width(f_ref) ) ;
  100.       if ( memcmp( buf, f4ptr(f_ref), f4width(f_ref)) != 0 )
  101.       {
  102.          u4error( 0, "t4large:  i4check", (char *) 0 ) ;
  103.          w4exit(1) ;
  104.       }
  105.  
  106.       d4skip(-1L) ;
  107.    }
  108.  
  109.    d4close_all() ;
  110.  
  111.  
  112.    #ifdef H4TEST
  113.    {
  114.       int  rc ;
  115.       d4init_undo() ;
  116.       rc = h4free_check(32000) ;
  117.       d4init() ;
  118.       if ( rc != 0 )
  119.       {
  120.          u4error( 0, "t4large:  Memory items not freed", (char *) 0 );
  121.          w4exit(1) ;
  122.       }
  123.    }
  124.    #endif
  125.  
  126.    w4handle(1) ;
  127.    w4( w4row()+1,0, "t4large:  SUCCESS" ) ;
  128.    w4exit(0) ;
  129. }
  130.