Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/ada/acats/tests/cxa/cxac003.a @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 -- CXAC003.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 the correct exceptions are raised when improperly | |
28 -- manipulating stream file objects. | |
29 -- | |
30 -- TEST DESCRIPTION: | |
31 -- This test is designed to focus on Stream_IO file manipulation | |
32 -- exceptions. Several potentially common user errors are examined in | |
33 -- the test: | |
34 -- | |
35 -- A Status_Error should be raised whenever an attempt is made to perform | |
36 -- an operation on a file that is closed. | |
37 -- | |
38 -- A Status_Error should be raised when an attempt is made to open a | |
39 -- stream file that is currently open. | |
40 -- | |
41 -- A Mode_Error should be raised when attempting to read from (use the | |
42 -- 'Read attribute) on an Out_File or Append_Mode file. | |
43 -- | |
44 -- A Mode_Error should be raised when checking for End Of File on a | |
45 -- file with mode Out_File or Append_Mode. | |
46 -- | |
47 -- A Mode_Error should be raised when attempting to write to (use the | |
48 -- 'Output attribute) on a file with mode In_File. | |
49 -- | |
50 -- A Name_Error should be raised when the string provided to the Name | |
51 -- parameter of an Open operation does not allow association of an | |
52 -- external file. | |
53 -- | |
54 -- APPLICABILITY CRITERIA: | |
55 -- This test is applicable to all implementations capable of supporting | |
56 -- external Stream_IO files. | |
57 -- | |
58 -- | |
59 -- CHANGE HISTORY: | |
60 -- 06 Dec 94 SAIC ACVC 2.0 | |
61 -- 25 Feb 97 PWB.CTA Allowed for non-support of some IO operations | |
62 -- 02 Mar 01 PHL Check that Ada.Streams.Stream_IO.Stream raises | |
63 -- Status_Error if the file is not open. (DR 8652/ | |
64 -- 0056). | |
65 -- 15 Mar 01 RLB Readied for release. | |
66 --! | |
67 | |
68 with Ada.Streams.Stream_IO; | |
69 with Report; | |
70 | |
71 procedure CXAC003 is | |
72 | |
73 Stream_File_Object : Ada.Streams.Stream_IO.File_Type; | |
74 Stream_Access_Value : Ada.Streams.Stream_IO.Stream_Access; | |
75 Stream_Filename : constant String := | |
76 Report.Legal_File_Name ( Nam => "CXAC003" ); | |
77 Incomplete : exception; | |
78 | |
79 begin | |
80 | |
81 Report.Test ("CXAC003", "Check that the correct exceptions are " & | |
82 "raised when improperly manipulating stream " & | |
83 "file objects"); | |
84 | |
85 Test_for_Stream_IO_Support: | |
86 begin | |
87 -- If an implementation does not support Stream_IO in a particular | |
88 -- environment, the exception Use_Error or Name_Error will be raised on | |
89 -- calls to various Stream_IO operations. This block statement | |
90 -- encloses a call to Create, which should produce an exception in a | |
91 -- non-supportive environment. These exceptions will be handled to | |
92 -- produce a Not_Applicable result. | |
93 | |
94 Ada.Streams.Stream_IO.Create (Stream_File_Object, | |
95 Ada.Streams.Stream_IO.Out_File, | |
96 Stream_Filename); | |
97 | |
98 exception | |
99 | |
100 when Ada.Streams.Stream_IO.Use_Error | Ada.Streams.Stream_IO.Name_Error => | |
101 Report.Not_Applicable | |
102 ( "Files not supported - Create as Out_File for Stream_IO" ); | |
103 raise Incomplete; | |
104 | |
105 end Test_for_Stream_IO_Support; | |
106 | |
107 Operational_Test_Block: | |
108 begin | |
109 -- A potentially common error in a file processing environment | |
110 -- is to attempt to perform an operation on a stream file that is | |
111 -- not currently open. Status_Error should be raised in this case. | |
112 Check_Status_Error: | |
113 begin | |
114 Ada.Streams.Stream_IO.Close (Stream_File_Object); | |
115 -- Attempt to reset a file that is closed. | |
116 Ada.Streams.Stream_IO.Reset (Stream_File_Object, | |
117 Ada.Streams.Stream_IO.Out_File); | |
118 Report.Failed ("Exception not raised on Reset of closed file"); | |
119 exception | |
120 when Ada.Streams.Stream_IO.Status_Error => | |
121 null; | |
122 when others => | |
123 Report.Failed ("Incorrect exception raised - 1"); | |
124 end Check_Status_Error; | |
125 | |
126 -- A similar error is to use Ada.Streams.Stream_IO.Stream | |
127 -- to attempt to perform an operation on a stream file that is | |
128 -- not currently open. Status_Error should be raised in this case. | |
129 -- (Defect Report 8652/0046, as reflected in Technical Corrigendum 1.) | |
130 Check_Status_Error2: | |
131 begin | |
132 -- Ensure that the file is not open. | |
133 if Ada.Streams.Stream_Io.Is_Open (Stream_File_Object) then | |
134 Ada.Streams.Stream_Io.Close (Stream_File_Object); | |
135 end if; | |
136 Stream_Access_Value := | |
137 Ada.Streams.Stream_Io.Stream (Stream_File_Object); | |
138 Report.Failed ("Exception not raised on Stream of closed file"); | |
139 exception | |
140 when Ada.Streams.Stream_Io.Status_Error => | |
141 null; | |
142 when others => | |
143 Report.Failed ("Incorrect exception raised - 2"); | |
144 end Check_Status_Error2; | |
145 | |
146 -- Another potentially common error in a file processing environment | |
147 -- is to attempt to Open a stream file that is currently open. | |
148 -- Status_Error should be raised in this case. | |
149 Check_Status_Error3: | |
150 begin | |
151 -- Ensure that the file is open. | |
152 if not Ada.Streams.Stream_IO.Is_Open (Stream_File_Object) then | |
153 Ada.Streams.Stream_IO.Open (Stream_File_Object, | |
154 Ada.Streams.Stream_IO.In_File, | |
155 Stream_Filename); | |
156 end if; | |
157 Ada.Streams.Stream_IO.Open (Stream_File_Object, | |
158 Ada.Streams.Stream_IO.In_File, | |
159 Stream_Filename); | |
160 Report.Failed ("Exception not raised on Open of open file"); | |
161 exception | |
162 when Ada.Streams.Stream_IO.Status_Error => | |
163 null; | |
164 when others => | |
165 Report.Failed ("Incorrect exception raised - 3"); | |
166 end Check_Status_Error3; | |
167 | |
168 -- Another example of a potential error occurring in a file | |
169 -- processing environment is to attempt to use the 'Read attribute | |
170 -- on a stream file that is currently in Out_File or Append_File | |
171 -- mode. Mode_Error should be raised in both of these cases. | |
172 Check_Mode_Error: | |
173 declare | |
174 Int_Var : Integer := -10; | |
175 begin | |
176 | |
177 Reset1: | |
178 begin | |
179 Ada.Streams.Stream_IO.Reset (Stream_File_Object, | |
180 Ada.Streams.Stream_IO.Out_File); | |
181 exception | |
182 when Ada.Streams.Stream_IO.Use_Error => | |
183 Report.Not_Applicable | |
184 ( "Reset to Out_File not supported for Stream_IO - 1" ); | |
185 raise Incomplete; | |
186 end Reset1; | |
187 | |
188 Stream_Access_Value := | |
189 Ada.Streams.Stream_IO.Stream (Stream_File_Object); | |
190 Integer'Write (Stream_Access_Value, Int_Var); | |
191 | |
192 -- File contains an integer value, but is of mode Out_File. | |
193 Integer'Read (Stream_Access_Value, Int_Var); | |
194 Report.Failed ("Exception not raised by 'Read of Out_File"); | |
195 exception | |
196 when Incomplete => | |
197 raise; | |
198 when Ada.Streams.Stream_IO.Mode_Error => | |
199 null; | |
200 Try_Read: | |
201 begin | |
202 Reset2: | |
203 begin | |
204 Ada.Streams.Stream_IO.Reset | |
205 (Stream_File_Object, Ada.Streams.Stream_IO.Append_File); | |
206 exception | |
207 when Ada.Streams.Stream_IO.Use_Error => | |
208 Report.Not_Applicable | |
209 ( "Reset to Append_File not supported " & | |
210 "for Stream_IO - 2" ); | |
211 raise Incomplete; | |
212 end Reset2; | |
213 | |
214 Integer'Write (Stream_Access_Value, Int_Var); | |
215 -- Attempt read from Append_File mode file. | |
216 Integer'Read (Stream_Access_Value, Int_Var); | |
217 Report.Failed | |
218 ("Exception not raised by 'Read of Append file"); | |
219 exception | |
220 when Incomplete => | |
221 null; | |
222 when Ada.Streams.Stream_IO.Mode_Error => | |
223 null; | |
224 when others => | |
225 Report.Failed ("Incorrect exception raised - 4b"); | |
226 end Try_Read; | |
227 | |
228 when others => Report.Failed ("Incorrect exception raised - 4a"); | |
229 end Check_Mode_Error; | |
230 | |
231 -- Another example of a this type of potential error is to attempt | |
232 -- to check for End Of File on a stream file that is currently in | |
233 -- Out_File or Append_File mode. Mode_Error should also be raised | |
234 -- in both of these cases. | |
235 Check_End_File: | |
236 declare | |
237 Test_Boolean : Boolean := False; | |
238 begin | |
239 Reset3: | |
240 begin | |
241 Ada.Streams.Stream_IO.Reset (Stream_File_Object, | |
242 Ada.Streams.Stream_IO.Out_File); | |
243 exception | |
244 when Ada.Streams.Stream_IO.Use_Error => | |
245 Report.Not_Applicable | |
246 ( "Reset to Out_File not supported for Stream_IO - 3" ); | |
247 raise Incomplete; | |
248 end Reset3; | |
249 | |
250 Test_Boolean := | |
251 Ada.Streams.Stream_IO.End_Of_File (Stream_File_Object); | |
252 Report.Failed ("Exception not raised by EOF on Out_File"); | |
253 exception | |
254 when Incomplete => | |
255 null; | |
256 when Ada.Streams.Stream_IO.Mode_Error => | |
257 null; | |
258 EOF_For_Append_File: | |
259 begin | |
260 Reset4: | |
261 begin | |
262 Ada.Streams.Stream_IO.Reset | |
263 (Stream_File_Object, Ada.Streams.Stream_IO.Append_File); | |
264 exception | |
265 when Ada.Streams.Stream_IO.Use_Error => | |
266 Report.Not_Applicable | |
267 ( "Reset to Append_File not supported " & | |
268 "for Stream_IO - 4" ); | |
269 raise Incomplete; | |
270 end Reset4; | |
271 | |
272 Test_Boolean := | |
273 Ada.Streams.Stream_IO.End_Of_File (Stream_File_Object); | |
274 Report.Failed | |
275 ("Exception not raised by EOF of Append file"); | |
276 exception | |
277 when Incomplete => | |
278 raise; | |
279 when Ada.Streams.Stream_IO.Mode_Error => | |
280 null; | |
281 when others => | |
282 Report.Failed ("Incorrect exception raised - 5b"); | |
283 end EOF_For_Append_File; | |
284 | |
285 when others => Report.Failed ("Incorrect exception raised - 5a"); | |
286 end Check_End_File; | |
287 | |
288 | |
289 | |
290 -- In a similar situation to the above cases for attribute 'Read, | |
291 -- an attempt to use the 'Output attribute on a stream file that | |
292 -- is currently in In_File mode should result in Mode_Error being | |
293 -- raised. | |
294 Check_Output_Mode_Error: | |
295 begin | |
296 Reset5: | |
297 begin | |
298 Ada.Streams.Stream_IO.Reset (Stream_File_Object, | |
299 Ada.Streams.Stream_IO.In_File); | |
300 exception | |
301 when Ada.Streams.Stream_IO.Use_Error => | |
302 Report.Not_Applicable | |
303 ( "Reset to In_File not supported for Stream_IO - 6" ); | |
304 raise Incomplete; | |
305 end Reset5; | |
306 | |
307 Stream_Access_Value := | |
308 Ada.Streams.Stream_IO.Stream (Stream_File_Object); | |
309 String'Output (Stream_Access_Value, "User-Oriented String"); | |
310 Report.Failed ("Exception not raised by 'Output to In_File"); | |
311 exception | |
312 when Incomplete => | |
313 null; | |
314 when Ada.Streams.Stream_IO.Mode_Error => | |
315 null; | |
316 when others => | |
317 Report.Failed ("Incorrect exception raised - 6"); | |
318 end Check_Output_Mode_Error; | |
319 | |
320 -- Any case of attempting to Open a stream file with a string for | |
321 -- the parameter Name that does not allow the identification of an | |
322 -- external file will result in the exception Name_Error being | |
323 -- raised. | |
324 Check_Illegal_File_Name: | |
325 begin | |
326 if Ada.Streams.Stream_IO.Is_Open (Stream_File_Object) then | |
327 Ada.Streams.Stream_IO.Close (Stream_File_Object); | |
328 end if; | |
329 -- No external file exists with this filename, allowing no | |
330 -- association with an internal file object, resulting in the | |
331 -- raising of the exception Name_Error. | |
332 Ada.Streams.Stream_IO.Open(File => Stream_File_Object, | |
333 Mode => Ada.Streams.Stream_IO.Out_File, | |
334 Name => Report.Legal_File_Name(2)); | |
335 Report.Failed ("Exception not raised by bad filename on Open"); | |
336 exception | |
337 when Ada.Streams.Stream_IO.Name_Error => | |
338 null; | |
339 when others => | |
340 Report.Failed ("Incorrect exception raised - 7"); | |
341 end Check_Illegal_File_Name; | |
342 | |
343 exception | |
344 when Incomplete => | |
345 null; | |
346 when others => | |
347 Report.Failed ("Unexpected exception in Operational Test Block"); | |
348 | |
349 end Operational_Test_Block; | |
350 | |
351 Deletion: | |
352 begin | |
353 if Ada.Streams.Stream_IO.Is_Open (Stream_File_Object) then | |
354 Ada.Streams.Stream_IO.Delete (Stream_File_Object); | |
355 else | |
356 Ada.Streams.Stream_IO.Open (Stream_File_Object, | |
357 Ada.Streams.Stream_IO.Out_File, | |
358 Stream_Filename); | |
359 Ada.Streams.Stream_IO.Delete (Stream_File_Object); | |
360 end if; | |
361 exception | |
362 when others => | |
363 Report.Failed | |
364 ( "Delete not properly implemented for Stream_IO" ); | |
365 end Deletion; | |
366 | |
367 Report.Result; | |
368 | |
369 exception | |
370 when Incomplete => | |
371 Report.Result; | |
372 when others => | |
373 Report.Failed ( "Unexpected exception" ); | |
374 Report.Result; | |
375 | |
376 end CXAC003; |