Dead
[official-gcc.git] / gomp-20050608-branch / gcc / testsuite / ada / acats / tests / cxf / cxf3a06.a
blob7b769ba96bf46277b00dcf3039ba7565c507c794
1 -- CXF3A06.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.
16 -- DISCLAIMER
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 --*
26 -- OBJECTIVE:
27 -- Check that Ada.Text_IO.Editing.Put and Ada.Text_IO.Put have the same
28 -- effect.
30 -- TEST DESCRIPTION:
31 -- This test is structured using tables of data, consisting of
32 -- numerical values, picture strings, and expected image
33 -- result strings. These data tables are found in package FXF3A00.
34 --
35 -- The testing approach used in this test is that of writing edited
36 -- output data to a text file, using two different approaches. First,
37 -- Ada.Text_IO.Put is used, with a call to an instantiated version of
38 -- Function Image supplied as the actual for parameter Item. The
39 -- second approach is to use a version of Function Put from an
40 -- instantiation of Ada.Text_IO.Editing.Decimal_Output, with the
41 -- appropriate parameters for decimal data, picture, and format
42 -- specific parameters. A call to New_Line follows each Put, so that
43 -- each entry is placed on a separate line in the text file.
44 --
45 -- Edited output for decimal data with two decimal places is in the
46 -- first loop, and once the data has been written to the file, the
47 -- text file is closed, then opened in In_File mode. The edited
48 -- output data is read from the file, and data on successive lines
49 -- is compared with the expected edited output result. The edited
50 -- output data produced by both of the Put procedures should be
51 -- identical.
52 --
53 -- This process is repeated for decimal data with no decimal places.
54 -- The file is reopened in Append_File mode, and the edited output
55 -- data is added to the file in the same manner as described above.
56 -- The file is closed, and reopened to verify the data written.
57 -- The data written above (with two decimal places) is skipped, then
58 -- the data to be verified is extracted as above and verified against
59 -- the expected edited output string values.
60 --
61 -- APPLICABILITY CRITERIA:
62 -- This test is applicable only to implementations that support
63 -- external text files.
65 -- TEST FILES:
66 -- The following files comprise this test:
68 -- FXF3A00.A (foundation code)
69 -- => CXF3A06.A
71 --
72 -- CHANGE HISTORY:
73 -- 26 JAN 95 SAIC Initial prerelease version.
74 -- 26 FEB 97 PWB.CTA Made input buffers sufficiently long
75 -- and removed code depending on shorter buffers
76 --!
78 with FXF3A00;
79 with Ada.Text_IO.Editing;
80 with Report;
82 procedure CXF3A06 is
83 use Ada;
84 begin
86 Report.Test ("CXF3A06", "Check that Ada.Text_IO.Editing.Put and " &
87 "Ada.Text_IO.Put have the same effect");
89 Test_for_Text_IO_Support:
90 declare
91 Text_File : Ada.Text_IO.File_Type;
92 Text_Filename : constant String := Report.Legal_File_Name(1);
93 begin
95 -- Use_Error will be raised if Text_IO operations or external files
96 -- are not supported.
98 Text_IO.Create (Text_File, Text_IO.Out_File, Text_Filename);
100 Test_Block:
101 declare
102 use Ada.Text_IO;
104 -- Instantiate the Decimal_Output generic package for two
105 -- different decimal data types.
107 package Pack_2DP is -- Uses decimal type with delta 0.01.
108 new Editing.Decimal_Output(FXF3A00.Decimal_Type_2DP);
110 package Pack_NDP is -- Uses decimal type with delta 1.0.
111 new Editing.Decimal_Output(Num => FXF3A00.Decimal_Type_NDP,
112 Default_Currency => "$",
113 Default_Fill => '*',
114 Default_Separator => ',',
115 Default_Radix_Mark => '.');
117 TC_Picture : Editing.Picture;
118 TC_Start_Loop : constant := 1;
119 TC_End_Loop_1 : constant := FXF3A00.Number_Of_2DP_Items - -- 20-10
120 FXF3A00.Number_Of_Foreign_Strings;
121 TC_End_Loop_2 : constant := FXF3A00.Number_Of_NDP_Items; -- 12
122 TC_Offset : constant := FXF3A00.Number_Of_2DP_Items; -- 20
124 TC_String_1, TC_String_2 : String(1..255) := (others => ' ');
125 TC_Last_1, TC_Last_2 : Natural := 0;
127 begin
129 -- Use the two versions of Put, for data with two decimal points,
130 -- to write edited output strings to the text file. Use a separate
131 -- line for each string entry.
133 for i in TC_Start_Loop..TC_End_Loop_1 loop -- 1..10
135 -- Create the picture object from the picture string.
137 TC_Picture := Editing.To_Picture(FXF3A00.Valid_Strings(i).all);
139 -- Use the Text_IO version of Put to place an edited output
140 -- string into a text file. Use default parameters in the call
141 -- to Image for Currency, Fill, Separator, and Radix_Mark.
143 Text_IO.Put(Text_File,
144 Pack_2DP.Image(Item => FXF3A00.Data_With_2DP(i),
145 Pic => TC_Picture));
146 Text_IO.New_Line(Text_File);
148 -- Use the version of Put from the instantiation of
149 -- Decimal_Output to place an edited output string on a separate
150 -- line of the Text_File. Use default parameters for Currency,
151 -- Fill, Separator, and Radix_Mark.
153 Pack_2DP.Put(File => Text_File,
154 Item => FXF3A00.Data_With_2DP(i),
155 Pic => TC_Picture);
156 Text_IO.New_Line(Text_File);
158 end loop;
160 Text_IO.Close(Text_File);
162 -- Reopen the text file in In_File mode, and verify the edited
163 -- output found on consecutive lines of the file.
165 Text_IO.Open(Text_File, Text_IO.In_File, Text_Filename);
167 for i in TC_Start_Loop..TC_End_Loop_1 loop
168 -- Read successive lines in the text file.
169 Text_IO.Get_Line(Text_File, TC_String_1, TC_Last_1);
170 Text_IO.Get_Line(Text_File, TC_String_2, TC_Last_2);
172 -- Compare the two strings for equality with the expected edited
173 -- output result. Failure results if strings don't match, or if
174 -- a reading error occurred from the attempted Get_Line resulting
175 -- from an improperly formed edited output string.
177 if TC_String_1(1..TC_Last_1) /= FXF3A00.Edited_Output(i).all or
178 TC_String_2(1..TC_Last_2) /= FXF3A00.Edited_Output(i).all
179 then
180 Report.Failed("Failed comparison of two edited output " &
181 "strings from data with two decimal points " &
182 ", loop number = " & Integer'Image(i));
183 end if;
184 end loop;
186 Text_IO.Close(Text_File);
188 -- Reopen the text file in Append_File mode.
189 -- Use the two versions of Put, for data with no decimal points,
190 -- to write edited output strings to the text file. Use a separate
191 -- line for each string entry.
193 Text_IO.Open(Text_File, Text_IO.Append_File, Text_Filename);
195 for i in TC_Start_Loop..TC_End_Loop_2 loop -- 1..12
197 -- Create the picture object from the picture string specific to
198 -- data with no decimal points. Use appropriate offset into the
199 -- Valid_Strings array to account for the string data used above.
201 TC_Picture :=
202 Editing.To_Picture(FXF3A00.Valid_Strings(i+TC_End_Loop_1).all);
204 -- Use the Text_IO version of Put to place an edited output
205 -- string into a text file. Use non-default parameters in the
206 -- call to Image for Currency, Fill, Separator, and Radix_Mark.
208 Text_IO.Put(Text_File,
209 Pack_NDP.Image(Item => FXF3A00.Data_With_NDP(i),
210 Pic => TC_Picture,
211 Currency => "$",
212 Fill => '*',
213 Separator => ',',
214 Radix_Mark => '.'));
215 Text_IO.New_Line(Text_File);
217 -- Use the version of Put from the instantiation of
218 -- Decimal_Output to place an edited output string on a separate
219 -- line of the Text_File. Use non-default parameters for
220 -- Currency, Fill, Separator, and Radix_Mark.
222 Pack_NDP.Put(File => Text_File,
223 Item => FXF3A00.Data_With_NDP(i),
224 Pic => TC_Picture,
225 Currency => "$",
226 Fill => '*',
227 Separator => ',',
228 Radix_Mark => '.');
229 Text_IO.New_Line(Text_File);
231 end loop;
233 Text_IO.Close(Text_File);
235 -- Reopen the text file in In_File mode, and verify the edited
236 -- output found on consecutive lines of the file.
238 Text_IO.Open(Text_File, Text_IO.In_File, Text_Filename);
240 -- Read past data that has been verified above, skipping two lines
241 -- of the data file for each loop.
243 for i in TC_Start_Loop..TC_End_Loop_1 loop -- 1..10
244 Text_IO.Skip_Line(Text_File, 2);
245 end loop;
247 -- Verify the last data set that was written to the file.
249 for i in TC_Start_Loop..TC_End_Loop_2 loop -- 1..12
250 Text_IO.Get_Line(Text_File, TC_String_1, TC_Last_1);
251 Text_IO.Get_Line(Text_File, TC_String_2, TC_Last_2);
253 -- Compare the two strings for equality with the expected edited
254 -- output result. Failure results if strings don't match, or if
255 -- a reading error occurred from the attempted Get_Line resulting
256 -- from an improperly formed edited output string.
258 if TC_String_1(1..TC_Last_1) /=
259 FXF3A00.Edited_Output(i+TC_Offset).all or
260 TC_String_2(1..TC_Last_2) /=
261 FXF3A00.Edited_Output(i+TC_Offset).all
262 then
263 Report.Failed("Failed comparison of two edited output " &
264 "strings from data with no decimal points " &
265 ", loop number = " &
266 Integer'Image(i));
267 end if;
269 end loop;
271 exception
272 when others => Report.Failed("Exception raised in Test_Block");
273 end Test_Block;
275 -- Delete the external file.
276 if Text_IO.Is_Open (Text_File) then
277 Text_IO.Delete (Text_File);
278 else
279 Text_IO.Open (Text_File, Text_IO.In_File, Text_Filename);
280 Text_IO.Delete (Text_File);
281 end if;
283 exception
285 -- Since Use_Error can be raised if, for the specified mode,
286 -- the environment does not support Text_IO operations, the
287 -- following handlers are included:
289 when Text_IO.Use_Error =>
290 Report.Not_Applicable ("Use_Error raised on Text_IO Create");
292 when Text_IO.Name_Error =>
293 Report.Not_Applicable ("Name_Error raised on Text_IO Create");
295 when others =>
296 Report.Failed ("Unexpected exception raised in Create block");
298 end Test_for_Text_IO_Support;
300 Report.Result;
302 end CXF3A06;