aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxb/cxb4006.a
blob: 6e491eebff7b08ea29668bdc33c09d9e78b825f2 (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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
-- CXB4006.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 the function Valid with Packed_Decimal and Packed_Format
--      parameters returns True if Item (the Packed_Decimal parameter) has
--      a value consistent with the Packed_Format parameter.
--
--      Check that the function Length with Packed_Format parameter returns
--      the minimal length of a Packed_Decimal value sufficient to hold any
--      value of type Num when represented according to parameter Format.
--
--      Check that the function To_Decimal with Packed_Decimal and 
--      Packed_Format parameters produces a decimal type value corresponding 
--      to the Packed_Decimal parameter value Item, under the conditions of 
--      the Packed_Format parameter Format.
--
--      Check that the function To_Packed with Decimal (Num) and 
--      Packed_Format parameters produces a Packed_Decimal result that 
--      corresponds to the decimal parameter under conditions of the 
--      Packed_Format parameter.
--
--      Check that Conversion_Error is propagated by function To_Packed if 
--      the value of the decimal parameter Item is negative and the specified
--      Packed_Format parameter is Packed_Unsigned.
--
--      
-- TEST DESCRIPTION:
--      This test checks the results from instantiated versions of 
--      several functions that deal with parameters or results of type
--      Packed_Decimal.  Since the rules for the formation of Packed_Decimal
--      values are implementation defined, several of the subtests cannot
--      directly check the accuracy of the results produced. Instead, they
--      verify that the result is within a range of possible values, or
--      that the result of one function can be converted back to the original 
--      actual parameter using a "mirror image" conversion function.
--      
-- APPLICABILITY CRITERIA: 
--      This test is applicable to all implementations that provide 
--      package Interfaces.COBOL.  If an implementation provides
--      package Interfaces.COBOL, this test must compile, execute, and 
--      report "PASSED".
--
--       
-- CHANGE HISTORY:
--      12 Feb 96   SAIC    Initial release for 2.1.
--      30 May 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--      27 Oct 96   SAIC    Incorporated reviewer comments.
--
--!

with Report;
with Ada.Exceptions;
with Interfaces.COBOL;                                          -- N/A => ERROR

procedure CXB4006 is
begin

   Report.Test ("CXB4006", "Check that the functions Valid, Length, "   &
                           "To_Decimal, and To_Packed specific to "     &
                           "Packed_Decimal parameters produce correct " &
                           "results");

   Test_Block:
   declare

      use Interfaces.COBOL;
      use Ada.Exceptions;
      use type Interfaces.COBOL.Numeric;

      type Decimal_Type_1 is delta 0.1    digits  6;
      type Decimal_Type_2 is delta 0.01   digits  8;
      type Decimal_Type_3 is delta 0.001  digits 10;
      type Decimal_Type_4 is delta 0.0001 digits 12;

      package Pack_1 is new Decimal_Conversions(Decimal_Type_1);
      package Pack_2 is new Decimal_Conversions(Decimal_Type_2);
      package Pack_3 is new Decimal_Conversions(Decimal_Type_3);
      package Pack_4 is new Decimal_Conversions(Decimal_Type_4);

      TC_Dec_1      : Decimal_Type_1 := 12345.6;
      TC_Dec_2      : Decimal_Type_2 := 123456.78;
      TC_Dec_3      : Decimal_Type_3 := 1234567.890;
      TC_Dec_4      : Decimal_Type_4 := 12345678.9012;
      TC_Min_Length : Natural        := 1;
      TC_Max_Length : Natural        := 16;

   begin

      -- Check that the function Valid with Packed_Decimal and Packed_Format
      -- parameters returns True if Item (the Packed_Decimal parameter) has 
      -- a value consistent with the Packed_Format parameter.
      -- Note: Since the formation rules for Packed_Decimal values are
      --       implementation defined, the parameter values here are 
      --       created by function To_Packed.

      TC_Dec_1 := 1434.3;
      if not Pack_1.Valid(Item   => Pack_1.To_Packed(TC_Dec_1, 
                                                     Packed_Unsigned),
                          Format => Packed_Unsigned)
      then
         Report.Failed("Incorrect result from function Valid - 1");
      end if;

      TC_Dec_2 := -4321.03;
      if not Pack_2.Valid(Pack_2.To_Packed(TC_Dec_2, Packed_Signed),
                          Format => Packed_Signed)                   or
         Pack_2.Valid(Pack_2.To_Packed(TC_Dec_2, Packed_Signed),
                      Format => Packed_Unsigned)
      then
         Report.Failed("Incorrect result from function Valid - 2");
      end if;

      TC_Dec_3 := 1234567.890;
      if not Pack_3.Valid(Pack_3.To_Packed(TC_Dec_3, Packed_Unsigned),
                          Packed_Unsigned)
      then
         Report.Failed("Incorrect result from function Valid - 3");
      end if;

      TC_Dec_4 := -234.6789;
      if not Pack_4.Valid(Item   => Pack_4.To_Packed(TC_Dec_4, 
                                                     Packed_Signed),
                          Format => Packed_Signed)                        or
         Pack_4.Valid(Item   => Pack_4.To_Packed(TC_Dec_4, Packed_Signed),
                      Format => Packed_Unsigned)
      then
         Report.Failed("Incorrect result from function Valid - 4");
      end if;



      -- Check that the function Length with Packed_Format parameter returns
      -- the minimal length of a Packed_Decimal value sufficient to hold any
      -- value of type Num when represented according to parameter Format.

      if NOT (Pack_1.Length(Packed_Signed)   >= TC_Min_Length AND
              Pack_1.Length(Packed_Signed)   <= TC_Max_Length AND
              Pack_1.Length(Packed_Unsigned) >= TC_Min_Length AND
              Pack_1.Length(Packed_Unsigned) <= TC_Max_Length)
      then
         Report.Failed("Incorrect result from function Length - 1");
      end if;

      if NOT (Pack_2.Length(Packed_Signed)   >= TC_Min_Length AND
              Pack_2.Length(Packed_Signed)   <= TC_Max_Length AND
              Pack_2.Length(Packed_Unsigned) >= TC_Min_Length AND
              Pack_2.Length(Packed_Unsigned) <= TC_Max_Length)
      then
         Report.Failed("Incorrect result from function Length - 2");
      end if;

      if NOT (Pack_3.Length(Packed_Signed)   >= TC_Min_Length AND
              Pack_3.Length(Packed_Signed)   <= TC_Max_Length AND
              Pack_3.Length(Packed_Unsigned) >= TC_Min_Length AND
              Pack_3.Length(Packed_Unsigned) <= TC_Max_Length)
      then
         Report.Failed("Incorrect result from function Length - 3");
      end if;

      if NOT (Pack_4.Length(Packed_Signed)   >= TC_Min_Length AND
              Pack_4.Length(Packed_Signed)   <= TC_Max_Length AND
              Pack_4.Length(Packed_Unsigned) >= TC_Min_Length AND
              Pack_4.Length(Packed_Unsigned) <= TC_Max_Length)
      then
         Report.Failed("Incorrect result from function Length - 4");
      end if;



      -- Check that the function To_Decimal with Packed_Decimal and 
      -- Packed_Format parameters produces a decimal type value corresponding 
      -- to the Packed_Decimal parameter value Item, under the conditions of 
      -- the Packed_Format parameter Format.

      begin
         TC_Dec_1 := 1234.5;
         if Pack_1.To_Decimal(Item   => Pack_1.To_Packed(TC_Dec_1,
                                                         Packed_Unsigned),
                              Format => Packed_Unsigned) /= TC_Dec_1
         then
            Report.Failed("Incorrect result from function To_Decimal - 1");
         end if;
      exception
         when The_Error : others => 
            Report.Failed("The following exception was raised in " &
                          "subtest 1 of function To_Decimal: "     & 
                          Exception_Name(The_Error));
      end;

      begin
         TC_Dec_2 := -123456.50;
         if Pack_2.To_Decimal(Pack_2.To_Packed(TC_Dec_2, Packed_Signed),
                              Format => Packed_Signed) /= TC_Dec_2
         then
            Report.Failed("Incorrect result from function To_Decimal - 2");
         end if;
      exception
         when The_Error : others => 
            Report.Failed("The following exception was raised in " &
                          "subtest 2 of function To_Decimal: "     & 
                          Exception_Name(The_Error));
      end;

      begin
         TC_Dec_3 := 1234567.809;
         if Pack_3.To_Decimal(Pack_3.To_Packed(TC_Dec_3, Packed_Unsigned),
                              Packed_Unsigned) /= TC_Dec_3
         then
            Report.Failed("Incorrect result from function To_Decimal - 3");
         end if;
      exception
         when The_Error : others => 
            Report.Failed("The following exception was raised in " &
                          "subtest 3 of function To_Decimal: "     & 
                          Exception_Name(The_Error));
      end;

      begin
         TC_Dec_4 := -789.1234;
         if Pack_4.To_Decimal(Item   => Pack_4.To_Packed(TC_Dec_4,
                                                         Packed_Signed),
                              Format => Packed_Signed) /= TC_Dec_4
         then
            Report.Failed("Incorrect result from function To_Decimal - 4");
         end if;
      exception
         when The_Error : others => 
            Report.Failed("The following exception was raised in " &
                          "subtest 4 of function To_Decimal: "     & 
                          Exception_Name(The_Error));
      end;



      -- Check that the function To_Packed with Decimal (Num) and 
      -- Packed_Format parameters produces a Packed_Decimal result that 
      -- corresponds to the decimal parameter under conditions of the 
      -- Packed_Format parameter.

      if Pack_1.To_Packed(Item =>  123.4, Format => Packed_Unsigned) =
         Pack_1.To_Packed(Item => -123.4, Format => Packed_Signed)
      then
         Report.Failed("Incorrect result from function To_Packed - 1");
      end if; 

      if Pack_2.To_Packed( 123.45, Format => Packed_Unsigned) =
         Pack_2.To_Packed(-123.45, Format => Packed_Signed)
      then
         Report.Failed("Incorrect result from function To_Packed - 2");
      end if; 

      if Pack_3.To_Packed(Item =>  123.456, Format => Packed_Unsigned) =
         Pack_3.To_Packed(Item => -123.456, Format => Packed_Signed)
      then
         Report.Failed("Incorrect result from function To_Packed - 3");
      end if; 

      if (Pack_4.To_Packed( 123.4567, Packed_Unsigned)     =
          Pack_4.To_Packed(-123.4567, Packed_Signed))       or
         (Pack_4.To_Packed(12345678.9012, Packed_Unsigned) =
          Pack_4.To_Packed(12345678.9013, Packed_Unsigned)) or
         (Pack_4.To_Packed(12345678.9012, Packed_Unsigned) =
          Pack_4.To_Packed(22345678.9012, Packed_Unsigned)) 
      then
         Report.Failed("Incorrect result from function To_Packed - 4");
      end if; 


      -- Check that Conversion_Error is propagated by function To_Packed if 
      -- the value of the decimal parameter Item is negative and the 
      -- specified Packed_Format parameter is Packed_Unsigned.

      begin
         if Pack_1.To_Packed(Item => -12.3, Format => Packed_Unsigned) =
            Pack_1.To_Packed(Item =>  12.3, Format => Packed_Signed)
         then
            Report.Comment("Should never be printed");
         end if;
         Report.Failed("Conversion_Error not raised following call to " & 
                       "function To_Packed with a negative parameter "  &  
                       "Item and Packed_Format parameter Packed_Unsigned");
      exception
         when Conversion_Error   => null;  -- OK, expected exception.
         when The_Error : others =>
            Report.Failed(Exception_Name(The_Error) & " was incorrectly " &
                          "raised following call to function To_Packed "  & 
                          "with a negative parameter Item and "           &
                          "Packed_Format parameter Packed_Unsigned"); 
      end;

   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 CXB4006;