summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxf/cxf3003.a
blob: 7cfce618e7cbfd2a7b6567afd18efdcdc60941a3 (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
-- CXF3003.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 statically identifiable picture strings can be used to
--      produce correctly formatted edited output.
--      
-- TEST DESCRIPTION:
--      This test defines several picture strings that are statically
--      identifiable, (i.e.,  Pic : Picture := To_Picture("..."); ).
--      These picture strings are used in conjunction with decimal data
--      as parameters in calls to functions Valid and Image.  These
--      functions are created by an instantiation of the generic package
--      Ada.Text_IO.Editing.Decimal_Output.
--
--       
-- CHANGE HISTORY:
--      04 Apr 96   SAIC    Initial release for 2.1.
--      13 Feb 97   PWB.CTA corrected incorrect picture strings.
--!

with Report;
with Ada.Text_IO.Editing;
with Ada.Exceptions;

procedure CXF3003 is
begin

   Report.Test ("CXF3003", "Check that statically identifiable "     &
                           "picture strings can be used to produce " &
                           "correctly formatted edited output");

   Test_Block:
   declare

      use Ada.Exceptions;
      use Ada.Text_IO.Editing;

      Def_Cur   : constant String    := "$";
      Def_Fill  : constant Character := '*';
      Def_Sep   : constant Character := Default_Separator;
      Def_Radix : constant Character := 
                    Ada.Text_IO.Editing.Default_Radix_Mark;

      type Str_Ptr is access String;
      type Edited_Output_Array_Type is array (Integer range <>) of Str_Ptr;

      -- Define a decimal data type, and instantiate the Decimal_Output 
      -- generic package for the data type.

      type Decimal_Data_Type is delta 0.01 digits 16;

      package Image_IO is 
        new Decimal_Output(Num                => Decimal_Data_Type,
                           Default_Currency   => Def_Cur,
                           Default_Fill       => '*',
                           Default_Separator  => Default_Separator,
                           Default_Radix_Mark => Def_Radix);


      type Decimal_Data_Array_Type is 
        array (Integer range <>) of Decimal_Data_Type;

      Decimal_Data : Decimal_Data_Array_Type(1..5) :=
          (1 =>  1357.99,
           2 => -9029.01,
           3 =>     0.00,
           4 =>     0.20,
           5 =>     3.45);

      -- Statically identifiable picture strings.

      Picture_1  : Picture := To_Picture("-$$_$$9.99"); 
      Picture_2  : Picture := To_Picture("-$$_$$$.$$"); 
      Picture_3  : Picture := To_Picture("-ZZZZ.ZZ");
      Picture_5  : Picture := To_Picture("-$$$_999.99");
      Picture_6  : Picture := To_Picture("-###**_***_**9.99");
      Picture_7  : Picture := To_Picture("-$**_***_**9.99");
      Picture_8  : Picture := To_Picture("-$$$$$$.$$");
      Picture_9  : Picture := To_Picture("-$$$$$$.$$");
      Picture_10 : Picture := To_Picture("+BBBZZ_ZZZ_ZZZ.ZZ");
      Picture_11 : Picture := To_Picture("--_---_---_--9");
      Picture_12 : Picture := To_Picture("-$_$$$_$$$_$$9.99");
      Picture_14 : Picture := To_Picture("$_$$9.99");
      Picture_15 : Picture := To_Picture("$$9.99");


      Picture_1_Output : Edited_Output_Array_Type(1..5) :=
          ( 1 => new String'(" $1,357.99"),      
            2 => new String'("-$9,029.01"),    
            3 => new String'("     $0.00"),
            4 => new String'("     $0.20"),
            5 => new String'("     $3.45"));

      Picture_2_Output : Edited_Output_Array_Type(1..5) :=
           (1 => new String'(" $1,357.99"),      
            2 => new String'("-$9,029.01"),    
            3 => new String'("          "),    
            4 => new String'("      $.20"),    
            5 => new String'("     $3.45"));

      Picture_3_Output : Edited_Output_Array_Type(1..5) :=
           (1 => new String'(" 1357.99"),       
            2 => new String'("-9029.01"),
            3 => new String'("        "),     
            4 => new String'("     .20"),     
            5 => new String'("    3.45"));

      Picture_5_Output : Edited_Output_Array_Type(1..5) := 
           (1 => new String'("  $1,357.99"),
            2 => new String'("- $9,029.01"),
            3 => new String'("   $ 000.00"),  
            4 => new String'("   $ 000.20"),
            5 => new String'("   $ 003.45"));

   begin

      -- Check the results of function Valid, using the first five decimal
      -- data items and picture strings.

      if not Image_IO.Valid(Decimal_Data(1), Picture_1) then
         Report.Failed("Picture string 1 not valid");
      elsif not Image_IO.Valid(Decimal_Data(2), Picture_2) then
         Report.Failed("Picture string 2 not valid");
      elsif not Image_IO.Valid(Decimal_Data(3), Picture_3) then
         Report.Failed("Picture string 3 not valid");
      elsif not Image_IO.Valid(Decimal_Data(5), Picture_5) then
         Report.Failed("Picture string 5 not valid");
      end if;


      -- Check the results of function Image, using the picture strings
      -- constructed above, with a variety of named vs. positional
      -- parameter notation and defaulted parameters.

      for i in 1..5 loop
         if Image_IO.Image(Item => Decimal_Data(i), Pic => Picture_1) /=
            Picture_1_Output(i).all
         then
            Report.Failed("Incorrect result from function Image with "    &
                          "decimal data item #" & Integer'Image(i) & ", " &
                          "combined with Picture_1 picture string."       &
                          "Expected: " & Picture_1_Output(i).all & ", "   &
                          "Found: " &
                          Image_IO.Image(Decimal_Data(i),Picture_1));
         end if;

         if Image_IO.Image(Decimal_Data(i), Pic => Picture_2) /=
            Picture_2_Output(i).all
         then
            Report.Failed("Incorrect result from function Image with "    &
                          "decimal data item #" & Integer'Image(i) & ", " &
                          "combined with Picture_2 picture string."       &
                          "Expected: " & Picture_2_Output(i).all & ", "   &
                          "Found: " &
                          Image_IO.Image(Decimal_Data(i),Picture_2));
         end if;

         if Image_IO.Image(Decimal_Data(i), Picture_3) /=
            Picture_3_Output(i).all
         then
            Report.Failed("Incorrect result from function Image with "    &
                          "decimal data item #" & Integer'Image(i) & ", " &
                          "combined with Picture_3 picture string."       &
                          "Expected: " & Picture_3_Output(i).all & ", "   &
                          "Found: " &
                          Image_IO.Image(Decimal_Data(i),Picture_3));
         end if;

         if Image_IO.Image(Decimal_Data(i), Picture_5) /=
            Picture_5_Output(i).all
         then
            Report.Failed("Incorrect result from function Image with "    &
                          "decimal data item #" & Integer'Image(i) & ", " &
                          "combined with Picture_5 picture string."       &
                          "Expected: " & Picture_5_Output(i).all & ", "   &
                          "Found: " &
                          Image_IO.Image(Decimal_Data(i),Picture_5));
         end if;
      end loop;


      if Image_IO.Image(Item       => 123456.78, 
                        Pic        => Picture_6,
                        Currency   => "$",
                        Fill       => Def_Fill,
                        Separator  => Def_Sep,
                        Radix_Mark => Def_Radix) /= "   $***123,456.78"
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_6");
      end if;

      if Image_IO.Image(123456.78, 
                        Pic        => Picture_7,
                        Currency   => Def_Cur,
                        Fill       => '*',
                        Separator  => Def_Sep,
                        Radix_Mark => Def_Radix) /= " $***123,456.78"
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_7");
      end if;

      if Image_IO.Image(0.0, 
                        Picture_8,
                        Currency   => "$",
                        Fill       => '*',
                        Separator  => Def_Sep,
                        Radix_Mark => Def_Radix) /= "          "
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_8");
      end if;

      if Image_IO.Image(0.20, 
                        Picture_9,
                        Def_Cur,
                        Fill       => Def_Fill,
                        Separator  => Default_Separator,
                        Radix_Mark => Default_Radix_Mark) /= "      $.20"
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_9");
      end if;

      if Image_IO.Image(123456.00,
                        Picture_10,
                        "$",
                        '*',
                        Separator  => Def_Sep,
                        Radix_Mark => Def_Radix) /= "+      123,456.00"
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_10");
      end if;

      if Image_IO.Image(-123456.78,
                        Picture_11,
                        Default_Currency,
                        Default_Fill,
                        Default_Separator,
                        Radix_Mark => Def_Radix) /= "      -123,457"
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_11");
      end if;

      if Image_IO.Image(123456.78, Picture_12, "$", '*', ',', '.') /= 
         "      $123,456.78"
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_12");
      end if;

      if Image_IO.Image(1.23,
                        Picture_14,
                        Currency => Def_Cur,
                        Fill     => Def_Fill) /= "   $1.23"
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_14");
      end if;

      if Image_IO.Image(12.34, Pic => Picture_15) /= "$12.34"
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_15");
      end if;

   exception
      when The_Error : others => 
         Report.Failed("The following exception was raised in the " &
                       "Test_Block: " & Exception_Name(The_Error));
   end Test_Block;

   Report.Result;

end CXF3003;