home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 311_01 / stest.c < prev    next >
C/C++ Source or Header  |  1990-04-22  |  4KB  |  117 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      stest.c  v1.3  (c) 1990  Ken Harris                                 */
  5. /*                                                                          */
  6. /*                                                                          */
  7. /****************************************************************************/
  8. /*                                                                          */
  9. /*      This software is made available on an AS-IS basis. Unrestricted     */
  10. /*      use is granted provided that the copyright notice remains intact.   */
  11. /*      The author makes no warranties expressed or implied.                */
  12. /*                                                                          */
  13. /****************************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include "db.h"
  17.  
  18. main()
  19. {
  20.         DATA_SET ds;
  21.         static char     data[50];
  22.         int      i;
  23.  
  24.     printf("stest - Test sequential file routines\n\n");
  25.     screate();
  26.         printf("...test file created...\n\n");
  27.  
  28.     ds = db_open("", "stest.dat");
  29.         if (db_error)
  30.         {       printf("Open Failure - %s\n", db_error_msg(db_error));
  31.                 exit(0);
  32.         }
  33.  
  34.         printf("...adding 100 records...\n");
  35.         for (i=1; i<100; i++)
  36.         {       printf("%d\n",i);
  37.                 sprintf(data,"%04d",i);
  38.                 db_add(ds, data);
  39.                 if (db_error)
  40.                 {       printf("Add Failure - %s\n", db_error_msg(db_error));
  41.                         exit(0);
  42.                 }
  43.         }
  44.         printf("...add complete...\n\n");
  45.  
  46.     printf("...read forward...\n");
  47.     db_read_first(ds, data);
  48.     while (!db_error)
  49.     {    printf("%5.5s\n", data);
  50.         db_read_next(ds, data);
  51.     }
  52.     printf("...read forward complete...\n\n");
  53.  
  54.         printf("...read reverse...\n");
  55.     db_read_last(ds, data);
  56.     while (!db_error)
  57.     {    printf("%5.5s\n", data);
  58.         db_read_prev(ds, data);
  59.     }
  60.     printf("...read reverse complete...\n\n");
  61.  
  62.     printf("...delete forward...\n");
  63.     db_read_first(ds, data);
  64.     while (!db_error)
  65.     {    printf("%5.5s\n", data);
  66.         db_delete(ds);
  67.         db_read_next(ds, data);
  68.     }
  69.     printf("...delete forward complete...\n\n");
  70.  
  71.         printf("...adding 100 records (again) ...\n");
  72.         for (i=1; i<100; i++)
  73.         {       printf("%d\n",i);
  74.                 sprintf(data,"%05d",i);
  75.                 db_add(ds, data);
  76.                 if (db_error)
  77.                 {       printf("Add Failure - %s\n", db_error_msg(db_error));
  78.                         exit(0);
  79.                 }
  80.         }
  81.         printf("...add complete...\n\n");
  82.  
  83.     printf("...delete reverse...\n");
  84.     db_read_last(ds, data);
  85.     while (!db_error)
  86.     {    printf("%5.5s\n", data);
  87.         db_delete(ds);
  88.         db_read_prev(ds, data);
  89.     }
  90.     printf("...delete forward complete...\n\n");
  91.  
  92.         db_close(ds);
  93.     unlink("stest.dat");
  94. }
  95.  
  96. /*
  97.  *    screate - create our test sequential file
  98.  */
  99.  
  100. screate()
  101. {
  102.         DATA_SET ds;
  103.  
  104.  
  105.     ds = db_create("", "stest.dat", "seq,rec=50");
  106.         if (db_error)
  107.         {       printf("Create Failure - %s\n", db_error_msg(db_error));
  108.                 exit(0);
  109.         }
  110.  
  111.         db_close(ds);
  112.         if (db_error)
  113.         {       printf("Close Failure - %s\n", db_error_msg(db_error));
  114.                 exit(0);
  115.         }
  116. }
  117.