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 an access type may be defined to designate the
28 -- class-wide type of an abstract type. Check that the access type
29 -- may then be used subsequently with types derived from the abstract
30 -- type. Check that dispatching operations dispatch correctly, when
31 -- called using values designated by objects of the access type.
34 -- This test declares an abstract type Breaker in a package, and
35 -- then derives from it. The type Basic_Breaker defines the least
36 -- possible in order to not be abstract. The type Ground_Fault is
37 -- defined to inherit as much as possible, whereas type Special_Breaker
38 -- overrides everything it can. The type Special_Breaker also includes
39 -- an embedded Basic_Breaker object. The main program then utilizes
40 -- each of the three types of breaker, and to ascertain that the
41 -- overloading and tagging resolution are correct, each "Create"
42 -- procedure is called with a unique value. The diagram below
43 -- illustrates the relationships.
45 -- Abstract type: Breaker(1)
49 -- Ground_Fault(3) Special_Breaker(4)
51 -- Test structure is a polymorphic linked list, modeling a circuit
52 -- as a list of components. The type component is the access type
53 -- defined to designate Breaker'Class values. The test then creates
54 -- some values, and traverses the list to determine correct operation.
55 -- This test is instrumented with a the trace facility found in
56 -- foundation F392C00 to simplify the verification process.
60 -- 06 Dec 94 SAIC ACVC 2.0
61 -- 10 Nov 95 SAIC Checked compilation for ACVC 2.0.1
62 -- 23 APR 96 SAIC Added pragma Elaborate_All
63 -- 26 NOV 96 SAIC Elaborate_Body changed to Elaborate_All
71 type Breaker
is abstract tagged private;
72 type Status
is ( Power_Off
, Power_On
, Tripped
, Failed
);
74 procedure Flip
( The_Breaker
: in out Breaker
) is abstract;
75 procedure Trip
( The_Breaker
: in out Breaker
) is abstract;
76 procedure Reset
( The_Breaker
: in out Breaker
) is abstract;
77 procedure Fail
( The_Breaker
: in out Breaker
);
79 procedure Set
( The_Breaker
: in out Breaker
'Class; To_State
: Status
);
81 function Status_Of
( The_Breaker
: Breaker
) return Status
;
84 type Breaker
is abstract tagged record
85 State
: Status
:= Power_Off
;
89 ----------------------------------------------------------------------------
92 package body C3A2001_1
is
93 procedure Fail
( The_Breaker
: in out Breaker
) is
95 TCTouch
.Touch
( 'a' ); --------------------------------------------- a
96 The_Breaker
.State
:= Failed
;
99 procedure Set
( The_Breaker
: in out Breaker
'Class; To_State
: Status
) is
101 The_Breaker
.State
:= To_State
;
104 function Status_Of
( The_Breaker
: Breaker
) return Status
is
106 TCTouch
.Touch
( 'b' ); --------------------------------------------- b
107 return The_Breaker
.State
;
111 ----------------------------------------------------------------------------
116 type Basic_Breaker
is new C3A2001_1
.Breaker
with private;
118 type Voltages
is ( V12
, V110
, V220
, V440
);
119 type Amps
is ( A1
, A5
, A10
, A25
, A100
);
121 function Construct
( Voltage
: Voltages
; Amperage
: Amps
)
122 return Basic_Breaker
;
124 procedure Flip
( The_Breaker
: in out Basic_Breaker
);
125 procedure Trip
( The_Breaker
: in out Basic_Breaker
);
126 procedure Reset
( The_Breaker
: in out Basic_Breaker
);
128 type Basic_Breaker
is new C3A2001_1
.Breaker
with record
129 Voltage_Level
: Voltages
:= V110
;
134 ----------------------------------------------------------------------------
137 package body C3A2001_2
is
138 function Construct
( Voltage
: Voltages
; Amperage
: Amps
)
139 return Basic_Breaker
is
142 TCTouch
.Touch
( 'c' ); --------------------------------------------- c
143 It
.Amperage
:= Amperage
;
144 It
.Voltage_Level
:= Voltage
;
145 C3A2001_1
.Set
( It
, C3A2001_1
.Power_Off
);
149 procedure Flip
( The_Breaker
: in out Basic_Breaker
) is
151 TCTouch
.Touch
( 'd' ); --------------------------------------------- d
152 case Status_Of
( The_Breaker
) is
153 when C3A2001_1
.Power_Off
=>
154 C3A2001_1
.Set
( The_Breaker
, C3A2001_1
.Power_On
);
155 when C3A2001_1
.Power_On
=>
156 C3A2001_1
.Set
( The_Breaker
, C3A2001_1
.Power_Off
);
157 when C3A2001_1
.Tripped | C3A2001_1
.Failed
=> null;
161 procedure Trip
( The_Breaker
: in out Basic_Breaker
) is
163 TCTouch
.Touch
( 'e' ); --------------------------------------------- e
164 C3A2001_1
.Set
( The_Breaker
, C3A2001_1
.Tripped
);
167 procedure Reset
( The_Breaker
: in out Basic_Breaker
) is
169 TCTouch
.Touch
( 'f' ); --------------------------------------------- f
170 case Status_Of
( The_Breaker
) is
171 when C3A2001_1
.Power_Off | C3A2001_1
.Tripped
=>
172 C3A2001_1
.Set
( The_Breaker
, C3A2001_1
.Power_On
);
173 when C3A2001_1
.Power_On | C3A2001_1
.Failed
=> null;
179 ----------------------------------------------------------------------------
181 with C3A2001_1
,C3A2001_2
;
183 use type C3A2001_1
.Status
;
185 type Ground_Fault
is new C3A2001_2
.Basic_Breaker
with private;
187 function Construct
( Voltage
: C3A2001_2
.Voltages
;
188 Amperage
: C3A2001_2
.Amps
)
191 procedure Set_Trip
( The_Breaker
: in out Ground_Fault
;
192 Capacitance
: in Integer );
195 type Ground_Fault
is new C3A2001_2
.Basic_Breaker
with record
196 Capacitance
: Integer;
200 ----------------------------------------------------------------------------
203 package body C3A2001_3
is
205 function Construct
( Voltage
: C3A2001_2
.Voltages
;
206 Amperage
: C3A2001_2
.Amps
)
207 return Ground_Fault
is
209 TCTouch
.Touch
( 'g' ); --------------------------------------------- g
210 return ( C3A2001_2
.Construct
( Voltage
, Amperage
)
211 with Capacitance
=> 0 );
215 procedure Set_Trip
( The_Breaker
: in out Ground_Fault
;
216 Capacitance
: in Integer ) is
218 TCTouch
.Touch
( 'h' ); --------------------------------------------- h
219 The_Breaker
.Capacitance
:= Capacitance
;
224 ----------------------------------------------------------------------------
226 with C3A2001_1
, C3A2001_2
;
229 type Special_Breaker
is new C3A2001_2
.Basic_Breaker
with private;
231 function Construct
( Voltage
: C3A2001_2
.Voltages
;
232 Amperage
: C3A2001_2
.Amps
)
233 return Special_Breaker
;
235 procedure Flip
( The_Breaker
: in out Special_Breaker
);
236 procedure Trip
( The_Breaker
: in out Special_Breaker
);
237 procedure Reset
( The_Breaker
: in out Special_Breaker
);
238 procedure Fail
( The_Breaker
: in out Special_Breaker
);
240 function Status_Of
( The_Breaker
: Special_Breaker
) return C3A2001_1
.Status
;
241 function On_Backup
( The_Breaker
: Special_Breaker
) return Boolean;
244 type Special_Breaker
is new C3A2001_2
.Basic_Breaker
with record
245 Backup
: C3A2001_2
.Basic_Breaker
;
249 ----------------------------------------------------------------------------
252 package body C3A2001_4
is
254 function Construct
( Voltage
: C3A2001_2
.Voltages
;
255 Amperage
: C3A2001_2
.Amps
)
256 return Special_Breaker
is
258 procedure Set_Root
( It
: in out C3A2001_2
.Basic_Breaker
) is
260 It
:= C3A2001_2
.Construct
( Voltage
, Amperage
);
263 TCTouch
.Touch
( 'i' ); --------------------------------------------- i
264 Set_Root
( C3A2001_2
.Basic_Breaker
( It
) );
265 Set_Root
( It
.Backup
);
269 function Status_Of
( It
: C3A2001_1
.Breaker
) return C3A2001_1
.Status
270 renames C3A2001_1
.Status_Of
;
272 procedure Flip
( The_Breaker
: in out Special_Breaker
) is
274 TCTouch
.Touch
( 'j' ); --------------------------------------------- j
275 case Status_Of
( C3A2001_1
.Breaker
( The_Breaker
)) is
276 when C3A2001_1
.Power_Off | C3A2001_1
.Power_On
=>
277 C3A2001_2
.Flip
( C3A2001_2
.Basic_Breaker
( The_Breaker
) );
279 C3A2001_2
.Flip
( The_Breaker
.Backup
);
283 procedure Trip
( The_Breaker
: in out Special_Breaker
) is
285 TCTouch
.Touch
( 'k' ); --------------------------------------------- k
286 case Status_Of
( C3A2001_1
.Breaker
( The_Breaker
)) is
287 when C3A2001_1
.Power_Off
=> null;
288 when C3A2001_1
.Power_On
=>
289 C3A2001_2
.Reset
( The_Breaker
.Backup
);
290 C3A2001_2
.Trip
( C3A2001_2
.Basic_Breaker
( The_Breaker
) );
292 C3A2001_2
.Trip
( The_Breaker
.Backup
);
296 procedure Reset
( The_Breaker
: in out Special_Breaker
) is
298 TCTouch
.Touch
( 'l' ); --------------------------------------------- l
299 case Status_Of
( C3A2001_1
.Breaker
( The_Breaker
)) is
300 when C3A2001_1
.Tripped
=>
301 C3A2001_2
.Reset
( C3A2001_2
.Basic_Breaker
( The_Breaker
));
302 when C3A2001_1
.Failed
=>
303 C3A2001_2
.Reset
( The_Breaker
.Backup
);
304 when C3A2001_1
.Power_On | C3A2001_1
.Power_Off
=>
309 procedure Fail
( The_Breaker
: in out Special_Breaker
) is
311 TCTouch
.Touch
( 'm' ); --------------------------------------------- m
312 case Status_Of
( C3A2001_1
.Breaker
( The_Breaker
)) is
313 when C3A2001_1
.Failed
=>
314 C3A2001_2
.Fail
( The_Breaker
.Backup
);
316 C3A2001_2
.Fail
( C3A2001_2
.Basic_Breaker
( The_Breaker
));
317 C3A2001_2
.Reset
( The_Breaker
.Backup
);
321 function Status_Of
( The_Breaker
: Special_Breaker
)
322 return C3A2001_1
.Status
is
324 TCTouch
.Touch
( 'n' ); --------------------------------------------- n
325 case Status_Of
( C3A2001_1
.Breaker
( The_Breaker
)) is
326 when C3A2001_1
.Power_On
=> return C3A2001_1
.Power_On
;
327 when C3A2001_1
.Power_Off
=> return C3A2001_1
.Power_Off
;
329 return C3A2001_2
.Status_Of
( The_Breaker
.Backup
);
333 function On_Backup
( The_Breaker
: Special_Breaker
) return Boolean is
335 use type C3A2001_1
.Status
;
337 return Status_Of
(Basic_Breaker
(The_Breaker
)) = C3A2001_1
.Tripped
338 or Status_Of
(Basic_Breaker
(The_Breaker
)) = C3A2001_1
.Failed
;
343 ----------------------------------------------------------------------------
348 type Component
is access C3A2001_1
.Breaker
'Class;
351 type Connection
is access Circuit
;
353 type Circuit
is record
354 The_Gadget
: Component
;
358 procedure Flipper
( The_Circuit
: Connection
);
359 procedure Tripper
( The_Circuit
: Connection
);
360 procedure Restore
( The_Circuit
: Connection
);
361 procedure Failure
( The_Circuit
: Connection
);
363 Short
: Connection
:= null;
367 ----------------------------------------------------------------------------
370 with C3A2001_1
, C3A2001_2
, C3A2001_3
, C3A2001_4
;
372 pragma Elaborate_All
( Report
, TCTouch
,
373 C3A2001_1
, C3A2001_2
, C3A2001_3
, C3A2001_4
);
375 package body C3A2001_5
is
377 function Neww
( Breaker
: in C3A2001_1
.Breaker
'Class )
380 return new C3A2001_1
.Breaker
'Class'( Breaker );
383 procedure Add( Gadget : in Component;
384 To_Circuit : in out Connection) is
386 To_Circuit := new Circuit'(Gadget
,To_Circuit
);
389 procedure Flipper
( The_Circuit
: Connection
) is
390 Probe
: Connection
:= The_Circuit
;
392 while Probe
/= null loop
393 C3A2001_1
.Flip
( Probe
.The_Gadget
.all );
398 procedure Tripper
( The_Circuit
: Connection
) is
399 Probe
: Connection
:= The_Circuit
;
401 while Probe
/= null loop
402 C3A2001_1
.Trip
( Probe
.The_Gadget
.all );
407 procedure Restore
( The_Circuit
: Connection
) is
408 Probe
: Connection
:= The_Circuit
;
410 while Probe
/= null loop
411 C3A2001_1
.Reset
( Probe
.The_Gadget
.all );
416 procedure Failure
( The_Circuit
: Connection
) is
417 Probe
: Connection
:= The_Circuit
;
419 while Probe
/= null loop
420 C3A2001_1
.Fail
( Probe
.The_Gadget
.all );
426 Add
( Neww
( C3A2001_2
.Construct
( C3A2001_2
.V440
, C3A2001_2
.A5
)), Short
);
427 Add
( Neww
( C3A2001_3
.Construct
( C3A2001_2
.V110
, C3A2001_2
.A1
)), Short
);
428 Add
( Neww
( C3A2001_4
.Construct
( C3A2001_2
.V12
, C3A2001_2
.A100
)), Short
);
431 ----------------------------------------------------------------------------
438 begin -- Main test procedure.
440 Report
.Test
("C3A2001", "Check that an abstract type can be declared " &
441 "and used. Check actual subprograms dispatch correctly" );
443 -- This Validate call must be _after_ the call to Report.Test
444 TCTouch
.Validate
( "cgcicc", "Adding" );
446 C3A2001_5
.Flipper
( C3A2001_5
.Short
);
447 TCTouch
.Validate
( "jbdbdbdb", "Flipping" );
449 C3A2001_5
.Tripper
( C3A2001_5
.Short
);
450 TCTouch
.Validate
( "kbfbeee", "Tripping" );
452 C3A2001_5
.Restore
( C3A2001_5
.Short
);
453 TCTouch
.Validate
( "lbfbfbfb", "Restoring" );
455 C3A2001_5
.Failure
( C3A2001_5
.Short
);
456 TCTouch
.Validate
( "mbafbaa", "Circuits Failing" );