3 -- Grant of Unlimited Rights
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
27 -- Check that explicit calls to Initialize, Adjust and Finalize
28 -- procedures that raise exceptions propagate the exception raised,
29 -- not Program_Error. Check this for both a user defined exception
30 -- and a language defined exception. Check that implicit calls to
31 -- initialize procedures that raise an exception propagate the
32 -- exception raised, not Program_Error;
34 -- Check that the utilization of a controlled type as the actual for
35 -- a generic formal tagged private parameter supports the correct
36 -- behavior in the instantiated software.
39 -- Declares a generic package instantiated to check that controlled
40 -- types are not impacted by the "generic boundary."
41 -- This instance is then used to perform the tests of various calls to
42 -- the procedures. After each operation in the main program that should
43 -- cause implicit calls where an exception is raised, the program handles
44 -- Program_Error. After each explicit call, the program handles the
45 -- Expected_Error. Handlers for the opposite exception are provided to
46 -- catch the obvious failure modes. The predefined exception
47 -- Tasking_Error is used to be certain that some other reason has not
48 -- raised a predefined exception.
53 -- C760010_1.Simple_Control is derived from
54 -- Ada.Finalization.Controlled
56 -- C760010_2.Embedded_Derived is derived from C760010_1.Simple_Control
57 -- by way of generic instantiation
61 -- 01 MAY 95 SAIC Initial version
62 -- 23 APR 96 SAIC Fix visibility problem for 2.1
63 -- 14 NOV 96 SAIC Revisit for 2.1 release
64 -- 26 JUN 98 EDS Added pragma Elaborate_Body to
65 -- package C760010_0.Check_Formal_Tagged
66 -- to avoid possible instantiation error
69 ---------------------------------------------------------------- C760010_0
73 User_Defined_Exception
: exception;
75 type Actions
is ( No_Action
,
76 Init_Raise_User_Defined
, Init_Raise_Standard
,
77 Adj_Raise_User_Defined
, Adj_Raise_Standard
,
78 Fin_Raise_User_Defined
, Fin_Raise_Standard
);
80 Action
: Actions
:= No_Action
;
82 function Unique
return Natural;
86 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
88 package body C760010_0
is
90 Value
: Natural := 101;
92 function Unique
return Natural is
100 ---------------------------------------------------------------- C760010_0
101 ------------------------------------------------------ Check_Formal_Tagged
105 type Formal_Tagged
is tagged private;
107 package C760010_0
.Check_Formal_Tagged
is
109 pragma Elaborate_Body
;
111 type Embedded_Derived
is new Formal_Tagged
with record
112 TC_Meaningless_Value
: Natural := Unique
;
115 procedure Initialize
( ED
: in out Embedded_Derived
);
116 procedure Adjust
( ED
: in out Embedded_Derived
);
117 procedure Finalize
( ED
: in out Embedded_Derived
);
119 end C760010_0
.Check_Formal_Tagged
;
122 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
125 package body C760010_0
.Check_Formal_Tagged
is
128 procedure Initialize
( ED
: in out Embedded_Derived
) is
130 ED
.TC_Meaningless_Value
:= Unique
;
132 when Init_Raise_User_Defined
=> raise User_Defined_Exception
;
133 when Init_Raise_Standard
=> raise Tasking_Error
;
138 procedure Adjust
( ED
: in out Embedded_Derived
) is
140 ED
.TC_Meaningless_Value
:= Unique
;
142 when Adj_Raise_User_Defined
=> raise User_Defined_Exception
;
143 when Adj_Raise_Standard
=> raise Tasking_Error
;
148 procedure Finalize
( ED
: in out Embedded_Derived
) is
150 ED
.TC_Meaningless_Value
:= Unique
;
152 when Fin_Raise_User_Defined
=> raise User_Defined_Exception
;
153 when Fin_Raise_Standard
=> raise Tasking_Error
;
158 end C760010_0
.Check_Formal_Tagged
;
160 ---------------------------------------------------------------- C760010_1
162 with Ada
.Finalization
;
165 procedure Check_Counters
(Init
,Adj
,Fin
: Natural; Message
: String);
166 procedure Reset_Counters
;
168 type Simple_Control
is new Ada
.Finalization
.Controlled
with record
171 procedure Initialize
( AV
: in out Simple_Control
);
172 procedure Adjust
( AV
: in out Simple_Control
);
173 procedure Finalize
( AV
: in out Simple_Control
);
177 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
180 package body C760010_1
is
182 Initialize_Called
: Natural;
183 Adjust_Called
: Natural;
184 Finalize_Called
: Natural;
186 procedure Check_Counters
(Init
,Adj
,Fin
: Natural; Message
: String) is
188 if Init
/= Initialize_Called
then
189 Report
.Failed
("Initialize mismatch " & Message
);
191 if Adj
/= Adjust_Called
then
192 Report
.Failed
("Adjust mismatch " & Message
);
194 if Fin
/= Finalize_Called
then
195 Report
.Failed
("Finalize mismatch " & Message
);
199 procedure Reset_Counters
is
201 Initialize_Called
:= 0;
203 Finalize_Called
:= 0;
206 procedure Initialize
( AV
: in out Simple_Control
) is
208 Initialize_Called
:= Initialize_Called
+1;
212 procedure Adjust
( AV
: in out Simple_Control
) is
214 Adjust_Called
:= Adjust_Called
+1;
215 AV
.Item
:= AV
.Item
+1;
218 procedure Finalize
( AV
: in out Simple_Control
) is
220 Finalize_Called
:= Finalize_Called
+1;
221 AV
.Item
:= AV
.Item
+1;
226 ---------------------------------------------------------------- C760010_2
228 with C760010_0
.Check_Formal_Tagged
;
231 new C760010_0
.Check_Formal_Tagged
(C760010_1
.Simple_Control
);
233 ---------------------------------------------------------------------------
241 use type C760010_0
.Actions
;
243 procedure Case_Failure
(Message
: String) is
245 Report
.Failed
(Message
& " for case "
246 & C760010_0
.Actions
'Image(C760010_0
.Action
) );
249 procedure Check_Implicit_Initialize
is
250 Item
: C760010_2
.Embedded_Derived
; -- exception here propagates to
251 Gadget
: C760010_2
.Embedded_Derived
; -- caller
254 in C760010_0
.Init_Raise_User_Defined
..C760010_0
.Init_Raise_Standard
256 Case_Failure
("Anticipated exception at implicit init");
259 Item
:= Gadget
; -- exception here handled locally
260 if C760010_0
.Action
in C760010_0
.Adj_Raise_User_Defined
261 .. C760010_0
.Fin_Raise_Standard
then
262 Case_Failure
("Anticipated exception at assignment");
265 when Program_Error
=>
266 if C760010_0
.Action
not in C760010_0
.Adj_Raise_User_Defined
267 .. C760010_0
.Fin_Raise_Standard
then
268 Report
.Failed
("Program_Error in Check_Implicit_Initialize");
270 when Tasking_Error
=>
271 Report
.Failed
("Tasking_Error in Check_Implicit_Initialize");
272 when C760010_0
.User_Defined_Exception
=>
273 Report
.Failed
("User_Error in Check_Implicit_Initialize");
275 Report
.Failed
("Wrong exception Check_Implicit_Initialize");
277 end Check_Implicit_Initialize
;
279 ---------------------------------------------------------------------------
281 Global_Item
: C760010_2
.Embedded_Derived
;
283 ---------------------------------------------------------------------------
285 procedure Check_Explicit_Initialize
is
288 C760010_2
.Initialize
( Global_Item
);
290 in C760010_0
.Init_Raise_User_Defined
..C760010_0
.Init_Raise_Standard
292 Case_Failure
("Anticipated exception at explicit init");
295 when Program_Error
=>
296 Report
.Failed
("Program_Error in Check_Explicit_Initialize");
297 when Tasking_Error
=>
298 if C760010_0
.Action
/= C760010_0
.Init_Raise_Standard
then
299 Report
.Failed
("Tasking_Error in Check_Explicit_Initialize");
301 when C760010_0
.User_Defined_Exception
=>
302 if C760010_0
.Action
/= C760010_0
.Init_Raise_User_Defined
then
303 Report
.Failed
("User_Error in Check_Explicit_Initialize");
306 Report
.Failed
("Wrong exception in Check_Explicit_Initialize");
308 end Check_Explicit_Initialize
;
310 ---------------------------------------------------------------------------
312 procedure Check_Explicit_Adjust
is
315 C760010_2
.Adjust
( Global_Item
);
317 in C760010_0
.Adj_Raise_User_Defined
..C760010_0
.Adj_Raise_Standard
319 Case_Failure
("Anticipated exception at explicit Adjust");
322 when Program_Error
=>
323 Report
.Failed
("Program_Error in Check_Explicit_Adjust");
324 when Tasking_Error
=>
325 if C760010_0
.Action
/= C760010_0
.Adj_Raise_Standard
then
326 Report
.Failed
("Tasking_Error in Check_Explicit_Adjust");
328 when C760010_0
.User_Defined_Exception
=>
329 if C760010_0
.Action
/= C760010_0
.Adj_Raise_User_Defined
then
330 Report
.Failed
("User_Error in Check_Explicit_Adjust");
333 Report
.Failed
("Wrong exception in Check_Explicit_Adjust");
335 end Check_Explicit_Adjust
;
337 ---------------------------------------------------------------------------
339 procedure Check_Explicit_Finalize
is
342 C760010_2
.Finalize
( Global_Item
);
344 in C760010_0
.Fin_Raise_User_Defined
..C760010_0
.Fin_Raise_Standard
346 Case_Failure
("Anticipated exception at explicit Finalize");
349 when Program_Error
=>
350 Report
.Failed
("Program_Error in Check_Explicit_Finalize");
351 when Tasking_Error
=>
352 if C760010_0
.Action
/= C760010_0
.Fin_Raise_Standard
then
353 Report
.Failed
("Tasking_Error in Check_Explicit_Finalize");
355 when C760010_0
.User_Defined_Exception
=>
356 if C760010_0
.Action
/= C760010_0
.Fin_Raise_User_Defined
then
357 Report
.Failed
("User_Error in Check_Explicit_Finalize");
360 Report
.Failed
("Wrong exception in Check_Explicit_Finalize");
362 end Check_Explicit_Finalize
;
364 ---------------------------------------------------------------------------
366 begin -- Main test procedure.
368 Report
.Test
("C760010", "Check that explicit calls to finalization " &
369 "procedures that raise exceptions propagate " &
370 "the exception raised. Check the utilization " &
371 "of a controlled type as the actual for a " &
372 "generic formal tagged private parameter" );
374 for Act
in C760010_0
.Actions
loop
375 C760010_1
.Reset_Counters
;
376 C760010_0
.Action
:= Act
;
379 Check_Implicit_Initialize
;
381 C760010_0
.Init_Raise_User_Defined
..C760010_0
.Init_Raise_Standard
then
382 Case_Failure
("No exception at Check_Implicit_Initialize");
385 when Tasking_Error
=>
386 if Act
/= C760010_0
.Init_Raise_Standard
then
387 Case_Failure
("Tasking_Error at Check_Implicit_Initialize");
389 when C760010_0
.User_Defined_Exception
=>
390 if Act
/= C760010_0
.Init_Raise_User_Defined
then
391 Case_Failure
("User_Error at Check_Implicit_Initialize");
393 when Program_Error
=>
394 -- If finalize raises an exception, all other object are finalized
395 -- first and Program_Error is raised upon leaving the master scope.
397 if Act
not in C760010_0
.Fin_Raise_User_Defined
..
398 C760010_0
.Fin_Raise_Standard
then
399 Case_Failure
("Program_Error at Check_Implicit_Initialize");
402 Case_Failure
("Wrong exception at Check_Implicit_Initialize");
405 Check_Explicit_Initialize
;
406 Check_Explicit_Adjust
;
407 Check_Explicit_Finalize
;
409 C760010_1
.Check_Counters
(0,0,0, C760010_0
.Actions
'Image(Act
));
413 -- Set to No_Action to avoid exception in finalizing Global_Item
414 C760010_0
.Action
:= C760010_0
.No_Action
;