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 type File_Access is available in Ada.Text_IO, and that
28 -- objects of this type designate File_Type objects.
29 -- Check that function Set_Error will set the current default error file.
30 -- Check that versions of Ada.Text_IO functions Standard_Input,
31 -- Standard_Output, Standard_Error return File_Access values designating
32 -- the standard system input, output, and error files.
33 -- Check that versions of Ada.Text_IO functions Current_Input,
34 -- Current_Output, Current_Error return File_Access values designating
35 -- the current system input, output, and error files.
38 -- This test tests the use of File_Access objects in referring
39 -- to File_Type objects, as well as several new functions that return
40 -- File_Access objects as results.
41 -- Four user-defined files are created. These files will be set to
42 -- function as current system input, output, and error files.
43 -- Data will be read from and written to these files during the
44 -- time at which they function as the current system files.
45 -- An array of File_Access objects will be defined. It will be
46 -- initialized using functions that return File_Access objects
47 -- referencing the Standard and Current Input, Output, and Error files.
48 -- This "saves" the initial system environment, which will be modified
49 -- to use the user-defined files as the current default Input, Output,
50 -- and Error files. At the end of the test, the data in this array
51 -- will be used to restore the initial system environment.
53 -- APPLICABILITY CRITERIA:
54 -- This test is applicable to implementations capable of supporting
55 -- external Text_IO files.
59 -- 25 May 95 SAIC Initial prerelease version.
60 -- 22 Apr 96 SAIC Incorporated reviewer comments for ACVC 2.1.
61 -- 26 Feb 97 PWB.CTA Allowed for non-support of some IO operations.
62 -- 18 Jan 99 RLB Repaired to allow Not_Applicable systems to
71 New_Error_File_2
: aliased Ada
.Text_IO
.File_Type
;
77 with Ada
.Text_IO
; use Ada
.Text_IO
;
78 with CXAA016_0
; use CXAA016_0
;
82 Non_Applicable_System
: exception;
84 Not_Applicable_System
: Boolean := False;
86 procedure Delete_File
( A_File
: in out Ada
.Text_IO
.File_Type
;
87 ID_Num
: in Integer ) is
89 if not Ada
.Text_IO
.Is_Open
( A_File
) then
90 Ada
.Text_IO
.Open
( A_File
,
92 Report
.Legal_File_Name
( ID_Num
) );
94 Ada
.Text_IO
.Delete
( A_File
);
96 when Ada
.Text_IO
.Name_Error
=>
97 if Not_Applicable_System
then
98 null; -- File probably wasn't created.
100 Report
.Failed
( "Can't open file for Text_IO" );
102 when Ada
.Text_IO
.Use_Error
=>
103 if Not_Applicable_System
then
104 null; -- File probably wasn't created.
106 Report
.Failed
( "Delete not properly implemented for Text_IO" );
109 Report
.Failed
( "Unexpected exception in Delete_File" );
114 Report
.Test
("CXAA016", "Check that the type File_Access is available " &
115 "in Ada.Text_IO, and that objects of this " &
116 "type designate File_Type objects");
122 type System_File_Array_Type
is
123 array (Integer range <>) of File_Access
;
125 -- Fill the following array with the File_Access results of six
128 Initial_Environment
: System_File_Array_Type
(1..6) :=
136 New_Input_Ptr
: File_Access
:= New_Input_File
'Access;
137 New_Output_Ptr
: File_Access
:= New_Output_File
'Access;
138 New_Error_Ptr
: File_Access
:= New_Error_File_1
'Access;
140 Line
: String(1..80);
141 Length
: Natural := 0;
143 Line_1
: constant String := "This is the first line in the Output file";
144 Line_2
: constant String := "This is the next line in the Output file";
145 Line_3
: constant String := "This is the first line in Error file 1";
146 Line_4
: constant String := "This is the next line in Error file 1";
147 Line_5
: constant String := "This is the first line in Error file 2";
148 Line_6
: constant String := "This is the next line in Error file 2";
152 procedure New_File
(The_File
: in out File_Type
;
154 Next
: in Integer) is
156 Create
(The_File
, Mode
, Report
.Legal_File_Name
(Next
));
158 -- The following two exceptions may be raised if a system is not
159 -- capable of supporting external Text_IO files. The handler will
160 -- raise a user-defined exception which will result in a
161 -- Not_Applicable result for the test.
162 when Use_Error | Name_Error
=> raise Non_Applicable_System
;
167 procedure Check_Initial_Environment
(Env
: System_File_Array_Type
) is
169 -- Check that the system has defined the following sources/
170 -- destinations for input/output/error, and that the six functions
171 -- returning File_Access values are available.
172 if not (Env
(1) = Standard_Input
and
173 Env
(2) = Standard_Output
and
174 Env
(3) = Standard_Error
and
175 Env
(4) = Current_Input
and
176 Env
(5) = Current_Output
and
177 Env
(6) = Current_Error
)
179 Report
.Failed
("At the start of the test, the Standard and " &
180 "Current File_Access values associated with " &
181 "system Input, Output, and Error files do " &
184 end Check_Initial_Environment
;
188 procedure Load_Input_File
(Input_Ptr
: in File_Access
) is
190 -- Load data into the file that will function as the user-defined
191 -- system input file.
192 Put_Line
(Input_Ptr
.all, Line_1
);
193 Put_Line
(Input_Ptr
.all, Line_2
);
194 Put_Line
(Input_Ptr
.all, Line_3
);
195 Put_Line
(Input_Ptr
.all, Line_4
);
196 Put_Line
(Input_Ptr
.all, Line_5
);
197 Put_Line
(Input_Ptr
.all, Line_6
);
202 procedure Restore_Initial_Environment
203 (Initial_Env
: System_File_Array_Type
) is
205 -- Restore the Current Input, Output, and Error files to their
208 Set_Input
(Initial_Env
(4).all);
209 Set_Output
(Initial_Env
(5).all);
210 Set_Error
(Initial_Env
(6).all);
212 -- At this point, the user-defined files that were functioning as
213 -- the Current Input, Output, and Error files have been replaced in
214 -- that capacity by the state of the original environment.
218 -- Capture the state of the current environment.
220 Current_Env
: System_File_Array_Type
(1..6) :=
221 (Standard_Input
, Standard_Output
, Standard_Error
,
222 Current_Input
, Current_Output
, Current_Error
);
225 -- Compare the current environment with that of the saved
226 -- initial environment.
228 if Current_Env
/= Initial_Env
then
229 Report
.Failed
("Restored file environment was not the same " &
230 "as the initial file environment");
233 end Restore_Initial_Environment
;
237 procedure Verify_Files
(O_File
, E_File_1
, E_File_2
: in File_Type
) is
238 Str_1
, Str_2
, Str_3
, Str_4
, Str_5
, Str_6
: String (1..80);
239 Len_1
, Len_2
, Len_3
, Len_4
, Len_5
, Len_6
: Natural;
242 -- Get the lines that are contained in all the files, and verify
243 -- them against the expected results.
245 Get_Line
(O_File
, Str_1
, Len_1
); -- The user defined output file
246 Get_Line
(O_File
, Str_2
, Len_2
); -- should contain two lines of data.
248 if Str_1
(1..Len_1
) /= Line_1
or
249 Str_2
(1..Len_2
) /= Line_2
251 Report
.Failed
("Incorrect results from Current_Output file");
254 Get_Line
(E_File_1
, Str_3
, Len_3
); -- The first error file received
255 Get_Line
(E_File_1
, Str_4
, Len_4
); -- two lines of data originally,
256 Get_Line
(E_File_1
, Str_5
, Len_5
); -- then had two additional lines
257 Get_Line
(E_File_1
, Str_6
, Len_6
); -- appended from the second error
259 if Str_3
(1..Len_3
) /= Line_3
or
260 Str_4
(1..Len_4
) /= Line_4
or
261 Str_5
(1..Len_5
) /= Line_5
or
262 Str_6
(1..Len_6
) /= Line_6
264 Report
.Failed
("Incorrect results from first Error file");
267 Get_Line
(E_File_2
, Str_5
, Len_5
); -- The second error file
268 Get_Line
(E_File_2
, Str_6
, Len_6
); -- received two lines of data.
270 if Str_5
(1..Len_5
) /= Line_5
or
271 Str_6
(1..Len_6
) /= Line_6
273 Report
.Failed
("Incorrect results from second Error file");
282 Check_Initial_Environment
(Initial_Environment
);
284 -- Create user-defined text files that will be set to serve as current
285 -- system input, output, and error files.
287 New_File
(New_Input_File
, Out_File
, 1); -- Will be reset prior to use.
288 New_File
(New_Output_File
, Out_File
, 2);
289 New_File
(New_Error_File_1
, Out_File
, 3);
290 New_File
(New_Error_File_2
, Out_File
, 4);
292 -- Enter several lines of text into the new input file. This file will
293 -- be reset to mode In_File to function as the current system input file.
294 -- Note: File_Access value used as parameter to this procedure.
296 Load_Input_File
(New_Input_Ptr
);
298 -- Reset the New_Input_File to mode In_File, to allow it to act as the
299 -- current system input file.
303 Reset
(New_Input_File
, In_File
);
305 when Ada
.Text_IO
.Use_Error
=>
306 Report
.Not_Applicable
307 ( "Reset to In_File not supported for Text_IO - 1" );
311 -- Establish new files that will function as the current system Input,
312 -- Output, and Error files.
314 Set_Input
(New_Input_File
);
315 Set_Output
(New_Output_Ptr
.all);
316 Set_Error
(New_Error_Ptr
.all);
318 -- Perform various file processing tasks, exercising specific new
319 -- Text_IO functionality.
321 -- Read two lines from Current_Input and write them to Current_Output.
324 Get_Line
(Current_Input
, Line
, Length
);
325 Put_Line
(Current_Output
, Line
(1..Length
));
328 -- Read two lines from Current_Input and write them to Current_Error.
331 Get_Line
(Current_Input
, Line
, Length
);
332 Put_Line
(Current_Error
, Line
(1..Length
));
335 -- Reset the Current system error file.
337 Set_Error
(New_Error_File_2
);
339 -- Read two lines from Current_Input and write them to Current_Error.
342 Get_Line
(Current_Input
, Line
, Length
);
343 Put_Line
(Current_Error
, Line
(1..Length
));
346 -- At this point in the processing, the new Output file, and each of
347 -- the two Error files, contain two lines of data.
348 -- Note that New_Error_File_1 has been replaced by New_Error_File_2
349 -- as the current system error file, allowing New_Error_File_1 to be
350 -- reset (Mode_Error raised otherwise).
352 -- Reset the first Error file to Append_File mode, and then set it to
353 -- function as the current system error file.
357 Reset
(New_Error_File_1
, Append_File
);
359 when Ada
.Text_IO
.Use_Error
=>
360 Report
.Not_Applicable
361 ( "Reset to Append_File not supported for Text_IO - 2" );
365 Set_Error
(New_Error_File_1
);
367 -- Reset the second Error file to In_File mode, then set it to become
368 -- the current system input file.
372 Reset
(New_Error_File_2
, In_File
);
374 when Ada
.Text_IO
.Use_Error
=>
375 Report
.Not_Applicable
376 ( "Reset to In_File not supported for Text_IO - 3" );
380 New_Error_Ptr
:= New_Error_File_2
'Access;
381 Set_Input
(New_Error_Ptr
.all);
383 -- Append all of the text lines (2) in the new current system input
384 -- file onto the current system error file.
386 while not End_Of_File
(Current_Input
) loop
387 Get_Line
(Current_Input
, Line
, Length
);
388 Put_Line
(Current_Error
, Line
(1..Length
));
391 -- Restore the original system file environment, based upon the values
392 -- stored at the start of this test.
393 -- Check that the original environment has been restored.
395 Restore_Initial_Environment
(Initial_Environment
);
397 -- Reset all three files to In_File_Mode prior to verification.
398 -- Note: If these three files had still been the designated Current
399 -- Input, Output, or Error files for the system, a Reset
400 -- operation at this point would raise Mode_Error.
401 -- However, at this point, the environment has been restored to
402 -- its original state, and these user-defined files are no longer
403 -- designated as current system files, allowing a Reset.
407 Reset
(New_Error_File_1
, In_File
);
409 when Ada
.Text_IO
.Use_Error
=>
410 Report
.Not_Applicable
411 ( "Reset to In_File not supported for Text_IO - 4" );
417 Reset
(New_Error_File_2
, In_File
);
419 when Ada
.Text_IO
.Use_Error
=>
420 Report
.Not_Applicable
421 ( "Reset to In_File not supported for Text_IO - 5" );
427 Reset
(New_Output_File
, In_File
);
429 when Ada
.Text_IO
.Use_Error
=>
430 Report
.Not_Applicable
431 ( "Reset to In_File not supported for Text_IO - 6" );
435 -- Check that all the files contain the appropriate data.
437 Verify_Files
(New_Output_File
, New_Error_File_1
, New_Error_File_2
);
442 when Non_Applicable_System
=>
443 Report
.Not_Applicable
("System not capable of supporting external " &
444 "text files -- Name_Error/Use_Error raised " &
445 "during text file creation");
446 Not_Applicable_System
:= True;
447 when The_Error
: others =>
448 Report
.Failed
("The following exception was raised in the " &
449 "Test_Block: " & Exception_Name
(The_Error
));
454 Delete_File
( New_Input_File
, 1 );
455 Delete_File
( New_Output_File
, 2 );
456 Delete_File
( New_Error_File_1
, 3 );
457 Delete_File
( New_Error_File_2
, 4 );