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 correct exceptions are raised when improperly
28 -- manipulating stream file objects.
31 -- This test is designed to focus on Stream_IO file manipulation
32 -- exceptions. Several potentially common user errors are examined in
35 -- A Status_Error should be raised whenever an attempt is made to perform
36 -- an operation on a file that is closed.
38 -- A Status_Error should be raised when an attempt is made to open a
39 -- stream file that is currently open.
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.
44 -- A Mode_Error should be raised when checking for End Of File on a
45 -- file with mode Out_File or Append_Mode.
47 -- A Mode_Error should be raised when attempting to write to (use the
48 -- 'Output attribute) on a file with mode In_File.
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
54 -- APPLICABILITY CRITERIA:
55 -- This test is applicable to all implementations capable of supporting
56 -- external Stream_IO files.
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/
65 -- 15 Mar 01 RLB Readied for release.
68 with Ada
.Streams
.Stream_IO
;
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;
81 Report
.Test
("CXAC003", "Check that the correct exceptions are " &
82 "raised when improperly manipulating stream " &
85 Test_for_Stream_IO_Support
:
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.
94 Ada
.Streams
.Stream_IO
.Create
(Stream_File_Object
,
95 Ada
.Streams
.Stream_IO
.Out_File
,
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" );
105 end Test_for_Stream_IO_Support
;
107 Operational_Test_Block
:
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.
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");
120 when Ada
.Streams
.Stream_IO
.Status_Error
=>
123 Report
.Failed
("Incorrect exception raised - 1");
124 end Check_Status_Error
;
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.)
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
);
136 Stream_Access_Value
:=
137 Ada
.Streams
.Stream_Io
.Stream
(Stream_File_Object
);
138 Report
.Failed
("Exception not raised on Stream of closed file");
140 when Ada
.Streams
.Stream_Io
.Status_Error
=>
143 Report
.Failed
("Incorrect exception raised - 2");
144 end Check_Status_Error2
;
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.
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
,
157 Ada
.Streams
.Stream_IO
.Open
(Stream_File_Object
,
158 Ada
.Streams
.Stream_IO
.In_File
,
160 Report
.Failed
("Exception not raised on Open of open file");
162 when Ada
.Streams
.Stream_IO
.Status_Error
=>
165 Report
.Failed
("Incorrect exception raised - 3");
166 end Check_Status_Error3
;
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.
174 Int_Var
: Integer := -10;
179 Ada
.Streams
.Stream_IO
.Reset
(Stream_File_Object
,
180 Ada
.Streams
.Stream_IO
.Out_File
);
182 when Ada
.Streams
.Stream_IO
.Use_Error
=>
183 Report
.Not_Applicable
184 ( "Reset to Out_File not supported for Stream_IO - 1" );
188 Stream_Access_Value
:=
189 Ada
.Streams
.Stream_IO
.Stream
(Stream_File_Object
);
190 Integer'Write (Stream_Access_Value
, Int_Var
);
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");
198 when Ada
.Streams
.Stream_IO
.Mode_Error
=>
204 Ada
.Streams
.Stream_IO
.Reset
205 (Stream_File_Object
, Ada
.Streams
.Stream_IO
.Append_File
);
207 when Ada
.Streams
.Stream_IO
.Use_Error
=>
208 Report
.Not_Applicable
209 ( "Reset to Append_File not supported " &
210 "for Stream_IO - 2" );
214 Integer'Write (Stream_Access_Value
, Int_Var
);
215 -- Attempt read from Append_File mode file.
216 Integer'Read (Stream_Access_Value
, Int_Var
);
218 ("Exception not raised by 'Read of Append file");
222 when Ada
.Streams
.Stream_IO
.Mode_Error
=>
225 Report
.Failed
("Incorrect exception raised - 4b");
228 when others => Report
.Failed
("Incorrect exception raised - 4a");
229 end Check_Mode_Error
;
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.
237 Test_Boolean
: Boolean := False;
241 Ada
.Streams
.Stream_IO
.Reset
(Stream_File_Object
,
242 Ada
.Streams
.Stream_IO
.Out_File
);
244 when Ada
.Streams
.Stream_IO
.Use_Error
=>
245 Report
.Not_Applicable
246 ( "Reset to Out_File not supported for Stream_IO - 3" );
251 Ada
.Streams
.Stream_IO
.End_Of_File
(Stream_File_Object
);
252 Report
.Failed
("Exception not raised by EOF on Out_File");
256 when Ada
.Streams
.Stream_IO
.Mode_Error
=>
262 Ada
.Streams
.Stream_IO
.Reset
263 (Stream_File_Object
, Ada
.Streams
.Stream_IO
.Append_File
);
265 when Ada
.Streams
.Stream_IO
.Use_Error
=>
266 Report
.Not_Applicable
267 ( "Reset to Append_File not supported " &
268 "for Stream_IO - 4" );
273 Ada
.Streams
.Stream_IO
.End_Of_File
(Stream_File_Object
);
275 ("Exception not raised by EOF of Append file");
279 when Ada
.Streams
.Stream_IO
.Mode_Error
=>
282 Report
.Failed
("Incorrect exception raised - 5b");
283 end EOF_For_Append_File
;
285 when others => Report
.Failed
("Incorrect exception raised - 5a");
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
294 Check_Output_Mode_Error
:
298 Ada
.Streams
.Stream_IO
.Reset
(Stream_File_Object
,
299 Ada
.Streams
.Stream_IO
.In_File
);
301 when Ada
.Streams
.Stream_IO
.Use_Error
=>
302 Report
.Not_Applicable
303 ( "Reset to In_File not supported for Stream_IO - 6" );
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");
314 when Ada
.Streams
.Stream_IO
.Mode_Error
=>
317 Report
.Failed
("Incorrect exception raised - 6");
318 end Check_Output_Mode_Error
;
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
324 Check_Illegal_File_Name
:
326 if Ada
.Streams
.Stream_IO
.Is_Open
(Stream_File_Object
) then
327 Ada
.Streams
.Stream_IO
.Close
(Stream_File_Object
);
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");
337 when Ada
.Streams
.Stream_IO
.Name_Error
=>
340 Report
.Failed
("Incorrect exception raised - 7");
341 end Check_Illegal_File_Name
;
347 Report
.Failed
("Unexpected exception in Operational Test Block");
349 end Operational_Test_Block
;
353 if Ada
.Streams
.Stream_IO
.Is_Open
(Stream_File_Object
) then
354 Ada
.Streams
.Stream_IO
.Delete
(Stream_File_Object
);
356 Ada
.Streams
.Stream_IO
.Open
(Stream_File_Object
,
357 Ada
.Streams
.Stream_IO
.Out_File
,
359 Ada
.Streams
.Stream_IO
.Delete
(Stream_File_Object
);
364 ( "Delete not properly implemented for Stream_IO" );
373 Report
.Failed
( "Unexpected exception" );