summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxf/cxf3004.a
blob: 146047bc82464d6aefbe4fda4375b45450120fc7 (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
-- CXF3004.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
--      in conjunction with function Image to produce output strings 
--      appropriate to foreign currency representations.
--
--      Check that statically identifiable picture strings will cause
--      function Image to raise Layout_Error under the appropriate 
--      conditions.
--      
-- 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 function Image.  
--
--       
-- CHANGE HISTORY:
--      11 Apr 96   SAIC    Initial release for 2.1.
--
--!

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

procedure CXF3004 is
begin

   Report.Test ("CXF3004", "Check that statically identifiable "        &
                           "picture strings will cause function Image " &
                           "to raise Layout_Error under appropriate "   &
                           "conditions");

   Test_Block:
   declare

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

      FF_Currency  : constant String    := "FF";
      DM_Currency  : constant String    := "DM";
      FF_Separator : constant Character := '.';
      DM_Separator : constant Character := ',';
      FF_Radix     : constant Character := ',';
      DM_Radix     : constant Character := '.';
      Blank_Fill   : constant Character := ' ';
      Star_Fill    : constant Character := '*';


      -- 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   => "$",
                           Default_Fill       => Star_Fill,
                           Default_Separator  => Default_Separator,
                           Default_Radix_Mark => DM_Radix);



      -- The following decimal data items are used with picture strings 
      -- in evaluating use of foreign currency symbols.

      Dec_Data_1 : Decimal_Data_Type := 123456.78;
      Dec_Data_2 : Decimal_Data_Type :=     32.10;
      Dec_Data_3 : Decimal_Data_Type :=  -1234.57;
      Dec_Data_4 : Decimal_Data_Type := 123456.78;
      Dec_Data_5 : Decimal_Data_Type :=     12.34;
      Dec_Data_6 : Decimal_Data_Type :=     12.34;
      Dec_Data_7 : Decimal_Data_Type :=  12345.67;


      -- Statically identifiable picture strings.
      -- These strings are used in conjunction with non-default values 
      -- for Currency string, Radix mark, and Separator in calls to
      -- function Image.

      Picture_1 : Picture := To_Picture("-###**_***_**9.99");    -- FF
      Picture_2 : Picture := To_Picture("###z_ZZ9.99");          -- FF
      Picture_3 : Picture := To_Picture("<<<<_<<<.<<###>");      -- DM
      Picture_4 : Picture := To_Picture("-$_$$$_$$$_$$9.99");    -- DM
      Picture_5 : Picture := To_Picture("$Zz9.99");              -- DM
      Picture_6 : Picture := To_Picture("$$$9.99");              -- DM
      Picture_7 : Picture := To_Picture("###_###_##9.99");       -- CHF


      -- The following ten edited output strings correspond to the ten
      -- foreign currency picture strings.

      Output_1 : constant String := "  FF***123.456,78";
      Output_2 : constant String := " FF   32,10";
      Output_3 : constant String := "  (1,234.57DM )";
      Output_4 : constant String := "      DM123,456.78"; 
      Output_5 : constant String := "DM 12.34";
      Output_6 : constant String := " DM12.34";
      Output_7 : constant String := "  CHF12,345.67";


   begin

      -- Check the results of function Image, using the picture strings
      -- constructed above, in creating foreign currency edited output
      -- strings.

      if Image_IO.Image(Item       => Dec_Data_1,
                        Pic        => Picture_1,
                        Currency   => FF_Currency,
                        Fill       => Star_Fill,
                        Separator  => FF_Separator,
                        Radix_Mark => FF_Radix) /= Output_1
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_1");
      end if;

      if Image_IO.Image(Item       => Dec_Data_2,
                        Pic        => Picture_2,
                        Currency   => FF_Currency,
                        Fill       => Blank_Fill,
                        Separator  => FF_Separator,
                        Radix_Mark => FF_Radix) /= Output_2
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_2");
      end if;

      if Image_IO.Image(Item       => Dec_Data_3,
                        Pic        => Picture_3,
                        Currency   => DM_Currency,
                        Fill       => Blank_Fill,
                        Separator  => DM_Separator,
                        Radix_Mark => DM_Radix) /= Output_3
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_3");
      end if;

      if Image_IO.Image(Item       => Dec_Data_4,
                        Pic        => Picture_4,
                        Currency   => DM_Currency,
                        Fill       => Blank_Fill,
                        Separator  => DM_Separator,
                        Radix_Mark => DM_Radix) /= Output_4
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_4");
      end if;

      if Image_IO.Image(Item       => Dec_Data_5,
                        Pic        => Picture_5,
                        Currency   => DM_Currency,
                        Fill       => Blank_Fill,
                        Separator  => DM_Separator,
                        Radix_Mark => DM_Radix) /= Output_5
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_5");
      end if;

      if Image_IO.Image(Item       => Dec_Data_6,
                        Pic        => Picture_6,
                        Currency   => DM_Currency,
                        Fill       => Blank_Fill,
                        Separator  => DM_Separator,
                        Radix_Mark => DM_Radix) /= Output_6
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_6");
      end if;

      if Image_IO.Image(Item       => Dec_Data_7,
                        Pic        => Picture_7,
                        Currency   => "CHF",
                        Fill       => Blank_Fill,
                        Separator  => ',',
                        Radix_Mark => '.') /= Output_7
      then
         Report.Failed("Incorrect result from Fn. Image using Picture_7");
      end if;


      -- The following calls of Function Image, using the specific
      -- decimal values and picture strings provided, will cause 
      -- a Layout_Error to be raised.
      -- Note: The data and the picture strings used in the following 
      --       evaluations are not themselves erroneous, but when used in
      --       combination will cause Layout_Error to be raised.

      Exception_Block_1 :
      declare
         Erroneous_Data_1    : Decimal_Data_Type :=  12.34;
         Erroneous_Picture_1 : Picture := To_Picture("9.99");
         N         : constant Natural := Image_IO.Length(Erroneous_Picture_1);
         TC_String : String(1..N);
      begin
         TC_String := Image_IO.Image(Erroneous_Data_1, Erroneous_Picture_1);
         Report.Failed("Layout_Error not raised by combination of "  &
                       "Erroneous_Picture_1 and Erroneous_Data_1");
         Report.Comment("Should never be printed: " & TC_String);
      exception
         when Ada.Text_IO.Layout_Error => null; -- OK, expected exception.
         when The_Error : others       => 
            Report.Failed
              ("The following exception was incorrectly raised in " &
               "Exception_Block_1: " & Exception_Name(The_Error));
      end Exception_Block_1;
  
      Exception_Block_2 :
      declare
         Erroneous_Data_2    : Decimal_Data_Type :=  -12.34;
         Erroneous_Picture_2 : Picture := To_Picture("99.99");
         N         : constant Natural := Image_IO.Length(Erroneous_Picture_2);
         TC_String : String(1..N);
      begin
         TC_String := Image_IO.Image(Erroneous_Data_2, Erroneous_Picture_2);
         Report.Failed("Layout_Error not raised by combination of "  &
                       "Erroneous_Picture_2 and Erroneous_Data_2");
         Report.Comment("Should never be printed: " & TC_String);
      exception
         when Ada.Text_IO.Layout_Error => null; -- OK, expected exception.
         when The_Error : others       => 
            Report.Failed
              ("The following exception was incorrectly raised in " &
               "Exception_Block_2: " & Exception_Name(The_Error));
      end Exception_Block_2;
  
   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 CXF3004;