annotate gcc/testsuite/ada/acats/tests/cxa/cxaca01.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 -- CXACA01.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 default attributes 'Write and 'Read work properly when
kono
parents:
diff changeset
28 -- used with objects of a variety of types, including records with
kono
parents:
diff changeset
29 -- default discriminants, records without default discriminants, but
kono
parents:
diff changeset
30 -- which have the discriminant described in a representation clause for
kono
parents:
diff changeset
31 -- the type, and arrays.
kono
parents:
diff changeset
32 --
kono
parents:
diff changeset
33 -- TEST DESCRIPTION:
kono
parents:
diff changeset
34 -- This test simulates a basic sales record system, using Stream_IO to
kono
parents:
diff changeset
35 -- allow the storage of heterogeneous data in a single stream file.
kono
parents:
diff changeset
36 --
kono
parents:
diff changeset
37 -- Four types of data are written to the stream file for each product.
kono
parents:
diff changeset
38 -- First, the "header" information on the product is written.
kono
parents:
diff changeset
39 -- This is an object of a discriminated (with default) record
kono
parents:
diff changeset
40 -- type. This is followed by an integer object containing a count of
kono
parents:
diff changeset
41 -- the number of sales data records to follow. The corresponding number
kono
parents:
diff changeset
42 -- of sales records follow in the stream. These are of a record type
kono
parents:
diff changeset
43 -- with a discriminant without a default, but where the discriminant is
kono
parents:
diff changeset
44 -- included in the representation clause for the type. Finally, an
kono
parents:
diff changeset
45 -- array object with statistical sales information for the product is
kono
parents:
diff changeset
46 -- written to the stream.
kono
parents:
diff changeset
47 --
kono
parents:
diff changeset
48 -- Objects of both record types specified below (discriminated records
kono
parents:
diff changeset
49 -- with defaults, and discriminated records w/o defaults that have the
kono
parents:
diff changeset
50 -- discriminant included in a representation clause for the type) should
kono
parents:
diff changeset
51 -- have their discriminants included in the stream when using 'Write.
kono
parents:
diff changeset
52 -- Likewise, discriminants should be extracted from the stream when
kono
parents:
diff changeset
53 -- using 'Read.
kono
parents:
diff changeset
54 --
kono
parents:
diff changeset
55 -- APPLICABILITY CRITERIA:
kono
parents:
diff changeset
56 -- Applicable to all implementations that support external
kono
parents:
diff changeset
57 -- Stream_IO files.
kono
parents:
diff changeset
58 --
kono
parents:
diff changeset
59 --
kono
parents:
diff changeset
60 -- CHANGE HISTORY:
kono
parents:
diff changeset
61 -- 06 Dec 94 SAIC ACVC 2.0
kono
parents:
diff changeset
62 --
kono
parents:
diff changeset
63 --!
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 with FXACA00;
kono
parents:
diff changeset
66 with Ada.Streams.Stream_IO;
kono
parents:
diff changeset
67 with Report;
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 procedure CXACA01 is
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 begin
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 Report.Test ("CXACA01", "Check that 'Write and 'Read work properly " &
kono
parents:
diff changeset
74 "when used with complex data types");
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 Test_for_Stream_IO_Support:
kono
parents:
diff changeset
77 declare
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 Info_File : Ada.Streams.Stream_IO.File_Type;
kono
parents:
diff changeset
80 Info_Stream : Ada.Streams.Stream_IO.Stream_Access;
kono
parents:
diff changeset
81 The_Filename : constant String := Report.Legal_File_Name;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 begin
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 -- If an implementation does not support Stream_IO in a particular
kono
parents:
diff changeset
86 -- environment, the exception Use_Error or Name_Error will be raised on
kono
parents:
diff changeset
87 -- calls to various Stream_IO operations. This block statement
kono
parents:
diff changeset
88 -- encloses a call to Create, which should produce an exception in a
kono
parents:
diff changeset
89 -- non-supportive environment. These exceptions will be handled to
kono
parents:
diff changeset
90 -- produce a Not_Applicable result.
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 Ada.Streams.Stream_IO.Create (Info_File,
kono
parents:
diff changeset
93 Ada.Streams.Stream_IO.Out_File,
kono
parents:
diff changeset
94 The_Filename);
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 Operational_Test_Block:
kono
parents:
diff changeset
97 declare
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 begin
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 Info_Stream := Ada.Streams.Stream_IO.Stream (Info_File);
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 -- Write all of the product information (record, integer, and array
kono
parents:
diff changeset
104 -- objects) defined in package FXACA00 into the stream.
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 Store_Data_Block:
kono
parents:
diff changeset
107 begin
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 -- Write information about first product to the stream.
kono
parents:
diff changeset
110 FXACA00.Product_Type'Write (Info_Stream, FXACA00.Product_01);
kono
parents:
diff changeset
111 Integer'Write (Info_Stream, FXACA00.Sale_Count_01);
kono
parents:
diff changeset
112 FXACA00.Sales_Record_Type'Write(Info_Stream, FXACA00.Sale_Rec_01);
kono
parents:
diff changeset
113 FXACA00.Sales_Record_Type'Write(Info_Stream, FXACA00.Sale_Rec_02);
kono
parents:
diff changeset
114 FXACA00.Sales_Statistics_Type'Write
kono
parents:
diff changeset
115 (Info_Stream, FXACA00.Product_01_Stats);
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 -- Write information about second product to the stream.
kono
parents:
diff changeset
118 -- Note: No Sales_Record_Type objects.
kono
parents:
diff changeset
119 FXACA00.Product_Type'Write (Info_Stream, FXACA00.Product_02);
kono
parents:
diff changeset
120 Integer'Write (Info_Stream, FXACA00.Sale_Count_02);
kono
parents:
diff changeset
121 FXACA00.Sales_Statistics_Type'Write
kono
parents:
diff changeset
122 (Info_Stream, FXACA00.Product_02_Stats);
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 -- Write information about third product to the stream.
kono
parents:
diff changeset
125 FXACA00.Product_Type'Write (Info_Stream, FXACA00.Product_03);
kono
parents:
diff changeset
126 Integer'Write (Info_Stream, FXACA00.Sale_Count_03);
kono
parents:
diff changeset
127 FXACA00.Sales_Record_Type'Write(Info_Stream, FXACA00.Sale_Rec_03);
kono
parents:
diff changeset
128 FXACA00.Sales_Record_Type'Write(Info_Stream, FXACA00.Sale_Rec_04);
kono
parents:
diff changeset
129 FXACA00.Sales_Record_Type'Write(Info_Stream, FXACA00.Sale_Rec_05);
kono
parents:
diff changeset
130 FXACA00.Sales_Statistics_Type'Write
kono
parents:
diff changeset
131 (Info_Stream, FXACA00.Product_03_Stats);
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 end Store_Data_Block;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 Verify_Data_Block:
kono
parents:
diff changeset
137 declare
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 use FXACA00; -- Used within this block only.
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 type Domestic_Rec_Array_Type is
kono
parents:
diff changeset
142 array (Positive range <>) of Sales_Record_Type (Domestic);
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 type Foreign_Rec_Array_Type is
kono
parents:
diff changeset
145 array (Positive range <>) of Sales_Record_Type (Foreign);
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 TC_Rec1 : Domestic_Rec_Array_Type (1..2);
kono
parents:
diff changeset
148 TC_Rec3 : Foreign_Rec_Array_Type (1..3);
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 TC_Product1 : Product_Type;
kono
parents:
diff changeset
151 TC_Product2,
kono
parents:
diff changeset
152 TC_Product3 : Product_Type (Foreign);
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 TC_Count1,
kono
parents:
diff changeset
155 TC_Count2,
kono
parents:
diff changeset
156 TC_Count3 : Integer := -10; -- Initialized to dummy value.
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 TC_Stat1,
kono
parents:
diff changeset
159 TC_Stat2,
kono
parents:
diff changeset
160 TC_Stat3 : Sales_Statistics_Type := (others => 500);
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 begin
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 Ada.Streams.Stream_IO.Reset (Info_File,
kono
parents:
diff changeset
165 Ada.Streams.Stream_IO.In_File);
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 -- Read all of the data that is contained in the stream.
kono
parents:
diff changeset
168 -- Compare all data with the original data in package FXACA00
kono
parents:
diff changeset
169 -- that was written to the stream.
kono
parents:
diff changeset
170 -- The calls to the read attribute are in anticipated order, based
kono
parents:
diff changeset
171 -- on the order of data written to the stream. Possible errors,
kono
parents:
diff changeset
172 -- such as data placement, overwriting, etc., will be manifest as
kono
parents:
diff changeset
173 -- exceptions raised by the attribute during an unsuccessful read
kono
parents:
diff changeset
174 -- attempt.
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 -- Extract data on first product.
kono
parents:
diff changeset
177 Product_Type'Read (Info_Stream, TC_Product1);
kono
parents:
diff changeset
178 Integer'Read (Info_Stream, TC_Count1);
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 -- Two "domestic" variant sales records will be read from the
kono
parents:
diff changeset
181 -- stream.
kono
parents:
diff changeset
182 for i in 1 .. TC_Count1 loop
kono
parents:
diff changeset
183 Sales_Record_Type'Read (Info_Stream, TC_Rec1(i) );
kono
parents:
diff changeset
184 end loop;
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 Sales_Statistics_Type'Read (Info_Stream, TC_Stat1);
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 -- Extract data on second product.
kono
parents:
diff changeset
190 Product_Type'Read (Info_Stream, TC_Product2);
kono
parents:
diff changeset
191 Integer'Read (Info_Stream, TC_Count2);
kono
parents:
diff changeset
192 Sales_Statistics_Type'Read (Info_Stream, TC_Stat2);
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 -- Extract data on third product.
kono
parents:
diff changeset
196 Product_Type'Read (Info_Stream, TC_Product3);
kono
parents:
diff changeset
197 Integer'Read (Info_Stream, TC_Count3);
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 -- Three "foreign" variant sales records will be read from the
kono
parents:
diff changeset
200 -- stream.
kono
parents:
diff changeset
201 for i in 1 .. TC_Count3 loop
kono
parents:
diff changeset
202 Sales_Record_Type'Read (Info_Stream, TC_Rec3(i) );
kono
parents:
diff changeset
203 end loop;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 Sales_Statistics_Type'Read (Info_Stream, TC_Stat3);
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 -- After all the data has been correctly extracted, the file
kono
parents:
diff changeset
209 -- should be empty.
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 if not Ada.Streams.Stream_IO.End_Of_File (Info_File) then
kono
parents:
diff changeset
212 Report.Failed ("Stream file not empty");
kono
parents:
diff changeset
213 end if;
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 -- Verify that the data values read from the stream are the same
kono
parents:
diff changeset
216 -- as those written to the stream.
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 -- Verify the information of the first product.
kono
parents:
diff changeset
219 if ((Product_01 /= TC_Product1) or else
kono
parents:
diff changeset
220 (Product_01.Manufacture /= TC_Product1.Manufacture) or else
kono
parents:
diff changeset
221 (Sale_Count_01 /= TC_Count1) or else
kono
parents:
diff changeset
222 (Sale_Rec_01 /= TC_Rec1(1)) or else
kono
parents:
diff changeset
223 (Sale_Rec_01.Buyer /= TC_Rec1(1).Buyer) or else
kono
parents:
diff changeset
224 (Sale_Rec_02 /= TC_Rec1(2)) or else
kono
parents:
diff changeset
225 (Sale_Rec_02.Buyer /= TC_Rec1(2).Buyer) or else
kono
parents:
diff changeset
226 (Product_01_Stats /= TC_Stat1))
kono
parents:
diff changeset
227 then
kono
parents:
diff changeset
228 Report.Failed ("Product 1 information incorrect");
kono
parents:
diff changeset
229 end if;
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 -- Verify the information of the second product.
kono
parents:
diff changeset
232 if not ((Product_02 = TC_Product2) and then
kono
parents:
diff changeset
233 (Sale_Count_02 = TC_Count2) and then
kono
parents:
diff changeset
234 (Product_02_Stats = TC_Stat2))
kono
parents:
diff changeset
235 then
kono
parents:
diff changeset
236 Report.Failed ("Product 2 information incorrect");
kono
parents:
diff changeset
237 end if;
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 -- Verify the information of the third product.
kono
parents:
diff changeset
240 if ((Product_03 /= TC_Product3) or else
kono
parents:
diff changeset
241 (Product_03.Manufacture /= TC_Product3.Manufacture) or else
kono
parents:
diff changeset
242 (Sale_Count_03 /= TC_Count3) or else
kono
parents:
diff changeset
243 (Sale_Rec_03 /= TC_Rec3(1)) or else
kono
parents:
diff changeset
244 (Sale_Rec_03.Buyer /= TC_Rec3(1).Buyer) or else
kono
parents:
diff changeset
245 (Sale_Rec_04 /= TC_Rec3(2)) or else
kono
parents:
diff changeset
246 (Sale_Rec_04.Buyer /= TC_Rec3(2).Buyer) or else
kono
parents:
diff changeset
247 (Sale_Rec_05 /= TC_Rec3(3)) or else
kono
parents:
diff changeset
248 (Sale_Rec_05.Buyer /= TC_Rec3(3).Buyer) or else
kono
parents:
diff changeset
249 (Product_03_Stats /= TC_Stat3))
kono
parents:
diff changeset
250 then
kono
parents:
diff changeset
251 Report.Failed ("Product 3 information incorrect");
kono
parents:
diff changeset
252 end if;
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 end Verify_Data_Block;
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 exception
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 when others =>
kono
parents:
diff changeset
259 Report.Failed ("Exception raised in Operational Test Block");
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 end Operational_Test_Block;
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 if Ada.Streams.Stream_IO.Is_Open (Info_File) then
kono
parents:
diff changeset
264 Ada.Streams.Stream_IO.Delete (Info_File);
kono
parents:
diff changeset
265 else
kono
parents:
diff changeset
266 Ada.Streams.Stream_IO.Open (Info_File,
kono
parents:
diff changeset
267 Ada.Streams.Stream_IO.In_File,
kono
parents:
diff changeset
268 The_Filename);
kono
parents:
diff changeset
269 Ada.Streams.Stream_IO.Delete (Info_File);
kono
parents:
diff changeset
270 end if;
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 exception
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 -- Since Use_Error or Name_Error can be raised if, for the specified
kono
parents:
diff changeset
275 -- mode, the environment does not support Stream_IO operations,
kono
parents:
diff changeset
276 -- the following handlers are included:
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 when Ada.Streams.Stream_IO.Name_Error =>
kono
parents:
diff changeset
279 Report.Not_Applicable ("Name_Error raised on Stream IO Create");
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 when Ada.Streams.Stream_IO.Use_Error =>
kono
parents:
diff changeset
282 Report.Not_Applicable ("Use_Error raised on Stream IO Create");
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 when others =>
kono
parents:
diff changeset
285 Report.Failed ("Unexpected exception raised on Stream IO Create");
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 end Test_for_Stream_IO_Support;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 Report.Result;
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 end CXACA01;