summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/c3/c391001.a
blob: bca7525765fa1202403479d8c6bb48d2102e933d (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
-- C391001.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 structures nesting discriminated records as
--      components in record extension are correctly supported.  Check
--      for this using limited private structures.
--      Check that record extensions inherit all the visible components
--      of their ancestor types. 
--      Check that discriminants are correctly inherited.
--
-- TEST DESCRIPTION:
--      This test defines a textbook object, a serial number plaque.
--      This object is used in each of several other structures modeled
--      after those used in an existing antenna modeling software system.
--      Record types discriminated and undiscriminated are nested to
--      produce a layered design.  Some parametrization is programmatic;
--      some parametrization is data-driven.
--
--
--
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--      19 Dec 94   SAIC    Removed RM references from objective text.
--      19 Apr 95   SAIC    Added "limited" to full type def of "Object"
--
--!
 
 package C391001_1 is 
   type Object is tagged limited private;
   -- Constructor operation
   procedure Create( The_Plaque : in out Object );
   -- Selector operations
   function "="( Left_Plaque,Right_Plaque : Object ) return Boolean;
   function TC_Match( Left_Plaque : Object; Right_Natural : Natural )
     return Boolean;
   function Serial_Number( A_Plaque : Object ) return Natural;
   Unserialized : exception;  -- Serial_Number called before Create
   Reserialized : exception;  -- Create called twice
 private
   type Object is tagged limited record
     Serial_Number : Natural := 0;
   end record;
 end C391001_1;
 
 package body C391001_1 is
   Counter : Natural := 0;
   procedure Create( The_Plaque : in out Object ) is
   begin
     if The_Plaque.Serial_Number = 0 then
       Counter := Counter +1;
       The_Plaque.Serial_Number := Counter;
     else
       raise Reserialized;
     end if;
   end Create;
 
   function "="( Left_Plaque,Right_Plaque : Object ) return Boolean is
   begin
     return (Left_Plaque.Serial_Number = Right_Plaque.Serial_Number)
            and then -- two uninitialized plates are unequal
              (Left_Plaque.Serial_Number /= 0);
   end "=";
 
   function TC_Match( Left_Plaque : Object; Right_Natural : Natural )
     return Boolean is
   begin
     return (Left_Plaque.Serial_Number = Right_Natural);
   end TC_Match;
 
   function Serial_Number( A_Plaque : Object ) return Natural is
   begin
     if A_Plaque.Serial_Number = 0 then
       raise Unserialized;
     end if;
     return A_Plaque.Serial_Number;
   end Serial_Number;
 end C391001_1;
 
 with C391001_1;
 package C391001_2 is -- package Boards is
 
   package Plaque renames C391001_1;
 
   type Modes is (Receiving, Transmitting, Standby);
   type Link(Mode: Modes := Standby) is record
     case Mode is
       when Receiving    => TC_R : Integer := 100; 
       when Transmitting => TC_T : Integer := 200;
       when Standby      => TC_S : Integer := 300; -- TGA, TSA, SSA
     end case;
   end record;
 
   type Data_Formats is (S_Band, KU_Band, UHF);
 
 
   type Transceiver(Band: Data_Formats) is tagged limited record
     ID : Plaque.Object;
     The_Link: Link;
     case Band is
       when S_Band  => TC_S_Band_Data  : Integer := 1; -- TGA, SSA
       when KU_Band => TC_KU_Band_Data : Integer := 2; -- TSA
       when UHF     => TC_UHF_Data     : Integer := 3;
     end case;
   end record;
 end C391001_2;
 
 with C391001_1;
 with C391001_2;
 package C391001_3 is -- package Modules
   package Plaque renames C391001_1;
   package Boards renames C391001_2;
   use type Boards.Modes;
   use type Boards.Data_Formats;
 
   type Command_Formats is ( Set_Compression_Code,
                             Set_Data_Rate,
                             Set_Power_State );
 
   type Electronics_Module(EBand             : Boards.Data_Formats;
                           The_Command_Format: Command_Formats)
     is new Boards.Transceiver(EBand) with record
       case The_Command_Format is
         when Set_Compression_Code => TC_SCC : Integer := 10; -- SSA
         when Set_Data_Rate        => TC_SDR : Integer := 20; -- TGA
         when Set_Power_State      => TC_SPS : Integer := 30; -- TSA
       end case;
     end record;
 end C391001_3;
 
 with Report;
 with C391001_1;
 with C391001_2;
 with C391001_3;
 procedure C391001 is
   package Plaque  renames C391001_1;
   package Boards  renames C391001_2;
   package Modules renames C391001_3;
   use type Boards.Modes;
   use type Boards.Data_Formats;
   use type Modules.Command_Formats;
 
   type Azimuth is range 0..359;
 
   type Ground_Antenna(The_Band          : Boards.Data_Formats;
                       The_Command_Format: Modules.Command_Formats) is
     record
       ID          : Plaque.Object;
       Electronics : Modules.Electronics_Module(The_Band,The_Command_Format);
       Pointing    : Azimuth;
     end record;
 
   type Space_Antenna(The_Band    : Boards.Data_Formats := Boards.KU_Band;
                      The_Command : Modules.Command_Formats
                                    := Modules.Set_Power_State)
   is
     record
       ID          : Plaque.Object;
       Electronics : Modules.Electronics_Module(The_Band,The_Command);
     end record;
 
   The_Ground_Antenna     : Ground_Antenna (Boards.S_Band,
                                            Modules.Set_Data_Rate);
   The_Space_Antenna      : Space_Antenna;
   Space_Station_Antenna  : Space_Antenna  (Boards.S_Band,
                                            Modules.Set_Compression_Code);
 
 
   procedure Validate( Condition : Boolean; Message: String ) is
   begin
     if not Condition then
       Report.Failed("Failed " & Message );
     end if;
   end Validate;
 
 begin
   Report.Test("C391001", "Check nested tagged discriminated "
                        & "record structures");
 
   Plaque.Create( The_Ground_Antenna.ID );               -- 1
   Plaque.Create( The_Ground_Antenna.Electronics.ID );   -- 2
   Plaque.Create( The_Space_Antenna.ID );                -- 3
   Plaque.Create( The_Space_Antenna.Electronics.ID );    -- 4
   Plaque.Create( Space_Station_Antenna.ID );            -- 5
   Plaque.Create( Space_Station_Antenna.Electronics.ID );-- 6
 
   The_Ground_Antenna.Pointing := 180;
   Validate( The_Ground_Antenna.The_Band = Boards.S_Band, "TGA discr 1" );
   Validate( The_Ground_Antenna.The_Command_Format = Modules.Set_Data_Rate,
             "TGA discr 2" );
   Validate( Plaque.TC_Match(The_Ground_Antenna.ID,1), "TGA comp 1" );
   Validate( The_Ground_Antenna.Electronics.EBand = Boards.S_Band,
             "TGA comp 2.discr 1" );
   Validate( The_Ground_Antenna.Electronics.The_Command_Format
             = Modules.Set_Data_Rate, "TGA comp 2.discr 2" );
   Validate( The_Ground_Antenna.Electronics.TC_SDR = 20,
             "TGA comp 2.1" );
   Validate( Plaque.TC_Match( The_Ground_Antenna.Electronics.ID, 2 ),
             "TGA comp 2.inher.1" );
   Validate( The_Ground_Antenna.Electronics.The_Link.Mode = Boards.Standby,
             "TGA comp 2.inher.2.discr" );
   Validate( The_Ground_Antenna.Electronics.The_Link.TC_S = 300,
             "TGA comp 2.inher.2.1" );
   Validate( The_Ground_Antenna.Electronics.TC_S_Band_Data = 1,
             "TGA comp 2.inher.3" );
   Validate( The_Ground_Antenna.Pointing = 180, "TGA comp 3" );
 
   Validate( The_Space_Antenna.The_Band = Boards.KU_Band, "TSA discr 1");
   Validate( The_Space_Antenna.The_Command = Modules.Set_Power_State,
             "TSA discr 2");
   Validate( Plaque.TC_Match(The_Space_Antenna.ID,3),
             "TSA comp 1");
   Validate( The_Space_Antenna.Electronics.EBand = Boards.KU_Band,
             "TSA comp 2.discr 1");
   Validate( The_Space_Antenna.Electronics.The_Command_Format
             = Modules.Set_Power_State,  "TSA comp 2.discr 2");
   Validate( Plaque.TC_Match(The_Space_Antenna.Electronics.ID,4),
             "TSA comp 2.inher.1");
   Validate( The_Space_Antenna.Electronics.The_Link.Mode = Boards.Standby,
             "TSA comp 2.inher.2.discr");
   Validate( The_Space_Antenna.Electronics.The_Link.TC_S = 300,
             "TSA comp 2.inher.2.1");
   Validate( The_Space_Antenna.Electronics.TC_KU_Band_Data = 2,
             "TSA comp 2.inher.3");
   Validate( The_Space_Antenna.Electronics.TC_SPS = 30,
             "TSA comp 2.1");
 
   Validate( Space_Station_Antenna.The_Band = Boards.S_Band, "SSA discr 1");
   Validate( Space_Station_Antenna.The_Command = Modules.Set_Compression_Code,
             "SSA discr 2");
   Validate( Plaque.TC_Match(Space_Station_Antenna.ID,5),
             "SSA comp 1");
   Validate( Space_Station_Antenna.Electronics.EBand = Boards.S_Band,
             "SSA comp 2.discr 1");
   Validate( Space_Station_Antenna.Electronics.The_Command_Format
             = Modules.Set_Compression_Code,  "SSA comp 2.discr 2");
   Validate( Plaque.TC_Match(Space_Station_Antenna.Electronics.ID,6),
             "SSA comp 2.inher.1");
   Validate( Space_Station_Antenna.Electronics.The_Link.Mode = Boards.Standby,
             "SSA comp 2.inher.2.discr");
   Validate( Space_Station_Antenna.Electronics.The_Link.TC_S = 300,
             "SSA comp 2.inher.2.1");
   Validate( Space_Station_Antenna.Electronics.TC_S_Band_Data = 1,
             "SSA comp 2.inher.3");
   Validate( Space_Station_Antenna.Electronics.TC_SCC = 10,
             "SSA comp 2.1");
 
   The_Ground_Antenna.Electronics.TC_SDR         := 1001;
   The_Ground_Antenna.Electronics.The_Link       :=
(Boards.Transmitting,2001);
   The_Ground_Antenna.Electronics.TC_S_Band_Data := 3001;
   The_Ground_Antenna.Pointing                   :=   41;
 
   The_Space_Antenna.Electronics.The_Link        := (Boards.Receiving,1010);
   The_Space_Antenna.Electronics.TC_KU_Band_Data := 2020;
   The_Space_Antenna.Electronics.TC_SPS          := 3030;
 
   Space_Station_Antenna.Electronics.The_Link
     := The_Space_Antenna.Electronics.The_Link;
   Space_Station_Antenna.Electronics.The_Link.TC_R  := 111;
   Space_Station_Antenna.Electronics.TC_S_Band_Data := 222;
   Space_Station_Antenna.Electronics.TC_SCC         := 333;
 
 ----------------------------------------------------------------------
   begin -- should fail discriminant check
     The_Ground_Antenna.Electronics.TC_SCC := 909;
     Report.Failed("Discriminant check, no exception");
   exception
     when Constraint_Error => null;
     when others =>
          Report.Failed("Discriminant check, wrong exception");
   end;
 
   Validate( The_Ground_Antenna.Electronics.TC_SDR         = 1001,
             "assigned value 1");
   Validate( The_Ground_Antenna.Electronics.The_Link.Mode
                                            = Boards.Transmitting,
             "assigned value 2.1");
   Validate( The_Ground_Antenna.Electronics.The_Link.TC_T  = 2001,
             "assigned value 2.2");
   Validate( The_Ground_Antenna.Electronics.TC_S_Band_Data = 3001,
             "assigned value 3");
   Validate( The_Ground_Antenna.Pointing                   =   41,
             "assigned value 4");
 
   Validate( The_Space_Antenna.Electronics.The_Link.Mode   = Boards.Receiving,
             "assigned value 5.1");
   Validate( The_Space_Antenna.Electronics.The_Link.TC_R   = 1010,
             "assigned value 5.2");
   Validate( The_Space_Antenna.Electronics.TC_KU_Band_Data = 2020,
             "assigned value 6");
   Validate( The_Space_Antenna.Electronics.TC_SPS          = 3030,
             "assigned value 7");
 
   Validate( Space_Station_Antenna.Electronics.The_Link.Mode
                                                 = Boards.Receiving,
             "assigned value 8.1");
   Validate( Space_Station_Antenna.Electronics.The_Link.TC_R  = 111,
             "assigned value 8.2");
   Validate( Space_Station_Antenna.Electronics.TC_S_Band_Data = 222,
             "assigned value 9");
   Validate( Space_Station_Antenna.Electronics.TC_SCC         = 333,
             "assigned value 10");
 
   Report.Result;
 
end C391001;