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 deriving abstract types from the types in Ada.Finalization
28 -- does not negatively impact the implicit operations.
29 -- Check that an object of a controlled type is finalized when the
30 -- enclosing master is complete.
31 -- Check that finalization occurs in the case where the master is
32 -- left by a transfer of control.
33 -- Check this for controlled types where the derived type has a
35 -- Check this for cases where the type is defined as private,
36 -- and the full type is derived from the types in Ada.Finalization.
38 -- Check that finalization of controlled objects is
39 -- performed in the correct order. In particular, check that if
40 -- multiple objects of controlled types are declared immediately
41 -- within the same declarative part then type are finalized in the
42 -- reverse order of their creation.
45 -- This test checks these conditions for subprograms and
46 -- block statements; both variables and constants of controlled
47 -- types; cases of a controlled component of a record type, as
48 -- well as an array with controlled components.
50 -- The base controlled types used for the test are defined
51 -- with a character discriminant. The initialize procedure for
52 -- the types will record the order of creation in a globally
53 -- accessible array, the finalize procedure for the types will call
54 -- TCTouch with that tag character. The test can then check that
55 -- the order of finalization is indeed the reverse of the order of
56 -- creation (assuming that the implementation calls Initialize in
57 -- the order that the objects are created).
61 -- 06 Dec 94 SAIC ACVC 2.0
62 -- 10 Oct 95 SAIC Fixed bugs for ACVC 2.0.1
66 package C761005_Support
is
68 function Pick_Char
return Character;
69 procedure Validate
(Initcount
: Natural; Testnumber
:Natural);
71 Inits_Order
: String(1..255);
72 Inits_Called
: Natural := 0;
78 package body C761005_Support
is
79 type Pick_Rotation
is mod 52;
80 type Pick_String
is array(Pick_Rotation
) of Character;
82 From
: constant Pick_String
:= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
83 & "abcdefghijklmnopqrstuvwxyz";
84 Recent_Pick
: Pick_Rotation
:= Pick_Rotation
'Last;
86 function Pick_Char
return Character is
88 Recent_Pick
:= Recent_Pick
+1;
89 return From
(Recent_Pick
);
92 function Invert
(S
:String) return String is
93 T
: String(1..S
'Length);
96 for SI
in reverse S
'Range loop
103 procedure Validate
(Initcount
: Natural; Testnumber
:Natural) is
104 Number
: constant String := Natural'Image(Testnumber
);
106 if Inits_Called
/= Initcount
then
107 Report
.Failed
("Wrong number of inits, Subtest " & Number
);
110 Invert
(Inits_Order
(1..Inits_Called
)),
111 "Subtest " & Number
, True);
118 -----------------------------------------------------------------------------
119 with Ada
.Finalization
;
121 type Final_Root
(Tag
: Character) is private;
123 type Ltd_Final_Root
(Tag
: Character) is limited private;
125 Inits_Order
: String(1..255);
126 Inits_Called
: Natural := 0;
128 type Final_Root
(Tag
: Character) is new Ada
.Finalization
.Controlled
130 procedure Initialize
( It
: in out Final_Root
);
131 procedure Finalize
( It
: in out Final_Root
);
133 type Ltd_Final_Root
(Tag
: Character) is new
134 Ada
.Finalization
.Limited_Controlled
136 procedure Initialize
( It
: in out Ltd_Final_Root
);
137 procedure Finalize
( It
: in out Ltd_Final_Root
);
140 -----------------------------------------------------------------------------
141 with Ada
.Finalization
;
143 type Final_Abstract
is abstract tagged private;
145 type Ltd_Final_Abstract_Child
is abstract tagged limited private;
147 Inits_Order
: String(1..255);
148 Inits_Called
: Natural := 0;
151 type Final_Abstract
is abstract new Ada
.Finalization
.Controlled
with record
154 procedure Initialize
( It
: in out Final_Abstract
);
155 procedure Finalize
( It
: in out Final_Abstract
);
157 type Ltd_Final_Abstract_Child
is
158 abstract new Ada
.Finalization
.Limited_Controlled
with record
161 procedure Initialize
( It
: in out Ltd_Final_Abstract_Child
);
162 procedure Finalize
( It
: in out Ltd_Final_Abstract_Child
);
166 -----------------------------------------------------------------------------
170 type Final_Child
is new C761005_1
.Final_Abstract
with null record;
171 type Ltd_Final_Child
is
172 new C761005_1
.Ltd_Final_Abstract_Child
with null record;
176 -----------------------------------------------------------------------------
179 with C761005_Support
;
180 package body C761005_0
is
182 package Sup
renames C761005_Support
;
184 procedure Initialize
( It
: in out Final_Root
) is
186 Sup
.Inits_Called
:= Sup
.Inits_Called
+1;
187 Sup
.Inits_Order
(Sup
.Inits_Called
) := It
.Tag
;
190 procedure Finalize
( It
: in out Final_Root
) is
192 TCTouch
.Touch
(It
.Tag
);
195 procedure Initialize
( It
: in out Ltd_Final_Root
) is
197 Sup
.Inits_Called
:= Sup
.Inits_Called
+1;
198 Sup
.Inits_Order
(Sup
.Inits_Called
) := It
.Tag
;
201 procedure Finalize
( It
: in out Ltd_Final_Root
) is
203 TCTouch
.Touch
(It
.Tag
);
207 -----------------------------------------------------------------------------
210 with C761005_Support
;
211 package body C761005_1
is
213 package Sup
renames C761005_Support
;
215 procedure Initialize
( It
: in out Final_Abstract
) is
217 Sup
.Inits_Called
:= Sup
.Inits_Called
+1;
218 It
.Tag
:= Sup
.Pick_Char
;
219 Sup
.Inits_Order
(Sup
.Inits_Called
) := It
.Tag
;
222 procedure Finalize
( It
: in out Final_Abstract
) is
224 TCTouch
.Touch
(It
.Tag
);
227 procedure Initialize
( It
: in out Ltd_Final_Abstract_Child
) is
229 Sup
.Inits_Called
:= Sup
.Inits_Called
+1;
230 It
.Tag
:= Sup
.Pick_Char
;
231 Sup
.Inits_Order
(Sup
.Inits_Called
) := It
.Tag
;
234 procedure Finalize
( It
: in out Ltd_Final_Abstract_Child
) is
236 TCTouch
.Touch
(It
.Tag
);
240 -----------------------------------------------------------------------------
245 with C761005_Support
;
248 package Sup
renames C761005_Support
;
250 Subtest_1_Inits_Expected
: constant := 4;
251 procedure Subtest_1
is
252 Item_1
: C761005_0
.Final_Root
(Sup
.Pick_Char
);
253 Item_2
, Item_3
: C761005_0
.Final_Root
(Sup
.Pick_Char
);
254 Item_4
: C761005_0
.Ltd_Final_Root
(Sup
.Pick_Char
);
256 -- check that nothing has happened yet!
257 TCTouch
.Validate
("","Subtest 1 body");
260 -- These declarations should cause calls to initialize and
261 -- finalize. The expected operations are the subprograms associated
262 -- with the abstract types.
263 Subtest_2_Inits_Expected
: constant := 4;
264 procedure Subtest_2
is
265 Item_1
: C761005_2
.Final_Child
;
266 Item_2
, Item_3
: C761005_2
.Final_Child
;
267 Item_4
: C761005_2
.Ltd_Final_Child
;
269 -- check that nothing has happened yet!
270 TCTouch
.Validate
("","Subtest 2 body");
273 begin -- Main test procedure.
275 Report
.Test
("C761005", "Check that an object of a controlled type "
276 & "is finalized when the enclosing master is "
277 & "complete, left by a transfer of control, "
278 & "and performed in the correct order" );
281 Sup
.Validate
(Subtest_1_Inits_Expected
,1);
284 Sup
.Validate
(Subtest_2_Inits_Expected
,2);