-
Notifications
You must be signed in to change notification settings - Fork 28
/
TESTPRG.CBL
469 lines (446 loc) · 37.1 KB
/
TESTPRG.CBL
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
IDENTIFICATION DIVISION.
PROGRAM-ID. GREETING.
*****************************************************************
* Trivial program to exercise CobolCheck.
*****************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
WORKING-STORAGE SECTION.
* ZUTZCWS.CPY
01 FILLER PIC X(16) VALUE '******* ZUTZCPC'.
01 FILLER PIC X(16) VALUE '******* 0.1.0'.
01 UT-FIELDS.
05 UT-CONST-ES PIC X(02) VALUE 'ES'.
05 UT-LABEL-EXPECTED-ACCESS.
10 FILLER PIC X(06) VALUE 'ACCESS'.
10 UT-LABEL-EXPECTED-ACCESS-PL
PIC X(02) VALUE SPACES.
05 UT-DISPLAY-MESSAGE PIC X(256) VALUE SPACES.
05 FILLER PIC X(01) VALUE SPACES.
88 UT-NORMAL-COMPARE VALUE 'N'.
88 UT-REVERSE-COMPARE VALUE 'Y'.
05 FILLER PIC X(01) VALUE '1'.
88 UT-VERIFY-EXACT VALUE '1'.
88 UT-VERIFY-AT-LEAST VALUE '2'.
88 UT-VERIFY-NO-MORE-THAN VALUE '3'.
05 FILLER PIC X(01) VALUE SPACES.
88 UT-VERIFY-PASSED VALUE 'Y'.
88 UT-VERIFY-FAILED VALUE SPACES.
05 FILLER PIC X(01) VALUE SPACES.
88 UT-COMPARE-DEFAULT VALUE SPACE.
88 UT-COMPARE-NUMERIC VALUE 'N'.
05 FILLER PIC X(01) VALUE SPACES.
88 UT-COMPARE-PASSED VALUE 'Y'.
88 UT-COMPARE-FAILED VALUE SPACES.
05 UT-EXPECTED PIC X(60) VALUE SPACES.
05 UT-ACTUAL PIC X(60) VALUE SPACES.
05 UT-EXPECTED-NUMERIC PIC S9(08) VALUE ZERO.
05 UT-ACTUAL-NUMERIC PIC S9(08) VALUE ZERO.
05 UT-EXPECTED-ACCESSES PIC 9(04) VALUE ZERO.
05 UT-ACTUAL-ACCESSES PIC 9(04) VALUE ZERO.
05 UT-EXPECTED-ACCESSES-FMT PIC Z,ZZ9.
05 UT-ACTUAL-ACCESSES-FMT PIC Z,ZZ9.
05 UT-FAILED PIC X(11) VALUE "**** FAIL: ".
05 UT-PASSED PIC X(11) VALUE " PASS: ".
05 UT-TEST-CASE-NAME PIC X(80) VALUE SPACES.
05 UT-TEST-CASE-NUMBER PIC ZZ9.
05 UT-RETCODE PIC 9(4) VALUE ZERO.
05 UT-TEST-CASE-COUNT PIC 9(4) VALUE ZERO.
05 UT-NUMBER-PASSED PIC 9(4) VALUE ZERO.
05 UT-NUMBER-FAILED PIC 9(4) VALUE ZERO.
01 UT-MOCKS.
05 FILLER PIC X(01) VALUE SPACES.
88 UT-MOCK-FOUND VALUE 'Y'.
88 UT-MOCK-NOT-FOUND VALUE SPACES.
05 UT-MOCK-FIND-TYPE PIC X(04).
88 UT-FIND-FILE-MOCK VALUE 'FILE'.
88 UT-FIND-CALL-MOCK VALUE 'CALL'.
88 UT-FIND-CICS-MOCK VALUE 'CICS'.
88 UT-FIND-SQL-MOCK VALUE 'SQL'.
88 UT-FIND-PARA-MOCK VALUE 'PARA'.
05 UT-MOCK-FIND-FILENAME PIC X(31).
05 UT-MOCK-FIND-PARA-NAME PIC X(31).
05 UT-MOCK-FIND-OPERATION PIC X(04).
05 UT-MOCK-FIND-CALL-TOKENS.
10 UT-MOCK-FIND-CALL-TOKEN OCCURS 25 PIC X(31).
05 UT-MOCK-FIND-CICS-KEYWORDS.
10 UT-MOCK-FIND-CICS-KEYWORD OCCURS 25 PIC X(31).
05 UT-MOCK-SET-RECORD PIC X(2048).
05 UT-MOCK-SET-FILE-STATUS PIC X(02).
05 UT-MOCK-MAX PIC 9(02) VALUE 10.
05 UT-MOCK-COUNT PIC 9(02) VALUE ZERO.
05 UT-MOCK OCCURS 20 INDEXED BY UT-MOCK-IX.
10 UT-MOCK-TYPE PIC X(04).
88 UT-MOCK-FILE VALUE 'FILE'.
88 UT-MOCK-CALL VALUE 'CALL'.
88 UT-MOCK-CICS VALUE 'CICS'.
88 UT-MOCK-SQL VALUE 'SQL'.
88 UT-MOCK-PARA VALUE 'PARA'.
10 UT-MOCK-ACCESS-COUNT PIC 9(04) VALUE ZERO.
10 UT-MOCK-RECORD PIC X(8192).
10 UT-MOCK-DATA PIC X(806).
10 UT-MOCK-FILE-DATA REDEFINES UT-MOCK-DATA.
15 UT-MOCK-FILENAME PIC X(31).
15 UT-MOCK-OPERATION PIC X(20).
15 UT-MOCK-FILE-STATUS PIC X(02).
15 FILLER PIC X(753).
10 UT-MOCK-CALL-DATA REDEFINES UT-MOCK-DATA.
15 UT-MOCK-CALL-TOKENS-KEY PIC X(806).
10 UT-MOCK-CICS-DATA REDEFINES UT-MOCK-DATA.
15 UT-MOCK-CICS-KEYWORDS-KEY PIC X(806).
10 UT-MOCK-PARA-DATA REDEFINES UT-MOCK-DATA.
15 UT-MOCK-PARA-NAME PIC X(31).
15 FILLER PIC X(775).
10 UT-MOCK-SQL-DATA REDEFINES UT-MOCK-DATA.
15 FILLER PIC X(806).
01 UT-FILES.
05 UT-FILE-MAX PIC 9(02) VALUE 10.
05 UT-FILE-COUNT PIC 9(02) VALUE ZERO.
05 FILLER PIC X(01) VALUE SPACE.
88 UT-FILENAME-MATCHED VALUE 'Y'.
88 UT-FILENAME-NOT-MATCHED VALUE 'N'.
05 UT-FILE-INFORMATION.
10 FILLER OCCURS 10 INDEXED BY UT-FILE-IX.
15 UT-INTERNAL-FILENAME PIC X(31).
15 UT-RECORD-FIELD-NAME PIC X(31).
15 UT-FILE-STATUS-FIELD-NAME PIC X(31).
* ZUTZCWS.CPY END
01 FILLER.
05 FILLER PIC X VALUE 'G'.
88 MESSAGE-IS-GREETING VALUE 'G'.
88 MESSAGE-IS-FAREWELL VALUE 'F'.
05 WS-FRIEND PIC X(10) VALUE SPACES.
05 WS-GREETING.
10 FILLER PIC X(07) VALUE 'Hello, '.
10 WS-USER-NAME PIC X(10) VALUE SPACES.
10 FILLER PIC X VALUE '!'.
05 WS-FAREWELL.
10 FILLER PIC X(15) VALUE 'See you later, '.
10 WS-USER-NAME PIC X(09) VALUE SPACES.
10 FILLER PIC X VALUE '!'.
PROCEDURE DIVISION.
PERFORM UT-INITIALIZE
DISPLAY "TESTSUITE:"
DISPLAY "Greeting returns the appropriate message based on me
- "ssage type"
MOVE "When message type is greeting it returns 'Hello, World!
- "'"
TO UT-TEST-CASE-NAME
PERFORM UT-BEFORE
SET MESSAGE-IS-GREETING TO TRUE
PERFORM 2000-SPEAK
ADD 1 TO UT-TEST-CASE-COUNT
SET UT-NORMAL-COMPARE TO TRUE
MOVE WS-GREETING TO UT-ACTUAL
MOVE "Hello, World !"
TO UT-EXPECTED
SET UT-COMPARE-DEFAULT TO TRUE
PERFORM UT-ASSERT-EQUAL
PERFORM UT-AFTER
MOVE "When message type is farewell it returns See you later,
- " alligator!"
TO UT-TEST-CASE-NAME
PERFORM UT-BEFORE
SET MESSAGE-IS-FAREWELL TO TRUE
PERFORM 2000-SPEAK
ADD 1 TO UT-TEST-CASE-COUNT
SET UT-NORMAL-COMPARE TO TRUE
MOVE WS-FAREWELL TO UT-ACTUAL
MOVE "See you later, alligator!"
TO UT-EXPECTED
SET UT-COMPARE-DEFAULT TO TRUE
PERFORM UT-ASSERT-EQUAL
PERFORM UT-AFTER
* ZUTZCPD.CPY
DISPLAY SPACE
MOVE UT-TEST-CASE-COUNT TO UT-TEST-CASE-NUMBER
DISPLAY UT-TEST-CASE-NUMBER ' TEST CASES WERE EXECUTED'
MOVE UT-NUMBER-PASSED TO UT-TEST-CASE-NUMBER
DISPLAY UT-TEST-CASE-NUMBER ' PASSED'
MOVE UT-NUMBER-FAILED TO UT-TEST-CASE-NUMBER
DISPLAY UT-TEST-CASE-NUMBER ' FAILED'
DISPLAY "================================================="
MOVE UT-RETCODE TO RETURN-CODE
GOBACK.
UT-ASSERT-EQUAL.
*****************************************************************
* COMPARE EXPECTED AND ACTUAL VALUES FOR EQUALITY.
*****************************************************************
MOVE UT-TEST-CASE-COUNT TO UT-TEST-CASE-NUMBER
PERFORM UT-COMPARE
IF UT-COMPARE-PASSED
PERFORM UT-DISPLAY-PASSED
ELSE
PERFORM UT-DISPLAY-FAILED
END-IF
.
UT-COMPARE.
SET UT-COMPARE-FAILED TO TRUE
IF UT-COMPARE-NUMERIC
IF UT-ACTUAL-NUMERIC IS EQUAL TO UT-EXPECTED-NUMERIC
SET UT-COMPARE-PASSED TO TRUE
END-IF
ELSE
IF UT-ACTUAL IS EQUAL TO UT-EXPECTED
SET UT-COMPARE-PASSED TO TRUE
END-IF
END-IF
PERFORM UT-REVERSE-RESULT
.
UT-REVERSE-RESULT.
IF UT-REVERSE-COMPARE
IF UT-COMPARE-PASSED
SET UT-COMPARE-FAILED TO TRUE
ELSE
SET UT-COMPARE-PASSED TO TRUE
END-IF
END-IF
.
UT-DISPLAY-PASSED.
ADD 1 TO UT-NUMBER-PASSED
DISPLAY UT-PASSED
UT-TEST-CASE-NUMBER '. '
UT-TEST-CASE-NAME
.
UT-DISPLAY-FAILED.
ADD 1 TO UT-NUMBER-FAILED
DISPLAY UT-FAILED
UT-TEST-CASE-NUMBER '. '
UT-TEST-CASE-NAME
IF UT-COMPARE-NUMERIC
DISPLAY ' EXPECTED ' UT-EXPECTED-NUMERIC
', WAS ' UT-ACTUAL-NUMERIC
ELSE
DISPLAY ' EXPECTED <' UT-EXPECTED
'>, WAS <' UT-ACTUAL '>'
END-IF
MOVE 4 TO UT-RETCODE
.
UT-ASSERT-ACCESSES.
*****************************************************************
* COMPARE THE NUMBER OF ACCESSES TO A MOCK WITH THE EXPECTED
* NUMBER OF ACCESSES.
*****************************************************************
MOVE UT-TEST-CASE-COUNT TO UT-TEST-CASE-NUMBER
MOVE UT-ACTUAL-ACCESSES TO UT-ACTUAL-ACCESSES-FMT
MOVE UT-EXPECTED-ACCESSES TO UT-EXPECTED-ACCESSES-FMT
IF UT-EXPECTED-ACCESSES IS EQUAL TO 1
MOVE SPACES TO UT-LABEL-EXPECTED-ACCESS-PL
ELSE
MOVE UT-CONST-ES TO UT-LABEL-EXPECTED-ACCESS-PL
END-IF
SET UT-VERIFY-FAILED TO TRUE
EVALUATE TRUE
WHEN UT-VERIFY-AT-LEAST
IF UT-ACTUAL-ACCESSES IS GREATER THAN OR EQUAL TO
UT-EXPECTED-ACCESSES
SET UT-VERIFY-PASSED TO TRUE
END-IF
WHEN UT-VERIFY-NO-MORE-THAN
IF UT-ACTUAL-ACCESSES IS LESS THAN OR EQUAL TO
UT-EXPECTED-ACCESSES
SET UT-VERIFY-PASSED TO TRUE
END-IF
WHEN OTHER
IF UT-ACTUAL-ACCESSES IS EQUAL TO
UT-EXPECTED-ACCESSES
SET UT-VERIFY-PASSED TO TRUE
END-IF
END-EVALUATE
IF UT-VERIFY-PASSED
ADD 1 TO UT-NUMBER-PASSED
DISPLAY UT-PASSED
UT-TEST-CASE-NUMBER '. '
'VERIFY ' UT-EXPECTED-ACCESSES-FMT SPACE
UT-LABEL-EXPECTED-ACCESS
ELSE
ADD 1 TO UT-NUMBER-FAILED
MOVE SPACES TO UT-DISPLAY-MESSAGE
IF UT-MOCK-FILE(UT-MOCK-IX)
STRING
UT-FAILED DELIMITED BY SIZE
UT-TEST-CASE-NUMBER DELIMITED BY SIZE
'. VERIFY ACCESSES TO ' DELIMITED BY SIZE
UT-MOCK-OPERATION(UT-MOCK-IX) DELIMITED BY SPACE
' ON ' DELIMITED BY SIZE
UT-MOCK-FILENAME(UT-MOCK-IX) DELIMITED BY SPACE
' | EXPECTED ' DELIMITED BY SIZE
UT-EXPECTED-ACCESSES-FMT DELIMITED BY SIZE
SPACE DELIMITED BY SIZE
UT-LABEL-EXPECTED-ACCESS DELIMITED BY SPACE
', WAS ' DELIMITED BY SIZE
UT-ACTUAL-ACCESSES-FMT DELIMITED BY SIZE
INTO UT-DISPLAY-MESSAGE
END-STRING
ELSE
STRING
UT-FAILED DELIMITED BY SIZE
UT-TEST-CASE-NUMBER DELIMITED BY SIZE
'. VERIFY ACCESSES TO ' DELIMITED BY SIZE
UT-MOCK-CICS-KEYWORDS-KEY(UT-MOCK-IX)
DELIMITED BY SIZE
INTO UT-DISPLAY-MESSAGE
END-STRING
DISPLAY UT-DISPLAY-MESSAGE
MOVE SPACES TO UT-DISPLAY-MESSAGE
STRING
' EXPECTED ' DELIMITED BY SIZE
UT-EXPECTED-ACCESSES-FMT DELIMITED BY SIZE
SPACE DELIMITED BY SIZE
UT-LABEL-EXPECTED-ACCESS DELIMITED BY SPACE
', WAS ' DELIMITED BY SIZE
UT-ACTUAL-ACCESSES-FMT DELIMITED BY SIZE
INTO UT-DISPLAY-MESSAGE
END-STRING
END-IF
DISPLAY UT-DISPLAY-MESSAGE
MOVE 4 TO UT-RETCODE
END-IF
.
UT-SET-MOCK.
*****************************************************************
* CREATE OR UPDATE A MOCK SPECIFICATION.
*****************************************************************
EVALUATE TRUE
WHEN UT-FIND-FILE-MOCK
PERFORM UT-SET-FILE-MOCK
WHEN UT-FIND-CALL-MOCK
PERFORM UT-SET-CALL-MOCK
WHEN UT-FIND-CICS-MOCK
PERFORM UT-SET-CICS-MOCK
WHEN UT-FIND-PARA-MOCK
PERFORM UT-SET-PARA-MOCK
END-EVALUATE
.
UT-SET-FILE-MOCK.
PERFORM UT-LOOKUP-MOCK
IF UT-MOCK-FOUND
CONTINUE
ELSE
ADD 1 TO UT-MOCK-COUNT
SET UT-MOCK-IX TO UT-MOCK-COUNT
SET UT-MOCK-FILE(UT-MOCK-IX) TO TRUE
MOVE UT-MOCK-FIND-FILENAME
TO UT-MOCK-FILENAME(UT-MOCK-IX)
MOVE UT-MOCK-FIND-OPERATION
TO UT-MOCK-OPERATION(UT-MOCK-IX)
END-IF
MOVE UT-MOCK-SET-RECORD
TO UT-MOCK-RECORD(UT-MOCK-IX)
MOVE UT-MOCK-SET-FILE-STATUS
TO UT-MOCK-FILE-STATUS(UT-MOCK-IX)
.
UT-SET-CALL-MOCK.
PERFORM UT-LOOKUP-MOCK
IF UT-MOCK-FOUND
CONTINUE
ELSE
ADD 1 TO UT-MOCK-COUNT
SET UT-MOCK-IX TO UT-MOCK-COUNT
MOVE UT-MOCK-FIND-CALL-TOKENS
TO UT-MOCK-CALL-TOKENS-KEY(UT-MOCK-IX)
END-IF
.
UT-SET-CICS-MOCK.
PERFORM UT-LOOKUP-MOCK
IF UT-MOCK-FOUND
CONTINUE
ELSE
ADD 1 TO UT-MOCK-COUNT
SET UT-MOCK-IX TO UT-MOCK-COUNT
MOVE UT-MOCK-FIND-CICS-KEYWORDS
TO UT-MOCK-CICS-KEYWORDS-KEY(UT-MOCK-IX)
END-IF
.
UT-SET-PARA-MOCK.
PERFORM UT-LOOKUP-MOCK
IF UT-MOCK-FOUND
CONTINUE
ELSE
ADD 1 TO UT-MOCK-COUNT
SET UT-MOCK-IX TO UT-MOCK-COUNT
MOVE UT-MOCK-FIND-PARA-NAME
TO UT-MOCK-PARA-NAME(UT-MOCK-IX)
END-IF
.
UT-LOOKUP-MOCK.
*****************************************************************
* LOOK UP A MOCK SPECIFICATION.
*****************************************************************
SET UT-MOCK-NOT-FOUND TO TRUE
PERFORM VARYING UT-MOCK-IX FROM 1 BY 1
UNTIL UT-MOCK-IX IS GREATER THAN UT-MOCK-MAX
OR UT-MOCK-FOUND
EVALUATE TRUE
WHEN UT-FIND-FILE-MOCK
IF UT-MOCK-FIND-FILENAME IS EQUAL TO
UT-MOCK-FILENAME(UT-MOCK-IX)
AND UT-MOCK-FIND-OPERATION IS EQUAL TO
UT-MOCK-OPERATION(UT-MOCK-IX)
SET UT-MOCK-FOUND TO TRUE
CONTINUE
END-IF
WHEN UT-FIND-CALL-MOCK
IF UT-MOCK-FIND-CALL-TOKENS IS EQUAL TO
UT-MOCK-CALL-TOKENS-KEY(UT-MOCK-IX)
SET UT-MOCK-FOUND TO TRUE
CONTINUE
END-IF
WHEN UT-FIND-CICS-MOCK
IF UT-MOCK-FIND-CICS-KEYWORDS IS EQUAL TO
UT-MOCK-CICS-KEYWORDS-KEY(UT-MOCK-IX)
SET UT-MOCK-FOUND TO TRUE
CONTINUE
END-IF
WHEN UT-FIND-PARA-MOCK
IF UT-MOCK-FIND-PARA-NAME IS EQUAL TO
UT-MOCK-PARA-NAME(UT-MOCK-IX)
SET UT-MOCK-FOUND TO TRUE
CONTINUE
END-IF
END-EVALUATE
END-PERFORM
SET UT-MOCK-IX DOWN BY 1
.
UT-LOOKUP-FILE.
*****************************************************************
* LOOK UP A FILE SPECIFICATION.
*****************************************************************
PERFORM VARYING UT-FILE-IX FROM 1 BY 1
UNTIL UT-FILE-IX GREATER UT-FILE-MAX
OR UT-INTERNAL-FILENAME(UT-FILE-IX)
EQUAL UT-MOCK-FIND-FILENAME
CONTINUE
END-PERFORM
SET UT-FILE-IX DOWN BY 1
.
UT-BEFORE.
.
UT-AFTER.
.
UT-INITIALIZE.
MOVE SPACES TO UT-FILE-INFORMATION
.
UT-END.
* ZUTZCPD.CPY END
ACCEPT WS-FRIEND.
2000-SPEAK.
IF MESSAGE-IS-GREETING
IF WS-FRIEND EQUALS SPACES
MOVE 'World' TO WS-USER-NAME OF WS-GREETING
ELSE
MOVE WS-FRIEND TO WS-USER-NAME OF WS-GREETING
END-IF
END-IF
IF MESSAGE-IS-FAREWELL
IF WS-FRIEND EQUALS SPACES
MOVE 'alligator!' TO WS-USER-NAME OF WS-FAREWELL
ELSE
MOVE WS-FRIEND TO WS-USER-NAME OF WS-FAREWELL
END-IF
END-IF
.
9999-END.
.