1
{****************************************************************}
2
{ CODE GENERATOR TEST PROGRAM }
3
{ By Carl Eric Codere }
4
{****************************************************************}
5
{ NODE TESTED : secondtryexcept() }
7
{****************************************************************}
8
{ PRE-REQUISITES: secondload() }
14
{****************************************************************}
16
{ FPC = Target is FreePascal compiler }
17
{****************************************************************}
18
{ REMARKS : Tested with Delphi 3 as reference implementation }
19
{****************************************************************}
27
TAObject = class(TObject)
30
TBObject = Class(TObject)
32
constructor create(c: longint);
36
{ The test cases were taken from the SAL internal architecture manual }
45
global_counter : integer;
48
constructor tbobject.create(c:longint);
55
Procedure raiseanexception;
61
{ Writeln ('Creating exception object');}
63
{ Writeln ('Raising with this object');}
65
{ this should never happen, if it does there is a problem! }
70
procedure IncrementCounter(x: integer);
75
procedure DecrementCounter(x: integer);
81
Function DoTryExceptOne: boolean;
85
Write('Try..Except clause...');
88
DoTryExceptOne := failed;
90
IncrementCounter(global_counter);
91
DecrementCounter(global_counter);
94
if global_counter = 0 then
96
DoTryExceptOne := failed;
100
Function DoTryExceptTwo : boolean;
104
Write('Try..Except with break statement...');
107
DoTryExceptTwo := failed;
111
IncrementCounter(global_counter);
112
DecrementCounter(global_counter);
117
if global_counter = 0 then
119
DoTryExceptTwo := failed;
125
Function DoTryExceptFour: boolean;
129
Write('Try..Except with exit statement...');
132
DoTryExceptFour := failed;
136
IncrementCounter(global_counter);
137
DecrementCounter(global_counter);
138
DoTryExceptFour := false;
146
Function DoTryExceptFive: boolean;
151
Write('Try..Except nested clauses (three-level nesting)...');
154
DoTryExceptFive := failed;
157
IncrementCounter(global_counter);
159
DecrementCounter(global_counter);
160
IncrementCounter(global_counter);
162
DecrementCounter(global_counter);
171
if (global_counter = 0) then
173
DoTryExceptFive := failed;
177
Function DoTryExceptSix : boolean;
182
Write('Try..Except nested clauses with break statement...');
186
DoTryExceptSix := failed;
190
IncrementCounter(global_counter);
192
DecrementCounter(global_counter);
193
IncrementCounter(global_counter);
195
DecrementCounter(global_counter);
206
if (global_counter = 0) then
208
DoTryExceptSix := failed;
212
Function DoTryExceptEight : boolean;
217
Write('Try..Except nested clauses with exit statement...');
221
DoTryExceptEight := failed;
225
IncrementCounter(global_counter);
227
DecrementCounter(global_counter);
228
IncrementCounter(global_counter);
230
DecrementCounter(global_counter);
231
DoTryExceptEight := false;
245
Function DoTryExceptNine : boolean;
250
Write('Try..Except nested clauses with break statement in other try-block...');
254
DoTryExceptNine := failed;
259
IncrementCounter(global_counter);
261
DecrementCounter(global_counter);
262
IncrementCounter(global_counter);
264
DecrementCounter(global_counter);
276
{ normally this should execute! }
277
DoTryExceptNine := failed;
279
if (global_counter = 0) and (x = 0) then
281
DoTryExceptNine := failed;
285
{****************************************************************************}
287
{***************************************************************************}
288
{ Exception is thrown }
289
{***************************************************************************}
290
Function DoTryExceptTen: boolean;
294
Write('Try..Except clause with raise...');
297
DoTryExceptTen := failed;
299
IncrementCounter(global_counter);
301
DecrementCounter(global_counter);
303
if global_counter = 1 then
305
DoTryExceptTen := failed;
309
Function DoTryExceptEleven : boolean;
313
Write('Try..Except with raise and break statement...');
316
DoTryExceptEleven := failed;
320
IncrementCounter(global_counter);
321
DecrementCounter(global_counter);
325
if global_counter = 0 then
327
DoTryExceptEleven := failed;
332
Function DoTryExceptTwelve: boolean;
337
Write('Try..Except nested clauses (three-level nesting)...');
340
DoTryExceptTwelve := failed;
343
IncrementCounter(global_counter);
345
DecrementCounter(global_counter);
346
IncrementCounter(global_counter);
348
DecrementCounter(global_counter);
351
if (global_counter = 0) then
353
DoTryExceptTwelve := failed;
356
DoTryExceptTwelve := true;
359
DoTryExceptTwelve := true;
364
Function DoTryExceptThirteen: boolean;
369
Write('Try..Except nested clauses (three-level nesting)...');
372
DoTryExceptThirteen := failed;
375
IncrementCounter(global_counter);
377
DecrementCounter(global_counter);
378
IncrementCounter(global_counter);
381
DecrementCounter(global_counter);
383
DoTryExceptThirteen := true;
386
if (global_counter = 1) then
388
DoTryExceptThirteen := failed;
391
DoTryExceptThirteen := true;
395
{***************************************************************************}
396
{ Exception is thrown in except block }
397
{***************************************************************************}
398
Function DoTryExceptFourteen: boolean;
403
Write('Try..Except nested clauses with single re-raise...');
406
DoTryExceptFourteen := failed;
409
IncrementCounter(global_counter);
411
DecrementCounter(global_counter);
412
IncrementCounter(global_counter);
414
DecrementCounter(global_counter);
417
{ raise to next block }
421
if (global_counter = 0) then
423
DoTryExceptFourteen := failed;
426
DoTryExceptFourteen := true;
432
Function DoTryExceptFifteen: boolean;
437
Write('Try..Except nested clauses with re-reraises (1)...');
440
DoTryExceptFifteen := failed;
443
IncrementCounter(global_counter);
445
DecrementCounter(global_counter);
446
IncrementCounter(global_counter);
448
DecrementCounter(global_counter);
451
{ raise to next block }
455
{ re-raise to next block }
459
if (global_counter = 0) then
461
DoTryExceptFifteen := failed;
465
procedure nestedtryblock(var global_counter: integer);
467
IncrementCounter(global_counter);
469
DecrementCounter(global_counter);
470
IncrementCounter(global_counter);
472
DecrementCounter(global_counter);
475
{ raise to next block }
479
{ re-raise to next block }
485
Function DoTryExceptSixteen: boolean;
490
Write('Try..Except nested clauses with re-reraises (2)...');
493
DoTryExceptSixteen := failed;
496
NestedTryBlock(global_counter);
498
if (global_counter = 0) then
500
DoTryExceptSixteen := failed;
505
Function DoTryExceptSeventeen: boolean;
510
Write('Try..Except nested clauses with raises...');
513
DoTryExceptSeventeen := failed;
516
IncrementCounter(global_counter);
518
DecrementCounter(global_counter);
519
IncrementCounter(global_counter);
521
DecrementCounter(global_counter);
524
{ raise to next block }
525
raise TAObject.Create;
528
{ re-raise to next block }
529
raise TBObject.Create(1234);
532
if (global_counter = 0) then
534
DoTryExceptSeventeen := failed;
538
{***************************************************************************}
539
{ Exception flow control in except block }
540
{***************************************************************************}
541
Function DoTryExceptEighteen: boolean;
545
Write('Try..Except clause with raise with break in except block...');
548
DoTryExceptEighteen := failed;
552
IncrementCounter(global_counter);
554
DecrementCounter(global_counter);
556
if global_counter = 1 then
558
DoTryExceptEighteen := failed;
565
Function DoTryExceptNineteen: boolean;
569
Write('Try..Except clause with raise with exit in except block...');
572
DoTryExceptNineteen := failed;
576
IncrementCounter(global_counter);
578
DecrementCounter(global_counter);
580
if global_counter = 1 then
582
DoTryExceptNineteen := failed;
589
Function DoTryExceptTwenty: boolean;
594
Write('Try..Except nested clauses with raises with break in inner try...');
597
DoTryExceptTwenty := failed;
600
IncrementCounter(global_counter);
604
DecrementCounter(global_counter);
605
IncrementCounter(global_counter);
607
DecrementCounter(global_counter);
610
{ raise to next block }
611
raise TAObject.Create;
616
{ re-raise to next block }
617
raise TBObject.Create(1234);
620
if (global_counter = 0) then
622
DoTryExceptTwenty := failed;
627
Function DoTryExceptTwentyOne: boolean;
632
Write('Try..Except nested clauses with raises with continue in inner try...');
635
DoTryExceptTwentyOne := failed;
638
IncrementCounter(global_counter);
642
DecrementCounter(global_counter);
643
IncrementCounter(global_counter);
645
DecrementCounter(global_counter);
648
{ raise to next block }
649
raise TAObject.Create;
655
{ re-raise to next block }
656
raise TBObject.Create(1234);
659
if (global_counter = 0) then
661
DoTryExceptTwentyOne := failed;
666
Function DoTryExceptTwentyTwo: boolean;
671
Write('Try..Except nested clauses with raises with exit in inner try...');
674
DoTryExceptTwentyTwo := failed;
677
IncrementCounter(global_counter);
681
DecrementCounter(global_counter);
682
IncrementCounter(global_counter);
684
DecrementCounter(global_counter);
687
{ raise to next block }
688
raise TAObject.Create;
693
{ re-raise to next block }
694
raise TBObject.Create(1234);
697
if (global_counter = 0) then
699
DoTryExceptTwentyTwo := failed;
707
failed := DoTryExceptOne;
712
failed := DoTryExceptTwo;
717
{ failed := DoTryExceptThree;
721
WriteLn('Success!');}
722
failed := DoTryExceptFour;
727
failed := DoTryExceptFive;
732
failed := DoTryExceptSix;
737
{ failed := DoTryExceptSeven;
741
WriteLn('Success!');}
742
failed := DoTryExceptEight;
747
failed := DoTryExceptNine;
752
(************************ Exceptions are created from here ****************************)
753
failed := DoTryExceptTen;
758
failed := DoTryExceptEleven;
763
failed := DoTryExceptTwelve;
768
failed := DoTryExceptThirteen;
773
(************************ Exceptions in except block ****************************)
774
failed := DoTryExceptFourteen;
779
failed := DoTryExceptFifteen;
784
failed := DoTryExceptSixteen;
789
failed := DoTryExceptSeventeen;
794
failed := DoTryExceptEighteen;
799
failed := DoTryExceptNineteen;
804
failed := DoTryExceptTwenty;
809
failed := DoTryExceptTwentyOne;
814
failed := DoTryExceptTwentyTwo;