3 -- Grant of Unlimited Rights
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
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.
27 -- Check that the operations defined in the generic package
28 -- Ada.Storage_IO provide the ability to store and retrieve objects
29 -- which may include implicit levels of indirection in their
30 -- implementation, from an in-memory buffer.
33 -- The following scenario demonstrates how an object of a type with
34 -- (potential) levels of indirection (based on the implementation)
35 -- can be "flattened" and written/read to/from a Direct_IO file.
36 -- In this small example, we have attempted to simulate the situation
37 -- where two independent programs are using a particular Direct_IO file,
38 -- one writing data to the file, and the second program reading that file.
39 -- The Storage_IO Read and Write procedures are used to "flatten"
40 -- and reconstruct objects of the record type.
42 -- APPLICABILITY CRITERIA:
43 -- Applicable to implementations capable of supporting external
48 -- 06 Dec 94 SAIC ACVC 2.0
49 -- 07 Jun 95 SAIC Modified to constrain type used with Storage_IO.
50 -- 20 Nov 95 SAIC Corrected and enhanced for ACVC 2.0.1.
51 -- 25 Feb 97 PWB.CTA Allowed for non-support of some IO operations
59 package Dir_IO
is new Ada
.Direct_IO
(Integer);
60 Test_File
: Dir_IO
.File_Type
;
61 Incomplete
: exception;
64 Report
.Test
("CXA9001", "Check that the operations defined in the " &
65 "generic package Ada.Storage_IO provide the " &
66 "ability to store and retrieve objects which " &
67 "may include implicit levels of indirection in " &
68 "their implementation, from an in-memory buffer");
71 Test_For_Direct_IO_Support
:
74 -- The following Create does not have any bearing on the test scenario,
75 -- but is included to check that the implementation supports Direct_IO
76 -- files. An exception on this Create statement will raise a Name_Error
77 -- or Use_Error, which will be handled to produce a Not_Applicable
78 -- result. If created, the file is immediately deleted, as it is not
79 -- needed for the program scenario.
81 Dir_IO
.Create
(Test_File
, Dir_IO
.Out_File
, Report
.Legal_File_Name
(1));
85 when Dir_IO
.Use_Error | Dir_IO
.Name_Error
=>
87 ( "Files not supported - Create as Out_File for Direct_IO" );
90 end Test_for_Direct_IO_Support
;
94 Dir_IO
.Delete
(Test_File
);
98 ( "Delete not properly implemented for Direct_IO - 1" );
105 The_Filename
: constant String := Report
.Legal_File_Name
(2);
107 -- The following type is the basic unit used in this test. It is
108 -- incorporated into the definition of the Unit_Array_Type.
112 Position
: Natural := 19;
113 String_Value
: String (1..9) := (others => 'X');
116 TC_Size
: Natural := Natural'First;
118 procedure Data_Storage
(Number_Of_Units
: in Natural;
119 Result
: out Natural) is
121 -- Type based on input parameter. Uses type Unit_Type
122 -- as the array element.
123 type Unit_Array_Type
is array (1..Number_Of_Units
)
126 -- This type definition is the ultimate storage type used
127 -- in this test; uses type Unit_Array_Type as a record
129 -- This record type contains a component that is an array of
130 -- records, with each of these records containing a Natural
131 -- and a String value (i.e., a record containing an array of
134 type Data_Storage_Type
is
136 Data_Value
: Natural := Number_Of_Units
;
137 Unit_Array
: Unit_Array_Type
;
140 -- The instantiation of the following generic package is a
141 -- central point in this test. Storage_IO is instantiated for
142 -- a specific data type, and will be used to "flatten" objects
143 -- of that type into buffers. Direct_IO is instantiated for
144 -- these Storage_IO buffers.
146 package Flat_Storage_IO
is
147 new Ada
.Storage_IO
(Data_Storage_Type
);
149 new Ada
.Direct_IO
(Flat_Storage_IO
.Buffer_Type
);
151 Buffer_File
: Buffer_IO
.File_Type
;
152 Outbound_Buffer
: Flat_Storage_IO
.Buffer_Type
;
153 Storage_Item
: Data_Storage_Type
;
155 begin -- procedure Data_Storage
157 Buffer_IO
.Create
(Buffer_File
,
161 Flat_Storage_IO
.Write
(Buffer
=> Outbound_Buffer
,
162 Item
=> Storage_Item
);
164 -- At this point, any levels of indirection have been removed
165 -- by the Storage_IO procedure, and the buffered data can be
166 -- written to a file.
168 Buffer_IO
.Write
(Buffer_File
, Outbound_Buffer
);
169 Buffer_IO
.Close
(Buffer_File
);
170 Result
:= Storage_Item
.Unit_Array
'Last + -- 5 +
171 Storage_Item
.Unit_Array
-- 9
172 (Storage_Item
.Unit_Array
'First).String_Value
'Length;
176 Report
.Failed
("Data storage error");
177 if Buffer_IO
.Is_Open
(Buffer_File
) then
178 Buffer_IO
.Close
(Buffer_File
);
182 procedure Data_Retrieval
(Number_Of_Units
: in Natural;
183 Result
: out Natural) is
184 type Unit_Array_Type
is array (1..Number_Of_Units
)
187 type Data_Storage_Type
is
189 Data_Value
: Natural := Number_Of_Units
;
190 Unit_Array
: Unit_Array_Type
;
193 package Flat_Storage_IO
is
194 new Ada
.Storage_IO
(Data_Storage_Type
);
196 new Ada
.Direct_IO
(Flat_Storage_IO
.Buffer_Type
);
198 Reader_File
: Reader_IO
.File_Type
;
199 Inbound_Buffer
: Flat_Storage_IO
.Buffer_Type
;
200 Storage_Item
: Data_Storage_Type
;
201 TC_Item
: Data_Storage_Type
;
203 begin -- procedure Data_Retrieval
205 Reader_IO
.Open
(Reader_File
, Reader_IO
.In_File
, The_Filename
);
206 Reader_IO
.Read
(Reader_File
, Inbound_Buffer
);
208 Flat_Storage_IO
.Read
(Inbound_Buffer
, Storage_Item
);
210 -- Validate the reconstructed value against an "unflattened"
213 if Storage_Item
.Data_Value
/= TC_Item
.Data_Value
215 Report
.Failed
("Data_Retrieval Error - 1");
218 for i
in 1..Number_Of_Units
loop
219 if Storage_Item
.Unit_Array
(i
).String_Value
'Length /=
220 TC_Item
.Unit_Array
(i
).String_Value
'Length or
221 Storage_Item
.Unit_Array
(i
).Position
/=
222 TC_Item
.Unit_Array
(i
).Position
or
223 Storage_Item
.Unit_Array
(i
).String_Value
/=
224 TC_Item
.Unit_Array
(i
).String_Value
226 Report
.Failed
("Data_Retrieval Error - 2");
230 Result
:= Storage_Item
.Unit_Array
'Last + -- 5 +
231 Storage_Item
.Unit_Array
-- 9
232 (Storage_Item
.Unit_Array
'First).String_Value
'Length;
234 if Reader_IO
.Is_Open
(Reader_File
) then
235 Reader_IO
.Delete
(Reader_File
);
237 Reader_IO
.Open
(Reader_File
,
240 Reader_IO
.Delete
(Reader_File
);
245 Report
.Failed
("Exception raised in Data_Retrieval");
246 if Reader_IO
.Is_Open
(Reader_File
) then
247 Reader_IO
.Delete
(Reader_File
);
249 Reader_IO
.Open
(Reader_File
,
252 Reader_IO
.Delete
(Reader_File
);
259 -- The number of Units is provided in this call to Data_Storage.
260 Data_Storage
(Number_Of_Units
=> Natural(Report
.Ident_Int
(5)),
263 if TC_Size
/= 14 then
264 Report
.Failed
("Data_Storage error in Data_Storage");
267 Data_Retrieval
(Number_Of_Units
=> Natural(Report
.Ident_Int
(5)),
270 if TC_Size
/= 14 then
271 Report
.Failed
("Data retrieval error in Data_Retrieval");
275 when others => Report
.Failed
("Exception raised in Test_Block");
284 Report
.Failed
( "Unexpected exception" );