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