111
|
1 -- CA11011.A
|
|
2 --
|
|
3 -- Grant of Unlimited Rights
|
|
4 --
|
|
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
|
|
14 -- to do so.
|
|
15 --
|
|
16 -- DISCLAIMER
|
|
17 --
|
|
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.
|
|
24 --*
|
|
25 --
|
|
26 -- OBJECTIVE:
|
|
27 -- Check that a private child package can use entities declared in the
|
|
28 -- private part of the parent unit of its parent unit.
|
|
29 --
|
|
30 -- TEST DESCRIPTION:
|
|
31 -- Declare a parent package containing private types and objects
|
|
32 -- used by the system. Declare a public child package that
|
|
33 -- provides a visible interface to the system functionality.
|
|
34 -- Declare a private grandchild package that uses the visible grandparent
|
|
35 -- components to provide the actual functionality to the system.
|
|
36 --
|
|
37 -- The public child (parent of the private grandchild) uses the
|
|
38 -- functionality of its private child (grandchild package) to provide
|
|
39 -- the visible interface to operations of the system.
|
|
40 --
|
|
41 -- The test itself will utilize the visible interface provided in the
|
|
42 -- public child package to demonstrate a possible solution to file
|
|
43 -- management.
|
|
44 --
|
|
45 --
|
|
46 -- CHANGE HISTORY:
|
|
47 -- 06 Dec 94 SAIC ACVC 2.0
|
|
48 --
|
|
49 --!
|
|
50
|
|
51 package CA11011_0 is -- Package OS.
|
|
52
|
|
53 type File_Descriptor_Type is private;
|
|
54
|
|
55 Default_Descriptor : constant File_Descriptor_Type;
|
|
56 First_File : constant File_Descriptor_Type;
|
|
57
|
|
58 procedure Verify_Initial_Conditions (Key : in File_Descriptor_Type;
|
|
59 Status : out Boolean);
|
|
60
|
|
61 function Final_Conditions_Valid (Key : File_Descriptor_Type)
|
|
62 return Boolean;
|
|
63
|
|
64
|
|
65 private
|
|
66
|
|
67 type File_Descriptor_Type is new Integer;
|
|
68 type File_Name_Type is new String (1 .. 11);
|
|
69 type Permission_Type is (None, User, System);
|
|
70 type File_Mode_Type is (Read_Only, Write_Only, Read_Write);
|
|
71 type File_Status_Type is (Open, Closed);
|
|
72
|
|
73 Default_Descriptor : constant File_Descriptor_Type := 0;
|
|
74 First_File : constant File_Descriptor_Type := 1;
|
|
75 Default_Permission : constant Permission_Type := None;
|
|
76 Default_Mode : constant File_Mode_Type := Read_Only;
|
|
77 Default_Status : constant File_Status_Type := Closed;
|
|
78 Default_Filename : constant File_Name_Type := " ";
|
|
79
|
|
80 Init_Permission : constant Permission_Type := User;
|
|
81 Init_Mode : constant File_Mode_Type := Read_Write;
|
|
82 Init_Status : constant File_Status_Type := Open;
|
|
83 An_Ada_File_Name : constant File_Name_Type := "AdaFileName";
|
|
84
|
|
85 Max_Files : constant File_Descriptor_Type := 10;
|
|
86
|
|
87 type File_Type is tagged
|
|
88 record
|
|
89 Descriptor : File_Descriptor_Type := Default_Descriptor;
|
|
90 Name : File_Name_Type := Default_Filename;
|
|
91 Acct_Access : Permission_Type := Default_Permission;
|
|
92 Mode : File_Mode_Type := Default_Mode;
|
|
93 Current_Status : File_Status_Type := Default_Status;
|
|
94 end record;
|
|
95
|
|
96 type File_Array_Type is array (1 .. Max_Files) of File_Type;
|
|
97
|
|
98 File_Table : File_Array_Type;
|
|
99 File_Counter : Integer := 0;
|
|
100
|
|
101 --
|
|
102
|
|
103 function Get_File_Name return File_Name_Type;
|
|
104
|
|
105 end CA11011_0; -- Package OS.
|
|
106
|
|
107 --=================================================================--
|
|
108
|
|
109 package body CA11011_0 is -- Package body OS.
|
|
110
|
|
111 function Get_File_Name return File_Name_Type is
|
|
112 begin
|
|
113 return (An_Ada_File_Name);
|
|
114 end Get_File_Name;
|
|
115 ---------------------------------------------------------------------
|
|
116 procedure Verify_Initial_Conditions (Key : in File_Descriptor_Type;
|
|
117 Status : out Boolean) is
|
|
118 begin
|
|
119 Status := False;
|
|
120 if (File_Table(Key).Descriptor = Default_Descriptor) and then
|
|
121 (File_Table(Key).Name = Default_Filename) and then
|
|
122 (File_Table(Key).Acct_Access = Default_Permission) and then
|
|
123 (File_Table(Key).Mode = Default_Mode) and then
|
|
124 (File_Table(Key).Current_Status = Default_Status)
|
|
125 then
|
|
126 Status := True;
|
|
127 end if;
|
|
128 end Verify_Initial_Conditions;
|
|
129 ---------------------------------------------------------------------
|
|
130 function Final_Conditions_Valid (Key : File_Descriptor_Type)
|
|
131 return Boolean is
|
|
132 begin
|
|
133 if ((File_Table(Key).Descriptor = First_File) and then
|
|
134 (File_Table(Key).Name = An_Ada_File_Name) and then
|
|
135 (File_Table(Key).Acct_Access = Init_Permission) and then
|
|
136 not ((File_Table(Key).Mode = Default_Mode) or else
|
|
137 (File_Table(Key).Current_Status = Default_Status)))
|
|
138 then
|
|
139 return (True);
|
|
140 else
|
|
141 return (False);
|
|
142 end if;
|
|
143 end Final_Conditions_Valid;
|
|
144
|
|
145 end CA11011_0; -- Package body OS.
|
|
146
|
|
147 --=================================================================--
|
|
148
|
|
149 package CA11011_0.CA11011_1 is -- Package OS.File_Manager
|
|
150
|
|
151 procedure Create_File (File_Key : in File_Descriptor_Type);
|
|
152
|
|
153 end CA11011_0.CA11011_1; -- Package OS.File_Manager
|
|
154
|
|
155 --=================================================================--
|
|
156
|
|
157 -- The Subprogram that performs the actual file operations is contained in a
|
|
158 -- private package so that it is not accessible to any client.
|
|
159 -- Default parameters are used in most cases in the subprogram calls, since
|
|
160 -- the caller does not have visibility to these private types.
|
|
161
|
|
162 -- Package OS.File_Manager.Internals
|
|
163 private package CA11011_0.CA11011_1.CA11011_2 is
|
|
164
|
|
165 Private_File_Counter : Integer renames File_Counter; -- Grandparent
|
|
166 -- object.
|
|
167 procedure Create
|
|
168 (Key : in File_Descriptor_Type;
|
|
169 File_Name : in File_Name_Type := Get_File_Name; -- Grandparent
|
|
170 -- prvt type,
|
|
171 -- prvt functn.
|
|
172 File_Mode : in File_Mode_Type := Init_Mode; -- Grandparent
|
|
173 -- prvt type,
|
|
174 -- prvt const.
|
|
175 File_Access : in Permission_Type := Init_Permission; -- Grandparent
|
|
176 -- prvt type,
|
|
177 -- prvt const.
|
|
178 File_Status : in File_Status_Type := Init_Status); -- Grandparent
|
|
179 -- prvt type,
|
|
180 -- prvt const.
|
|
181
|
|
182 end CA11011_0.CA11011_1.CA11011_2; -- Package OS.File_Manager.Internals
|
|
183
|
|
184 --=================================================================--
|
|
185
|
|
186 -- Package Body OS.File_Manager.Internals
|
|
187 package body CA11011_0.CA11011_1.CA11011_2 is
|
|
188
|
|
189 procedure Create
|
|
190 (Key : in File_Descriptor_Type;
|
|
191 File_Name : in File_Name_Type := Get_File_Name;
|
|
192 File_Mode : in File_Mode_Type := Init_Mode;
|
|
193 File_Access : in Permission_Type := Init_Permission;
|
|
194 File_Status : in File_Status_Type := Init_Status) is
|
|
195 begin
|
|
196 Private_File_Counter := Private_File_Counter + 1;
|
|
197 File_Table(Key).Descriptor := Key; -- Grandparent object.
|
|
198 File_Table(Key).Name := File_Name;
|
|
199 File_Table(Key).Mode := File_Mode;
|
|
200 File_Table(Key).Acct_Access := File_Access;
|
|
201 File_Table(Key).Current_Status := File_Status;
|
|
202 end Create;
|
|
203
|
|
204 end CA11011_0.CA11011_1.CA11011_2; -- Package body OS.File_Manager.Internals
|
|
205
|
|
206 --=================================================================--
|
|
207
|
|
208 with CA11011_0.CA11011_1.CA11011_2; -- with Child OS.File_Manager.Internals
|
|
209
|
|
210 package body CA11011_0.CA11011_1 is -- Package body OS.File_Manager
|
|
211
|
|
212 package Internal renames CA11011_0.CA11011_1.CA11011_2;
|
|
213
|
|
214 -- This subprogram utilizes a call to a subprogram contained in a private
|
|
215 -- child to perform the actual processing.
|
|
216
|
|
217 procedure Create_File (File_Key : in File_Descriptor_Type) is
|
|
218 begin
|
|
219 Internal.Create (Key => File_Key); -- Other parameters are defaults,
|
|
220 -- since they are of private types
|
|
221 -- from the parent package.
|
|
222 -- File_Descriptor_Type is private,
|
|
223 -- but declared in visible part of
|
|
224 -- parent spec.
|
|
225 end Create_File;
|
|
226
|
|
227 end CA11011_0.CA11011_1; -- Package body OS.File_Manager
|
|
228
|
|
229 --=================================================================--
|
|
230
|
|
231 with CA11011_0.CA11011_1; -- with public Child Package OS.File_Manager
|
|
232 with Report;
|
|
233
|
|
234 procedure CA11011 is
|
|
235
|
|
236 package OS renames CA11011_0;
|
|
237 package File_Manager renames CA11011_0.CA11011_1;
|
|
238
|
|
239 Data_Base_File_Key : OS.File_Descriptor_Type := OS.First_File;
|
|
240 TC_Status : Boolean := False;
|
|
241
|
|
242 begin
|
|
243
|
|
244 -- This test indicates one approach to file management operations.
|
|
245 -- It is not intended to demonstrate full functionality, but rather
|
|
246 -- that the use of a private child package can provide a solution
|
|
247 -- to a typical user situation.
|
|
248
|
|
249 Report.Test ("CA11011", "Check that a private child package can use " &
|
|
250 "entities declared in the private part of the " &
|
|
251 "parent unit of its parent unit");
|
|
252
|
|
253 OS.Verify_Initial_Conditions (Data_Base_File_Key, TC_Status);
|
|
254
|
|
255 if not TC_Status then
|
|
256 Report.Failed ("Initial condition failure");
|
|
257 end if;
|
|
258
|
|
259 -- Perform file initializations.
|
|
260
|
|
261 File_Manager.Create_File (File_Key => Data_Base_File_Key);
|
|
262
|
|
263 TC_Status := OS.Final_Conditions_Valid (Data_Base_File_Key);
|
|
264
|
|
265 if not TC_Status then
|
|
266 Report.Failed ("Bad status return from Create_File");
|
|
267 end if;
|
|
268
|
|
269 Report.Result;
|
|
270
|
|
271 end CA11011;
|