| 1 |
-- CXB4006.A |
| 2 |
-- |
| 3 |
-- Grant of Unlimited Rights |
| 4 |
-- |
| 5 |
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, |
| 6 |
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained |
| 7 |
-- unlimited rights in the software and documentation contained herein. |
| 8 |
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making |
| 9 |
-- this public release, the Government intends to confer upon all |
| 10 |
-- recipients unlimited rights equal to those held by the Government. |
| 11 |
-- These rights include rights to use, duplicate, release or disclose the |
| 12 |
-- released technical data and computer software in whole or in part, in |
| 13 |
-- any manner and for any purpose whatsoever, and to have or permit others |
| 14 |
-- to do so. |
| 15 |
-- |
| 16 |
-- DISCLAIMER |
| 17 |
-- |
| 18 |
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR |
| 19 |
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED |
| 20 |
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE |
| 21 |
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE |
| 22 |
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A |
| 23 |
-- PARTICULAR PURPOSE OF SAID MATERIAL. |
| 24 |
--* |
| 25 |
-- |
| 26 |
-- OBJECTIVE: |
| 27 |
-- Check that the function Valid with Packed_Decimal and Packed_Format |
| 28 |
-- parameters returns True if Item (the Packed_Decimal parameter) has |
| 29 |
-- a value consistent with the Packed_Format parameter. |
| 30 |
-- |
| 31 |
-- Check that the function Length with Packed_Format parameter returns |
| 32 |
-- the minimal length of a Packed_Decimal value sufficient to hold any |
| 33 |
-- value of type Num when represented according to parameter Format. |
| 34 |
-- |
| 35 |
-- Check that the function To_Decimal with Packed_Decimal and |
| 36 |
-- Packed_Format parameters produces a decimal type value corresponding |
| 37 |
-- to the Packed_Decimal parameter value Item, under the conditions of |
| 38 |
-- the Packed_Format parameter Format. |
| 39 |
-- |
| 40 |
-- Check that the function To_Packed with Decimal (Num) and |
| 41 |
-- Packed_Format parameters produces a Packed_Decimal result that |
| 42 |
-- corresponds to the decimal parameter under conditions of the |
| 43 |
-- Packed_Format parameter. |
| 44 |
-- |
| 45 |
-- Check that Conversion_Error is propagated by function To_Packed if |
| 46 |
-- the value of the decimal parameter Item is negative and the specified |
| 47 |
-- Packed_Format parameter is Packed_Unsigned. |
| 48 |
-- |
| 49 |
-- |
| 50 |
-- TEST DESCRIPTION: |
| 51 |
-- This test checks the results from instantiated versions of |
| 52 |
-- several functions that deal with parameters or results of type |
| 53 |
-- Packed_Decimal. Since the rules for the formation of Packed_Decimal |
| 54 |
-- values are implementation defined, several of the subtests cannot |
| 55 |
-- directly check the accuracy of the results produced. Instead, they |
| 56 |
-- verify that the result is within a range of possible values, or |
| 57 |
-- that the result of one function can be converted back to the original |
| 58 |
-- actual parameter using a "mirror image" conversion function. |
| 59 |
-- |
| 60 |
-- APPLICABILITY CRITERIA: |
| 61 |
-- This test is applicable to all implementations that provide |
| 62 |
-- package Interfaces.COBOL. If an implementation provides |
| 63 |
-- package Interfaces.COBOL, this test must compile, execute, and |
| 64 |
-- report "PASSED". |
| 65 |
-- |
| 66 |
-- |
| 67 |
-- CHANGE HISTORY: |
| 68 |
-- 12 Feb 96 SAIC Initial release for 2.1. |
| 69 |
-- 30 May 96 SAIC Incorporated reviewer comments for ACVC 2.1. |
| 70 |
-- 27 Oct 96 SAIC Incorporated reviewer comments. |
| 71 |
-- |
| 72 |
--! |
| 73 |
|
| 74 |
with Report; |
| 75 |
with Ada.Exceptions; |
| 76 |
with Interfaces.COBOL; -- N/A => ERROR |
| 77 |
|
| 78 |
procedure CXB4006 is |
| 79 |
begin |
| 80 |
|
| 81 |
Report.Test ("CXB4006", "Check that the functions Valid, Length, " & |
| 82 |
"To_Decimal, and To_Packed specific to " & |
| 83 |
"Packed_Decimal parameters produce correct " & |
| 84 |
"results"); |
| 85 |
|
| 86 |
Test_Block: |
| 87 |
declare |
| 88 |
|
| 89 |
use Interfaces.COBOL; |
| 90 |
use Ada.Exceptions; |
| 91 |
use type Interfaces.COBOL.Numeric; |
| 92 |
|
| 93 |
type Decimal_Type_1 is delta 0.1 digits 6; |
| 94 |
type Decimal_Type_2 is delta 0.01 digits 8; |
| 95 |
type Decimal_Type_3 is delta 0.001 digits 10; |
| 96 |
type Decimal_Type_4 is delta 0.0001 digits 12; |
| 97 |
|
| 98 |
package Pack_1 is new Decimal_Conversions(Decimal_Type_1); |
| 99 |
package Pack_2 is new Decimal_Conversions(Decimal_Type_2); |
| 100 |
package Pack_3 is new Decimal_Conversions(Decimal_Type_3); |
| 101 |
package Pack_4 is new Decimal_Conversions(Decimal_Type_4); |
| 102 |
|
| 103 |
TC_Dec_1 : Decimal_Type_1 := 12345.6; |
| 104 |
TC_Dec_2 : Decimal_Type_2 := 123456.78; |
| 105 |
TC_Dec_3 : Decimal_Type_3 := 1234567.890; |
| 106 |
TC_Dec_4 : Decimal_Type_4 := 12345678.9012; |
| 107 |
TC_Min_Length : Natural := 1; |
| 108 |
TC_Max_Length : Natural := 16; |
| 109 |
|
| 110 |
begin |
| 111 |
|
| 112 |
-- Check that the function Valid with Packed_Decimal and Packed_Format |
| 113 |
-- parameters returns True if Item (the Packed_Decimal parameter) has |
| 114 |
-- a value consistent with the Packed_Format parameter. |
| 115 |
-- Note: Since the formation rules for Packed_Decimal values are |
| 116 |
-- implementation defined, the parameter values here are |
| 117 |
-- created by function To_Packed. |
| 118 |
|
| 119 |
TC_Dec_1 := 1434.3; |
| 120 |
if not Pack_1.Valid(Item => Pack_1.To_Packed(TC_Dec_1, |
| 121 |
Packed_Unsigned), |
| 122 |
Format => Packed_Unsigned) |
| 123 |
then |
| 124 |
Report.Failed("Incorrect result from function Valid - 1"); |
| 125 |
end if; |
| 126 |
|
| 127 |
TC_Dec_2 := -4321.03; |
| 128 |
if not Pack_2.Valid(Pack_2.To_Packed(TC_Dec_2, Packed_Signed), |
| 129 |
Format => Packed_Signed) or |
| 130 |
Pack_2.Valid(Pack_2.To_Packed(TC_Dec_2, Packed_Signed), |
| 131 |
Format => Packed_Unsigned) |
| 132 |
then |
| 133 |
Report.Failed("Incorrect result from function Valid - 2"); |
| 134 |
end if; |
| 135 |
|
| 136 |
TC_Dec_3 := 1234567.890; |
| 137 |
if not Pack_3.Valid(Pack_3.To_Packed(TC_Dec_3, Packed_Unsigned), |
| 138 |
Packed_Unsigned) |
| 139 |
then |
| 140 |
Report.Failed("Incorrect result from function Valid - 3"); |
| 141 |
end if; |
| 142 |
|
| 143 |
TC_Dec_4 := -234.6789; |
| 144 |
if not Pack_4.Valid(Item => Pack_4.To_Packed(TC_Dec_4, |
| 145 |
Packed_Signed), |
| 146 |
Format => Packed_Signed) or |
| 147 |
Pack_4.Valid(Item => Pack_4.To_Packed(TC_Dec_4, Packed_Signed), |
| 148 |
Format => Packed_Unsigned) |
| 149 |
then |
| 150 |
Report.Failed("Incorrect result from function Valid - 4"); |
| 151 |
end if; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
-- Check that the function Length with Packed_Format parameter returns |
| 156 |
-- the minimal length of a Packed_Decimal value sufficient to hold any |
| 157 |
-- value of type Num when represented according to parameter Format. |
| 158 |
|
| 159 |
if NOT (Pack_1.Length(Packed_Signed) >= TC_Min_Length AND |
| 160 |
Pack_1.Length(Packed_Signed) <= TC_Max_Length AND |
| 161 |
Pack_1.Length(Packed_Unsigned) >= TC_Min_Length AND |
| 162 |
Pack_1.Length(Packed_Unsigned) <= TC_Max_Length) |
| 163 |
then |
| 164 |
Report.Failed("Incorrect result from function Length - 1"); |
| 165 |
end if; |
| 166 |
|
| 167 |
if NOT (Pack_2.Length(Packed_Signed) >= TC_Min_Length AND |
| 168 |
Pack_2.Length(Packed_Signed) <= TC_Max_Length AND |
| 169 |
Pack_2.Length(Packed_Unsigned) >= TC_Min_Length AND |
| 170 |
Pack_2.Length(Packed_Unsigned) <= TC_Max_Length) |
| 171 |
then |
| 172 |
Report.Failed("Incorrect result from function Length - 2"); |
| 173 |
end if; |
| 174 |
|
| 175 |
if NOT (Pack_3.Length(Packed_Signed) >= TC_Min_Length AND |
| 176 |
Pack_3.Length(Packed_Signed) <= TC_Max_Length AND |
| 177 |
Pack_3.Length(Packed_Unsigned) >= TC_Min_Length AND |
| 178 |
Pack_3.Length(Packed_Unsigned) <= TC_Max_Length) |
| 179 |
then |
| 180 |
Report.Failed("Incorrect result from function Length - 3"); |
| 181 |
end if; |
| 182 |
|
| 183 |
if NOT (Pack_4.Length(Packed_Signed) >= TC_Min_Length AND |
| 184 |
Pack_4.Length(Packed_Signed) <= TC_Max_Length AND |
| 185 |
Pack_4.Length(Packed_Unsigned) >= TC_Min_Length AND |
| 186 |
Pack_4.Length(Packed_Unsigned) <= TC_Max_Length) |
| 187 |
then |
| 188 |
Report.Failed("Incorrect result from function Length - 4"); |
| 189 |
end if; |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
-- Check that the function To_Decimal with Packed_Decimal and |
| 194 |
-- Packed_Format parameters produces a decimal type value corresponding |
| 195 |
-- to the Packed_Decimal parameter value Item, under the conditions of |
| 196 |
-- the Packed_Format parameter Format. |
| 197 |
|
| 198 |
begin |
| 199 |
TC_Dec_1 := 1234.5; |
| 200 |
if Pack_1.To_Decimal(Item => Pack_1.To_Packed(TC_Dec_1, |
| 201 |
Packed_Unsigned), |
| 202 |
Format => Packed_Unsigned) /= TC_Dec_1 |
| 203 |
then |
| 204 |
Report.Failed("Incorrect result from function To_Decimal - 1"); |
| 205 |
end if; |
| 206 |
exception |
| 207 |
when The_Error : others => |
| 208 |
Report.Failed("The following exception was raised in " & |
| 209 |
"subtest 1 of function To_Decimal: " & |
| 210 |
Exception_Name(The_Error)); |
| 211 |
end; |
| 212 |
|
| 213 |
begin |
| 214 |
TC_Dec_2 := -123456.50; |
| 215 |
if Pack_2.To_Decimal(Pack_2.To_Packed(TC_Dec_2, Packed_Signed), |
| 216 |
Format => Packed_Signed) /= TC_Dec_2 |
| 217 |
then |
| 218 |
Report.Failed("Incorrect result from function To_Decimal - 2"); |
| 219 |
end if; |
| 220 |
exception |
| 221 |
when The_Error : others => |
| 222 |
Report.Failed("The following exception was raised in " & |
| 223 |
"subtest 2 of function To_Decimal: " & |
| 224 |
Exception_Name(The_Error)); |
| 225 |
end; |
| 226 |
|
| 227 |
begin |
| 228 |
TC_Dec_3 := 1234567.809; |
| 229 |
if Pack_3.To_Decimal(Pack_3.To_Packed(TC_Dec_3, Packed_Unsigned), |
| 230 |
Packed_Unsigned) /= TC_Dec_3 |
| 231 |
then |
| 232 |
Report.Failed("Incorrect result from function To_Decimal - 3"); |
| 233 |
end if; |
| 234 |
exception |
| 235 |
when The_Error : others => |
| 236 |
Report.Failed("The following exception was raised in " & |
| 237 |
"subtest 3 of function To_Decimal: " & |
| 238 |
Exception_Name(The_Error)); |
| 239 |
end; |
| 240 |
|
| 241 |
begin |
| 242 |
TC_Dec_4 := -789.1234; |
| 243 |
if Pack_4.To_Decimal(Item => Pack_4.To_Packed(TC_Dec_4, |
| 244 |
Packed_Signed), |
| 245 |
Format => Packed_Signed) /= TC_Dec_4 |
| 246 |
then |
| 247 |
Report.Failed("Incorrect result from function To_Decimal - 4"); |
| 248 |
end if; |
| 249 |
exception |
| 250 |
when The_Error : others => |
| 251 |
Report.Failed("The following exception was raised in " & |
| 252 |
"subtest 4 of function To_Decimal: " & |
| 253 |
Exception_Name(The_Error)); |
| 254 |
end; |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
-- Check that the function To_Packed with Decimal (Num) and |
| 259 |
-- Packed_Format parameters produces a Packed_Decimal result that |
| 260 |
-- corresponds to the decimal parameter under conditions of the |
| 261 |
-- Packed_Format parameter. |
| 262 |
|
| 263 |
if Pack_1.To_Packed(Item => 123.4, Format => Packed_Unsigned) = |
| 264 |
Pack_1.To_Packed(Item => -123.4, Format => Packed_Signed) |
| 265 |
then |
| 266 |
Report.Failed("Incorrect result from function To_Packed - 1"); |
| 267 |
end if; |
| 268 |
|
| 269 |
if Pack_2.To_Packed( 123.45, Format => Packed_Unsigned) = |
| 270 |
Pack_2.To_Packed(-123.45, Format => Packed_Signed) |
| 271 |
then |
| 272 |
Report.Failed("Incorrect result from function To_Packed - 2"); |
| 273 |
end if; |
| 274 |
|
| 275 |
if Pack_3.To_Packed(Item => 123.456, Format => Packed_Unsigned) = |
| 276 |
Pack_3.To_Packed(Item => -123.456, Format => Packed_Signed) |
| 277 |
then |
| 278 |
Report.Failed("Incorrect result from function To_Packed - 3"); |
| 279 |
end if; |
| 280 |
|
| 281 |
if (Pack_4.To_Packed( 123.4567, Packed_Unsigned) = |
| 282 |
Pack_4.To_Packed(-123.4567, Packed_Signed)) or |
| 283 |
(Pack_4.To_Packed(12345678.9012, Packed_Unsigned) = |
| 284 |
Pack_4.To_Packed(12345678.9013, Packed_Unsigned)) or |
| 285 |
(Pack_4.To_Packed(12345678.9012, Packed_Unsigned) = |
| 286 |
Pack_4.To_Packed(22345678.9012, Packed_Unsigned)) |
| 287 |
then |
| 288 |
Report.Failed("Incorrect result from function To_Packed - 4"); |
| 289 |
end if; |
| 290 |
|
| 291 |
|
| 292 |
-- Check that Conversion_Error is propagated by function To_Packed if |
| 293 |
-- the value of the decimal parameter Item is negative and the |
| 294 |
-- specified Packed_Format parameter is Packed_Unsigned. |
| 295 |
|
| 296 |
begin |
| 297 |
if Pack_1.To_Packed(Item => -12.3, Format => Packed_Unsigned) = |
| 298 |
Pack_1.To_Packed(Item => 12.3, Format => Packed_Signed) |
| 299 |
then |
| 300 |
Report.Comment("Should never be printed"); |
| 301 |
end if; |
| 302 |
Report.Failed("Conversion_Error not raised following call to " & |
| 303 |
"function To_Packed with a negative parameter " & |
| 304 |
"Item and Packed_Format parameter Packed_Unsigned"); |
| 305 |
exception |
| 306 |
when Conversion_Error => null; -- OK, expected exception. |
| 307 |
when The_Error : others => |
| 308 |
Report.Failed(Exception_Name(The_Error) & " was incorrectly " & |
| 309 |
"raised following call to function To_Packed " & |
| 310 |
"with a negative parameter Item and " & |
| 311 |
"Packed_Format parameter Packed_Unsigned"); |
| 312 |
end; |
| 313 |
|
| 314 |
exception |
| 315 |
when The_Error : others => |
| 316 |
Report.Failed("The following exception was raised in the " & |
| 317 |
"Test_Block: " & Exception_Name(The_Error)); |
| 318 |
end Test_Block; |
| 319 |
|
| 320 |
Report.Result; |
| 321 |
|
| 322 |
end CXB4006; |