annotate gcc/testsuite/ada/acats/tests/cxa/cxa9001.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- CXA9001.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that the operations defined in the generic package
kono
parents:
diff changeset
28 -- Ada.Storage_IO provide the ability to store and retrieve objects
kono
parents:
diff changeset
29 -- which may include implicit levels of indirection in their
kono
parents:
diff changeset
30 -- implementation, from an in-memory buffer.
kono
parents:
diff changeset
31 --
kono
parents:
diff changeset
32 -- TEST DESCRIPTION:
kono
parents:
diff changeset
33 -- The following scenario demonstrates how an object of a type with
kono
parents:
diff changeset
34 -- (potential) levels of indirection (based on the implementation)
kono
parents:
diff changeset
35 -- can be "flattened" and written/read to/from a Direct_IO file.
kono
parents:
diff changeset
36 -- In this small example, we have attempted to simulate the situation
kono
parents:
diff changeset
37 -- where two independent programs are using a particular Direct_IO file,
kono
parents:
diff changeset
38 -- one writing data to the file, and the second program reading that file.
kono
parents:
diff changeset
39 -- The Storage_IO Read and Write procedures are used to "flatten"
kono
parents:
diff changeset
40 -- and reconstruct objects of the record type.
kono
parents:
diff changeset
41 --
kono
parents:
diff changeset
42 -- APPLICABILITY CRITERIA:
kono
parents:
diff changeset
43 -- Applicable to implementations capable of supporting external
kono
parents:
diff changeset
44 -- Direct_IO files.
kono
parents:
diff changeset
45 --
kono
parents:
diff changeset
46 --
kono
parents:
diff changeset
47 -- CHANGE HISTORY:
kono
parents:
diff changeset
48 -- 06 Dec 94 SAIC ACVC 2.0
kono
parents:
diff changeset
49 -- 07 Jun 95 SAIC Modified to constrain type used with Storage_IO.
kono
parents:
diff changeset
50 -- 20 Nov 95 SAIC Corrected and enhanced for ACVC 2.0.1.
kono
parents:
diff changeset
51 -- 25 Feb 97 PWB.CTA Allowed for non-support of some IO operations
kono
parents:
diff changeset
52 --!
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 with Report;
kono
parents:
diff changeset
55 with Ada.Storage_IO;
kono
parents:
diff changeset
56 with Ada.Direct_IO;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 procedure CXA9001 is
kono
parents:
diff changeset
59 package Dir_IO is new Ada.Direct_IO (Integer);
kono
parents:
diff changeset
60 Test_File : Dir_IO.File_Type;
kono
parents:
diff changeset
61 Incomplete : exception;
kono
parents:
diff changeset
62 begin
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 Report.Test ("CXA9001", "Check that the operations defined in the " &
kono
parents:
diff changeset
65 "generic package Ada.Storage_IO provide the " &
kono
parents:
diff changeset
66 "ability to store and retrieve objects which " &
kono
parents:
diff changeset
67 "may include implicit levels of indirection in " &
kono
parents:
diff changeset
68 "their implementation, from an in-memory buffer");
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 Test_For_Direct_IO_Support:
kono
parents:
diff changeset
72 begin
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 -- The following Create does not have any bearing on the test scenario,
kono
parents:
diff changeset
75 -- but is included to check that the implementation supports Direct_IO
kono
parents:
diff changeset
76 -- files. An exception on this Create statement will raise a Name_Error
kono
parents:
diff changeset
77 -- or Use_Error, which will be handled to produce a Not_Applicable
kono
parents:
diff changeset
78 -- result. If created, the file is immediately deleted, as it is not
kono
parents:
diff changeset
79 -- needed for the program scenario.
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 Dir_IO.Create (Test_File, Dir_IO.Out_File, Report.Legal_File_Name(1));
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 exception
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 when Dir_IO.Use_Error | Dir_IO.Name_Error =>
kono
parents:
diff changeset
86 Report.Not_Applicable
kono
parents:
diff changeset
87 ( "Files not supported - Create as Out_File for Direct_IO" );
kono
parents:
diff changeset
88 raise Incomplete;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 end Test_for_Direct_IO_Support;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 Deletion1:
kono
parents:
diff changeset
93 begin
kono
parents:
diff changeset
94 Dir_IO.Delete (Test_File);
kono
parents:
diff changeset
95 exception
kono
parents:
diff changeset
96 when others =>
kono
parents:
diff changeset
97 Report.Failed
kono
parents:
diff changeset
98 ( "Delete not properly implemented for Direct_IO - 1" );
kono
parents:
diff changeset
99 end Deletion1;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 Test_Block:
kono
parents:
diff changeset
103 declare
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 The_Filename : constant String := Report.Legal_File_Name(2);
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 -- The following type is the basic unit used in this test. It is
kono
parents:
diff changeset
108 -- incorporated into the definition of the Unit_Array_Type.
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 type Unit_Type is
kono
parents:
diff changeset
111 record
kono
parents:
diff changeset
112 Position : Natural := 19;
kono
parents:
diff changeset
113 String_Value : String (1..9) := (others => 'X');
kono
parents:
diff changeset
114 end record;
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 TC_Size : Natural := Natural'First;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 procedure Data_Storage (Number_Of_Units : in Natural;
kono
parents:
diff changeset
119 Result : out Natural) is
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 -- Type based on input parameter. Uses type Unit_Type
kono
parents:
diff changeset
122 -- as the array element.
kono
parents:
diff changeset
123 type Unit_Array_Type is array (1..Number_Of_Units)
kono
parents:
diff changeset
124 of Unit_Type;
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 -- This type definition is the ultimate storage type used
kono
parents:
diff changeset
127 -- in this test; uses type Unit_Array_Type as a record
kono
parents:
diff changeset
128 -- component field.
kono
parents:
diff changeset
129 -- This record type contains a component that is an array of
kono
parents:
diff changeset
130 -- records, with each of these records containing a Natural
kono
parents:
diff changeset
131 -- and a String value (i.e., a record containing an array of
kono
parents:
diff changeset
132 -- records).
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 type Data_Storage_Type is
kono
parents:
diff changeset
135 record
kono
parents:
diff changeset
136 Data_Value : Natural := Number_Of_Units;
kono
parents:
diff changeset
137 Unit_Array : Unit_Array_Type;
kono
parents:
diff changeset
138 end record;
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 -- The instantiation of the following generic package is a
kono
parents:
diff changeset
141 -- central point in this test. Storage_IO is instantiated for
kono
parents:
diff changeset
142 -- a specific data type, and will be used to "flatten" objects
kono
parents:
diff changeset
143 -- of that type into buffers. Direct_IO is instantiated for
kono
parents:
diff changeset
144 -- these Storage_IO buffers.
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 package Flat_Storage_IO is
kono
parents:
diff changeset
147 new Ada.Storage_IO (Data_Storage_Type);
kono
parents:
diff changeset
148 package Buffer_IO is
kono
parents:
diff changeset
149 new Ada.Direct_IO (Flat_Storage_IO.Buffer_Type);
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 Buffer_File : Buffer_IO.File_Type;
kono
parents:
diff changeset
152 Outbound_Buffer : Flat_Storage_IO.Buffer_Type;
kono
parents:
diff changeset
153 Storage_Item : Data_Storage_Type;
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 begin -- procedure Data_Storage
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 Buffer_IO.Create (Buffer_File,
kono
parents:
diff changeset
158 Buffer_IO.Out_File,
kono
parents:
diff changeset
159 The_Filename);
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 Flat_Storage_IO.Write (Buffer => Outbound_Buffer,
kono
parents:
diff changeset
162 Item => Storage_Item);
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 -- At this point, any levels of indirection have been removed
kono
parents:
diff changeset
165 -- by the Storage_IO procedure, and the buffered data can be
kono
parents:
diff changeset
166 -- written to a file.
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 Buffer_IO.Write (Buffer_File, Outbound_Buffer);
kono
parents:
diff changeset
169 Buffer_IO.Close (Buffer_File);
kono
parents:
diff changeset
170 Result := Storage_Item.Unit_Array'Last + -- 5 +
kono
parents:
diff changeset
171 Storage_Item.Unit_Array -- 9
kono
parents:
diff changeset
172 (Storage_Item.Unit_Array'First).String_Value'Length;
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 exception
kono
parents:
diff changeset
175 when others =>
kono
parents:
diff changeset
176 Report.Failed ("Data storage error");
kono
parents:
diff changeset
177 if Buffer_IO.Is_Open (Buffer_File) then
kono
parents:
diff changeset
178 Buffer_IO.Close (Buffer_File);
kono
parents:
diff changeset
179 end if;
kono
parents:
diff changeset
180 end Data_Storage;
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 procedure Data_Retrieval (Number_Of_Units : in Natural;
kono
parents:
diff changeset
183 Result : out Natural) is
kono
parents:
diff changeset
184 type Unit_Array_Type is array (1..Number_Of_Units)
kono
parents:
diff changeset
185 of Unit_Type;
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 type Data_Storage_Type is
kono
parents:
diff changeset
188 record
kono
parents:
diff changeset
189 Data_Value : Natural := Number_Of_Units;
kono
parents:
diff changeset
190 Unit_Array : Unit_Array_Type;
kono
parents:
diff changeset
191 end record;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 package Flat_Storage_IO is
kono
parents:
diff changeset
194 new Ada.Storage_IO (Data_Storage_Type);
kono
parents:
diff changeset
195 package Reader_IO is
kono
parents:
diff changeset
196 new Ada.Direct_IO (Flat_Storage_IO.Buffer_Type);
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 Reader_File : Reader_IO.File_Type;
kono
parents:
diff changeset
199 Inbound_Buffer : Flat_Storage_IO.Buffer_Type;
kono
parents:
diff changeset
200 Storage_Item : Data_Storage_Type;
kono
parents:
diff changeset
201 TC_Item : Data_Storage_Type;
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 begin -- procedure Data_Retrieval
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 Reader_IO.Open (Reader_File, Reader_IO.In_File, The_Filename);
kono
parents:
diff changeset
206 Reader_IO.Read (Reader_File, Inbound_Buffer);
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 Flat_Storage_IO.Read (Inbound_Buffer, Storage_Item);
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 -- Validate the reconstructed value against an "unflattened"
kono
parents:
diff changeset
211 -- value.
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 if Storage_Item.Data_Value /= TC_Item.Data_Value
kono
parents:
diff changeset
214 then
kono
parents:
diff changeset
215 Report.Failed ("Data_Retrieval Error - 1");
kono
parents:
diff changeset
216 end if;
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 for i in 1..Number_Of_Units loop
kono
parents:
diff changeset
219 if Storage_Item.Unit_Array(i).String_Value'Length /=
kono
parents:
diff changeset
220 TC_Item.Unit_Array(i).String_Value'Length or
kono
parents:
diff changeset
221 Storage_Item.Unit_Array(i).Position /=
kono
parents:
diff changeset
222 TC_Item.Unit_Array(i).Position or
kono
parents:
diff changeset
223 Storage_Item.Unit_Array(i).String_Value /=
kono
parents:
diff changeset
224 TC_Item.Unit_Array(i).String_Value
kono
parents:
diff changeset
225 then
kono
parents:
diff changeset
226 Report.Failed ("Data_Retrieval Error - 2");
kono
parents:
diff changeset
227 end if;
kono
parents:
diff changeset
228 end loop;
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 Result := Storage_Item.Unit_Array'Last + -- 5 +
kono
parents:
diff changeset
231 Storage_Item.Unit_Array -- 9
kono
parents:
diff changeset
232 (Storage_Item.Unit_Array'First).String_Value'Length;
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 if Reader_IO.Is_Open (Reader_File) then
kono
parents:
diff changeset
235 Reader_IO.Delete (Reader_File);
kono
parents:
diff changeset
236 else
kono
parents:
diff changeset
237 Reader_IO.Open (Reader_File,
kono
parents:
diff changeset
238 Reader_IO.In_File,
kono
parents:
diff changeset
239 The_Filename);
kono
parents:
diff changeset
240 Reader_IO.Delete (Reader_File);
kono
parents:
diff changeset
241 end if;
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 exception
kono
parents:
diff changeset
244 when others =>
kono
parents:
diff changeset
245 Report.Failed ("Exception raised in Data_Retrieval");
kono
parents:
diff changeset
246 if Reader_IO.Is_Open (Reader_File) then
kono
parents:
diff changeset
247 Reader_IO.Delete (Reader_File);
kono
parents:
diff changeset
248 else
kono
parents:
diff changeset
249 Reader_IO.Open (Reader_File,
kono
parents:
diff changeset
250 Reader_IO.In_File,
kono
parents:
diff changeset
251 The_Filename);
kono
parents:
diff changeset
252 Reader_IO.Delete (Reader_File);
kono
parents:
diff changeset
253 end if;
kono
parents:
diff changeset
254 end Data_Retrieval;
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 begin -- Test_Block
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 -- The number of Units is provided in this call to Data_Storage.
kono
parents:
diff changeset
260 Data_Storage (Number_Of_Units => Natural(Report.Ident_Int(5)),
kono
parents:
diff changeset
261 Result => TC_Size);
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 if TC_Size /= 14 then
kono
parents:
diff changeset
264 Report.Failed ("Data_Storage error in Data_Storage");
kono
parents:
diff changeset
265 end if;
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 Data_Retrieval (Number_Of_Units => Natural(Report.Ident_Int(5)),
kono
parents:
diff changeset
268 Result => TC_Size);
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 if TC_Size /= 14 then
kono
parents:
diff changeset
271 Report.Failed ("Data retrieval error in Data_Retrieval");
kono
parents:
diff changeset
272 end if;
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 exception
kono
parents:
diff changeset
275 when others => Report.Failed ("Exception raised in Test_Block");
kono
parents:
diff changeset
276 end Test_Block;
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 Report.Result;
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 exception
kono
parents:
diff changeset
281 when Incomplete =>
kono
parents:
diff changeset
282 Report.Result;
kono
parents:
diff changeset
283 when others =>
kono
parents:
diff changeset
284 Report.Failed ( "Unexpected exception" );
kono
parents:
diff changeset
285 Report.Result;
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 end CXA9001;