home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lclint.zip / lclint-2_3h-os2-bin.zip / test / db1 / drive.c < prev    next >
C/C++ Source or Header  |  1997-09-03  |  3KB  |  164 lines

  1. /* Part of a driver used to test dbase  */
  2.  
  3. /* Include those modules that export things that are used explicitly here */
  4.  
  5. # include <stdio.h>
  6. # include "bool.h"
  7. # include "employee.h"
  8. # include "empset.h"
  9. # include "dbase.h"
  10.  
  11. int main(int argc, char *argv[]) 
  12. {
  13.   employee e;
  14.   empset em1, em2, em3;
  15.   char na[10000];
  16.   char * sprintResult;
  17.   int i, j;
  18.   db_q q;
  19.   
  20.   /* Initialize all of the LCL-specified modules that were included */
  21.   bool_initMod();
  22.   employee_initMod();
  23.   empset_initMod();
  24.   db_initMod();
  25.   
  26.   if (argc != 1) 
  27.     {
  28.       printf ("FormatPos: Wrong number of arguments. Given %d needs 0.\n",
  29.           argc - 1);
  30.       return 1;
  31.     }
  32.   
  33.   /* Unit test empset */
  34.   em1 = empset_create();
  35.  
  36.   if (!(empset_size(em1) == 0))
  37.     {
  38.       printf("Size should be 0.\n");
  39.     }
  40.  
  41.   for (i = 0; i < 500; i++) 
  42.     {
  43.       e.ssNum = i;
  44.       e.salary = 100000;
  45.       e.gen = MALE;
  46.       e.j = MGR;
  47.       (void) sprintf(na, "S.S. Doe %d", i);
  48.       employee_setName(&e, na);
  49.       empset_insert(em1, e);
  50.     }
  51.  
  52.   if (!(empset_size(em1) == 500)) 
  53.     {
  54.       printf("Size should be 500.\n");
  55.     }
  56.  
  57.   for (i = 0; i < 250; i++) 
  58.     {
  59.       e.ssNum = i;
  60.       e.salary = 100000;
  61.       e.gen = MALE;
  62.       e.j = MGR;
  63.       (void) sprintf(na, "S.S. Doe %d", i);
  64.       employee_setName(&e, na);
  65.       empset_delete(em1, e);
  66.     }
  67.  
  68.   if (!(empset_size(em1) == 250)) 
  69.     {
  70.       printf("Size should be 250.\n");
  71.     }
  72.  
  73.   em2 = empset_create();
  74.  
  75.   for (i = 0; i < 100; i++) 
  76.     {
  77.       e.ssNum = i;
  78.       e.salary = 100000;
  79.       e.gen = MALE;
  80.       e.j = MGR;
  81.       (void) sprintf(na, "S.S. Doe %d", i);
  82.       employee_setName(&e, na);
  83.       empset_insert(em2, e);
  84.     }
  85.  
  86.   em3 = empset_union(em1, em2);
  87.  
  88.   if (!(empset_size(em3) == 350))
  89.     {
  90.       printf("Size should be 350.\n");
  91.     }
  92.  
  93.   empset_intersect(em3, em3);
  94.  
  95.   if (!(empset_size(em3) == 350))
  96.     {
  97.       printf("Size should be 350.\n");
  98.     }
  99.  
  100.   printf("Print two different employees:\n");
  101.  
  102.   for (i = 0; i < 2; i++) 
  103.     {
  104.       e = empset_choose(em3);
  105.       employee_sprint(na, e);
  106.       printf("%s\n", &(na[0]));
  107.       empset_delete(em3, e);
  108.     }
  109.   
  110.   /* Test dbase  */
  111.  
  112.   for (i = 0; i < 20; i++) 
  113.     {
  114.       e.ssNum = i;
  115.       e.salary = 10 * i;
  116.       if (i < 10) e.gen = MALE; else e.gen = FEMALE;
  117.       if (i < 15) e.j = NONMGR; else e.j = MGR;
  118.       (void) sprintf(na, "J. Doe %d", i);
  119.       employee_setName(&e, na);
  120.  
  121.       if ((i/2)*2 == i) 
  122.     {
  123.       hire(e); 
  124.     }
  125.       else 
  126.     {
  127.       uncheckedHire(e); j = hire(e);
  128.     }
  129.     }
  130.   
  131.   printf("Should print 4: %d\n", j); 
  132.   printf("Employees 0 - 19\n");
  133.   db_print();
  134.   fire(17);
  135.   q.g = FEMALE; q.j = job_ANY; q.l = 158; q.h = 185;
  136.   printf("Employees 0 - 16, 18 - 19\n");
  137.   db_print();
  138.  
  139.   i = query(q, em1 = empset_create());
  140.   sprintResult = empset_sprint(em1);
  141.   printf("Should get two females: %d\n%s\n", i, sprintResult);
  142.   free(sprintResult);
  143.  
  144.   q.g = MALE; q.j = NONMGR; q.l = 0; q.h = 185;
  145.   i = query(q, em2 = empset_create());
  146.   em3 = empset_disjointUnion(em2, em1);
  147.   sprintResult = empset_sprint(em3);
  148.   i = empset_size(em3);
  149.   printf("Should get two females and ten males: %d\n%s\n", i, sprintResult);
  150.   free(sprintResult);
  151.   
  152.   empset_intersect(em1, em3);
  153.   sprintResult = empset_sprint(em1);
  154.   i = empset_size(em1);
  155.   printf("Should get two females: %d\n%s\n", i, sprintResult);
  156.   free(sprintResult); 
  157.  
  158.   fire(empset_choose(em3).ssNum);
  159.   printf("Should get 18 employees\n");
  160.   db_print();
  161.   
  162.   return 0;
  163. }
  164.