annotate gcc/testsuite/ada/acats/tests/cxb/cxb4007.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- CXB4007.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that the function Valid with Byte_Array and Binary_Format
kono
parents:
diff changeset
28 -- parameters returns True if the Byte_Array parameter corresponds
kono
parents:
diff changeset
29 -- to any value inside the range of type Num.
kono
parents:
diff changeset
30 -- Check that function Valid returns False if the Byte_Array parameter
kono
parents:
diff changeset
31 -- corresponds to a value outside the range of Num.
kono
parents:
diff changeset
32 --
kono
parents:
diff changeset
33 -- Check that function Length with Binary_Format parameter will return
kono
parents:
diff changeset
34 -- the minimum length of a Byte_Array value required to hold any value
kono
parents:
diff changeset
35 -- of decimal type Num.
kono
parents:
diff changeset
36 --
kono
parents:
diff changeset
37 -- Check that function To_Decimal with Byte_Array and Binary_Format
kono
parents:
diff changeset
38 -- parameters will return a decimal type value that corresponds to
kono
parents:
diff changeset
39 -- parameter Item (of type Byte_Array) under the specified Format.
kono
parents:
diff changeset
40 --
kono
parents:
diff changeset
41 -- Check that Conversion_Error is propagated by function To_Decimal if
kono
parents:
diff changeset
42 -- the Byte_Array parameter Item represents a decimal value outside the
kono
parents:
diff changeset
43 -- range of decimal type Num.
kono
parents:
diff changeset
44 --
kono
parents:
diff changeset
45 -- Check that function To_Binary will produce a Byte_Array result that
kono
parents:
diff changeset
46 -- corresponds to the decimal type parameter Item, under the specified
kono
parents:
diff changeset
47 -- Binary_Format.
kono
parents:
diff changeset
48 --
kono
parents:
diff changeset
49 -- TEST DESCRIPTION:
kono
parents:
diff changeset
50 -- This test uses several instantiations of generic package
kono
parents:
diff changeset
51 -- Decimal_Conversions to provide appropriate test material.
kono
parents:
diff changeset
52 -- This test uses the function To_Binary to create all Byte_Array
kono
parents:
diff changeset
53 -- parameter values used in calls to functions Valid and To_Decimal.
kono
parents:
diff changeset
54 -- The function Valid is tested with parameters to provide both
kono
parents:
diff changeset
55 -- valid and invalid expected results. This test also checks that
kono
parents:
diff changeset
56 -- Function To_Decimal produces expected results in cases where each
kono
parents:
diff changeset
57 -- of the three predefined Binary_Format constants are used in the
kono
parents:
diff changeset
58 -- function calls. In addition, the prescribed propagation of
kono
parents:
diff changeset
59 -- Conversion_Error by function To_Decimal is verified.
kono
parents:
diff changeset
60 --
kono
parents:
diff changeset
61 -- APPLICABILITY CRITERIA:
kono
parents:
diff changeset
62 -- This test is applicable to all implementations that provide
kono
parents:
diff changeset
63 -- package Interfaces.COBOL. If an implementation provides
kono
parents:
diff changeset
64 -- package Interfaces.COBOL, this test must compile, execute, and
kono
parents:
diff changeset
65 -- report "PASSED".
kono
parents:
diff changeset
66 --
kono
parents:
diff changeset
67 --
kono
parents:
diff changeset
68 -- CHANGE HISTORY:
kono
parents:
diff changeset
69 -- 14 Feb 96 SAIC Initial release for 2.1.
kono
parents:
diff changeset
70 -- 30 May 96 SAIC Incorporated reviewer comments for ACVC 2.1.
kono
parents:
diff changeset
71 -- 27 Oct 96 SAIC Incorporated reviewer comments.
kono
parents:
diff changeset
72 -- 05 JAN 98 EDS Remove incorrect subtest.
kono
parents:
diff changeset
73 --!
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 with Report;
kono
parents:
diff changeset
76 with Ada.Exceptions;
kono
parents:
diff changeset
77 with Interfaces.COBOL; -- N/A => ERROR
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 procedure CXB4007 is
kono
parents:
diff changeset
80 begin
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 Report.Test ("CXB4007", "Check that functions Valid, Length, To_Decimal " &
kono
parents:
diff changeset
83 "and To_Binary specific to Byte_Array and " &
kono
parents:
diff changeset
84 "Binary_Format parameters produce correct results");
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 Test_Block:
kono
parents:
diff changeset
87 declare
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 use Interfaces.COBOL;
kono
parents:
diff changeset
90 use Ada.Exceptions;
kono
parents:
diff changeset
91 use type Interfaces.COBOL.Numeric;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 type Decimal_Type_1 is delta 0.1 digits 6;
kono
parents:
diff changeset
94 type Decimal_Type_2 is delta 0.01 digits 8;
kono
parents:
diff changeset
95 type Decimal_Type_3 is delta 0.001 digits 10;
kono
parents:
diff changeset
96 type Decimal_Type_4 is delta 0.0001 digits 12;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 package Pack_1 is new Decimal_Conversions(Decimal_Type_1);
kono
parents:
diff changeset
99 package Pack_2 is new Decimal_Conversions(Decimal_Type_2);
kono
parents:
diff changeset
100 package Pack_3 is new Decimal_Conversions(Decimal_Type_3);
kono
parents:
diff changeset
101 package Pack_4 is new Decimal_Conversions(Decimal_Type_4);
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 TC_Dec_1 : Decimal_Type_1 := 12345.6;
kono
parents:
diff changeset
104 TC_Dec_2 : Decimal_Type_2 := 123456.78;
kono
parents:
diff changeset
105 TC_Dec_3 : Decimal_Type_3 := 1234567.890;
kono
parents:
diff changeset
106 TC_Dec_4 : Decimal_Type_4 := 12345678.9012;
kono
parents:
diff changeset
107 TC_Min_Length : Natural := 1;
kono
parents:
diff changeset
108 TC_Max_Length : Natural := 16;
kono
parents:
diff changeset
109 TC_Valid : Boolean := False;
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 begin
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -- Check that the function Valid with Byte_Array and Binary_Format
kono
parents:
diff changeset
114 -- parameters returns True if the Byte_Array parameter corresponds to
kono
parents:
diff changeset
115 -- any value inside the range of type Num.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 if not Pack_1.Valid(Item => Pack_1.To_Binary(TC_Dec_1,
kono
parents:
diff changeset
118 High_Order_First),
kono
parents:
diff changeset
119 Format => High_Order_First) or
kono
parents:
diff changeset
120 not Pack_1.Valid(Pack_1.To_Binary(0.0, Low_Order_First),
kono
parents:
diff changeset
121 Format => Low_Order_First)
kono
parents:
diff changeset
122 then
kono
parents:
diff changeset
123 Report.Failed("Incorrect result from function Valid, using " &
kono
parents:
diff changeset
124 "parameters that should return a positive result - 1");
kono
parents:
diff changeset
125 end if;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 TC_Valid := (Pack_2.Valid(Pack_2.To_Binary(TC_Dec_2, High_Order_First),
kono
parents:
diff changeset
128 Format => High_Order_First) and
kono
parents:
diff changeset
129 Pack_2.Valid(Pack_2.To_Binary(0.01, Low_Order_First),
kono
parents:
diff changeset
130 Format => Low_Order_First));
kono
parents:
diff changeset
131 if not TC_Valid then
kono
parents:
diff changeset
132 Report.Failed("Incorrect result from function Valid, using " &
kono
parents:
diff changeset
133 "parameters that should return a positive result - 2");
kono
parents:
diff changeset
134 end if;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 if not Pack_3.Valid(Item => Pack_3.To_Binary(TC_Dec_3,
kono
parents:
diff changeset
137 Low_Order_First),
kono
parents:
diff changeset
138 Format => Low_Order_First) or
kono
parents:
diff changeset
139 not Pack_3.Valid(Pack_3.To_Binary(0.001, High_Order_First),
kono
parents:
diff changeset
140 Format => High_Order_First) or
kono
parents:
diff changeset
141 not Pack_3.Valid(Pack_3.To_Binary(123.456, Native_Binary),
kono
parents:
diff changeset
142 Native_Binary)
kono
parents:
diff changeset
143 then
kono
parents:
diff changeset
144 Report.Failed("Incorrect result from function Valid, using " &
kono
parents:
diff changeset
145 "parameters that should return a positive result - 3");
kono
parents:
diff changeset
146 end if;
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 -- Check that function Valid returns False if the Byte_Array parameter
kono
parents:
diff changeset
150 -- corresponds to a value outside the range of Num.
kono
parents:
diff changeset
151 -- Note: use a Byte_Array value Item created by an instantiation of
kono
parents:
diff changeset
152 -- To_Binary with a larger Num type as the generic formal.
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 if Pack_1.Valid(Item => Pack_2.To_Binary(TC_Dec_2, Low_Order_First),
kono
parents:
diff changeset
155 Format => Low_Order_First) or
kono
parents:
diff changeset
156 Pack_2.Valid(Pack_3.To_Binary(TC_Dec_3, High_Order_First),
kono
parents:
diff changeset
157 Format => High_Order_First) or
kono
parents:
diff changeset
158 Pack_3.Valid(Pack_4.To_Binary(TC_Dec_4, Native_Binary),
kono
parents:
diff changeset
159 Native_Binary)
kono
parents:
diff changeset
160 then
kono
parents:
diff changeset
161 Report.Failed("Incorrect result from function Valid, using " &
kono
parents:
diff changeset
162 "parameters that should return a negative result");
kono
parents:
diff changeset
163 end if;
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 -- Check that function Length with Binary_Format parameter will return
kono
parents:
diff changeset
167 -- the minimum length of a Byte_Array value required to hold any value
kono
parents:
diff changeset
168 -- of decimal type Num.
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 if not (Pack_1.Length(Native_Binary) >= TC_Min_Length and
kono
parents:
diff changeset
171 Pack_1.Length(Low_Order_First) <= TC_Max_Length and
kono
parents:
diff changeset
172 Pack_2.Length(High_Order_First) >= TC_Min_Length and
kono
parents:
diff changeset
173 Pack_2.Length(Native_Binary) <= TC_Max_Length and
kono
parents:
diff changeset
174 Pack_3.Length(Low_Order_First) >= TC_Min_Length and
kono
parents:
diff changeset
175 Pack_3.Length(High_Order_First) <= TC_Max_Length and
kono
parents:
diff changeset
176 Pack_4.Length(Native_Binary) >= TC_Min_Length and
kono
parents:
diff changeset
177 Pack_4.Length(Low_Order_First) <= TC_Max_Length)
kono
parents:
diff changeset
178 then
kono
parents:
diff changeset
179 Report.Failed("Incorrect result from function Length");
kono
parents:
diff changeset
180 end if;
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 -- Check that function To_Decimal with Byte_Array and Binary_Format
kono
parents:
diff changeset
185 -- parameters will return a decimal type value that corresponds to
kono
parents:
diff changeset
186 -- parameter Item (of type Byte_Array) under the specified Format.
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 if Pack_1.To_Decimal(Item => Pack_1.To_Binary(Item => TC_Dec_1,
kono
parents:
diff changeset
189 Format => Native_Binary),
kono
parents:
diff changeset
190 Format => Native_Binary) /=
kono
parents:
diff changeset
191 TC_Dec_1
kono
parents:
diff changeset
192 then
kono
parents:
diff changeset
193 Report.Failed("Incorrect result from function To_Decimal - 1");
kono
parents:
diff changeset
194 end if;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 if Pack_3.To_Decimal(Pack_3.To_Binary(TC_Dec_3, High_Order_First),
kono
parents:
diff changeset
197 Format => High_Order_First) /=
kono
parents:
diff changeset
198 TC_Dec_3
kono
parents:
diff changeset
199 then
kono
parents:
diff changeset
200 Report.Failed("Incorrect result from function To_Decimal - 2");
kono
parents:
diff changeset
201 end if;
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 if Pack_4.To_Decimal(Pack_4.To_Binary(TC_Dec_4, Low_Order_First),
kono
parents:
diff changeset
204 Low_Order_First) /=
kono
parents:
diff changeset
205 TC_Dec_4
kono
parents:
diff changeset
206 then
kono
parents:
diff changeset
207 Report.Failed("Incorrect result from function To_Decimal - 3");
kono
parents:
diff changeset
208 end if;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 -- Check that Conversion_Error is propagated by function To_Decimal
kono
parents:
diff changeset
213 -- if the Byte_Array parameter Item represents a decimal value outside
kono
parents:
diff changeset
214 -- the range of decimal type Num.
kono
parents:
diff changeset
215 -- Note: use a Byte_Array value Item created by an instantiation of
kono
parents:
diff changeset
216 -- To_Binary with a larger Num type as the generic formal.
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 begin
kono
parents:
diff changeset
219 TC_Dec_4 := 99999.9001;
kono
parents:
diff changeset
220 TC_Dec_1 := Pack_1.To_Decimal(Pack_4.To_Binary(TC_Dec_4,
kono
parents:
diff changeset
221 Native_Binary),
kono
parents:
diff changeset
222 Format => Native_Binary);
kono
parents:
diff changeset
223 if TC_Dec_1 = 99999.9 then
kono
parents:
diff changeset
224 Report.Comment("Minimize dead assignment optimization -- " &
kono
parents:
diff changeset
225 "Should never be printed");
kono
parents:
diff changeset
226 end if;
kono
parents:
diff changeset
227 Report.Failed("Conversion_Error not raised following call to " &
kono
parents:
diff changeset
228 "function To_Decimal if the Byte_Array parameter " &
kono
parents:
diff changeset
229 "Item represents a decimal value outside the " &
kono
parents:
diff changeset
230 "range of decimal type Num");
kono
parents:
diff changeset
231 exception
kono
parents:
diff changeset
232 when Conversion_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
233 when The_Error : others =>
kono
parents:
diff changeset
234 Report.Failed(Exception_Name(The_Error) & " was incorrectly " &
kono
parents:
diff changeset
235 "raised following call to function To_Decimal " &
kono
parents:
diff changeset
236 "if the Byte_Array parameter Item represents " &
kono
parents:
diff changeset
237 "a decimal value outside the range of decimal " &
kono
parents:
diff changeset
238 "type Num");
kono
parents:
diff changeset
239 end;
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 -- Check that function To_Binary will produce a Byte_Array result that
kono
parents:
diff changeset
244 -- corresponds to the decimal type parameter Item, under the specified
kono
parents:
diff changeset
245 -- Binary_Format.
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 -- Different ordering.
kono
parents:
diff changeset
248 TC_Dec_1 := 12345.6;
kono
parents:
diff changeset
249 if Pack_1.To_Binary(TC_Dec_1, Low_Order_First) =
kono
parents:
diff changeset
250 Pack_1.To_Binary(TC_Dec_1, High_Order_First)
kono
parents:
diff changeset
251 then
kono
parents:
diff changeset
252 Report.Failed("Incorrect result from function To_Binary - 1");
kono
parents:
diff changeset
253 end if;
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 -- Variable vs. literal.
kono
parents:
diff changeset
256 TC_Dec_2 := 12345.00;
kono
parents:
diff changeset
257 if Pack_2.To_Binary(TC_Dec_2, Native_Binary) /=
kono
parents:
diff changeset
258 Pack_2.To_Binary(12345.00, Native_Binary)
kono
parents:
diff changeset
259 then
kono
parents:
diff changeset
260 Report.Failed("Incorrect result from function To_Binary - 2");
kono
parents:
diff changeset
261 end if;
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 exception
kono
parents:
diff changeset
264 when The_Error : others =>
kono
parents:
diff changeset
265 Report.Failed("The following exception was raised in the " &
kono
parents:
diff changeset
266 "Test_Block: " & Exception_Name(The_Error));
kono
parents:
diff changeset
267 end Test_Block;
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 Report.Result;
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 end CXB4007;