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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
-- C730001.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 full view of a private extension may be derived
-- indirectly from the ancestor type (i.e., the parent type of the full
-- type may be any descendant of the ancestor type). Check that, for
-- a primitive subprogram of the private extension that is inherited from
-- the ancestor type and not overridden, the formal parameter names and
-- default expressions come from the corresponding primitive subprogram
-- of the ancestor type, while the body comes from that of the parent
-- type. Check both dispatching and non-dispatching cases.
--
-- TEST DESCRIPTION:
-- Consider:
--
-- package P is
-- type Ancestor is tagged ...
-- procedure Op (P1: Ancestor; P2: Boolean := True);
-- end P;
--
-- with P;
-- package Q is
-- type Derived is new P.Ancestor with ...
-- procedure Op (X: Ancestor; Y: Boolean := False);
-- end Q;
--
-- with P, Q;
-- package R is
-- type Priv_Ext is new P.Ancestor with private; -- (A)
-- -- Inherits procedure Op (P1: Priv_Ext; P2: Boolean := True);
-- -- But body executed is that of Q.Op.
-- private
-- type Priv_Ext is new Q.Derived with record ... -- (B)
-- end R;
--
-- The ancestor type in (A) differs from the parent type in (B); the
-- parent of the full type is descended from the ancestor type of the
-- private extension. For a call to Op (from outside the scope of the
-- full view) with an operand of type Priv_Ext, the formal parameter
-- names and default expression come from that of P.Op (the ancestor
-- type's version), but the body executed will be that of
-- Q.Op (the parent type's version)
--
-- One half of the test mirrors the above template, where an inherited
-- subprogram (Set_Display) is called using the formal parameter
-- name (C) and default parameter expression of the ancestor type's
-- version (type Clock), but the version of the body executed is from
-- the parent type.
--
-- The test also includes an examination of the dynamic evaluation
-- case, where correct body associations are required through dispatching
-- calls. As described for the non-dispatching case above, the formal
-- parameter name and default values of the ancestor type's (Phone)
-- version of the inherited subprogram (Answer) are used in the
-- dispatching call, but the body executed is from the parent type.
--
--
-- CHANGE HISTORY:
-- 06 Dec 94 SAIC ACVC 2.0
--
--!
package C730001_0 is
type Display_Kind is (None, Analog, Digital);
type Illumination_Type is (None, Light, Phosphorescence);
type Capability_Type is (Available, In_Use, Call_Waiting, Conference);
type Indicator_Type is (None, Light, Bell, Buzzer, Click, Modem);
type Clock is abstract tagged record -- ancestor type associated
Display : Display_Kind := None; -- with non-dispatching case.
Illumination : Illumination_Type := None;
end record;
type Phone is tagged record -- ancestor type associated
Status : Capability_Type := Available; -- with dispatching case.
Indicator : Indicator_Type := None;
end record;
-- The Set_Display procedure for type Clock implements a basic, no-frills
-- clock display.
procedure Set_Display (C : in out Clock;
Disp: in Display_Kind := Digital);
-- The Answer procedure for type Phone implements a phone status change
-- operation.
procedure Answer (The_Phone : in out Phone;
Ind : in Indicator_Type := Light);
-- ...Other general clock and/or phone operations (not specified in this
-- test scenario).
end C730001_0;
--==================================================================--
package body C730001_0 is
procedure Set_Display (C : in out Clock;
Disp: in Display_Kind := Digital) is
begin
C.Display := Disp;
C.Illumination := Light;
end Set_Display;
procedure Answer (The_Phone : in out Phone;
Ind : in Indicator_Type := Light) is
begin
The_Phone.Status := In_Use;
The_Phone.Indicator := Ind;
end Answer;
end C730001_0;
--==================================================================--
with C730001_0; use C730001_0;
package C730001_1 is
type Power_Supply_Type is (Spring, Battery, AC_Current);
type Speaker_Type is (None, Present, Adjustable, Stereo);
type Wall_Clock is new Clock with record
Power_Source : Power_Supply_Type := Spring;
end record;
type Office_Phone is new Phone with record
Speaker : Speaker_Type := Present;
end record;
-- Note: Both procedures below, parameter names and defaults differ from
-- parent's version.
-- The Set_Display procedure for type Wall_Clock improves upon the
-- basic Set_Display procedure of type Clock.
procedure Set_Display (WC: in out Wall_Clock;
D : in Display_Kind := Analog);
procedure Answer (OP : in out Office_Phone;
OI : in Indicator_Type := Buzzer);
-- ...Other wall clock and/or Office_Phone operations (not specified in
-- this test scenario).
end C730001_1;
--==================================================================--
package body C730001_1 is
-- Note: This body is the one that should be executed in the test block
-- below, not the version of the body corresponding to type Clock.
procedure Set_Display (WC: in out Wall_Clock;
D : in Display_Kind := Analog) is
begin
WC.Display := D;
WC.Illumination := Phosphorescence;
end Set_Display;
procedure Answer (OP : in out Office_Phone;
OI : in Indicator_Type := Buzzer) is
begin
OP.Status := Call_Waiting;
OP.Indicator := OI;
end Answer;
end C730001_1;
--==================================================================--
with C730001_0; use C730001_0;
with C730001_1; use C730001_1;
package C730001_2 is
type Alarm_Type is (Buzzer, Radio, Both);
type Video_Type is (None, TV_Monitor, Wall_Projection);
type Alarm_Clock is new Clock with private;
-- Inherits proc Set_Display (C : in out Clock;
-- Disp: in Display_Kind := Digital); -- (A)
--
-- Would also inherit other general clock operations (if present).
type Conference_Room_Phone is new Office_Phone with record
Display : Video_Type := TV_Monitor;
end record;
procedure Answer (CP : in out Conference_Room_Phone;
CI : in Indicator_Type := Modem);
function TC_Get_Display (C: Alarm_Clock) return Display_Kind;
function TC_Get_Display_Illumination (C: Alarm_Clock)
return Illumination_Type;
private
-- ...however, certain of the wall clock's operations (Set_Display, in
-- this example) improve on the implementations provided for the general
-- clock. We want to call the improved implementations, so we
-- derive from Wall_Clock in the private part.
type Alarm_Clock is new Wall_Clock with record
Alarm : Alarm_Type := Buzzer;
end record;
-- Inherits proc Set_Display (WC: in out Wall_Clock;
-- D : in Display_Kind := Analog); -- (B)
-- The implicit Set_Display at (B) overrides the implicit Set_Display at
-- (A), but only within the scope of the full view.
--
-- Outside the scope of the full view, only (A) is visible, so calls
-- from outside the scope will get the formal parameter names and default
-- from (A). Both inside and outside the scope, however, the body executed
-- will be that corresponding to Set_Display of the parent type.
end C730001_2;
--==================================================================--
package body C730001_2 is
procedure Answer (CP : in out Conference_Room_Phone;
CI : in Indicator_Type := Modem)is
begin
CP.Status := Conference;
CP.Indicator := CI;
end Answer;
function TC_Get_Display (C: Alarm_Clock) return Display_Kind is
begin
return C.Display;
end TC_Get_Display;
function TC_Get_Display_Illumination (C: Alarm_Clock)
return Illumination_Type is
begin
return C.Illumination;
end TC_Get_Display_Illumination;
end C730001_2;
--==================================================================--
with C730001_0; use C730001_0;
with C730001_1; use C730001_1;
with C730001_2; use C730001_2;
package C730001_3 is
-- Types extended from the ancestor (Phone) type in the specification.
type Secure_Phone_Type is new Phone with private;
type Auditorium_Phone_Type is new Phone with private;
-- Inherit versions of Answer from ancestor (Phone).
function TC_Get_Phone_Status (P : Phone'Class) return Capability_Type;
function TC_Get_Indicator (P : Phone'Class) return Indicator_Type;
private
-- Types extended from descendents of Phone_Type in the private part.
type Secure_Phone_Type is new Office_Phone with record
Scrambled_Communication : Boolean := True;
end record;
type Auditorium_Phone_Type is new Conference_Room_Phone with record
Volume_Control : Boolean := True;
end record;
end C730001_3;
--==================================================================--
package body C730001_3 is
function TC_Get_Phone_Status (P : Phone'Class) return Capability_Type is
begin
return P.Status;
end TC_Get_Phone_Status;
function TC_Get_Indicator (P : Phone'Class) return Indicator_Type is
begin
return P.Indicator;
end TC_Get_Indicator;
end C730001_3;
--==================================================================--
with C730001_0; use C730001_0;
with C730001_1; use C730001_1;
with C730001_2; use C730001_2;
with C730001_3; use C730001_3;
with Report;
procedure C730001 is
begin
Report.Test ("C730001","Check that the full view of a private extension " &
"may be derived indirectly from the ancestor " &
"type. Check that, for a primitive subprogram " &
"of the private extension that is inherited from " &
"the ancestor type and not overridden, the " &
"formal parameter names and default expressions " &
"come from the corresponding primitive " &
"subprogram of the ancestor type, while the body " &
"comes from that of the parent type");
Test_Block:
declare
Alarm : Alarm_Clock;
Hot_Line : Secure_Phone_Type;
TeleConference_Phone : Auditorium_Phone_Type;
begin
-- Evaluate non-dispatching case:
-- Call Set_Display using formal parameter name from
-- C730001_0.Set_Display.
-- Give no 2nd parameter so that default expression must be used.
Set_Display (C => Alarm);
-- The value of the Display component should equal Digital, which is
-- the default value from the ancestor's version of Set_Display,
-- and not the default value from the parent's version of Set_Display.
if TC_Get_Display (Alarm) /= Digital then
Report.Failed ("Default expression for ancestor op not used " &
"in non-dispatching case");
end if;
-- However, the value of the Illumination component should equal
-- Phosphorescence, which is assigned in the parent type's version of
-- the body of Set_Display.
if TC_Get_Display_Illumination (Alarm) /= Phosphorescence then
Report.Failed ("Wrong body was executed in non-dispatching case");
end if;
-- Evaluate dispatching case:
declare
Hot_Line : Secure_Phone_Type;
TeleConference_Phone : Auditorium_Phone_Type;
procedure Answer_The_Phone (P : in out Phone'Class) is
begin
-- Give no 2nd parameter so that default expression must be used.
Answer (P);
end Answer_The_Phone;
begin
Answer_The_Phone (Hot_Line);
Answer_The_Phone (TeleConference_Phone);
-- The value of the Indicator field shold equal "Light", the default
-- value from the ancestor's version of Answer, and not the default
-- from either of the parent versions of Answer.
if TC_Get_Indicator(Hot_Line) /= Light or
TC_Get_Indicator(TeleConference_Phone) /= Light
then
Report.Failed("Default expression from ancestor operation " &
"not used in dispatching case");
end if;
-- However, the value of the Status component should equal
-- Call_Waiting or Conference respectively, based on the assignment
-- in the parent type's version of the body of Answer.
if TC_Get_Phone_Status(Hot_Line) /= Call_Waiting then
Report.Failed("Wrong body executed in dispatching case - 1");
end if;
if TC_Get_Phone_Status(TeleConference_Phone) /= Conference then
Report.Failed("Wrong body executed in dispatching case - 2");
end if;
end;
exception
when others => Report.Failed ("Exception raised in Test_Block");
end Test_Block;
Report.Result;
end C730001;
|