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
404
|
-- C390004.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 the tags of allocated objects correctly identify the
-- type of the allocated object. Check that the tag corresponds
-- correctly to the value resulting from both normal and view
-- conversion. Check that the tags of accessed values designating
-- aliased objects correctly identify the type of the object. Check
-- that the tag of a function result correctly evaluates. Check this
-- for class-wide functions. The tag of a class-wide function result
-- should be the tag appropriate to the actual value returned, not the
-- tag of the ancestor type.
--
-- TEST DESCRIPTION:
-- This test defines a class hierarchy of types, with reference
-- semantics (an access type to the class-wide type). Similar in
-- structure to C392005, this test checks that dynamic allocation does
-- not adversely impact the tagging of types.
--
--
-- CHANGE HISTORY:
-- 06 Dec 94 SAIC ACVC 2.0
--
--!
package C390004_1 is -- DMV
type Equipment is ( T_Veh, T_Car, T_Con, T_Jep );
type Vehicle is tagged record
Wheels : Natural := 4;
Parked : Boolean := False;
end record;
function Wheels ( It: Vehicle ) return Natural;
procedure Park ( It: in out Vehicle );
procedure UnPark ( It: in out Vehicle );
procedure Set_Wheels( It: in out Vehicle; To_Count: in Natural );
procedure TC_Check ( It: in Vehicle; To_Equip: in Equipment );
type Car is new Vehicle with record
Passengers : Natural := 0;
end record;
function Passengers ( It: Car ) return Natural;
procedure Load_Passengers( It: in out Car; To_Count: in Natural );
procedure Park ( It: in out Car );
procedure TC_Check ( It: in Car; To_Equip: in Equipment );
type Convertible is new Car with record
Top_Up : Boolean := True;
end record;
function Top_Up ( It: Convertible ) return Boolean;
procedure Lower_Top( It: in out Convertible );
procedure Park ( It: in out Convertible );
procedure Raise_Top( It: in out Convertible );
procedure TC_Check ( It: in Convertible; To_Equip: in Equipment );
type Jeep is new Convertible with record
Windshield_Up : Boolean := True;
end record;
function Windshield_Up ( It: Jeep ) return Boolean;
procedure Lower_Windshield( It: in out Jeep );
procedure Park ( It: in out Jeep );
procedure Raise_Windshield( It: in out Jeep );
procedure TC_Check ( It: in Jeep; To_Equip: in Equipment );
end C390004_1;
with Report;
package body C390004_1 is
procedure Set_Wheels( It: in out Vehicle; To_Count: in Natural ) is
begin
It.Wheels := To_Count;
end Set_Wheels;
function Wheels( It: Vehicle ) return Natural is
begin
return It.Wheels;
end Wheels;
procedure Park ( It: in out Vehicle ) is
begin
It.Parked := True;
end Park;
procedure UnPark ( It: in out Vehicle ) is
begin
It.Parked := False;
end UnPark;
procedure TC_Check ( It: in Vehicle; To_Equip: in Equipment ) is
begin
if To_Equip /= T_Veh then
Report.Failed ("Failed, called Vehicle for "
& Equipment'Image(To_Equip));
end if;
end TC_Check;
procedure TC_Check ( It: in Car; To_Equip: in Equipment ) is
begin
if To_Equip /= T_Car then
Report.Failed ("Failed, called Car for "
& Equipment'Image(To_Equip));
end if;
end TC_Check;
procedure TC_Check ( It: in Convertible; To_Equip: in Equipment ) is
begin
if To_Equip /= T_Con then
Report.Failed ("Failed, called Convertible for "
& Equipment'Image(To_Equip));
end if;
end TC_Check;
procedure TC_Check ( It: in Jeep; To_Equip: in Equipment ) is
begin
if To_Equip /= T_Jep then
Report.Failed ("Failed, called Jeep for "
& Equipment'Image(To_Equip));
end if;
end TC_Check;
procedure Load_Passengers( It: in out Car; To_Count: in Natural ) is
begin
It.Passengers := To_Count;
UnPark( It );
end Load_Passengers;
procedure Park( It: in out Car ) is
begin
It.Passengers := 0;
Park( Vehicle( It ) );
end Park;
function Passengers( It: Car ) return Natural is
begin
return It.Passengers;
end Passengers;
procedure Raise_Top( It: in out Convertible ) is
begin
It.Top_Up := True;
end Raise_Top;
procedure Lower_Top( It: in out Convertible ) is
begin
It.Top_Up := False;
end Lower_Top;
function Top_Up ( It: Convertible ) return Boolean is
begin
return It.Top_Up;
end Top_Up;
procedure Park ( It: in out Convertible ) is
begin
It.Top_Up := True;
Park( Car( It ) );
end Park;
procedure Raise_Windshield( It: in out Jeep ) is
begin
It.Windshield_Up := True;
end Raise_Windshield;
procedure Lower_Windshield( It: in out Jeep ) is
begin
It.Windshield_Up := False;
end Lower_Windshield;
function Windshield_Up( It: Jeep ) return Boolean is
begin
return It.Windshield_Up;
end Windshield_Up;
procedure Park( It: in out Jeep ) is
begin
It.Windshield_Up := True;
Park( Convertible( It ) );
end Park;
end C390004_1;
with Report;
with Ada.Tags;
with C390004_1;
procedure C390004 is
package DMV renames C390004_1;
The_Vehicle : aliased DMV.Vehicle;
The_Car : aliased DMV.Car;
The_Convertible : aliased DMV.Convertible;
The_Jeep : aliased DMV.Jeep;
type C_Reference is access all DMV.Car'Class;
type V_Reference is access all DMV.Vehicle'Class;
Designator : V_Reference;
Storage : Natural;
procedure Valet( It: in out DMV.Vehicle'Class ) is
begin
DMV.Park( It );
end Valet;
procedure TC_Match( Object: DMV.Vehicle'Class;
Taglet: Ada.Tags.Tag;
Where : String ) is
use Ada.Tags;
begin
if Object'Tag /= Taglet then
Report.Failed("Tag mismatch: " & Where);
end if;
end TC_Match;
procedure Parking_Validation( It: DMV.Vehicle; TC_Message: String ) is
begin
if DMV.Wheels( It ) /= 1 or not It.Parked then
Report.Failed ("Failed Vehicle " & TC_Message);
end if;
end Parking_Validation;
procedure Parking_Validation( It: DMV.Car; TC_Message: String ) is
begin
if DMV.Wheels( It ) /= 2 or DMV.Passengers( It ) /= 0
or not It.Parked then
Report.Failed ("Failed Car " & TC_Message);
end if;
end Parking_Validation;
procedure Parking_Validation( It: DMV.Convertible;
TC_Message: String ) is
begin
if DMV.Wheels( It ) /= 3 or DMV.Passengers( It ) /= 0
or not DMV.Top_Up( It ) or not It.Parked then
Report.Failed ("Failed Convertible " & TC_Message);
end if;
end Parking_Validation;
procedure Parking_Validation( It: DMV.Jeep; TC_Message: String ) is
begin
if DMV.Wheels( It ) /= 4 or DMV.Passengers( It ) /= 0
or not DMV.Top_Up( It ) or not DMV.Windshield_Up( It )
or not It.Parked then
Report.Failed ("Failed Jeep " & TC_Message);
end if;
end Parking_Validation;
function Wash( It: V_Reference; TC_Expect : Ada.Tags.Tag )
return DMV.Vehicle'Class is
This_Machine : DMV.Vehicle'Class := It.all;
begin
TC_Match( It.all, TC_Expect, "Class-wide object in Wash" );
Storage := DMV.Wheels( This_Machine );
return This_Machine;
end Wash;
function Wash( It: C_Reference; TC_Expect : Ada.Tags.Tag )
return DMV.Car'Class is
This_Machine : DMV.Car'Class := It.all;
begin
TC_Match( It.all, TC_Expect, "Class-wide object in Wash" );
Storage := DMV.Wheels( This_Machine );
return This_Machine;
end Wash;
begin
Report.Test( "C390004", "Check that the tags of allocated objects "
& "correctly identify the type of the allocated "
& "object. Check that tags resulting from "
& "normal and view conversions. Check tags of "
& "accessed values designating aliased objects. "
& "Check function result tags" );
DMV.Set_Wheels( The_Vehicle, 1 );
DMV.Set_Wheels( The_Car, 2 );
DMV.Set_Wheels( The_Convertible, 3 );
DMV.Set_Wheels( The_Jeep, 4 );
Valet( The_Vehicle );
Valet( The_Car );
Valet( The_Convertible );
Valet( The_Jeep );
Parking_Validation( The_Vehicle, "setup" );
Parking_Validation( The_Car, "setup" );
Parking_Validation( The_Convertible, "setup" );
Parking_Validation( The_Jeep, "setup" );
-- Check that the tags of allocated objects correctly identify the type
-- of the allocated object.
Designator := new DMV.Vehicle;
DMV.TC_Check( Designator.all, DMV.T_Veh );
TC_Match( Designator.all, DMV.Vehicle'Tag, "allocated Vehicle" );
Designator := new DMV.Car;
DMV.TC_Check( Designator.all, DMV.T_Car );
TC_Match( Designator.all, DMV.Car'Tag, "allocated Car");
Designator := new DMV.Convertible;
DMV.TC_Check( Designator.all, DMV.T_Con );
TC_Match( Designator.all, DMV.Convertible'Tag, "allocated Convertible" );
Designator := new DMV.Jeep;
DMV.TC_Check( Designator.all, DMV.T_Jep );
TC_Match( Designator.all, DMV.Jeep'Tag, "allocated Jeep" );
-- Check that view conversion causes the correct dispatch
DMV.TC_Check( DMV.Vehicle( The_Jeep ), DMV.T_Veh );
DMV.TC_Check( DMV.Car( The_Jeep ), DMV.T_Car );
DMV.TC_Check( DMV.Convertible( The_Jeep ), DMV.T_Con );
-- And that view conversion does not change the tag
TC_Match( DMV.Vehicle( The_Jeep ), DMV.Jeep'Tag, "View Conv Veh" );
TC_Match( DMV.Car( The_Jeep ), DMV.Jeep'Tag, "View Conv Car" );
TC_Match( DMV.Convertible( The_Jeep ), DMV.Jeep'Tag, "View Conv Jep" );
-- Check that the tags of accessed values designating aliased objects
-- correctly identify the type of the object.
Designator := The_Vehicle'Access;
DMV.TC_Check( Designator.all, DMV.T_Veh );
TC_Match( Designator.all, DMV.Vehicle'Tag, "aliased Vehicle" );
Designator := The_Car'Access;
DMV.TC_Check( Designator.all, DMV.T_Car );
TC_Match( Designator.all, DMV.Car'Tag, "aliased Car" );
Designator := The_Convertible'Access;
DMV.TC_Check( Designator.all, DMV.T_Con );
TC_Match( Designator.all, DMV.Convertible'Tag, "aliased Convertible" );
Designator := The_Jeep'Access;
DMV.TC_Check( Designator.all, DMV.T_Jep );
TC_Match( Designator.all, DMV.Jeep'Tag, "aliased Jeep" );
-- Check that the tag of a function result correctly evaluates.
-- Check this for class-wide functions. The tag of a class-wide
-- function result should be the tag appropriate to the actual value
-- returned, not the tag of the ancestor type.
Function_Check: declare
A_Vehicle : V_Reference := new DMV.Vehicle'( The_Vehicle );
A_Car : C_Reference := new DMV.Car'( The_Car );
A_Convertible : C_Reference := new DMV.Convertible'( The_Convertible );
A_Jeep : C_Reference := new DMV.Jeep'( The_Jeep );
begin
DMV.Unpark( A_Vehicle.all );
DMV.Load_Passengers( A_Car.all, 5 );
DMV.Load_Passengers( A_Convertible.all, 6 );
DMV.Load_Passengers( A_Jeep.all, 7 );
DMV.Lower_Top( DMV.Convertible(A_Convertible.all) );
DMV.Lower_Top( DMV.Jeep(A_Jeep.all) );
DMV.Lower_Windshield( DMV.Jeep(A_Jeep.all) );
if DMV.Wheels( Wash( A_Jeep, DMV.Jeep'Tag ) ) /= 4
or Storage /= 4 then
Report.Failed("Did not correctly wash Jeep");
end if;
if DMV.Wheels( Wash( A_Convertible, DMV.Convertible'Tag ) ) /= 3
or Storage /= 3 then
Report.Failed("Did not correctly wash Convertible");
end if;
if DMV.Wheels( Wash( A_Car, DMV.Car'Tag ) ) /= 2
or Storage /= 2 then
Report.Failed("Did not correctly wash Car");
end if;
if DMV.Wheels( Wash( A_Vehicle, DMV.Vehicle'Tag ) ) /= 1
or Storage /= 1 then
Report.Failed("Did not correctly wash Vehicle");
end if;
end Function_Check;
Report.Result;
end C390004;
|