summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/ca/ca11003.a
blob: ff894250ed03b1b3ed5fe5fbca1002e595b747fc (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
-- CA11003.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 public grandchild can utilize its ancestor unit's visible 
--      definitions.
--
-- TEST DESCRIPTION:
--      Declare a public package, public child package, and public 
--      grandchild package and library unit function.  Within the 
--      grandchild package and function, make use of components that are 
--      declared in the ancestor packages, both parent and grandparent.  
--
--      Use the following ancestral components in the grandchildren library
--      units:
--                       Grandparent   Parent
--          Type              X           X
--          Constant          X           X
--          Object            X           X
--          Subprogram        X           X
--          Exception         X           X
--
--
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--      21 Dec 94   SAIC    Modified procedure Create_File
--      15 Nov 95   SAIC    Update and repair for ACVC 2.0.1
--
--!
   
package CA11003_0 is      -- Package OS 

   type File_Descriptor is new Integer;
   type File_Mode       is (Read_Only, Write_Only, Read_Write);

   Null_File       : constant File_Descriptor := 0;
   Default_Mode    : constant File_Mode       := Read_Only;
   File_Data_Error : exception;

   type File_Type is tagged
     record
        Descriptor : File_Descriptor := Null_File;
        Mode       : File_Mode       := Read_Write;
     end record;

   System_File : File_Type;

   function Next_Available_File return File_Descriptor;

   procedure Reclaim_File_Descriptor;

end CA11003_0;               -- Package OS 

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

package body CA11003_0 is    -- Package body OS 
   
   File_Count : Integer := 0;

   function Next_Available_File return File_Descriptor is
   begin
      File_Count := File_Count + 1;
      return (File_Descriptor(File_Count));
   end Next_Available_File;
   --------------------------------------------------
   procedure Reclaim_File_Descriptor is
   begin
      null;                                        -- Dummy processing unit.
   end Reclaim_File_Descriptor;

end CA11003_0;                          -- Package body OS 

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

package CA11003_0.CA11003_1 is          -- Child package OS.Operations

   subtype File_Length_Type is Integer range 0 .. 1000;
   Min_File_Size : File_Length_Type := File_Length_Type'First;
   Max_File_Size : File_Length_Type := File_Length_Type'Last;

   File_Duplication_Error : exception;

   type Extended_File_Type is new File_Type with private;

   procedure Create_File (Mode : in     File_Mode;
                          File :    out Extended_File_Type);    

   procedure Duplicate_File (Original  : in     Extended_File_Type;
                             Duplicate :    out Extended_File_Type);

private
   type Extended_File_Type is new File_Type with
      record
         Blocks : File_Length_Type := Min_File_Size;
      end record;

   System_Extended_File : Extended_File_Type;

end CA11003_0.CA11003_1;                -- Child Package OS.Operations 

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

package body CA11003_0.CA11003_1 is     -- Child package body OS.Operations

   procedure Create_File 
     (Mode : in     File_Mode;
      File :    out Extended_File_Type) is                 
   begin
      File.Descriptor := Next_Available_File;           -- Parent subprogram.
      File.Mode       := Default_Mode;                  -- Parent constant.
      File.Blocks     := Min_File_Size;
   end Create_File;
   --------------------------------------------------
   procedure Duplicate_File (Original  : in     Extended_File_Type;
                             Duplicate :    out Extended_File_Type) is
   begin
      Duplicate.Descriptor := Next_Available_File;      -- Parent subprogram.
      Duplicate.Mode       := Original.Mode;
      Duplicate.Blocks     := Original.Blocks;
   end Duplicate_File;

end CA11003_0.CA11003_1;                   -- Child package body OS.Operations

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

-- This package contains menu selectable operations for manipulating files.
-- This abstraction builds on the capabilities available from ancestor
-- packages.

package CA11003_0.CA11003_1.CA11003_2 is   

   procedure News (Mode : in     File_Mode;
                   File :    out Extended_File_Type);    

   procedure Copy (Original  : in     Extended_File_Type;
                   Duplicate :    out Extended_File_Type);

   procedure Delete   (File : in Extended_File_Type);

end CA11003_0.CA11003_1.CA11003_2;  -- Grandchild package OS.Operations.Menu
 
     --=================================================================--

-- Grandchild subprogram Validate 
function  CA11003_0.CA11003_1.CA11003_3 (File : in Extended_File_Type) 
  return Boolean;     

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

-- Grandchild subprogram Validate 
function  CA11003_0.CA11003_1.CA11003_3         
  (File : in Extended_File_Type)                            -- Parent type.
  return Boolean is      

   function New_File_Validated (File : Extended_File_Type) 
       return Boolean is  
   begin                                                
      if (File.Descriptor > System_File.Descriptor) and     -- Grandparent
         (File.Mode in File_Mode ) and                      -- object and type
         not ((File.Blocks < System_Extended_File.Blocks) or       
              (File.Blocks > Max_File_Size))                -- Parent object
      then                                                  -- and constant.
         return True;
      else
         return False;
      end if;
   end New_File_Validated;
      
begin
   return (New_File_Validated (File)) and    
          (File.Descriptor /= Null_File);              -- Grandparent constant.
                                                 
end CA11003_0.CA11003_1.CA11003_3;      -- Grandchild subprogram Validate

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

with CA11003_0.CA11003_1.CA11003_3;
                                 -- Grandchild package body OS.Operations.Menu
package body CA11003_0.CA11003_1.CA11003_2 is  

   procedure News (Mode : in     File_Mode;
                   File :    out Extended_File_Type) is   -- Parent type.
   begin
      Create_File (Mode, File);                           -- Parent subprogram.
      if not CA11003_0.CA11003_1.CA11003_3 (File) then                       
         raise File_Data_Error;                       -- Grandparent exception.
      end if;
   end News;
   --------------------------------------------------
   procedure Copy (Original  : in     Extended_File_Type;
                   Duplicate :    out Extended_File_Type) is
   begin
      Duplicate_File (Original, Duplicate);               -- Parent subprogram.

      if Original.Descriptor = Duplicate.Descriptor then
         raise File_Duplication_Error;                    -- Parent exception.
      end if;

   end Copy;
   --------------------------------------------------
   procedure Delete (File : in Extended_File_Type) is
   begin
      Reclaim_File_Descriptor;                            -- Grandparent
   end Delete;                                            -- subprogram.

end CA11003_0.CA11003_1.CA11003_2;  

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

with CA11003_0.CA11003_1.CA11003_2;  -- Grandchild Pkg OS.Operations.Menu
with CA11003_0.CA11003_1.CA11003_3;  -- Grandchild Ftn OS.Operations.Validate
with Report;

procedure CA11003 is

   package Menu renames CA11003_0.CA11003_1.CA11003_2;

begin

   Report.Test ("CA11003", "Check that a public grandchild can utilize " &
                "its ancestor unit's visible definitions");

   File_Processing:         -- Validate all of the capabilities contained in 
                            -- the Menu package by exercising them on specific 
                            -- files.  This will demonstrate the use of child
                            -- and grandchild functionality based on components
                            -- that have been declared in the
                            -- parent/grandparent package.
   declare

      function Validate (File : CA11003_0.CA11003_1.Extended_File_Type) 
        return Boolean renames CA11003_0.CA11003_1.CA11003_3;

      MacWrite_File,
      Backup_Copy : CA11003_0.CA11003_1.Extended_File_Type;        
      MacWrite_File_Mode : CA11003_0.File_Mode := CA11003_0.Read_Write;
                                     
   begin                                                
                                                        
      Menu.News (MacWrite_File_Mode, MacWrite_File);                          

      if not Validate (MacWrite_File) then
         Report.Failed ("Incorrect initialization of files");
      end if;

      Menu.Copy (MacWrite_File, Backup_Copy);

      if not (Validate (MacWrite_File) and 
              Validate (Backup_Copy))
      then
         Report.Failed ("Incorrect duplication of files");
      end if;

      Menu.Delete (Backup_Copy);

   exception
      when CA11003_0.File_Data_Error =>
          Report.Failed ("Exception raised during file validation");
      when CA11003_0.CA11003_1.File_Duplication_Error =>
          Report.Failed ("Exception raised during file duplication");
      when others =>
          Report.Failed ("Unexpected exception in test procedure");

   end File_Processing;

   Report.Result;

end CA11003;