aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cc/cc40001.a
blob: bf42470e65bdeee9f2ce5031a247c1dc2ff38415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
-- CC40001.A
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
--      Check that adjust is called on the value of a constant object created
--      by the evaluation of a generic association for a formal object of
--      mode in.
--
--      Check that those values are also subsequently finalized.
--
-- TEST DESCRIPTION:
--      Create a backdrop of a controlled type sufficient to check that the
--      correct operations get called at appropriate times.  Create a generic
--      unit that takes a formal parameter of a formal type.  Create instances
--      of this generic using various "levels" of the controlled type.  Check
--      the same case for a generic child unit.
--
--      The cases tested are where the type of the formal object is:
--        a visible classwide type  : CC40001_2
--        a formal private type     : CC40001_3
--        a formal tagged type      : CC40001_4
--
--      To more fully take advantage of the features of the language, and
--      present a test which is "user oriented" this test utilizes multiple
--      aspects of the language in combination.  Using Ada.Strings.Unbounded
--      in combination with Ada.Finalization and Ada.Calendar to build layers
--      of an object oriented system will likely be very common in actual
--      practice.  A common paradigm in the language will also be the use of
--      a parent package defining "basic" tagged types, and child packages
--      will expand on those types via derivation.  The model used in this
--      test is a simple type containing a character identity (used in the
--      identity).  The next level of type add a timestamp.  Further levels
--      might add location information, etc. however for the purposes of this
--      test we stop at the second layer, as it is sufficient to test the
--      stated objective.
--
--
-- CHANGE HISTORY:
--      06 FEB 96   SAIC   Initial version
--      30 APR 96   SAIC   Added finalization checks for 2.1
--      13 FEB 97   PWB.CTA  Moved global objects into bodies, after Initialize
--                         body is elaborated; counted finalizations correctly.
--!

----------------------------------------------------------------- CC40001_0

with Ada.Finalization;
with Ada.Strings.Unbounded;
package CC40001_0 is

  type States is ( Erroneous, Defaulted, Initialized, Reset, Adjusted );

  type Simple_Object(ID: Character) is
    new Ada.Finalization.Controlled with
      record
        TC_Current_State : States := Defaulted;
        Name : Ada.Strings.Unbounded.Unbounded_String;
      end record;

  procedure User_Operation( COB: in out Simple_Object; Name : String );
  procedure Initialize( COB: in out Simple_Object );
  procedure Adjust    ( COB: in out Simple_Object );
  procedure Finalize  ( COB: in out Simple_Object );

  Finalization_Count : Natural;

end CC40001_0;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

with Report;
with TCTouch;
package body CC40001_0 is

  procedure User_Operation( COB: in out Simple_Object; Name : String ) is
  begin
    COB.Name := Ada.Strings.Unbounded.To_Unbounded_String(Name);
  end User_Operation;

  procedure Initialize( COB: in out Simple_Object ) is
  begin
    COB.TC_Current_State := Initialized;
  end Initialize;

  procedure Adjust    ( COB: in out Simple_Object ) is
  begin
    COB.TC_Current_State := Adjusted;
    TCTouch.Touch('A');  -------------------------------------------------- A
    TCTouch.Touch(COB.ID); ------------------------------------------------ ID
    -- note that the calls to touch will not be directly validated, it is
    -- expected that some number > 0 of calls will be made to this procedure,
    -- the subtests then clear (Flush) the Touch buffer and perform actions
    -- where an incorrect implementation might call this procedure.  Such a
    -- call will fail on the attempt to "Validate" the null string.
  end Adjust;

  procedure Finalize  ( COB: in out Simple_Object ) is
  begin
    COB.TC_Current_State := Erroneous;
    Finalization_Count := Finalization_Count +1;
  end Finalize;

  TC_Global_Object : Simple_Object('G');

end CC40001_0;

----------------------------------------------------------------- CC40001_1

with Ada.Calendar;
package CC40001_0.CC40001_1 is

  type Object_In_Time(ID: Character) is
    new Simple_Object(ID) with
      record
        Birth : Ada.Calendar.Time;
        Activity : Ada.Calendar.Time;
      end record;

  procedure User_Operation( COB: in out Object_In_Time;
                           Name: String );

  procedure Initialize( COB: in out Object_In_Time );
  procedure Adjust    ( COB: in out Object_In_Time );
  procedure Finalize  ( COB: in out Object_In_Time );

end CC40001_0.CC40001_1;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

with Report;
with TCTouch;
package body CC40001_0.CC40001_1 is

  procedure Initialize( COB: in out Object_In_Time ) is
  begin
    COB.TC_Current_State := Initialized;
    COB.Birth := Ada.Calendar.Clock;
  end Initialize;

  procedure Adjust    ( COB: in out Object_In_Time ) is
  begin
    COB.TC_Current_State := Adjusted;
    TCTouch.Touch('a');    ------------------------------------------------ a
    TCTouch.Touch(COB.ID); ------------------------------------------------ ID
  end Adjust;

  procedure Finalize  ( COB: in out Object_In_Time ) is
  begin
    COB.TC_Current_State := Erroneous;
    Finalization_Count := Finalization_Count +1;
  end Finalize;

  procedure User_Operation( COB: in out Object_In_Time;
                           Name: String ) is
  begin
    CC40001_0.User_Operation( Simple_Object(COB), Name );
    COB.Activity := Ada.Calendar.Clock;
    COB.TC_Current_State := Reset;
  end User_Operation;

  TC_Time_Object  : Object_In_Time('g');

end CC40001_0.CC40001_1;

----------------------------------------------------------------- CC40001_2

generic
  TC_Check_Object : in CC40001_0.Simple_Object'Class;
package CC40001_0.CC40001_2 is
  procedure TC_Verify_State;
end CC40001_0.CC40001_2;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

with Report;
package body CC40001_0.CC40001_2 is

  procedure TC_Verify_State is
  begin
    if TC_Check_Object.TC_Current_State /= Adjusted then
      Report.Failed( "CC40001_2 : Formal Object not adjusted" );
    end if;
  end TC_Verify_State;

end CC40001_0.CC40001_2;

----------------------------------------------------------------- CC40001_3

generic
  type Formal_Private(<>) is private;
  TC_Check_Object : in Formal_Private;
  with function Bad_Status( O: Formal_Private ) return Boolean;
package CC40001_0.CC40001_3 is
  procedure TC_Verify_State;
end CC40001_0.CC40001_3;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

with Report;
package body CC40001_0.CC40001_3 is

  procedure TC_Verify_State is
  begin
    if Bad_Status( TC_Check_Object ) then
      Report.Failed( "CC40001_3 : Formal Object not adjusted" );
    end if;
  end TC_Verify_State;

end CC40001_0.CC40001_3;

----------------------------------------------------------------- CC40001_4

generic
  type Formal_Tagged_Private(<>) is tagged private; 
  TC_Check_Object : in Formal_Tagged_Private;
  with function Bad_Status( O: Formal_Tagged_Private ) return Boolean;
package CC40001_0.CC40001_4 is
  procedure TC_Verify_State;
end CC40001_0.CC40001_4;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

with Report;
package body CC40001_0.CC40001_4 is

  procedure TC_Verify_State is
  begin
    if Bad_Status( TC_Check_Object ) then
      Report.Failed( "CC40001_4 : Formal Object not adjusted" );
    end if;
  end TC_Verify_State;

end CC40001_0.CC40001_4;

------------------------------------------------------------------- CC40001

with Report;
with TCTouch;
with CC40001_0.CC40001_1;
with CC40001_0.CC40001_2;
with CC40001_0.CC40001_3;
with CC40001_0.CC40001_4;
procedure CC40001 is

  function Not_Adjusted( CO : CC40001_0.Simple_Object )
    return Boolean is
     use type CC40001_0.States;
  begin
    return CO.TC_Current_State /= CC40001_0.Adjusted;
  end Not_Adjusted;

  function Not_Adjusted( CO : CC40001_0.CC40001_1.Object_In_Time )
    return Boolean is
     use type CC40001_0.States;
  begin
    return CO.TC_Current_State /= CC40001_0.Adjusted;
  end Not_Adjusted;

   -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Subtest 1

  procedure Subtest_1 is
    Object_0 : CC40001_0.Simple_Object('T');
    Object_1 : CC40001_0.CC40001_1.Object_In_Time('t');

    package Subtest_1_1 is
      new CC40001_0.CC40001_2( Object_0 ); -- classwide generic formal object

    package Subtest_1_2 is
      new CC40001_0.CC40001_2( Object_1 ); -- classwide generic formal object
  begin
    TCTouch.Flush;  -- clear out all "A" and "T" entries, no further calls
                    -- to Touch should occur before the call to Validate

    -- set the objects TC_Current_State to "Reset"
    CC40001_0.User_Operation( Object_0, "Subtest 1" );
    CC40001_0.CC40001_1.User_Operation( Object_1, "Subtest 1" );

    -- check that the objects TC_Current_State is "Adjusted"
    Subtest_1_1.TC_Verify_State;
    Subtest_1_2.TC_Verify_State;

    TCTouch.Validate( "", "No actions should occur here, subtest 1" );

  end Subtest_1;

   -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Subtest 2

  procedure Subtest_2 is
    Object_0 : CC40001_0.Simple_Object('T');
    Object_1 : CC40001_0.CC40001_1.Object_In_Time('t');

    package Subtest_2_1 is -- generic formal object is discriminated private
      new CC40001_0.CC40001_3( CC40001_0.Simple_Object,
                               Object_0,
                               Not_Adjusted );

    package Subtest_2_2 is -- generic formal object is discriminated private
      new CC40001_0.CC40001_3( CC40001_0.CC40001_1.Object_In_Time,
                               Object_1,
                               Not_Adjusted );

  begin
    TCTouch.Flush;  -- clear out all "A" and "T" entries

    -- set the objects state to "Reset"
    CC40001_0.User_Operation( Object_0, "Subtest 2" );
    CC40001_0.CC40001_1.User_Operation( Object_1, "Subtest 2" );

    Subtest_2_1.TC_Verify_State;
    Subtest_2_2.TC_Verify_State;

    TCTouch.Validate( "", "No actions should occur here, subtest 2" );

  end Subtest_2;

   -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Subtest 3

  procedure Subtest_3 is
    Object_0 : CC40001_0.Simple_Object('T');
    Object_1 : CC40001_0.CC40001_1.Object_In_Time('t');

    package Subtest_3_1 is -- generic formal object is discriminated tagged
      new CC40001_0.CC40001_4( CC40001_0.Simple_Object,
                               Object_0,
                               Not_Adjusted );

    package Subtest_3_2 is -- generic formal object is discriminated tagged
      new CC40001_0.CC40001_4( CC40001_0.CC40001_1.Object_In_Time,
                               Object_1,
                               Not_Adjusted );
  begin
    TCTouch.Flush;  -- clear out all "A" and "T" entries

    -- set the objects state to "Reset"
    CC40001_0.User_Operation( Object_0, "Subtest 3" );
    CC40001_0.CC40001_1.User_Operation( Object_1, "Subtest 3" );

    Subtest_3_1.TC_Verify_State;
    Subtest_3_2.TC_Verify_State;

    TCTouch.Validate( "", "No actions should occur here, subtest 3" );

  end Subtest_3;

begin  -- Main test procedure.

  Report.Test ("CC40001", "Check that adjust and finalize are called on " &
                          "the constant object created by the " &
                          "evaluation of a generic association for a " &
                          "formal object of mode in" );

  -- check that the created constant objects are properly adjusted
  -- and subsequently finalized

  CC40001_0.Finalization_Count := 0;

  Subtest_1;

  if CC40001_0.Finalization_Count < 4 then
    Report.Failed("Insufficient Finalizations for Subtest 1");
  end if;

  CC40001_0.Finalization_Count := 0;

  Subtest_2;

  if CC40001_0.Finalization_Count < 4 then
    Report.Failed("Insufficient Finalizations for Subtest 2");
  end if;

  CC40001_0.Finalization_Count := 0;

  Subtest_3;

  if CC40001_0.Finalization_Count < 4 then
    Report.Failed("Insufficient Finalizations for Subtest 3");
  end if;

  Report.Result;

end CC40001;