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 adjust is called on the value of a constant object created
28 -- by the evaluation of a generic association for a formal object of
31 -- Check that those values are also subsequently finalized.
34 -- Create a backdrop of a controlled type sufficient to check that the
35 -- correct operations get called at appropriate times. Create a generic
36 -- unit that takes a formal parameter of a formal type. Create instances
37 -- of this generic using various "levels" of the controlled type. Check
38 -- the same case for a generic child unit.
40 -- The cases tested are where the type of the formal object is:
41 -- a visible classwide type : CC40001_2
42 -- a formal private type : CC40001_3
43 -- a formal tagged type : CC40001_4
45 -- To more fully take advantage of the features of the language, and
46 -- present a test which is "user oriented" this test utilizes multiple
47 -- aspects of the language in combination. Using Ada.Strings.Unbounded
48 -- in combination with Ada.Finalization and Ada.Calendar to build layers
49 -- of an object oriented system will likely be very common in actual
50 -- practice. A common paradigm in the language will also be the use of
51 -- a parent package defining "basic" tagged types, and child packages
52 -- will expand on those types via derivation. The model used in this
53 -- test is a simple type containing a character identity (used in the
54 -- identity). The next level of type add a timestamp. Further levels
55 -- might add location information, etc. however for the purposes of this
56 -- test we stop at the second layer, as it is sufficient to test the
61 -- 06 FEB 96 SAIC Initial version
62 -- 30 APR 96 SAIC Added finalization checks for 2.1
63 -- 13 FEB 97 PWB.CTA Moved global objects into bodies, after Initialize
64 -- body is elaborated; counted finalizations correctly.
67 ----------------------------------------------------------------- CC40001_0
69 with Ada
.Finalization
;
70 with Ada
.Strings
.Unbounded
;
73 type States
is ( Erroneous
, Defaulted
, Initialized
, Reset
, Adjusted
);
75 type Simple_Object
(ID
: Character) is
76 new Ada
.Finalization
.Controlled
with
78 TC_Current_State
: States
:= Defaulted
;
79 Name
: Ada
.Strings
.Unbounded
.Unbounded_String
;
82 procedure User_Operation
( COB
: in out Simple_Object
; Name
: String );
83 procedure Initialize
( COB
: in out Simple_Object
);
84 procedure Adjust
( COB
: in out Simple_Object
);
85 procedure Finalize
( COB
: in out Simple_Object
);
87 Finalization_Count
: Natural;
91 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
95 package body CC40001_0
is
97 procedure User_Operation
( COB
: in out Simple_Object
; Name
: String ) is
99 COB
.Name
:= Ada
.Strings
.Unbounded
.To_Unbounded_String
(Name
);
102 procedure Initialize
( COB
: in out Simple_Object
) is
104 COB
.TC_Current_State
:= Initialized
;
107 procedure Adjust
( COB
: in out Simple_Object
) is
109 COB
.TC_Current_State
:= Adjusted
;
110 TCTouch
.Touch
('A'); -------------------------------------------------- A
111 TCTouch
.Touch
(COB
.ID
); ------------------------------------------------ ID
112 -- note that the calls to touch will not be directly validated, it is
113 -- expected that some number > 0 of calls will be made to this procedure,
114 -- the subtests then clear (Flush) the Touch buffer and perform actions
115 -- where an incorrect implementation might call this procedure. Such a
116 -- call will fail on the attempt to "Validate" the null string.
119 procedure Finalize
( COB
: in out Simple_Object
) is
121 COB
.TC_Current_State
:= Erroneous
;
122 Finalization_Count
:= Finalization_Count
+1;
125 TC_Global_Object
: Simple_Object
('G');
129 ----------------------------------------------------------------- CC40001_1
132 package CC40001_0
.CC40001_1
is
134 type Object_In_Time
(ID
: Character) is
135 new Simple_Object
(ID
) with
137 Birth
: Ada
.Calendar
.Time
;
138 Activity
: Ada
.Calendar
.Time
;
141 procedure User_Operation
( COB
: in out Object_In_Time
;
144 procedure Initialize
( COB
: in out Object_In_Time
);
145 procedure Adjust
( COB
: in out Object_In_Time
);
146 procedure Finalize
( COB
: in out Object_In_Time
);
148 end CC40001_0
.CC40001_1
;
150 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
154 package body CC40001_0
.CC40001_1
is
156 procedure Initialize
( COB
: in out Object_In_Time
) is
158 COB
.TC_Current_State
:= Initialized
;
159 COB
.Birth
:= Ada
.Calendar
.Clock
;
162 procedure Adjust
( COB
: in out Object_In_Time
) is
164 COB
.TC_Current_State
:= Adjusted
;
165 TCTouch
.Touch
('a'); ------------------------------------------------ a
166 TCTouch
.Touch
(COB
.ID
); ------------------------------------------------ ID
169 procedure Finalize
( COB
: in out Object_In_Time
) is
171 COB
.TC_Current_State
:= Erroneous
;
172 Finalization_Count
:= Finalization_Count
+1;
175 procedure User_Operation
( COB
: in out Object_In_Time
;
178 CC40001_0
.User_Operation
( Simple_Object
(COB
), Name
);
179 COB
.Activity
:= Ada
.Calendar
.Clock
;
180 COB
.TC_Current_State
:= Reset
;
183 TC_Time_Object
: Object_In_Time
('g');
185 end CC40001_0
.CC40001_1
;
187 ----------------------------------------------------------------- CC40001_2
190 TC_Check_Object
: in CC40001_0
.Simple_Object
'Class;
191 package CC40001_0
.CC40001_2
is
192 procedure TC_Verify_State
;
193 end CC40001_0
.CC40001_2
;
195 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
198 package body CC40001_0
.CC40001_2
is
200 procedure TC_Verify_State
is
202 if TC_Check_Object
.TC_Current_State
/= Adjusted
then
203 Report
.Failed
( "CC40001_2 : Formal Object not adjusted" );
207 end CC40001_0
.CC40001_2
;
209 ----------------------------------------------------------------- CC40001_3
212 type Formal_Private
(<>) is private;
213 TC_Check_Object
: in Formal_Private
;
214 with function Bad_Status
( O
: Formal_Private
) return Boolean;
215 package CC40001_0
.CC40001_3
is
216 procedure TC_Verify_State
;
217 end CC40001_0
.CC40001_3
;
219 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
222 package body CC40001_0
.CC40001_3
is
224 procedure TC_Verify_State
is
226 if Bad_Status
( TC_Check_Object
) then
227 Report
.Failed
( "CC40001_3 : Formal Object not adjusted" );
231 end CC40001_0
.CC40001_3
;
233 ----------------------------------------------------------------- CC40001_4
236 type Formal_Tagged_Private
(<>) is tagged private;
237 TC_Check_Object
: in Formal_Tagged_Private
;
238 with function Bad_Status
( O
: Formal_Tagged_Private
) return Boolean;
239 package CC40001_0
.CC40001_4
is
240 procedure TC_Verify_State
;
241 end CC40001_0
.CC40001_4
;
243 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
246 package body CC40001_0
.CC40001_4
is
248 procedure TC_Verify_State
is
250 if Bad_Status
( TC_Check_Object
) then
251 Report
.Failed
( "CC40001_4 : Formal Object not adjusted" );
255 end CC40001_0
.CC40001_4
;
257 ------------------------------------------------------------------- CC40001
261 with CC40001_0
.CC40001_1
;
262 with CC40001_0
.CC40001_2
;
263 with CC40001_0
.CC40001_3
;
264 with CC40001_0
.CC40001_4
;
267 function Not_Adjusted
( CO
: CC40001_0
.Simple_Object
)
269 use type CC40001_0
.States
;
271 return CO
.TC_Current_State
/= CC40001_0
.Adjusted
;
274 function Not_Adjusted
( CO
: CC40001_0
.CC40001_1
.Object_In_Time
)
276 use type CC40001_0
.States
;
278 return CO
.TC_Current_State
/= CC40001_0
.Adjusted
;
281 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Subtest 1
283 procedure Subtest_1
is
284 Object_0
: CC40001_0
.Simple_Object
('T');
285 Object_1
: CC40001_0
.CC40001_1
.Object_In_Time
('t');
287 package Subtest_1_1
is
288 new CC40001_0
.CC40001_2
( Object_0
); -- classwide generic formal object
290 package Subtest_1_2
is
291 new CC40001_0
.CC40001_2
( Object_1
); -- classwide generic formal object
293 TCTouch
.Flush
; -- clear out all "A" and "T" entries, no further calls
294 -- to Touch should occur before the call to Validate
296 -- set the objects TC_Current_State to "Reset"
297 CC40001_0
.User_Operation
( Object_0
, "Subtest 1" );
298 CC40001_0
.CC40001_1
.User_Operation
( Object_1
, "Subtest 1" );
300 -- check that the objects TC_Current_State is "Adjusted"
301 Subtest_1_1
.TC_Verify_State
;
302 Subtest_1_2
.TC_Verify_State
;
304 TCTouch
.Validate
( "", "No actions should occur here, subtest 1" );
308 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Subtest 2
310 procedure Subtest_2
is
311 Object_0
: CC40001_0
.Simple_Object
('T');
312 Object_1
: CC40001_0
.CC40001_1
.Object_In_Time
('t');
314 package Subtest_2_1
is -- generic formal object is discriminated private
315 new CC40001_0
.CC40001_3
( CC40001_0
.Simple_Object
,
319 package Subtest_2_2
is -- generic formal object is discriminated private
320 new CC40001_0
.CC40001_3
( CC40001_0
.CC40001_1
.Object_In_Time
,
325 TCTouch
.Flush
; -- clear out all "A" and "T" entries
327 -- set the objects state to "Reset"
328 CC40001_0
.User_Operation
( Object_0
, "Subtest 2" );
329 CC40001_0
.CC40001_1
.User_Operation
( Object_1
, "Subtest 2" );
331 Subtest_2_1
.TC_Verify_State
;
332 Subtest_2_2
.TC_Verify_State
;
334 TCTouch
.Validate
( "", "No actions should occur here, subtest 2" );
338 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Subtest 3
340 procedure Subtest_3
is
341 Object_0
: CC40001_0
.Simple_Object
('T');
342 Object_1
: CC40001_0
.CC40001_1
.Object_In_Time
('t');
344 package Subtest_3_1
is -- generic formal object is discriminated tagged
345 new CC40001_0
.CC40001_4
( CC40001_0
.Simple_Object
,
349 package Subtest_3_2
is -- generic formal object is discriminated tagged
350 new CC40001_0
.CC40001_4
( CC40001_0
.CC40001_1
.Object_In_Time
,
354 TCTouch
.Flush
; -- clear out all "A" and "T" entries
356 -- set the objects state to "Reset"
357 CC40001_0
.User_Operation
( Object_0
, "Subtest 3" );
358 CC40001_0
.CC40001_1
.User_Operation
( Object_1
, "Subtest 3" );
360 Subtest_3_1
.TC_Verify_State
;
361 Subtest_3_2
.TC_Verify_State
;
363 TCTouch
.Validate
( "", "No actions should occur here, subtest 3" );
367 begin -- Main test procedure.
369 Report
.Test
("CC40001", "Check that adjust and finalize are called on " &
370 "the constant object created by the " &
371 "evaluation of a generic association for a " &
372 "formal object of mode in" );
374 -- check that the created constant objects are properly adjusted
375 -- and subsequently finalized
377 CC40001_0
.Finalization_Count
:= 0;
381 if CC40001_0
.Finalization_Count
< 4 then
382 Report
.Failed
("Insufficient Finalizations for Subtest 1");
385 CC40001_0
.Finalization_Count
:= 0;
389 if CC40001_0
.Finalization_Count
< 4 then
390 Report
.Failed
("Insufficient Finalizations for Subtest 2");
393 CC40001_0
.Finalization_Count
:= 0;
397 if CC40001_0
.Finalization_Count
< 4 then
398 Report
.Failed
("Insufficient Finalizations for Subtest 3");