comparison gcc/testsuite/ada/acats/tests/cxa/cxaa004.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 -- CXAA004.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 procedures New_Page, Set_Line, Set_Col, and New_Line
28 -- perform properly on a text file opened with mode Append_File.
29 -- Check that the attributes Page, Line, and Column are all set to 1
30 -- following the opening of a text file with mode Append_File.
31 -- Check that the functions Page, Line, and Col perform properly on a
32 -- text file opened with mode Append_File.
33 -- Check that the procedures Put and Put_Line perform properly on text
34 -- files opened with mode Append_File.
35 -- Check that the procedure Set_Line sets the current line number to
36 -- the value specified by the parameter "To" for text files opened with
37 -- mode Append_File.
38 -- Check that the procedure Set_Col sets the current column number to
39 -- the value specified by the parameter "To" for text files reset with
40 -- mode Append_File.
41 --
42 -- TEST DESCRIPTION:
43 -- This test is designed to simulate the text processing that could
44 -- occur with files that have been created in Out_File mode,
45 -- and then reset to Append_File mode.
46 -- Various calls to Text_IO formatting subprograms are called to properly
47 -- position text appended to a document. The text content and position
48 -- are subsequently verified for accuracy.
49 --
50 -- APPLICABILITY CRITERIA:
51 -- This test is applicable only to implementations that support text
52 -- files.
53 --
54 --
55 -- CHANGE HISTORY:
56 -- 06 Dec 94 SAIC ACVC 2.0
57 -- 24 Feb 97 PWB.CTA Allowed for non-support of some IO operations.
58 --!
59
60 with Ada.Text_IO;
61 with Report;
62
63 procedure CXAA004 is
64 use Ada;
65 Data_File : Text_IO.File_Type;
66 Data_Filename : constant String :=
67 Report.Legal_File_Name ( Nam => "CXAA004" );
68 Incomplete : exception;
69
70 begin
71
72 Report.Test ("CXAA004", "Check that page, line, and column formatting " &
73 "subprograms perform properly on text files " &
74 "opened with mode Append_File");
75
76 Test_for_Text_IO_Support:
77 begin
78
79 -- An implementation that does not support Text_IO in a particular
80 -- environment will raise Use_Error on calls to various
81 -- Text_IO operations. This block statement encloses a call to
82 -- Create, which should raise the exception in a non-supportive
83 -- environment. This exception will be handled to produce a
84 -- Not_Applicable result.
85
86 Text_IO.Create (File => Data_File,
87 Mode => Text_IO.Out_File,
88 Name => Data_Filename);
89
90 exception
91 when Text_IO.Use_Error | Text_IO.Name_Error =>
92 Report.Not_Applicable
93 ( "Files not supported - Create for Text_IO" );
94 raise Incomplete;
95 end Test_for_Text_IO_Support;
96
97 Operational_Test_Block:
98 declare
99 use Text_IO; -- To provide visibility to the "/=" operator.
100
101 Default_Position : constant Text_IO.Positive_Count := 1;
102
103 Section_Header : constant String := "X. ";
104 Reference_Title : constant String := "REFERENCES";
105 Reference_Content : constant String := "Available Upon Request";
106
107 begin
108
109 -- Some amount of text processing would occur here in the scenario
110 -- following file creation, prior to file closure.
111 Text_IO.Put_Line (File => Data_File, Item => "Some optional data");
112
113 -- Close has the effect of a call to New_Page (adding a page
114 -- terminator).
115 Text_IO.Close (Data_File);
116
117 -- This code section simulates a scenario that could occur in a
118 -- text processing environment:
119 -- Certain text is to be appended to a document.
120 -- The file is opened in Append_File mode.
121 -- The position on the appended page is set, verified, and text
122 -- is placed in the file.
123 --
124 -- Note: The text file has been originally created in Out_File
125 -- mode, has been subsequently closed and is now being reopened in
126 -- Append_File mode for further processing.
127
128 Text_IO.Open (Data_File, Text_IO.Append_File, Data_Filename);
129
130 -- Test control code.
131 if (Text_IO.Page(Data_File) /= Default_Position) then -- Verify init.
132 Report.Failed ("Incorrect default page number"); -- page value.
133 end if;
134 if (Text_IO.Line(Data_File) /= Default_Position) then -- Verify init.
135 Report.Failed ("Incorrect default line number"); -- line number.
136 end if;
137 if (Text_IO.Col (Data_File) /= Default_Position) then -- Verify init.
138 Report.Failed ("Incorrect default column number"); -- column no.
139 end if;
140
141 -- Simulated usage code.
142 Text_IO.New_Page (Data_File); -- Set new page/
143 Text_IO.New_Line (File => Data_File, Spacing => 2); -- line pos.
144 Text_IO.Put (Data_File, Section_Header); -- Position
145 Text_IO.Put_Line (Data_File, Reference_Title); -- title.
146
147 -- Test control code. -- Verify new
148 if (Integer(Text_IO.Page (Data_File)) /= -- page and
149 Report.Ident_Int(2)) or else -- line.
150 (Integer(Text_IO.Line (Data_File)) /=
151 Report.Ident_Int(4)) then
152 Report.Failed ("Incorrect results from page/line positioning");
153 end if;
154
155 -- Simulated usage code.
156 Text_IO.Set_Line (File => Data_File, To => 8); -- Set new
157 Text_IO.Set_Col (File => Data_File, To => 30); -- position.
158 Text_IO.Put_Line (Data_File, Reference_Content);
159
160 -- Test control code.
161 if (Integer(Text_IO.Line (Data_File)) /=
162 Report.Ident_Int(9)) or -- Verify new
163 (Integer(Text_IO.Col (Data_File)) /= -- position.
164 Report.Ident_Int(1)) then
165 Report.Failed ("Incorrect results from line/column positioning");
166 end if;
167
168 Test_Verification_Block:
169 declare
170 TC_Page, TC_Line, TC_Column : Text_IO.Positive_Count;
171 TC_Position : Natural := 0;
172 TC_String : String (1 .. 55) := (others => ' ');
173 begin
174
175 Reset1:
176 begin
177 Text_IO.Reset (Data_File, Text_IO.In_File);
178 exception
179 when Text_IO.Use_Error =>
180 Report.Not_Applicable
181 ( "Reset to In_File not supported for Text_IO" );
182 raise Incomplete;
183 end Reset1;
184
185 Text_IO.Skip_Page (Data_File);
186
187 -- If the Reset to Append_File mode actually put a page terminator
188 -- in the file, as allowed (but not required) by RM A.10.2(4), then
189 -- we are now on page 2, an empty page. Therefore, we need to skip
190 -- one more page.
191
192 if Text_IO.End_Of_Page (Data_File) then
193 Text_IO.Skip_Page (Data_File);
194 end if;
195
196 -- Now we're on the reference page.
197
198 -- Loop to the third line
199 for I in 1 .. 3 loop -- and read the contents.
200 Text_IO.Get_Line (Data_File, TC_String, TC_Position);
201 end loop;
202
203 if (TC_Position /= 14) or else -- Verify the title line.
204 (TC_String (1..6) /= "X. RE") or else
205 (TC_String (2..14) /= (". " & Reference_Title)) then
206 Report.Failed ("Incorrect positioning of title line");
207 end if;
208 -- Loop to the eighth line
209 for I in 4 .. 8 loop -- and read the contents.
210 Text_IO.Get_Line (Data_File, TC_String, TC_Position);
211 end loop;
212
213 if (TC_Position /= 51) or -- Verify the contents.
214 (TC_String (30..51) /= "Available Upon Request") then
215 Report.Failed ("Incorrect positioning of contents line");
216 end if;
217
218 exception
219
220 when Incomplete =>
221 raise;
222 when others =>
223 Report.Failed ("Error raised during data verification");
224
225 end Test_Verification_Block;
226
227 exception
228
229 when Incomplete =>
230 raise;
231 when others =>
232 Report.Failed ("Exception raised during Text_IO processing");
233
234 end Operational_Test_Block;
235
236 Final_Block:
237 begin
238 -- Delete the external file.
239 if Text_IO.Is_Open (Data_File) then
240 Text_IO.Delete (Data_File);
241 else
242 Text_IO.Open (Data_File, Text_IO.In_File, Data_Filename);
243 Text_IO.Delete (Data_File);
244 end if;
245 exception
246 when others =>
247 Report.Failed ( "Delete not properly implemented - Text_IO" );
248 end Final_Block;
249
250 Report.Result;
251
252 exception
253
254 when Incomplete =>
255 Report.Result;
256 when others =>
257 Report.Failed ("Unexpected exception");
258 Report.Result;
259
260 end CXAA004;