-- CXB4007.A
|
-- CXB4007.A
|
--
|
--
|
-- Grant of Unlimited Rights
|
-- Grant of Unlimited Rights
|
--
|
--
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
|
-- 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
|
-- 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 in the software and documentation contained herein.
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- this public release, the Government intends to confer upon all
|
-- this public release, the Government intends to confer upon all
|
-- recipients unlimited rights equal to those held by the Government.
|
-- recipients unlimited rights equal to those held by the Government.
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- released technical data and computer software in whole or in part, in
|
-- 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
|
-- any manner and for any purpose whatsoever, and to have or permit others
|
-- to do so.
|
-- to do so.
|
--
|
--
|
-- DISCLAIMER
|
-- DISCLAIMER
|
--
|
--
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
--*
|
--*
|
--
|
--
|
-- OBJECTIVE:
|
-- OBJECTIVE:
|
-- Check that the function Valid with Byte_Array and Binary_Format
|
-- Check that the function Valid with Byte_Array and Binary_Format
|
-- parameters returns True if the Byte_Array parameter corresponds
|
-- parameters returns True if the Byte_Array parameter corresponds
|
-- to any value inside the range of type Num.
|
-- to any value inside the range of type Num.
|
-- Check that function Valid returns False if the Byte_Array parameter
|
-- Check that function Valid returns False if the Byte_Array parameter
|
-- corresponds to a value outside the range of Num.
|
-- corresponds to a value outside the range of Num.
|
--
|
--
|
-- Check that function Length with Binary_Format parameter will return
|
-- Check that function Length with Binary_Format parameter will return
|
-- the minimum length of a Byte_Array value required to hold any value
|
-- the minimum length of a Byte_Array value required to hold any value
|
-- of decimal type Num.
|
-- of decimal type Num.
|
--
|
--
|
-- Check that function To_Decimal with Byte_Array and Binary_Format
|
-- Check that function To_Decimal with Byte_Array and Binary_Format
|
-- parameters will return a decimal type value that corresponds to
|
-- parameters will return a decimal type value that corresponds to
|
-- parameter Item (of type Byte_Array) under the specified Format.
|
-- parameter Item (of type Byte_Array) under the specified Format.
|
--
|
--
|
-- Check that Conversion_Error is propagated by function To_Decimal if
|
-- Check that Conversion_Error is propagated by function To_Decimal if
|
-- the Byte_Array parameter Item represents a decimal value outside the
|
-- the Byte_Array parameter Item represents a decimal value outside the
|
-- range of decimal type Num.
|
-- range of decimal type Num.
|
--
|
--
|
-- Check that function To_Binary will produce a Byte_Array result that
|
-- Check that function To_Binary will produce a Byte_Array result that
|
-- corresponds to the decimal type parameter Item, under the specified
|
-- corresponds to the decimal type parameter Item, under the specified
|
-- Binary_Format.
|
-- Binary_Format.
|
--
|
--
|
-- TEST DESCRIPTION:
|
-- TEST DESCRIPTION:
|
-- This test uses several instantiations of generic package
|
-- This test uses several instantiations of generic package
|
-- Decimal_Conversions to provide appropriate test material.
|
-- Decimal_Conversions to provide appropriate test material.
|
-- This test uses the function To_Binary to create all Byte_Array
|
-- This test uses the function To_Binary to create all Byte_Array
|
-- parameter values used in calls to functions Valid and To_Decimal.
|
-- parameter values used in calls to functions Valid and To_Decimal.
|
-- The function Valid is tested with parameters to provide both
|
-- The function Valid is tested with parameters to provide both
|
-- valid and invalid expected results. This test also checks that
|
-- valid and invalid expected results. This test also checks that
|
-- Function To_Decimal produces expected results in cases where each
|
-- Function To_Decimal produces expected results in cases where each
|
-- of the three predefined Binary_Format constants are used in the
|
-- of the three predefined Binary_Format constants are used in the
|
-- function calls. In addition, the prescribed propagation of
|
-- function calls. In addition, the prescribed propagation of
|
-- Conversion_Error by function To_Decimal is verified.
|
-- Conversion_Error by function To_Decimal is verified.
|
--
|
--
|
-- APPLICABILITY CRITERIA:
|
-- APPLICABILITY CRITERIA:
|
-- This test is applicable to all implementations that provide
|
-- This test is applicable to all implementations that provide
|
-- package Interfaces.COBOL. If an implementation provides
|
-- package Interfaces.COBOL. If an implementation provides
|
-- package Interfaces.COBOL, this test must compile, execute, and
|
-- package Interfaces.COBOL, this test must compile, execute, and
|
-- report "PASSED".
|
-- report "PASSED".
|
--
|
--
|
--
|
--
|
-- CHANGE HISTORY:
|
-- CHANGE HISTORY:
|
-- 14 Feb 96 SAIC Initial release for 2.1.
|
-- 14 Feb 96 SAIC Initial release for 2.1.
|
-- 30 May 96 SAIC Incorporated reviewer comments for ACVC 2.1.
|
-- 30 May 96 SAIC Incorporated reviewer comments for ACVC 2.1.
|
-- 27 Oct 96 SAIC Incorporated reviewer comments.
|
-- 27 Oct 96 SAIC Incorporated reviewer comments.
|
-- 05 JAN 98 EDS Remove incorrect subtest.
|
-- 05 JAN 98 EDS Remove incorrect subtest.
|
--!
|
--!
|
|
|
with Report;
|
with Report;
|
with Ada.Exceptions;
|
with Ada.Exceptions;
|
with Interfaces.COBOL; -- N/A => ERROR
|
with Interfaces.COBOL; -- N/A => ERROR
|
|
|
procedure CXB4007 is
|
procedure CXB4007 is
|
begin
|
begin
|
|
|
Report.Test ("CXB4007", "Check that functions Valid, Length, To_Decimal " &
|
Report.Test ("CXB4007", "Check that functions Valid, Length, To_Decimal " &
|
"and To_Binary specific to Byte_Array and " &
|
"and To_Binary specific to Byte_Array and " &
|
"Binary_Format parameters produce correct results");
|
"Binary_Format parameters produce correct results");
|
|
|
Test_Block:
|
Test_Block:
|
declare
|
declare
|
|
|
use Interfaces.COBOL;
|
use Interfaces.COBOL;
|
use Ada.Exceptions;
|
use Ada.Exceptions;
|
use type Interfaces.COBOL.Numeric;
|
use type Interfaces.COBOL.Numeric;
|
|
|
type Decimal_Type_1 is delta 0.1 digits 6;
|
type Decimal_Type_1 is delta 0.1 digits 6;
|
type Decimal_Type_2 is delta 0.01 digits 8;
|
type Decimal_Type_2 is delta 0.01 digits 8;
|
type Decimal_Type_3 is delta 0.001 digits 10;
|
type Decimal_Type_3 is delta 0.001 digits 10;
|
type Decimal_Type_4 is delta 0.0001 digits 12;
|
type Decimal_Type_4 is delta 0.0001 digits 12;
|
|
|
package Pack_1 is new Decimal_Conversions(Decimal_Type_1);
|
package Pack_1 is new Decimal_Conversions(Decimal_Type_1);
|
package Pack_2 is new Decimal_Conversions(Decimal_Type_2);
|
package Pack_2 is new Decimal_Conversions(Decimal_Type_2);
|
package Pack_3 is new Decimal_Conversions(Decimal_Type_3);
|
package Pack_3 is new Decimal_Conversions(Decimal_Type_3);
|
package Pack_4 is new Decimal_Conversions(Decimal_Type_4);
|
package Pack_4 is new Decimal_Conversions(Decimal_Type_4);
|
|
|
TC_Dec_1 : Decimal_Type_1 := 12345.6;
|
TC_Dec_1 : Decimal_Type_1 := 12345.6;
|
TC_Dec_2 : Decimal_Type_2 := 123456.78;
|
TC_Dec_2 : Decimal_Type_2 := 123456.78;
|
TC_Dec_3 : Decimal_Type_3 := 1234567.890;
|
TC_Dec_3 : Decimal_Type_3 := 1234567.890;
|
TC_Dec_4 : Decimal_Type_4 := 12345678.9012;
|
TC_Dec_4 : Decimal_Type_4 := 12345678.9012;
|
TC_Min_Length : Natural := 1;
|
TC_Min_Length : Natural := 1;
|
TC_Max_Length : Natural := 16;
|
TC_Max_Length : Natural := 16;
|
TC_Valid : Boolean := False;
|
TC_Valid : Boolean := False;
|
|
|
begin
|
begin
|
|
|
-- Check that the function Valid with Byte_Array and Binary_Format
|
-- Check that the function Valid with Byte_Array and Binary_Format
|
-- parameters returns True if the Byte_Array parameter corresponds to
|
-- parameters returns True if the Byte_Array parameter corresponds to
|
-- any value inside the range of type Num.
|
-- any value inside the range of type Num.
|
|
|
if not Pack_1.Valid(Item => Pack_1.To_Binary(TC_Dec_1,
|
if not Pack_1.Valid(Item => Pack_1.To_Binary(TC_Dec_1,
|
High_Order_First),
|
High_Order_First),
|
Format => High_Order_First) or
|
Format => High_Order_First) or
|
not Pack_1.Valid(Pack_1.To_Binary(0.0, Low_Order_First),
|
not Pack_1.Valid(Pack_1.To_Binary(0.0, Low_Order_First),
|
Format => Low_Order_First)
|
Format => Low_Order_First)
|
then
|
then
|
Report.Failed("Incorrect result from function Valid, using " &
|
Report.Failed("Incorrect result from function Valid, using " &
|
"parameters that should return a positive result - 1");
|
"parameters that should return a positive result - 1");
|
end if;
|
end if;
|
|
|
TC_Valid := (Pack_2.Valid(Pack_2.To_Binary(TC_Dec_2, High_Order_First),
|
TC_Valid := (Pack_2.Valid(Pack_2.To_Binary(TC_Dec_2, High_Order_First),
|
Format => High_Order_First) and
|
Format => High_Order_First) and
|
Pack_2.Valid(Pack_2.To_Binary(0.01, Low_Order_First),
|
Pack_2.Valid(Pack_2.To_Binary(0.01, Low_Order_First),
|
Format => Low_Order_First));
|
Format => Low_Order_First));
|
if not TC_Valid then
|
if not TC_Valid then
|
Report.Failed("Incorrect result from function Valid, using " &
|
Report.Failed("Incorrect result from function Valid, using " &
|
"parameters that should return a positive result - 2");
|
"parameters that should return a positive result - 2");
|
end if;
|
end if;
|
|
|
if not Pack_3.Valid(Item => Pack_3.To_Binary(TC_Dec_3,
|
if not Pack_3.Valid(Item => Pack_3.To_Binary(TC_Dec_3,
|
Low_Order_First),
|
Low_Order_First),
|
Format => Low_Order_First) or
|
Format => Low_Order_First) or
|
not Pack_3.Valid(Pack_3.To_Binary(0.001, High_Order_First),
|
not Pack_3.Valid(Pack_3.To_Binary(0.001, High_Order_First),
|
Format => High_Order_First) or
|
Format => High_Order_First) or
|
not Pack_3.Valid(Pack_3.To_Binary(123.456, Native_Binary),
|
not Pack_3.Valid(Pack_3.To_Binary(123.456, Native_Binary),
|
Native_Binary)
|
Native_Binary)
|
then
|
then
|
Report.Failed("Incorrect result from function Valid, using " &
|
Report.Failed("Incorrect result from function Valid, using " &
|
"parameters that should return a positive result - 3");
|
"parameters that should return a positive result - 3");
|
end if;
|
end if;
|
|
|
|
|
-- Check that function Valid returns False if the Byte_Array parameter
|
-- Check that function Valid returns False if the Byte_Array parameter
|
-- corresponds to a value outside the range of Num.
|
-- corresponds to a value outside the range of Num.
|
-- Note: use a Byte_Array value Item created by an instantiation of
|
-- Note: use a Byte_Array value Item created by an instantiation of
|
-- To_Binary with a larger Num type as the generic formal.
|
-- To_Binary with a larger Num type as the generic formal.
|
|
|
if Pack_1.Valid(Item => Pack_2.To_Binary(TC_Dec_2, Low_Order_First),
|
if Pack_1.Valid(Item => Pack_2.To_Binary(TC_Dec_2, Low_Order_First),
|
Format => Low_Order_First) or
|
Format => Low_Order_First) or
|
Pack_2.Valid(Pack_3.To_Binary(TC_Dec_3, High_Order_First),
|
Pack_2.Valid(Pack_3.To_Binary(TC_Dec_3, High_Order_First),
|
Format => High_Order_First) or
|
Format => High_Order_First) or
|
Pack_3.Valid(Pack_4.To_Binary(TC_Dec_4, Native_Binary),
|
Pack_3.Valid(Pack_4.To_Binary(TC_Dec_4, Native_Binary),
|
Native_Binary)
|
Native_Binary)
|
then
|
then
|
Report.Failed("Incorrect result from function Valid, using " &
|
Report.Failed("Incorrect result from function Valid, using " &
|
"parameters that should return a negative result");
|
"parameters that should return a negative result");
|
end if;
|
end if;
|
|
|
|
|
-- Check that function Length with Binary_Format parameter will return
|
-- Check that function Length with Binary_Format parameter will return
|
-- the minimum length of a Byte_Array value required to hold any value
|
-- the minimum length of a Byte_Array value required to hold any value
|
-- of decimal type Num.
|
-- of decimal type Num.
|
|
|
if not (Pack_1.Length(Native_Binary) >= TC_Min_Length and
|
if not (Pack_1.Length(Native_Binary) >= TC_Min_Length and
|
Pack_1.Length(Low_Order_First) <= TC_Max_Length and
|
Pack_1.Length(Low_Order_First) <= TC_Max_Length and
|
Pack_2.Length(High_Order_First) >= TC_Min_Length and
|
Pack_2.Length(High_Order_First) >= TC_Min_Length and
|
Pack_2.Length(Native_Binary) <= TC_Max_Length and
|
Pack_2.Length(Native_Binary) <= TC_Max_Length and
|
Pack_3.Length(Low_Order_First) >= TC_Min_Length and
|
Pack_3.Length(Low_Order_First) >= TC_Min_Length and
|
Pack_3.Length(High_Order_First) <= TC_Max_Length and
|
Pack_3.Length(High_Order_First) <= TC_Max_Length and
|
Pack_4.Length(Native_Binary) >= TC_Min_Length and
|
Pack_4.Length(Native_Binary) >= TC_Min_Length and
|
Pack_4.Length(Low_Order_First) <= TC_Max_Length)
|
Pack_4.Length(Low_Order_First) <= TC_Max_Length)
|
then
|
then
|
Report.Failed("Incorrect result from function Length");
|
Report.Failed("Incorrect result from function Length");
|
end if;
|
end if;
|
|
|
|
|
|
|
-- Check that function To_Decimal with Byte_Array and Binary_Format
|
-- Check that function To_Decimal with Byte_Array and Binary_Format
|
-- parameters will return a decimal type value that corresponds to
|
-- parameters will return a decimal type value that corresponds to
|
-- parameter Item (of type Byte_Array) under the specified Format.
|
-- parameter Item (of type Byte_Array) under the specified Format.
|
|
|
if Pack_1.To_Decimal(Item => Pack_1.To_Binary(Item => TC_Dec_1,
|
if Pack_1.To_Decimal(Item => Pack_1.To_Binary(Item => TC_Dec_1,
|
Format => Native_Binary),
|
Format => Native_Binary),
|
Format => Native_Binary) /=
|
Format => Native_Binary) /=
|
TC_Dec_1
|
TC_Dec_1
|
then
|
then
|
Report.Failed("Incorrect result from function To_Decimal - 1");
|
Report.Failed("Incorrect result from function To_Decimal - 1");
|
end if;
|
end if;
|
|
|
if Pack_3.To_Decimal(Pack_3.To_Binary(TC_Dec_3, High_Order_First),
|
if Pack_3.To_Decimal(Pack_3.To_Binary(TC_Dec_3, High_Order_First),
|
Format => High_Order_First) /=
|
Format => High_Order_First) /=
|
TC_Dec_3
|
TC_Dec_3
|
then
|
then
|
Report.Failed("Incorrect result from function To_Decimal - 2");
|
Report.Failed("Incorrect result from function To_Decimal - 2");
|
end if;
|
end if;
|
|
|
if Pack_4.To_Decimal(Pack_4.To_Binary(TC_Dec_4, Low_Order_First),
|
if Pack_4.To_Decimal(Pack_4.To_Binary(TC_Dec_4, Low_Order_First),
|
Low_Order_First) /=
|
Low_Order_First) /=
|
TC_Dec_4
|
TC_Dec_4
|
then
|
then
|
Report.Failed("Incorrect result from function To_Decimal - 3");
|
Report.Failed("Incorrect result from function To_Decimal - 3");
|
end if;
|
end if;
|
|
|
|
|
|
|
-- Check that Conversion_Error is propagated by function To_Decimal
|
-- Check that Conversion_Error is propagated by function To_Decimal
|
-- if the Byte_Array parameter Item represents a decimal value outside
|
-- if the Byte_Array parameter Item represents a decimal value outside
|
-- the range of decimal type Num.
|
-- the range of decimal type Num.
|
-- Note: use a Byte_Array value Item created by an instantiation of
|
-- Note: use a Byte_Array value Item created by an instantiation of
|
-- To_Binary with a larger Num type as the generic formal.
|
-- To_Binary with a larger Num type as the generic formal.
|
|
|
begin
|
begin
|
TC_Dec_4 := 99999.9001;
|
TC_Dec_4 := 99999.9001;
|
TC_Dec_1 := Pack_1.To_Decimal(Pack_4.To_Binary(TC_Dec_4,
|
TC_Dec_1 := Pack_1.To_Decimal(Pack_4.To_Binary(TC_Dec_4,
|
Native_Binary),
|
Native_Binary),
|
Format => Native_Binary);
|
Format => Native_Binary);
|
if TC_Dec_1 = 99999.9 then
|
if TC_Dec_1 = 99999.9 then
|
Report.Comment("Minimize dead assignment optimization -- " &
|
Report.Comment("Minimize dead assignment optimization -- " &
|
"Should never be printed");
|
"Should never be printed");
|
end if;
|
end if;
|
Report.Failed("Conversion_Error not raised following call to " &
|
Report.Failed("Conversion_Error not raised following call to " &
|
"function To_Decimal if the Byte_Array parameter " &
|
"function To_Decimal if the Byte_Array parameter " &
|
"Item represents a decimal value outside the " &
|
"Item represents a decimal value outside the " &
|
"range of decimal type Num");
|
"range of decimal type Num");
|
exception
|
exception
|
when Conversion_Error => null; -- OK, expected exception.
|
when Conversion_Error => null; -- OK, expected exception.
|
when The_Error : others =>
|
when The_Error : others =>
|
Report.Failed(Exception_Name(The_Error) & " was incorrectly " &
|
Report.Failed(Exception_Name(The_Error) & " was incorrectly " &
|
"raised following call to function To_Decimal " &
|
"raised following call to function To_Decimal " &
|
"if the Byte_Array parameter Item represents " &
|
"if the Byte_Array parameter Item represents " &
|
"a decimal value outside the range of decimal " &
|
"a decimal value outside the range of decimal " &
|
"type Num");
|
"type Num");
|
end;
|
end;
|
|
|
|
|
|
|
-- Check that function To_Binary will produce a Byte_Array result that
|
-- Check that function To_Binary will produce a Byte_Array result that
|
-- corresponds to the decimal type parameter Item, under the specified
|
-- corresponds to the decimal type parameter Item, under the specified
|
-- Binary_Format.
|
-- Binary_Format.
|
|
|
-- Different ordering.
|
-- Different ordering.
|
TC_Dec_1 := 12345.6;
|
TC_Dec_1 := 12345.6;
|
if Pack_1.To_Binary(TC_Dec_1, Low_Order_First) =
|
if Pack_1.To_Binary(TC_Dec_1, Low_Order_First) =
|
Pack_1.To_Binary(TC_Dec_1, High_Order_First)
|
Pack_1.To_Binary(TC_Dec_1, High_Order_First)
|
then
|
then
|
Report.Failed("Incorrect result from function To_Binary - 1");
|
Report.Failed("Incorrect result from function To_Binary - 1");
|
end if;
|
end if;
|
|
|
-- Variable vs. literal.
|
-- Variable vs. literal.
|
TC_Dec_2 := 12345.00;
|
TC_Dec_2 := 12345.00;
|
if Pack_2.To_Binary(TC_Dec_2, Native_Binary) /=
|
if Pack_2.To_Binary(TC_Dec_2, Native_Binary) /=
|
Pack_2.To_Binary(12345.00, Native_Binary)
|
Pack_2.To_Binary(12345.00, Native_Binary)
|
then
|
then
|
Report.Failed("Incorrect result from function To_Binary - 2");
|
Report.Failed("Incorrect result from function To_Binary - 2");
|
end if;
|
end if;
|
|
|
exception
|
exception
|
when The_Error : others =>
|
when The_Error : others =>
|
Report.Failed("The following exception was raised in the " &
|
Report.Failed("The following exception was raised in the " &
|
"Test_Block: " & Exception_Name(The_Error));
|
"Test_Block: " & Exception_Name(The_Error));
|
end Test_Block;
|
end Test_Block;
|
|
|
Report.Result;
|
Report.Result;
|
|
|
end CXB4007;
|
end CXB4007;
|
|
|