File: drive.c

package info (click to toggle)
splint 3.1.2.dfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 12,908 kB
  • ctags: 15,816
  • sloc: ansic: 150,306; yacc: 3,463; sh: 3,426; makefile: 2,218; lex: 412
file content (164 lines) | stat: -rw-r--r-- 3,569 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* Part of a driver used to test dbase  */

/* Include those modules that export things that are used explicitly here */
 
# include <stdio.h>
# include <assert.h>
# include "bool.h"
# include "employee.h"
# include "empset.h"
# include "dbase.h"

int main (int argc, /*@unused@*/ char *argv[]) 
{
  employee e;
  empset em1, em2, em3;
  char na[10000];
  char * sprintResult;
  int i, j;
  db_q q;
  
  /* Initialize all of the LCL-specified modules that were included */
  bool_initMod();
  employee_initMod();
  empset_initMod();
  db_initMod();
  
  if (argc != 1) 
    {
      printf ("FormatPos: Wrong number of arguments. Given %d needs 0.\n",
	      argc - 1);
      return 1;
    }
  
  /* Unit test empset */
  em1 = empset_create();

  if (!(empset_size(em1) == 0))
    {
      printf("Size should be 0.\n");
    }

  for (i = 0; i < 500; i++) 
    {
      e.ssNum = i;
      e.salary = 100000;
      e.gen = MALE;
      e.j = MGR;
      (void) sprintf(na, "S.S. Doe %d", i);
      check (employee_setName(&e, na));
      empset_insert(em1, e);
    }

  if (!(empset_size(em1) == 500)) 
    {
      printf("Size should be 500.\n");
    }

  for (i = 0; i < 250; i++) 
    {
      e.ssNum = i;
      e.salary = 100000;
      e.gen = MALE;
      e.j = MGR;
      (void) sprintf(na, "S.S. Doe %d", i);
      check (employee_setName(&e, na));
      empset_delete(em1, e);
    }

  if (!(empset_size(em1) == 250)) 
    {
      printf("Size should be 250.\n");
    }

  em2 = empset_create();

  for (i = 0; i < 100; i++) 
    {
      e.ssNum = i;
      e.salary = 100000;
      e.gen = MALE;
      e.j = MGR;
      (void) sprintf(na, "S.S. Doe %d", i);
      check (employee_setName(&e, na));
      empset_insert(em2, e);
    }

  em3 = empset_union(em1, em2);

  if (!(empset_size(em3) == 350))
    {
      printf("Size should be 350.\n");
    }

  empset_intersect(em3, em3);

  if (!(empset_size(em3) == 350))
    {
      printf("Size should be 350.\n");
    }

  printf("Print two different employees:\n");

  for (i = 0; i < 2; i++) 
    {
      e = empset_choose(em3);
      employee_sprint(na, e);
      printf("%s\n", &(na[0]));
      empset_delete(em3, e);
    }
  
  /* Test dbase  */

  for (i = 0; i < 20; i++) 
    {
      e.ssNum = i;
      e.salary = 10 * i;
      if (i < 10) e.gen = MALE; else e.gen = FEMALE;
      if (i < 15) e.j = NONMGR; else e.j = MGR;
      (void) sprintf(na, "J. Doe %d", i);
      check (employee_setName(&e, na));

      if ((i/2)*2 == i) 
	{
	  check (hire(e) == db_OK); 
	}
      else 
	{
	  uncheckedHire(e); j = hire(e);
	}
    }
  
  printf("Should print 4: %d\n", /*@-usedef@*/ j /*@=usedef@*/); 
  printf("Employees 0 - 19\n");
  db_print();
  check (fire(17));
  q.g = FEMALE; q.j = job_ANY; q.l = 158; q.h = 185;
  printf("Employees 0 - 16, 18 - 19\n");
  db_print();

  i = query(q, em1 = empset_create());
  sprintResult = empset_sprint(em1);
  printf("Should get two females: %d\n%s\n", i, sprintResult);
  free(sprintResult);

  q.g = MALE; q.j = NONMGR; q.l = 0; q.h = 185;
  i = query(q, em2 = empset_create());
  em3 = empset_disjointUnion(em2, em1);
  sprintResult = empset_sprint(em3);
  i = empset_size(em3);
  printf("Should get two females and ten males: %d\n%s\n", i, sprintResult);
  free(sprintResult);
  
  empset_intersect(em1, em3);
  sprintResult = empset_sprint(em1);
  i = empset_size(em1);
  printf("Should get two females: %d\n%s\n", i, sprintResult);
  free(sprintResult); 

  check (fire(empset_choose(em3).ssNum));
  printf("Should get 18 employees\n");
  db_print();
  
  return 0;
}