3 -- Grant of Unlimited Rights
5 -- The Ada Conformity Assessment Authority (ACAA) holds unlimited
6 -- rights in the software and documentation contained herein. Unlimited
7 -- rights are the same as those granted by the U.S. Government for older
8 -- parts of the Ada Conformity Assessment Test Suite, and are defined
9 -- in DFAR 252.227-7013(a)(19). By making this public release, the ACAA
10 -- intends to confer upon all recipients unlimited rights equal to those
11 -- held by the ACAA. These rights include rights to use, duplicate,
12 -- release or disclose the released technical data and computer software
13 -- in whole or in part, in any manner and for any purpose whatsoever, and
14 -- to have or permit others to do so.
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 if a Finalize propagates an exception, other Finalizes due
28 -- to be performed are performed.
29 -- Case 1: A Finalize invoked due to the end of execution of
30 -- a master. (Defect Report 8652/0023, as reflected in Technical
32 -- Case 2: A Finalize invoked due to finalization of an anonymous
33 -- object. (Defect Report 8652/0023, as reflected in Technical
35 -- Case 3: A Finalize invoked due to the transfer of control
36 -- due to an exit statement.
37 -- Case 4: A Finalize invoked due to the transfer of control
38 -- due to a goto statement.
39 -- Case 5: A Finalize invoked due to the transfer of control
40 -- due to a return statement.
41 -- Case 6: A Finalize invoked due to the transfer of control
42 -- due to raises an exception.
46 -- 29 JAN 2001 PHL Initial version
47 -- 15 MAR 2001 RLB Readied for release; added optimization blockers.
48 -- Added test cases for paragraphs 18 and 19 of the
49 -- standard (the previous tests were withdrawn).
52 with Ada
.Finalization
;
56 type Ctrl
(D
: Boolean) is new Ada
.Finalization
.Controlled
with
58 Finalized
: Boolean := False;
67 function Create
(Id
: Integer) return Ctrl
;
68 procedure Finalize
(Obj
: in out Ctrl
);
69 function Was_Finalized
(Id
: Integer) return Boolean;
70 procedure Use_It
(Obj
: in Ctrl
);
71 -- Use Obj to prevent optimization.
77 package body C761011_0
is
79 User_Error
: exception;
81 Finalize_Called
: array (0 .. 50) of Boolean := (others => False);
83 function Create
(Id
: Integer) return Ctrl
is
84 Obj
: Ctrl
(Boolean'Val (Id
mod Ident_Int
(2)));
88 Obj
.C1
:= Ident_Int
(Id
);
90 Obj
.C2
:= Float (Ident_Int
(Id
+ Ident_Int
(Id
)));
95 procedure Finalize
(Obj
: in out Ctrl
) is
97 if not Obj
.Finalized
then
98 Obj
.Finalized
:= True;
100 if Integer (Obj
.C2
/ 2.0) mod Ident_Int
(10) =
104 Finalize_Called
(Integer (Obj
.C2
) / 2) := True;
107 if Obj
.C1
mod Ident_Int
(10) = Ident_Int
(0) then
110 Finalize_Called
(Obj
.C1
) := True;
116 function Was_Finalized
(Id
: Integer) return Boolean is
118 return Finalize_Called
(Ident_Int
(Id
));
121 procedure Use_It
(Obj
: in Ctrl
) is
122 -- Use Obj to prevent optimization.
126 if not Equal
(Boolean'Pos(Obj
.Finalized
),
127 Boolean'Pos(Obj
.Finalized
)) then
128 Failed
("Identity check - 1");
131 if not Equal
(Obj
.C1
, Obj
.C1
) then
132 Failed
("Identity check - 2");
141 with Ada
.Finalization
;
150 " Check that if a finalize propagates an exception, other finalizes " &
151 "due to be performed are performed");
156 Obj1
: Ctrl
:= Create
(Ident_Int
(1));
157 Obj2
: constant Ctrl
:= (Ada
.Finalization
.Controlled
with
159 Finalized
=> Ident_Bool
(False),
160 C1
=> Ident_Int
(2));
162 (Ada
.Finalization
.Controlled
with
164 Finalized
=> Ident_Bool
(False),
165 C2
=> 2.0 * Float (Ident_Int
166 (3))); -- Finalization: User_Error
167 Obj4
: Ctrl
:= Create
(Ident_Int
(4));
169 Comment
("Finalization of normal object");
170 Use_It
(Obj1
); -- Prevent optimization of Objects.
171 Use_It
(Obj2
); -- (Critical if AI-147 is adopted.)
175 Failed
("No exception raised by finalization of normal object");
177 when Program_Error
=>
178 if not Was_Finalized
(Ident_Int
(1)) or
179 not Was_Finalized
(Ident_Int
(2)) or
180 not Was_Finalized
(Ident_Int
(4)) then
181 Failed
("Missing finalizations - 1");
184 Failed
("Exception " & Exception_Name
(E
) &
185 " raised - " & Exception_Message
(E
) & " - 1");
191 Obj1
: Ctrl
:= (Ada
.Finalization
.Controlled
with
193 Finalized
=> Ident_Bool
(False),
194 C2
=> 2.0 * Float (Ident_Int
(5)));
195 Obj2
: constant Ctrl
:= (Ada
.Finalization
.Controlled
with
197 Finalized
=> Ident_Bool
(False),
198 C1
=> Ident_Int
(6));
199 Obj3
: Ctrl
:= (Ada
.Finalization
.Controlled
with
201 Finalized
=> Ident_Bool
(False),
202 C2
=> 2.0 * Float (Ident_Int
(7)));
203 Obj4
: Ctrl
:= Create
(Ident_Int
(8));
205 Comment
("Finalization of anonymous object");
207 -- The finalization of the anonymous object below will raise
209 if Create
(Ident_Int
(10)).C1
/= Ident_Int
(10) then
210 Failed
("Incorrect construction of an anonymous object");
212 Failed
("Anonymous object not finalized at the end of the " &
213 "enclosing statement");
214 Use_It
(Obj1
); -- Prevent optimization of Objects.
215 Use_It
(Obj2
); -- (Critical if AI-147 is adopted.)
219 Failed
("No exception raised by finalization of an anonymous " &
220 "object of a function");
222 when Program_Error
=>
223 if not Was_Finalized
(Ident_Int
(5)) or
224 not Was_Finalized
(Ident_Int
(6)) or
225 not Was_Finalized
(Ident_Int
(7)) or
226 not Was_Finalized
(Ident_Int
(8)) then
227 Failed
("Missing finalizations - 2");
230 Failed
("Exception " & Exception_Name
(E
) &
231 " raised - " & Exception_Message
(E
) & " - 2");
236 for Counter
in 1 .. 4 loop
238 Obj1
: Ctrl
:= Create
(Ident_Int
(11));
239 Obj2
: constant Ctrl
:= (Ada
.Finalization
.Controlled
with
241 Finalized
=> Ident_Bool
(False),
242 C1
=> Ident_Int
(12));
244 (Ada
.Finalization
.Controlled
with
246 Finalized
=> Ident_Bool
(False),
248 Ident_Int
(13))); -- Finalization: User_Error
249 Obj4
: Ctrl
:= Create
(Ident_Int
(14));
251 Comment
("Finalization because of exit of loop");
253 Use_It
(Obj1
); -- Prevent optimization of Objects.
254 Use_It
(Obj2
); -- (Critical if AI-147 is adopted.)
258 exit when not Ident_Bool
(Obj2
.D
);
260 Failed
("Exit not taken");
263 Failed
("No exception raised by finalization on exit");
265 when Program_Error
=>
266 if not Was_Finalized
(Ident_Int
(11)) or
267 not Was_Finalized
(Ident_Int
(12)) or
268 not Was_Finalized
(Ident_Int
(14)) then
269 Failed
("Missing finalizations - 3");
272 Failed
("Exception " & Exception_Name
(E
) &
273 " raised - " & Exception_Message
(E
) & " - 3");
279 Obj1
: Ctrl
:= Create
(Ident_Int
(15));
280 Obj2
: constant Ctrl
:= (Ada
.Finalization
.Controlled
with
282 Finalized
=> Ident_Bool
(False),
283 C1
=> Ident_Int
(0));
284 -- Finalization: Tasking_Error
285 Obj3
: Ctrl
:= Create
(Ident_Int
(16));
286 Obj4
: Ctrl
:= (Ada
.Finalization
.Controlled
with
288 Finalized
=> Ident_Bool
(False),
289 C2
=> 2.0 * Float (Ident_Int
(17)));
291 Comment
("Finalization because of goto statement");
293 Use_It
(Obj1
); -- Prevent optimization of Objects.
294 Use_It
(Obj2
); -- (Critical if AI-147 is adopted.)
298 if Ident_Bool
(Obj4
.D
) then
302 Failed
("Goto not taken");
305 Failed
("No exception raised by finalization on goto");
307 when Program_Error
=>
308 if not Was_Finalized
(Ident_Int
(15)) or
309 not Was_Finalized
(Ident_Int
(16)) or
310 not Was_Finalized
(Ident_Int
(17)) then
311 Failed
("Missing finalizations - 4");
314 Failed
("Exception " & Exception_Name
(E
) &
315 " raised - " & Exception_Message
(E
) & " - 4");
320 procedure Do_Something
is
321 Obj1
: Ctrl
:= Create
(Ident_Int
(18));
322 Obj2
: Ctrl
:= (Ada
.Finalization
.Controlled
with
324 Finalized
=> Ident_Bool
(False),
325 C2
=> 2.0 * Float (Ident_Int
(19)));
326 Obj3
: constant Ctrl
:= (Ada
.Finalization
.Controlled
with
328 Finalized
=> Ident_Bool
(False),
329 C1
=> Ident_Int
(20));
330 -- Finalization: Tasking_Error
332 Comment
("Finalization because of return statement");
334 Use_It
(Obj1
); -- Prevent optimization of Objects.
335 Use_It
(Obj2
); -- (Critical if AI-147 is adopted.)
338 if not Ident_Bool
(Obj3
.D
) then
342 Failed
("Return not taken");
346 Failed
("No exception raised by finalization on return statement");
348 when Program_Error
=>
349 if not Was_Finalized
(Ident_Int
(18)) or
350 not Was_Finalized
(Ident_Int
(19)) then
351 Failed
("Missing finalizations - 5");
354 Failed
("Exception " & Exception_Name
(E
) &
355 " raised - " & Exception_Message
(E
) & " - 5");
360 Funky_Error
: exception;
362 procedure Do_Something
is
364 (Ada
.Finalization
.Controlled
with
366 Finalized
=> Ident_Bool
(False),
368 Ident_Int
(23))); -- Finalization: User_Error
369 Obj2
: Ctrl
:= Create
(Ident_Int
(24));
370 Obj3
: Ctrl
:= Create
(Ident_Int
(25));
371 Obj4
: constant Ctrl
:= (Ada
.Finalization
.Controlled
with
373 Finalized
=> Ident_Bool
(False),
374 C1
=> Ident_Int
(26));
376 Comment
("Finalization because of exception propagation");
378 Use_It
(Obj1
); -- Prevent optimization of Objects.
379 Use_It
(Obj2
); -- (Critical if AI-147 is adopted.)
383 if not Ident_Bool
(Obj4
.D
) then
387 Failed
("Exception not raised");
391 Failed
("No exception raised by finalization on exception " &
394 when Program_Error
=>
395 if not Was_Finalized
(Ident_Int
(24)) or
396 not Was_Finalized
(Ident_Int
(25)) or
397 not Was_Finalized
(Ident_Int
(26)) then
398 Failed
("Missing finalizations - 6");
401 Failed
("Wrong exception propagated");
402 -- Should be Program_Error (7.6.1(19)).
404 Failed
("Exception " & Exception_Name
(E
) &
405 " raised - " & Exception_Message
(E
) & " - 6");