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

  1.  
  2. /* t4skip.c
  3.  
  4.    (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
  5.  
  6.    Tests Code Base 'd4skip' routine.
  7. */
  8.  
  9. #include "p4misc.h"
  10. #include "d4all.h"
  11. #include "w4.h"
  12. #include "u4error.h"
  13.  
  14. static FIELD skip_fields[] =
  15. {
  16.    {"FLD",   'N',    13,    1,    0    },
  17.    {"CHR",   'C',    99,    0,    0    },
  18. };
  19.  
  20.  
  21. static void  eof( int, int ) ;
  22.  
  23. static void eof( int bof_cond, int eof_cond )
  24. {
  25.    int  rc ;
  26.  
  27.    rc = 0 ;
  28.    
  29.    if ( bof_cond )
  30.    {
  31.       if ( ! d4bof() )   rc =  -1 ;
  32.    }
  33.    else
  34.    {
  35.       if ( d4bof() )   rc =  -1 ;
  36.    }
  37.    if ( rc )
  38.    {
  39.       u4error( 0, "t4skip: d4bof()", (char *) 0 ) ;
  40.       w4exit(1) ;
  41.    }
  42.    
  43.    if ( eof_cond )
  44.    {
  45.       if ( ! d4eof() )   rc =  -1 ;
  46.    }
  47.    else
  48.    {
  49.       if ( d4eof() )   rc =  -1 ;
  50.    }
  51.    if ( rc )
  52.    {
  53.       u4error( 0, "t4skip: d4eof()", (char *) 0 ) ;
  54.       w4exit(1) ;
  55.    }
  56. }
  57.  
  58. static void rec( long ) ;
  59. static void rec( long rec_no )
  60. {
  61.    if ( d4recno() != rec_no )
  62.    {
  63.       u4error( 0, "t4skip: d4recno()", (char *) 0 ) ;
  64.       w4exit(1) ;
  65.    }
  66. }
  67.  
  68. main()
  69. {
  70.    long  i_rec ;
  71.  
  72.    #ifdef NO_HUGE
  73.       #ifdef IS_386
  74.          d4init() ;
  75.       #else
  76.          d4initialize( 4, 4, 20, 1000, 20000L ) ;
  77.       #endif
  78.    #else
  79.       d4init() ;
  80.    #endif
  81.    w4clear(-1) ;
  82.    w4( 0,0, "t4skip Testing" ) ;
  83.  
  84.    if ( d4create("t4skip", 2, skip_fields, 0) < 0 )
  85.    {
  86.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  87.       w4exit(1) ;
  88.    }
  89.  
  90.    /* First Execute Skips on an Empty Database */
  91.    if ( d4bottom() != 3 ) 
  92.    {
  93.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  94.       w4exit(1) ;
  95.    }
  96.    eof( 1,1 ) ;    rec( 1L ) ;
  97.  
  98.    if ( d4top() != 3 )  
  99.    {
  100.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  101.       w4exit(1) ;
  102.    }
  103.    eof( 1,1 ) ;    rec( 1L ) ;
  104.  
  105.    if ( d4skip( -1L ) != 1 )  
  106.    {
  107.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  108.       w4exit(1) ;
  109.    }
  110.    eof( 1,1 ) ;    rec( 1L ) ;
  111.  
  112.    if ( d4skip( 1L )  != 3 )  
  113.    {
  114.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  115.       w4exit(1) ;
  116.    }
  117.    eof( 1,1 ) ;    rec( 1L ) ;
  118.  
  119.    if ( i4index( "t4skip", "CHR", 0, 0 )  < 0 )  
  120.    {
  121.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  122.       w4exit(1) ;
  123.    }
  124.    eof( 1,1 ) ;    rec( 1L ) ;
  125.  
  126.    /* Index File Skips on an Empty Database */
  127.    if ( d4bottom() != 3 ) 
  128.    {
  129.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  130.       w4exit(1) ;
  131.    }
  132.    eof( 1,1 ) ;    rec( 1L ) ;
  133.  
  134.    if ( d4top() != 3 )  
  135.    {
  136.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  137.       w4exit(1) ;
  138.    }
  139.    eof( 1,1 ) ;    rec( 1L ) ;
  140.  
  141.    if ( d4skip(-1L ) != 1 )  
  142.    {
  143.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  144.       w4exit(1) ;
  145.    }
  146.    eof( 1,1 ) ;    rec( 1L ) ;
  147.  
  148.    if ( d4skip( 1L )  != 3 )  
  149.    {
  150.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  151.       w4exit(1) ;
  152.    }
  153.    eof( 1,1 ) ;    rec( 1L ) ;
  154.  
  155.    /* Index File Skips on a One Record Database */
  156.    if ( d4append() != 0 )  
  157.    {
  158.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  159.       w4exit(1) ;
  160.    }
  161.    eof( 0,0 ) ;     rec( 1L ) ; 
  162.  
  163.    if ( d4skip(  1L ) != 3 )  
  164.    {
  165.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  166.       w4exit(1) ;
  167.    }
  168.    eof( 0,1 ) ;  rec( 2L ) ;
  169.  
  170.    if ( d4skip( -1L ) != 0 )  
  171.    {
  172.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  173.       w4exit(1) ;
  174.    }
  175.    eof( 0,0 ) ;  rec( 1L ) ;
  176.  
  177.    if ( d4skip( -1L ) != 1 )  
  178.    {
  179.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  180.       w4exit(1) ;
  181.    }
  182.    eof( 1,0 ) ;  rec( 1L ) ;
  183.  
  184.    /* Database Skips on a One Record Database */
  185.    i4unselect() ;
  186.    if ( d4skip(  1L ) != 3 )  
  187.    {
  188.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  189.       w4exit(1) ;
  190.    }
  191.    eof( 0,1 ) ;   rec( 2L ) ;
  192.  
  193.    if ( d4skip( -1L ) != 0 )  
  194.    {
  195.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  196.       w4exit(1) ;
  197.    }
  198.    eof( 0,0 ) ;   rec( 1L ) ;
  199.  
  200.    if ( d4skip( -1L ) != 1 )  
  201.    {
  202.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  203.       w4exit(1) ;
  204.    }
  205.    eof( 1,0 ) ;   rec( 1L ) ;
  206.  
  207.    if ( d4zap( 1L, d4reccount()) < 0)  return -1 ;
  208.    eof( 1,1 ) ;   rec( 1L ) ;
  209.  
  210.    /* Write  100  Records */
  211.    for ( i_rec = 1; i_rec <= 100; i_rec++ )
  212.    {
  213.       f4r_long( f4j_ref(2), (i_rec+1)/3 ) ;
  214.       if ( d4append() < 0 )  
  215.       {
  216.          u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  217.          w4exit(1) ;
  218.       }
  219.       eof( 0,0 ) ;   rec( i_rec ) ;
  220.    }
  221.  
  222.    /* Skip Test Without Index File */
  223.    if ( d4skip( -99L ) != 0 )  
  224.    {
  225.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  226.       w4exit(1) ;
  227.    }
  228.    eof( 0,0 ) ;   rec( 1L ) ;
  229.  
  230.    if ( d4skip( -1L ) != 1 )
  231.    {
  232.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  233.       w4exit(1) ;
  234.    }
  235.    eof( 1,0 ) ;  rec( 1L ) ;
  236.  
  237.    for ( i_rec = 2; i_rec <= 100; i_rec++ ) 
  238.    {
  239.       if ( d4skip( 1L ) != 0 )  
  240.       {
  241.          u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  242.          w4exit(1) ;
  243.       }
  244.       eof( 0,0 ) ;   rec( i_rec ) ;
  245.    }
  246.  
  247.    if ( d4skip( 1L ) != 3 )  
  248.    {
  249.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  250.       w4exit(1) ;
  251.    }
  252.    eof( 0,1 ) ;  rec( 101L ) ;
  253.  
  254.    for ( i_rec = 100; i_rec >=1; i_rec-- ) 
  255.    {
  256.       if ( d4skip( -1L ) != 0 )  
  257.       {
  258.          u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  259.          w4exit(1) ;
  260.       }
  261.       eof( 0,0 ) ;  rec( i_rec ) ;
  262.    }
  263.  
  264.    /* Skip Test With an Index File */
  265.    i4select( i4ref("D4LEARN") ) ;
  266.  
  267.    if ( d4bottom() != 0 )  
  268.    {
  269.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  270.       w4exit(1) ;
  271.    }
  272.    eof( 0,0 ) ;   rec( 100L ) ;
  273.  
  274.    if ( d4skip( -99L ) != 0 )  
  275.    {
  276.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  277.       w4exit(1) ;
  278.    }
  279.    eof( 0,0 ) ;  rec( 1L ) ;
  280.  
  281.    if ( d4skip( -1L ) != 1 )  
  282.    {
  283.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  284.       w4exit(1) ;
  285.    }
  286.    eof( 1,0 ) ;      rec( 1L ) ;
  287.  
  288.    for ( i_rec = 2; i_rec <= 100; i_rec++ ) 
  289.    {
  290.       if ( d4skip( 1L ) != 0 )  
  291.       {
  292.          u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  293.          w4exit(1) ;
  294.       }
  295.       eof( 0,0 ) ;   rec( i_rec ) ;
  296.    }
  297.  
  298.    if ( d4skip( 1L ) != 3 )  
  299.    {
  300.       u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  301.       w4exit(1) ;
  302.    }
  303.    eof( 0,1 ) ;     rec( 101L ) ;
  304.  
  305.    for ( i_rec = 100; i_rec >=1; i_rec-- ) 
  306.    {
  307.       if ( d4skip( -1L ) != 0 )
  308.       {
  309.          u4error( 0, "t4skip:  Error", (char *) 0 ) ;
  310.          w4exit(1) ;
  311.       }
  312.       eof( 0,0 ) ;   rec( i_rec ) ;
  313.    }
  314.  
  315.    d4close_all() ;
  316.  
  317.    #ifdef H4TEST
  318.    {
  319.       int  rc ;
  320.       d4init_undo() ;
  321.       rc = h4free_check(32000) ;
  322.       d4init() ;
  323.       if ( rc != 0 )
  324.       {
  325.          u4error( 0, "t4skip:  Memory items not freed", (char *) 0 );
  326.          w4exit(1) ;
  327.       }
  328.    }
  329.    #endif
  330.  
  331.    w4handle(1) ;
  332.    w4( w4row()+1,0, "t4skip:  SUCCESS" ) ;
  333.    w4exit(0) ;
  334. }
  335.