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

  1.  
  2. /* t4memo.c
  3.  
  4.    (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
  5.  
  6.    Tests Code Base memo routines.
  7. */
  8.  
  9. #include "p4misc.h"
  10. #include "d4all.h"
  11. #include "w4.h"
  12. #include "u4error.h"
  13.  
  14. #include <string.h>
  15. #include <stdlib.h>
  16.  
  17. #ifdef TURBO
  18.    extern  unsigned _stklen =  28000 ;
  19. #endif
  20.  
  21. static FIELD  fields[]=
  22. {
  23.    {"MEMO_DAT", 'M', 0,0,0},
  24. } ;
  25.  
  26. #define  RW_SIZE  12000
  27.  
  28. main()
  29. {
  30.    char *write_data ;
  31.    char *read_data ;
  32.    long binary_out[260], binary_read[262] ;
  33.    long f_ref ;
  34.    long *data ;
  35.    int  rc, i, len ;
  36.  
  37.    #ifdef NO_HUGE
  38.       #ifdef IS_386
  39.          d4init() ;
  40.       #else
  41.          d4initialize( 4, 4, 20, 1000, 5000L ) ;
  42.       #endif
  43.    #else
  44.       d4init() ;
  45.    #endif
  46.  
  47.    write_data =  h4alloc( RW_SIZE ) ;
  48.    read_data  =  h4alloc( RW_SIZE ) ;
  49.  
  50.    w4clear(-1) ;
  51.  
  52.    /* First the  > 64K Test */
  53.    d4create( "t4memo", 1, fields, 0) ;
  54.    if ( (f_ref =  f4ref("MEMO_DAT")) < 0L )
  55.    {
  56.       u4error( 0, "t4memo:  10", (char *) 0 ) ;
  57.       w4exit(1) ;
  58.    }
  59.  
  60.    /* Test the reading and writing of Binary Data. */
  61.    for ( i=0; i< 260; i++ )
  62.       binary_out[i] = 256-i ;
  63.  
  64.    m4write( f_ref, 1L, (char *) binary_out, sizeof(binary_out) ) ;
  65.  
  66.    memset( (char *) binary_read, 0, sizeof(binary_read) ) ;
  67.    rc = m4read( f_ref, 1L, (char *) binary_read, sizeof(binary_read) ) ;
  68.    if ( rc != sizeof(binary_out) )
  69.    {
  70.       u4error( 0, "t4memo:  15", (char *) 0 ) ;
  71.       w4exit(1) ;
  72.    }
  73.  
  74.    for ( i=0; i<260; i++ )
  75.       if ( binary_read[i] != 256-i )
  76.       {
  77.          u4error( 0, "t4memo:  17", (char *) 0 ) ;
  78.          w4exit(1) ;
  79.       }
  80.  
  81.  
  82.    for ( i=1; i< 200; i++ )
  83.    {
  84.       len =  i/20 + 2 ;
  85.       c4ltoa( (long) i, write_data, len) ;
  86.       write_data[len] =  '\0' ;
  87.  
  88.       if ( m4write( f_ref, (long) i, write_data, strlen(write_data)) !=
  89.           strlen(write_data) ) 
  90.       {
  91.          u4error( 0, "t4memo:  20", (char *) 0 ) ;
  92.          w4exit(1) ;
  93.       }
  94.    }
  95.  
  96.    data =  m4check( f_ref ) ;
  97.    if ( data == (long *) 0 )  
  98.    {
  99.       u4error( 0, "t4memo:  30", (char *) 0 ) ;
  100.       w4exit(1) ;
  101.    }
  102.  
  103.    for ( i=0; i< 3; i++ )
  104.       if ( data[i] != 0L )
  105.       {
  106.          u4error( 0, "t4memo:  40", (char *) 0 ) ;
  107.          w4exit(1) ;
  108.       }
  109.  
  110.    for ( i=1; i< 200; i++ ) 
  111.    {
  112.       len =  i/20 + 2 ;
  113.       c4ltoa( (long) i, write_data, len) ;
  114.       write_data[len] =  '\0' ;
  115.       if ( m4read( f_ref, (long) i, read_data, 1000) != 
  116.           strlen(write_data) ) 
  117.       {
  118.          u4error( 0, "t4memo:  50", (char *) 0 ) ;
  119.          w4exit(1) ;
  120.       }
  121.       if ( i !=  atoi(read_data) )  
  122.       {
  123.          u4error( 0, "t4memo:  60", (char *) 0 ) ;
  124.          w4exit(1) ;
  125.       }
  126.    }
  127.  
  128.    /* First the Write/Read test */
  129.    d4create( "t4memo2", 1, fields, 0) ;
  130.    f_ref =  f4ref("MEMO_DAT") ;
  131.  
  132.    memset( write_data, (int) '1', RW_SIZE ) ;
  133.  
  134.    rc =  m4read( f_ref, 1L, read_data, 100 ) ;
  135.    if ( rc != 0 )  
  136.    {
  137.       u4error( 0, "t4memo:  70", (char *) 0 ) ;
  138.       w4exit(1) ;
  139.    }
  140.  
  141.    if ( m4write( f_ref, 1L, write_data, 10000 ) != 10000 )
  142.    {
  143.       u4error( 0, "t4memo:  80", (char *) 0 ) ;
  144.       w4exit(1) ;
  145.    }
  146.  
  147.    data =  m4check( f_ref ) ;
  148.    if ( data == (long *) 0 )  
  149.    {
  150.       u4error( 0, "t4memo:  90", (char *) 0 ) ;
  151.       w4exit(1) ;
  152.    }
  153.  
  154.    for ( i=0; i< 3; i++ )
  155.       if ( data[i] != 0L )
  156.       {
  157.          u4error( 0, "t4memo:  100", (char *) 0 ) ;
  158.          w4exit(1) ;
  159.       }
  160.  
  161.    w4( 0,0, "Read Loop") ;
  162.  
  163.    for ( i=9998; i< 10000; i++)
  164.    {
  165.       if ( i > 100 && i< 9000 ) i+= 100 ;
  166.       if ( i > 9000 && i< 9980 ) i+= 10 ;
  167.       w4int( 1,0, i, 5 ) ;
  168.       if ( m4read( f_ref, 1L, read_data, i+1) != i)
  169.       {
  170.          u4error( 0, "t4memo:  110", (char *) 0 ) ;
  171.          w4exit(1) ;
  172.       }
  173.       if ( strlen(read_data) != i )
  174.       {
  175.          u4error( 0, "t4memo:  120", (char *) 0 ) ;
  176.          w4exit(1) ;
  177.       }
  178.       if ( memcmp(read_data, write_data, i ) != 0)         
  179.       {
  180.          u4error( 0, "t4memo:  130", (char *) 0 ) ;
  181.          w4exit(1) ;
  182.       }
  183.    }
  184.  
  185.    if ( m4read( f_ref, 1L, read_data, 10001) != 10000)         
  186.    {
  187.       u4error( 0, "t4memo:  140", (char *) 0 ) ;
  188.       w4exit(1) ;
  189.    }
  190.    if ( strlen(read_data) != 10000 )
  191.    {
  192.       u4error( 0, "t4memo:  150", (char *) 0 ) ;
  193.       w4exit(1) ;
  194.    }
  195.  
  196.    w4( 0,0, "Write Loop") ;
  197.  
  198.    for ( i=10000; i>0; i-- )
  199.    {
  200.       int chr ;
  201.       w4int( 1,0, i, 5 ) ;
  202.       if ( i > 50 && i< 9990 ) i-= 40 ;
  203.       chr =  (int) 'A' + i % 26 ;
  204.       memset( write_data, chr, i) ;
  205.  
  206.       if ( m4write( f_ref, 1L, write_data, i ) != i )         
  207.       {
  208.          u4error( 0, "t4memo:  160", (char *) 0 ) ;
  209.          w4exit(1) ;
  210.       }
  211.  
  212.       if ( m4read( f_ref, 1L, read_data, 11000 ) != i )
  213.       {
  214.          u4error( 0, "t4memo:  170", (char *) 0 ) ;
  215.          w4exit(1) ;
  216.       }
  217.  
  218.       if ( memcmp(read_data, write_data, i ) != 0)
  219.       {
  220.          u4error( 0, "t4memo:  180", (char *) 0 ) ;
  221.          w4exit(1) ;
  222.       }
  223.    }
  224.  
  225.    data =  m4check( f_ref ) ;
  226.    if ( data == (long *) 0 )
  227.    {
  228.       u4error( 0, "t4memo:  190", (char *) 0 ) ;
  229.       w4exit(1) ;
  230.    }
  231.  
  232.    if ( data[3] != 0L  )
  233.    {
  234.       u4error( 0, "t4memo:  200", (char *) 0 ) ;
  235.       w4exit(1) ;
  236.    }
  237.  
  238.    d4close_all() ;
  239.  
  240.    h4free_memory( read_data ) ;
  241.    h4free_memory( write_data ) ;
  242.  
  243.    #ifdef H4TEST
  244.    {
  245.       int  rc ;
  246.       d4init_undo() ;
  247.       rc = h4free_check(32000) ;
  248.       d4init() ;
  249.       if ( rc != 0 )
  250.       {
  251.          u4error( 0, "t4memo:  Memory items not freed", (char *) 0 );
  252.          w4exit(1) ;
  253.       }
  254.    }
  255.    #endif
  256.  
  257.    w4handle(1) ;
  258.    w4( w4row()+1,0, "t4memo:  SUCCESS" ) ;
  259.    w4exit(0) ;
  260. }
  261.  
  262.