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 Initialize is called for objects and components of
28 -- a controlled type when the objects and components are not
29 -- assigned explicit initial values. Check this for "simple" controlled
30 -- objects, controlled record components and arrays with controlled
33 -- Check that if an explicit initial value is assigned to an object
34 -- or component of a controlled type then Initialize is not called.
37 -- This test derives a type for Ada.Finalization.Controlled, and
38 -- overrides the Initialize and Adjust operations for the type. The
39 -- intent of the type is that it should carry incremental values
40 -- indicating the ordering of events with respect to these (and default
41 -- initialization) operations. The body of the test uses these values
42 -- to determine that the implicit calls to these subprograms happen
43 -- (or don't) at the appropriate times.
45 -- The test further derives types from this "root" type, which are the
46 -- actual types used in the test. One of the types is "simply" derived
47 -- from the "root" type, the other contains a component of the first
48 -- type, thus nesting a controlled object as a record component in
49 -- controlled objects.
51 -- The main program declares objects of these types and checks the
52 -- values of the components to ascertain that they have been touched
55 -- Note that Finalization procedures are provided. This test does not
56 -- test that the calls to Finalization are made correctly. The
57 -- Finalization procedures are provided to catch an implementation that
58 -- calls Finalization at an incorrect time.
62 -- 06 Dec 94 SAIC ACVC 2.0
63 -- 10 Oct 95 SAIC Update and repair for ACVC 2.0.1
67 ---------------------------------------------------------------- C760001_0
69 with Ada
.Finalization
;
71 subtype Unique_ID
is Natural;
72 function Unique_Value
return Unique_ID
;
73 -- increments each time it's called
75 function Most_Recent_Unique_Value
return Unique_ID
;
76 -- returns the same value as the most recent call to Unique_Value
78 type Root_Controlled
is new Ada
.Finalization
.Controlled
with record
79 My_ID
: Unique_ID
:= Unique_Value
;
80 My_Init_ID
: Unique_ID
:= Unique_ID
'First;
81 My_Adj_ID
: Unique_ID
:= Unique_ID
'First;
84 procedure Initialize
( R
: in out Root_Controlled
);
85 procedure Adjust
( R
: in out Root_Controlled
);
87 TC_Initialize_Calls_Is_Failing
: Boolean := False;
91 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
94 package body C760001_0
is
96 Global_Unique_Counter
: Unique_ID
:= 0;
98 function Unique_Value
return Unique_ID
is
100 Global_Unique_Counter
:= Global_Unique_Counter
+1;
101 return Global_Unique_Counter
;
104 function Most_Recent_Unique_Value
return Unique_ID
is
106 return Global_Unique_Counter
;
107 end Most_Recent_Unique_Value
;
109 procedure Initialize
( R
: in out Root_Controlled
) is
111 if TC_Initialize_Calls_Is_Failing
then
112 Report
.Failed
("Initialized incorrectly called");
114 R
.My_Init_ID
:= Unique_Value
;
117 procedure Adjust
( R
: in out Root_Controlled
) is
119 R
.My_Adj_ID
:= Unique_Value
;
124 ---------------------------------------------------------------- C760001_1
126 with Ada
.Finalization
;
130 type Proc_ID
is (None
, Init
, Adj
, Fin
);
132 type Test_Controlled
is new C760001_0
.Root_Controlled
with record
133 Last_Proc_Called
: Proc_ID
:= None
;
136 procedure Initialize
( TC
: in out Test_Controlled
);
137 procedure Adjust
( TC
: in out Test_Controlled
);
138 procedure Finalize
( TC
: in out Test_Controlled
);
140 type Nested_Controlled
is new C760001_0
.Root_Controlled
with record
141 Nested
: C760001_0
.Root_Controlled
;
142 Last_Proc_Called
: Proc_ID
:= None
;
145 procedure Initialize
( TC
: in out Nested_Controlled
);
146 procedure Adjust
( TC
: in out Nested_Controlled
);
147 procedure Finalize
( TC
: in out Nested_Controlled
);
151 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
154 package body C760001_1
is
156 procedure Initialize
( TC
: in out Test_Controlled
) is
158 if TC
.Last_Proc_Called
/= None
then
159 Report
.Failed
("Initialize for Test_Controlled");
161 TC
.Last_Proc_Called
:= Init
;
162 C760001_0
.Initialize
(C760001_0
.Root_Controlled
(TC
));
165 procedure Adjust
( TC
: in out Test_Controlled
) is
167 TC
.Last_Proc_Called
:= Adj
;
168 C760001_0
.Adjust
(C760001_0
.Root_Controlled
(TC
));
171 procedure Finalize
( TC
: in out Test_Controlled
) is
173 TC
.Last_Proc_Called
:= Fin
;
176 procedure Initialize
( TC
: in out Nested_Controlled
) is
178 if TC
.Last_Proc_Called
/= None
then
179 Report
.Failed
("Initialize for Nested_Controlled");
181 TC
.Last_Proc_Called
:= Init
;
182 C760001_0
.Initialize
(C760001_0
.Root_Controlled
(TC
));
185 procedure Adjust
( TC
: in out Nested_Controlled
) is
187 TC
.Last_Proc_Called
:= Adj
;
188 C760001_0
.Adjust
(C760001_0
.Root_Controlled
(TC
));
191 procedure Finalize
( TC
: in out Nested_Controlled
) is
193 TC
.Last_Proc_Called
:= Fin
;
198 ---------------------------------------------------------------- C760001
204 with Ada
.Finalization
;
207 use type C760001_1
.Proc_ID
;
209 -- in the first test, test the simple case. Check that a controlled object
210 -- causes a call to the procedure Initialize.
211 -- Also check that assignment causes a call to Adjust.
213 procedure Check_Simple_Objects
is
214 S
,T
: C760001_1
.Test_Controlled
;
216 TCTouch
.Assert
(S
.My_ID
< S
.My_Init_ID
,"Default before dispatch");
217 TCTouch
.Assert
((S
.Last_Proc_Called
= C760001_1
.Init
) and
218 (T
.Last_Proc_Called
= C760001_1
.Init
),
219 "Initialize for simple object");
221 TCTouch
.Assert
((S
.Last_Proc_Called
= C760001_1
.Adj
),
222 "Adjust for simple object");
223 TCTouch
.Assert
((S
.My_ID
= T
.My_ID
),
224 "Simple object My_ID's don't match");
225 TCTouch
.Assert
((S
.My_Init_ID
= T
.My_Init_ID
),
226 "Simple object My_Init_ID's don't match");
227 TCTouch
.Assert
((S
.My_Adj_ID
> T
.My_Adj_ID
),
228 "Simple object My_Adj_ID's in wrong order");
229 end Check_Simple_Objects
;
231 -- in the second test, test a more complex case, check that a controlled
232 -- component of a controlled object gets processed correctly
234 procedure Check_Nested_Objects
is
235 NO1
: C760001_1
.Nested_Controlled
;
237 TCTouch
.Assert
((NO1
.My_ID
< NO1
.My_Init_Id
),
238 "Default value order incorrect");
239 TCTouch
.Assert
((NO1
.My_Init_Id
> NO1
.Nested
.My_Init_ID
),
240 "Initialization call order incorrect");
241 end Check_Nested_Objects
;
243 -- check that objects assigned an initial value at declaration are Adjusted
244 -- and NOT Initialized
246 procedure Check_Objects_With_Initial_Values
is
248 TC_Now
: constant C760001_0
.Unique_ID
:= C760001_0
.Unique_Value
;
250 A
: C760001_1
.Test_Controlled
:=
251 ( Ada
.Finalization
.Controlled
257 B
: C760001_1
.Nested_Controlled
:=
258 ( Ada
.Finalization
.Controlled
262 C760001_0
.Root_Controlled
(A
),
266 -- the implementation may or may not call Adjust for the values
267 -- assigned into A and B,
268 -- but should NOT call Initialize.
269 -- if the value used in the aggregate is overwritten by Initialize,
270 -- this indicates failure
271 TCTouch
.Assert
(A
.My_Init_Id
= TC_Now
,
272 "Initialize was called for A with initial value");
273 TCTouch
.Assert
(B
.My_Init_Id
= TC_Now
,
274 "Initialize was called for B with initial value");
275 TCTouch
.Assert
(B
.Nested
.My_Init_ID
= TC_Now
,
276 "Initialize was called for B.Nested initial value");
277 end Check_Objects_With_Initial_Values
;
279 procedure Check_Array_Case
is
280 type Array_Simple
is array(1..4) of C760001_1
.Test_Controlled
;
281 type Array_Nested
is array(1..4) of C760001_1
.Nested_Controlled
;
283 Simple_Array_Default
: Array_Simple
;
285 Nested_Array_Default
: Array_Nested
;
287 TC_A_Bit_Later
: C760001_0
.Unique_ID
;
290 TC_A_Bit_Later
:= C760001_0
.Unique_Value
;
292 TCTouch
.Assert
(Simple_Array_Default
(N
).Last_Proc_Called
294 "Initialize for array initial value");
296 TCTouch
.Assert
( (Simple_Array_Default
(N
).My_Init_ID
297 > C760001_0
.Unique_ID
'First)
298 and (Simple_Array_Default
(N
).My_Init_ID
300 "Initialize timing for simple array");
302 TCTouch
.Assert
( (Nested_Array_Default
(N
).My_Init_ID
303 > C760001_0
.Unique_ID
'First)
304 and (Nested_Array_Default
(N
).My_Init_ID
306 "Initialize timing for container array");
308 TCTouch
.Assert
(Nested_Array_Default
(N
).Last_Proc_Called
310 "Initialize for nested array (outer) initial value");
312 TCTouch
.Assert
( (Nested_Array_Default
(N
).Nested
.My_Init_ID
313 > C760001_0
.Unique_ID
'First)
314 and (Nested_Array_Default
(N
).Nested
.My_Init_ID
315 < Nested_Array_Default
(N
).My_Init_ID
),
316 "Initialize timing for array content");
318 end Check_Array_Case
;
320 procedure Check_Array_Case_With_Initial_Values
is
322 TC_Now
: constant C760001_0
.Unique_ID
:= C760001_0
.Unique_Value
;
324 type Array_Simple
is array(1..4) of C760001_1
.Test_Controlled
;
325 type Array_Nested
is array(1..4) of C760001_1
.Nested_Controlled
;
327 Simple_Array_Explicit
: Array_Simple
:= ( 1..4 => (
328 Ada
.Finalization
.Controlled
334 A
: constant C760001_0
.Root_Controlled
:=
335 ( Ada
.Finalization
.Controlled
336 with others => TC_Now
);
338 Nested_Array_Explicit
: Array_Nested
:= ( 1..4 => (
339 Ada
.Finalization
.Controlled
347 -- the implementation may or may not call Adjust for the values
348 -- assigned into Simple_Array_Explicit and Nested_Array_Explicit,
349 -- but should NOT call Initialize.
350 -- if the value used in the aggregate is overwritten by Initialize,
351 -- this indicates failure
353 TCTouch
.Assert
(Simple_Array_Explicit
(N
).My_Init_ID
355 "Initialize was called for array with initial value");
356 TCTouch
.Assert
(Nested_Array_Explicit
(N
).My_Init_ID
358 "Initialize was called for nested array (outer) with initial value");
359 TCTouch
.Assert
(Nested_Array_Explicit
(N
).Nested
.My_Init_ID
= TC_Now
,
360 "Initialize was called for nested array (inner) with initial value");
362 end Check_Array_Case_With_Initial_Values
;
364 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
366 begin -- Main test procedure.
368 Report
.Test
("C760001", "Check that Initialize is called for objects " &
369 "and components of a controlled type when the " &
370 "objects and components are not assigned " &
371 "explicit initial values. Check that if an " &
372 "explicit initial value is assigned to an " &
373 "object or component of a controlled type " &
374 "then Initialize is not called" );
376 Check_Simple_Objects
;
378 Check_Nested_Objects
;
382 C760001_0
.TC_Initialize_Calls_Is_Failing
:= True;
384 Check_Objects_With_Initial_Values
;
386 Check_Array_Case_With_Initial_Values
;