summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/ca/ca11016.a
blob: d6d4089a959c3a969c87462f7d5dd70dced67dce (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
-- CA11016.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 child of a non-generic package can be a private generic 
--      package. Check that the private child instance can use its parent's
--      declarations and operations.  Check that the body of a public child 
--      package can instantiate its sibling private generic package.
--
-- TEST DESCRIPTION:
--      Declare a map abstraction in a package which manages basic physical
--      map[s].  Declare a private generic child of this package which can be
--      instantiated for any display device which has display locations of 
--      the physical map that can be characterized by any integer type, i.e., 
--      the intensity of the display point.
--
--      Declare a public child of the physical map which specifies the 
--      display device.  In the body of this child, declare an instance of 
--      its generic sibling to display the geographic locations.
--
--      In the main program, check that the operations in the parent, public 
--      child and instance of the private child package perform as expected.  
--
--
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--      17 Apr 96   SAIC    ACVC 2.1: Added pragma Elaborate.
--
--!

-- Simulates map of physical features, i.e., desert, forest, or water.

package CA11016_0 is              
   type Map_Type is private;
   subtype Latitude is integer range 1 .. 9;
   subtype Longitude is integer range 1 .. 7;

   type Physical_Features is (Desert, Forest, Water);
   
   -- Use geographic database to initialize the basic map.

   procedure Initialize_Basic_Map (Map  : in out Map_Type);

   function Get_Physical_Feature (Lat  : Latitude;
                                  Long : Longitude;
                                  Map  : Map_Type) return Physical_Features;

private
   type Map_Type is array (Latitude, Longitude) of Physical_Features;
   Basic_Map : Map_Type;

end CA11016_0;

     --==================================================================--

package body CA11016_0 is              

   procedure Initialize_Basic_Map (Map : in out Map_Type) is
   -- Not a real initialization.  Real application can use geographic
   -- database to create the basic map.

   begin
      for I in Latitude'first .. Latitude'last loop
         for J in 1 .. 2 loop
            Map (I, J) := Desert;
         end loop;
         for J in 3 .. 4 loop
            Map (I, J) := Forest;
         end loop;
         for J in 5 .. 7 loop
            Map (I, J) := Water;
         end loop;
      end loop;

   end Initialize_Basic_Map;
   --------------------------------------------------------
   function Get_Physical_Feature (Lat  : Latitude;
                                  Long : Longitude;
                                  Map  : Map_Type) 
     return Physical_Features is
   begin
     return (Map (Lat, Long));
   end Get_Physical_Feature;
   --------------------------------------------------------

   begin
      -- Initialize a basic map.
      Initialize_Basic_Map (Basic_Map);

end CA11016_0;

     --==================================================================--

-- Private generic child package of physical map.  This generic package may
-- be instantiated for any display device which has display locations 
-- (latitude, longitude) that can be characterized by an integer value.
-- For example, the intensity of the display point might be so characterized.
-- It can be instantiated for any desired range of values (which would 
-- correspond to the range accepted by the display device).


private 

generic               

   type Display_Value is range <>;  -- Any display feature that is 
                                    -- represented by an integer.

package CA11016_0.CA11016_1 is              

   function Get_Display_Value (Lat  : Latitude;
                               Long : Longitude;
                               Map  : Map_Type) return Display_Value;

end CA11016_0.CA11016_1;


     --==================================================================--


package body CA11016_0.CA11016_1 is              

   function Get_Display_Value (Lat  : Latitude;
                               Long : Longitude;
                               Map  : Map_Type) 
     return Display_Value is
   begin
      case Get_Physical_Feature (Lat, Long, Map) is
                                          -- Parent's operation,
           when Forest => return (Display_Value'first);
                                          -- Parent's type.
           when Desert => return (Display_Value'last);
                                          -- Parent's type.
           when others => return 
                            ( (Display_Value'last - Display_Value'first) / 2 );
                                          -- NOTE: Results are truncated.
      end case;

   end Get_Display_Value;

end CA11016_0.CA11016_1;


     --==================================================================--

-- Map display operation, public child of physical map.

package CA11016_0.CA11016_2 is              

   -- Super-duper Ultra Geographic Display Device (SDUGD) can display 
   -- geographic locations with light intensity values ranging from 1 to 7.

   type Display_Val is range 1 .. 7;

   type Device_Color is (Brown, Blue, Green);

   type IO_Packet is
      record
         Lat       : Latitude;       -- Parent's type.
         Long      : Longitude;      -- Parent's type.
         Color     : Device_Color;
         Intensity : Display_Val;
      end record;

   procedure Data_For_SDUGD (Lat           : in     Latitude;
                             Long          : in     Longitude;
                             Output_Packet : in out IO_Packet);

end CA11016_0.CA11016_2;

     --==================================================================--


with CA11016_0.CA11016_1;          -- Private generic sibling.
pragma Elaborate (CA11016_0.CA11016_1);

package body CA11016_0.CA11016_2 is              

   -- Declare instance of the private generic sibling for 
   -- an integer type that represents color intensity.

   package SDUGD is new CA11016_0.CA11016_1 (Display_Val);

   procedure Data_For_SDUGD (Lat           : in     Latitude;
                             Long          : in     Longitude;
                             Output_Packet : in out IO_Packet) is

   -- Simulates sending control information to a display device.
   -- Control information consists of latitude, longitude, a
   -- color, and an intensity.

   begin
      case Get_Physical_Feature (Lat, Long, Basic_Map) is
                                           -- Parent's operation.
         when Water  => Output_Packet.Color     := Blue;
                        Output_Packet.Intensity := SDUGD.Get_Display_Value 
                                                   (Lat, Long, Basic_Map);
                                           -- Sibling's operation.
         when Forest => Output_Packet.Color     := Green;
                        Output_Packet.Intensity := SDUGD.Get_Display_Value 
                                                   (Lat, Long, Basic_Map);
                                           -- Sibling's operation.
         when others => Output_Packet.Color     := Brown;
                        Output_Packet.Intensity := SDUGD.Get_Display_Value 
                                                   (Lat, Long, Basic_Map);
                                           -- Sibling's operation.
       end case;

   end Data_For_SDUGD;

end CA11016_0.CA11016_2;

     --==================================================================--

with CA11016_0.CA11016_2;            -- Map display device operation,
                                     -- implicitly withs parent, physical map
                                     -- application.

use CA11016_0.CA11016_2;             -- Allows direct visibility to the simple
                                     -- name of CA11016_0.CA11016_2.

with Report;

procedure CA11016 is

   TC_Packet : IO_Packet;

begin 

   Report.Test ("CA11016", "Check that body of a public child package can " &
                           "use its sibling private generic package "       &
                           "declarations and operations");

-- Simulate control information at coordinates 3 and 7 of the
-- basic map for the SDUGD.
         
         Water_Display_Subtest:
         begin
            TC_Packet.Lat  := 3;
            TC_Packet.Long := 7;

            -- Build color and light intensity of the basic map at 
            -- latitude 3 and longitude 7.

            Data_For_SDUGD (TC_Packet.Lat, TC_Packet.Long, TC_Packet);

            if ( (TC_Packet.Color     /= Blue) or
                 (TC_Packet.Intensity /= 3) ) then
                Report.Failed ("Map display device contains " &
                               "incorrect values for water subtest");
            end if;

         end Water_Display_Subtest;

-- Simulate control information at coordinates 2 and 1 of the
-- basic map for the SDUGD.
         
         Desert_Display_Subtest:
         begin
            TC_Packet.Lat  := 9;
            TC_Packet.Long := 2;

            -- Build color and light intensity of the basic map at 
            -- latitude 9 and longitude 2.

            Data_For_SDUGD (TC_Packet.Lat, TC_Packet.Long, TC_Packet);

            if ( (TC_Packet.Color     /= Brown) or
                 (TC_Packet.Intensity /= 7) ) then
                Report.Failed ("Map display device contains " &
                               "incorrect values for desert subtest");
            end if;

         end Desert_Display_Subtest;

-- Simulate control information at coordinates 8 and 4 of the
-- basic map for the SDUGD.
         
         Forest_Display_Subtest:
         begin
            TC_Packet.Lat  := 8;
            TC_Packet.Long := 4;

            -- Build color and light intensity of the basic map at 
            -- latitude 8 and longitude 4.

            Data_For_SDUGD (TC_Packet.Lat, TC_Packet.Long, TC_Packet);

            if ( (TC_Packet.Color     /= Green) or
                 (TC_Packet.Intensity /= 1) ) then
                Report.Failed ("Map display device contains " &
                               "incorrect values for forest subtest");
            end if;

         end Forest_Display_Subtest;

   Report.Result;

end CA11016;