summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxf/cxf3a06.a
blob: 7b769ba96bf46277b00dcf3039ba7565c507c794 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
-- CXF3A06.A 
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
--      Check that Ada.Text_IO.Editing.Put and Ada.Text_IO.Put have the same
--      effect.  
--
-- TEST DESCRIPTION:
--      This test is structured using tables of data, consisting of
--      numerical values, picture strings, and expected image
--      result strings.  These data tables are found in package FXF3A00.
--      
--      The testing approach used in this test is that of writing edited
--      output data to a text file, using two different approaches.  First,
--      Ada.Text_IO.Put is used, with a call to an instantiated version of
--      Function Image supplied as the actual for parameter Item.  The 
--      second approach is to use a version of Function Put from an 
--      instantiation of Ada.Text_IO.Editing.Decimal_Output, with the
--      appropriate parameters for decimal data, picture, and format
--      specific parameters.  A call to New_Line follows each Put, so that
--      each entry is placed on a separate line in the text file.
--      
--      Edited output for decimal data with two decimal places is in the 
--      first loop, and once the data has been written to the file, the 
--      text file is closed, then opened in In_File mode.  The edited
--      output data is read from the file, and data on successive lines
--      is compared with the expected edited output result.  The edited
--      output data produced by both of the Put procedures should be
--      identical.
--      
--      This process is repeated for decimal data with no decimal places.
--      The file is reopened in Append_File mode, and the edited output
--      data is added to the file in the same manner as described above.
--      The file is closed, and reopened to verify the data written.  
--      The data written above (with two decimal places) is skipped, then
--      the data to be verified is extracted as above and verified against
--      the expected edited output string values.
--      
-- APPLICABILITY CRITERIA: 
--      This test is applicable only to implementations that support
--      external text files.
--
-- TEST FILES:
--      The following files comprise this test:
--
--         FXF3A00.A   (foundation code)
--      => CXF3A06.A
--
--       
-- CHANGE HISTORY:
--      26 JAN 95   SAIC    Initial prerelease version.
--      26 FEB 97   PWB.CTA Made input buffers sufficiently long
--                          and removed code depending on shorter buffers
--!

with FXF3A00;
with Ada.Text_IO.Editing;
with Report;

procedure CXF3A06 is
   use Ada;
begin

   Report.Test ("CXF3A06", "Check that Ada.Text_IO.Editing.Put and " &
                           "Ada.Text_IO.Put have the same effect");

   Test_for_Text_IO_Support:
   declare
      Text_File     : Ada.Text_IO.File_Type;
      Text_Filename : constant String := Report.Legal_File_Name(1);
   begin

      -- Use_Error will be raised if Text_IO operations or external files
      -- are not supported.

      Text_IO.Create (Text_File, Text_IO.Out_File, Text_Filename);

      Test_Block:
      declare
         use Ada.Text_IO;

         -- Instantiate the Decimal_Output generic package for two
         -- different decimal data types.

         package Pack_2DP is          -- Uses decimal type with delta 0.01.
           new Editing.Decimal_Output(FXF3A00.Decimal_Type_2DP);

         package Pack_NDP is          -- Uses decimal type with delta 1.0.
           new Editing.Decimal_Output(Num => FXF3A00.Decimal_Type_NDP,
                                      Default_Currency   => "$",
                                      Default_Fill       => '*',
                                      Default_Separator  => ',',
                                      Default_Radix_Mark => '.');

         TC_Picture    : Editing.Picture;
         TC_Start_Loop : constant :=  1;
         TC_End_Loop_1 : constant := FXF3A00.Number_Of_2DP_Items -    -- 20-10
                                     FXF3A00.Number_Of_Foreign_Strings;
         TC_End_Loop_2 : constant := FXF3A00.Number_Of_NDP_Items;     -- 12
         TC_Offset     : constant := FXF3A00.Number_Of_2DP_Items;     -- 20

         TC_String_1, TC_String_2 : String(1..255) := (others => ' ');
         TC_Last_1,   TC_Last_2   : Natural := 0;

      begin

         -- Use the two versions of Put, for data with two decimal points,
         -- to write edited output strings to the text file.  Use a separate
         -- line for each string entry.

         for i in TC_Start_Loop..TC_End_Loop_1 loop               -- 1..10

            -- Create the picture object from the picture string.

            TC_Picture := Editing.To_Picture(FXF3A00.Valid_Strings(i).all);

            -- Use the Text_IO version of Put to place an edited output 
            -- string into a text file. Use default parameters in the call
            -- to Image for Currency, Fill, Separator, and Radix_Mark.

            Text_IO.Put(Text_File,
                        Pack_2DP.Image(Item => FXF3A00.Data_With_2DP(i),
                                       Pic  => TC_Picture));
            Text_IO.New_Line(Text_File);

            -- Use the version of Put from the instantiation of 
            -- Decimal_Output to place an edited output string on a separate
            -- line of the Text_File.  Use default parameters for Currency,
            -- Fill, Separator, and Radix_Mark.

            Pack_2DP.Put(File => Text_File,
                         Item => FXF3A00.Data_With_2DP(i),
                         Pic  => TC_Picture);
            Text_IO.New_Line(Text_File);

         end loop;

         Text_IO.Close(Text_File);

         -- Reopen the text file in In_File mode, and verify the edited
         -- output found on consecutive lines of the file.

         Text_IO.Open(Text_File, Text_IO.In_File, Text_Filename);

         for i in TC_Start_Loop..TC_End_Loop_1 loop
               -- Read successive lines in the text file.
               Text_IO.Get_Line(Text_File, TC_String_1, TC_Last_1);
               Text_IO.Get_Line(Text_File, TC_String_2, TC_Last_2);

            -- Compare the two strings for equality with the expected edited
            -- output result.  Failure results if strings don't match, or if
            -- a reading error occurred from the attempted Get_Line resulting 
            -- from an improperly formed edited output string.

            if TC_String_1(1..TC_Last_1) /= FXF3A00.Edited_Output(i).all  or 
               TC_String_2(1..TC_Last_2) /= FXF3A00.Edited_Output(i).all
            then
               Report.Failed("Failed comparison of two edited output "    &
                             "strings from data with two decimal points " &
                             ", loop number = " & Integer'Image(i));
            end if;
         end loop;

         Text_IO.Close(Text_File);

         -- Reopen the text file in Append_File mode.
         -- Use the two versions of Put, for data with no decimal points,
         -- to write edited output strings to the text file.  Use a separate
         -- line for each string entry.

         Text_IO.Open(Text_File, Text_IO.Append_File, Text_Filename);

         for i in TC_Start_Loop..TC_End_Loop_2 loop               -- 1..12

            -- Create the picture object from the picture string specific to
            -- data with no decimal points.  Use appropriate offset into the
            -- Valid_Strings array to account for the string data used above.

            TC_Picture := 
              Editing.To_Picture(FXF3A00.Valid_Strings(i+TC_End_Loop_1).all);

            -- Use the Text_IO version of Put to place an edited output 
            -- string into a text file.  Use non-default parameters in the
            -- call to Image for Currency, Fill, Separator, and Radix_Mark.

            Text_IO.Put(Text_File,
                        Pack_NDP.Image(Item => FXF3A00.Data_With_NDP(i),
                                       Pic  => TC_Picture,
                                       Currency   => "$",
                                       Fill       => '*',
                                       Separator  => ',',
                                       Radix_Mark => '.'));
            Text_IO.New_Line(Text_File);

            -- Use the version of Put from the instantiation of 
            -- Decimal_Output to place an edited output string on a separate
            -- line of the Text_File.  Use non-default parameters for
            -- Currency, Fill, Separator, and Radix_Mark.

            Pack_NDP.Put(File       => Text_File,
                         Item       => FXF3A00.Data_With_NDP(i),
                         Pic        => TC_Picture,
                         Currency   => "$",
                         Fill       => '*',
                         Separator  => ',',
                         Radix_Mark => '.');
            Text_IO.New_Line(Text_File);

         end loop;

         Text_IO.Close(Text_File);

         -- Reopen the text file in In_File mode, and verify the edited
         -- output found on consecutive lines of the file.

         Text_IO.Open(Text_File, Text_IO.In_File, Text_Filename);

         -- Read past data that has been verified above, skipping two lines 
         -- of the data file for each loop.

         for i in TC_Start_Loop..TC_End_Loop_1 loop               -- 1..10
            Text_IO.Skip_Line(Text_File, 2);
         end loop;

         -- Verify the last data set that was written to the file.

         for i in TC_Start_Loop..TC_End_Loop_2 loop               -- 1..12
               Text_IO.Get_Line(Text_File, TC_String_1, TC_Last_1);
               Text_IO.Get_Line(Text_File, TC_String_2, TC_Last_2);

            -- Compare the two strings for equality with the expected edited
            -- output result.  Failure results if strings don't match, or if
            -- a reading error occurred from the attempted Get_Line resulting 
            -- from an improperly formed edited output string.

            if TC_String_1(1..TC_Last_1)              /= 
               FXF3A00.Edited_Output(i+TC_Offset).all    or 
               TC_String_2(1..TC_Last_2)              /= 
               FXF3A00.Edited_Output(i+TC_Offset).all
            then
               Report.Failed("Failed comparison of two edited output "   &
                             "strings from data with no decimal points " &
                             ", loop number = " & 
                             Integer'Image(i));
            end if;

         end loop;

      exception
         when others => Report.Failed("Exception raised in Test_Block");
      end Test_Block;

      -- Delete the external file.
      if Text_IO.Is_Open (Text_File) then
         Text_IO.Delete (Text_File);
      else
         Text_IO.Open (Text_File, Text_IO.In_File, Text_Filename);
         Text_IO.Delete (Text_File);
      end if;

   exception

      -- Since Use_Error can be raised if, for the specified mode,
      -- the environment does not support Text_IO operations, the 
      -- following handlers are included:

      when Text_IO.Use_Error  =>
         Report.Not_Applicable ("Use_Error raised on Text_IO Create");

      when Text_IO.Name_Error =>
         Report.Not_Applicable ("Name_Error raised on Text_IO Create");

      when others             =>
         Report.Failed ("Unexpected exception raised in Create block");

   end Test_for_Text_IO_Support;

   Report.Result;

end CXF3A06;