summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/c3/c393a06.a
blob: c257d5fa0a042583d3c191dfcfaeeb9b88e759c4 (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
-- C393A06.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 a type that inherits abstract operations but
--      overrides each of these operations is not required to be
--      abstract, and that objects of the type and its class-wide type
--      may be declared and passed in calls to the overriding
--      subprograms.
--
-- TEST DESCRIPTION:
--      This test derives a type from the root abstract type available
--      in foundation F393A00.  It declares subprograms as required by
--      the language to override the abstract subprograms, allowing the
--      derived type itself to be not abstract.  It also declares
--      operations on the new type, as well as on the associated class-
--      wide type.  The main program then uses two objects of the type
--      and two objects of the class-wide type as parameters for each of
--      the subprograms.  Correct execution is determined by path
--      analysis and value checking.
--
-- TEST FILES:
--      The following files comprise this test:
--
--         F393A00.A   (foundation code)
--         C393A06.A
--
--
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--      19 Dec 94   SAIC    Removed RM references from objective text.
--
--!
 
 with F393A00_1;
 package C393A06_0 is
   type Organism is new F393A00_1.Object with private;
   type Kingdoms is ( Animal, Vegetable, Unspecified );
 
   procedure Swap( A,B: in out Organism );
   function  Create return Organism;
 
   procedure Initialize( The_Entity     : in out Organism;
                         In_The_Kingdom : Kingdoms );
   function  Kingdom( Of_The_Entity : Organism ) return Kingdoms;
 
   procedure TC_Check( An_Entity   : Organism'Class;
                       In_Kingdom  : Kingdoms;
                       Initialized : Boolean );
 
   Incompatible : exception;
 
 private
   type Organism is new F393A00_1.Object with
     record
       In_Kingdom : Kingdoms;
     end record;
 end C393A06_0;
 
 with F393A00_0;
 package body C393A06_0 is
 
   procedure Swap( A,B: in out Organism ) is
   begin
     F393A00_0.TC_Touch( 'A' );  ------------------------------------------- A
     if A.In_Kingdom /= B.In_Kingdom then
       F393A00_0.TC_Touch( 'X' );
       raise Incompatible;
     else
       declare
         T: constant Organism := A;
       begin
         A := B;
         B := T;
       end;
     end if;
   end Swap;
 
   function  Create return Organism is
     Widget : Organism;
   begin
     F393A00_0.TC_Touch( 'B' ); ------------------------------------------- B
     Initialize( Widget );
     Widget.In_Kingdom := Unspecified;
     return Widget;
   end Create;
 
   procedure Initialize( The_Entity     : in out Organism;
                         In_The_Kingdom : Kingdoms ) is
   begin
     F393A00_0.TC_Touch( 'C' ); ------------------------------------------- C
     F393A00_1.Initialize( F393A00_1.Object( The_Entity ) );
     The_Entity.In_Kingdom := In_The_Kingdom;
   end Initialize;
 
   function  Kingdom( Of_The_Entity : Organism ) return Kingdoms is
   begin
     F393A00_0.TC_Touch( 'D' ); ------------------------------------------- D
     return Of_The_Entity.In_Kingdom;
   end Kingdom;
 
   procedure TC_Check( An_Entity   : Organism'Class;
                       In_Kingdom  : Kingdoms;
                       Initialized : Boolean ) is
   begin
     if F393A00_1.Initialized( An_Entity ) /= Initialized then
       F393A00_0.TC_Touch( '-' ); ------------------------------------------- -
     elsif An_Entity.In_Kingdom /= In_Kingdom then
       F393A00_0.TC_Touch( '!' ); ------------------------------------------- !
     else
       F393A00_0.TC_Touch( '+' ); ------------------------------------------- +
     end if;
   end TC_Check;
 
 end C393A06_0;
 
 with Report;
 
 with C393A06_0;
 with F393A00_0;
 with F393A00_1;
 procedure C393A06 is
 
   package Darwin  renames C393A06_0;
   package Tagger  renames F393A00_0;
   package Objects renames F393A00_1;
 
   Lion      : Darwin.Organism;
   Tigerlily : Darwin.Organism;
   Bear      : Darwin.Organism'Class := Darwin.Create;
   Sunflower : Darwin.Organism'Class := Darwin.Create;
 
   use type Darwin.Kingdoms;
 
 begin  -- Main test procedure.
 
    Report.Test ("C393A06", "Check that a type that inherits abstract "
                          & "operations but overrides each of these "
                          & "operations is not required to be abstract. "
                          & "Check that objects of the type and its "
                          & "class-wide type may be declared and passed "
                          & "in calls to the overriding subprograms" );
 
   Tagger.TC_Validate( "BaBa", "Declaration Initializations" );
 
   Darwin.Initialize( Lion,      Darwin.Animal );
   Darwin.Initialize( Tigerlily, Darwin.Vegetable );
   Darwin.Initialize( Bear,      Darwin.Animal );
   Darwin.Initialize( Sunflower, Darwin.Vegetable );
 
   Tagger.TC_Validate( "CaCaCaCa", "Initialization sequence" );
 
   Oh_My: begin
     Darwin.Swap( Lion, Darwin.Organism( Bear ) );
     Darwin.Swap( Lion, Tigerlily );
     Report.Failed("Exception not raised");
   exception
     when Darwin.Incompatible => null;
   end Oh_My;
 
   Tagger.TC_Validate( "AAX", "Swap sequence" );
 
   if Darwin.Kingdom( Darwin.Create ) = Darwin.Unspecified then
     Darwin.Swap( Sunflower, Darwin.Organism'Class( Tigerlily ) );
   end if;
 
   Tagger.TC_Validate( "BaDA", "Vegetable swap sequence" );
 
   Darwin.TC_Check( Lion,      Darwin.Animal,    True );
   Darwin.TC_Check( Tigerlily, Darwin.Vegetable, True );
   Darwin.TC_Check( Bear,      Darwin.Animal,    True );
   Darwin.TC_Check( Sunflower, Darwin.Vegetable, True );
 
   Tagger.TC_Validate( "b+b+b+b+", "Final sequence" );
 
   Report.Result;
 
 end C393A06;