-- CXA4012.A
|
-- CXA4012.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 types, operations, and other entities defined within
|
-- Check that the types, operations, and other entities defined within
|
-- the package Ada.Strings.Wide_Maps are available and produce correct
|
-- the package Ada.Strings.Wide_Maps are available and produce correct
|
-- results.
|
-- results.
|
--
|
--
|
-- TEST DESCRIPTION:
|
-- TEST DESCRIPTION:
|
-- This test demonstrates the availability and function of the types and
|
-- This test demonstrates the availability and function of the types and
|
-- operations defined in package Ada.Strings.Wide_Maps. It demonstrates
|
-- operations defined in package Ada.Strings.Wide_Maps. It demonstrates
|
-- the use of these types and functions as they would be used in common
|
-- the use of these types and functions as they would be used in common
|
-- programming practice.
|
-- programming practice.
|
-- Wide_Character set creation, assignment, and comparison are evaluated
|
-- Wide_Character set creation, assignment, and comparison are evaluated
|
-- in this test. Each of the functions provided in package
|
-- in this test. Each of the functions provided in package
|
-- Ada.Strings.Wide_Maps is utilized in creating or manipulating set
|
-- Ada.Strings.Wide_Maps is utilized in creating or manipulating set
|
-- objects, and the function results are evaluated for correctness.
|
-- objects, and the function results are evaluated for correctness.
|
-- Wide_Character sequences are examined using the functions provided for
|
-- Wide_Character sequences are examined using the functions provided for
|
-- manipulating objects of this type. Likewise, Wide_Character maps are
|
-- manipulating objects of this type. Likewise, Wide_Character maps are
|
-- created, and their contents evaluated. Exception raising conditions
|
-- created, and their contents evaluated. Exception raising conditions
|
-- from the function To_Mapping are also created.
|
-- from the function To_Mapping are also created.
|
-- Note: Throughout this test, the set logical operators are printed in
|
-- Note: Throughout this test, the set logical operators are printed in
|
-- capital letters to enhance their visibility.
|
-- capital letters to enhance their visibility.
|
--
|
--
|
--
|
--
|
-- CHANGE HISTORY:
|
-- CHANGE HISTORY:
|
-- 06 Dec 94 SAIC ACVC 2.0
|
-- 06 Dec 94 SAIC ACVC 2.0
|
-- 01 Nov 95 SAIC Update and repair for ACVC 2.0.1.
|
-- 01 Nov 95 SAIC Update and repair for ACVC 2.0.1.
|
--
|
--
|
--!
|
--!
|
|
|
with Ada.Characters.Handling;
|
with Ada.Characters.Handling;
|
with Ada.Strings.Wide_Maps;
|
with Ada.Strings.Wide_Maps;
|
|
|
package CXA40120 is
|
package CXA40120 is
|
|
|
function Equiv (Ch : Character) return Wide_Character;
|
function Equiv (Ch : Character) return Wide_Character;
|
function Equiv (Str : String)
|
function Equiv (Str : String)
|
return Ada.Strings.Wide_Maps.Wide_Character_Sequence;
|
return Ada.Strings.Wide_Maps.Wide_Character_Sequence;
|
function X_Map(From : Wide_Character) return Wide_Character;
|
function X_Map(From : Wide_Character) return Wide_Character;
|
|
|
end CXA40120;
|
end CXA40120;
|
|
|
package body CXA40120 is
|
package body CXA40120 is
|
|
|
-- The following two functions are used to translate character and string
|
-- The following two functions are used to translate character and string
|
-- values to "Wide" values. They will be applied to certain Wide_Map
|
-- values to "Wide" values. They will be applied to certain Wide_Map
|
-- subprogram parameters to simulate the use of Wide_Characters and
|
-- subprogram parameters to simulate the use of Wide_Characters and
|
-- Wide_Character_Sequences in actual practice.
|
-- Wide_Character_Sequences in actual practice.
|
-- Note: These functions do not actually return "equivalent" wide
|
-- Note: These functions do not actually return "equivalent" wide
|
-- characters to their character inputs, just "non-character"
|
-- characters to their character inputs, just "non-character"
|
-- wide characters.
|
-- wide characters.
|
|
|
function Equiv (Ch : Character) return Wide_Character is
|
function Equiv (Ch : Character) return Wide_Character is
|
C : Character := Ch;
|
C : Character := Ch;
|
begin
|
begin
|
if Ch = ' ' then
|
if Ch = ' ' then
|
return Ada.Characters.Handling.To_Wide_Character(C);
|
return Ada.Characters.Handling.To_Wide_Character(C);
|
else
|
else
|
return Wide_Character'Val(Character'Pos(Ch) +
|
return Wide_Character'Val(Character'Pos(Ch) +
|
Character'Pos(Character'Last) + 1);
|
Character'Pos(Character'Last) + 1);
|
end if;
|
end if;
|
end Equiv;
|
end Equiv;
|
|
|
function Equiv (Str : String)
|
function Equiv (Str : String)
|
return Ada.Strings.Wide_Maps.Wide_Character_Sequence is
|
return Ada.Strings.Wide_Maps.Wide_Character_Sequence is
|
use Ada.Strings;
|
use Ada.Strings;
|
WS : Wide_Maps.Wide_Character_Sequence(Str'First..Str'Last);
|
WS : Wide_Maps.Wide_Character_Sequence(Str'First..Str'Last);
|
begin
|
begin
|
for i in Str'First..Str'Last loop
|
for i in Str'First..Str'Last loop
|
WS(i) := Equiv(Str(i));
|
WS(i) := Equiv(Str(i));
|
end loop;
|
end loop;
|
return WS;
|
return WS;
|
end Equiv;
|
end Equiv;
|
|
|
function X_Map(From : Wide_Character) return Wide_Character is
|
function X_Map(From : Wide_Character) return Wide_Character is
|
begin
|
begin
|
return Equiv('X');
|
return Equiv('X');
|
end X_Map;
|
end X_Map;
|
|
|
end CXA40120;
|
end CXA40120;
|
|
|
|
|
|
|
with CXA40120;
|
with CXA40120;
|
with Ada.Characters.Handling;
|
with Ada.Characters.Handling;
|
with Ada.Strings.Wide_Maps;
|
with Ada.Strings.Wide_Maps;
|
with Report;
|
with Report;
|
|
|
procedure CXA4012 is
|
procedure CXA4012 is
|
|
|
use CXA40120;
|
use CXA40120;
|
use Ada.Strings;
|
use Ada.Strings;
|
|
|
begin
|
begin
|
|
|
Report.Test ("CXA4012", "Check that the types, operations, and other " &
|
Report.Test ("CXA4012", "Check that the types, operations, and other " &
|
"entities defined within the package " &
|
"entities defined within the package " &
|
"Ada.Strings.Wide_Maps are available and " &
|
"Ada.Strings.Wide_Maps are available and " &
|
"produce correct results");
|
"produce correct results");
|
|
|
Test_Block:
|
Test_Block:
|
declare
|
declare
|
|
|
use type Wide_Maps.Wide_Character_Set;
|
use type Wide_Maps.Wide_Character_Set;
|
|
|
MidPoint_Letter : constant := 13;
|
MidPoint_Letter : constant := 13;
|
Last_Letter : constant := 26;
|
Last_Letter : constant := 26;
|
|
|
Vowels : constant Wide_Maps.Wide_Character_Sequence :=
|
Vowels : constant Wide_Maps.Wide_Character_Sequence :=
|
Equiv("aeiou");
|
Equiv("aeiou");
|
Quasi_Vowel : constant Wide_Character := Equiv('y');
|
Quasi_Vowel : constant Wide_Character := Equiv('y');
|
|
|
Alphabet : Wide_Maps.Wide_Character_Sequence(1..Last_Letter);
|
Alphabet : Wide_Maps.Wide_Character_Sequence(1..Last_Letter);
|
Half_Alphabet : Wide_Maps.Wide_Character_Sequence(1..MidPoint_Letter);
|
Half_Alphabet : Wide_Maps.Wide_Character_Sequence(1..MidPoint_Letter);
|
Inverse_Alphabet : Wide_Maps.Wide_Character_Sequence(1..Last_Letter);
|
Inverse_Alphabet : Wide_Maps.Wide_Character_Sequence(1..Last_Letter);
|
|
|
Alphabet_Set,
|
Alphabet_Set,
|
Consonant_Set,
|
Consonant_Set,
|
Vowel_Set,
|
Vowel_Set,
|
Full_Vowel_Set,
|
Full_Vowel_Set,
|
First_Half_Set,
|
First_Half_Set,
|
Second_Half_Set : Wide_Maps.Wide_Character_Set := Wide_Maps.Null_Set;
|
Second_Half_Set : Wide_Maps.Wide_Character_Set := Wide_Maps.Null_Set;
|
|
|
begin
|
begin
|
|
|
-- Load the alphabet string for use in creating sets.
|
-- Load the alphabet string for use in creating sets.
|
|
|
for i in 0..MidPoint_Letter-1 loop
|
for i in 0..MidPoint_Letter-1 loop
|
Half_Alphabet(i+1) :=
|
Half_Alphabet(i+1) :=
|
Wide_Character'Val(Wide_Character'Pos(Equiv('a')) + i);
|
Wide_Character'Val(Wide_Character'Pos(Equiv('a')) + i);
|
end loop;
|
end loop;
|
|
|
for i in 0..Last_Letter-1 loop
|
for i in 0..Last_Letter-1 loop
|
Alphabet(i+1) :=
|
Alphabet(i+1) :=
|
Wide_Character'Val(Wide_Character'Pos(Equiv('a')) + i);
|
Wide_Character'Val(Wide_Character'Pos(Equiv('a')) + i);
|
end loop;
|
end loop;
|
|
|
|
|
-- Initialize a series of Wide_Character_Set objects.
|
-- Initialize a series of Wide_Character_Set objects.
|
|
|
Alphabet_Set := Wide_Maps.To_Set(Alphabet);
|
Alphabet_Set := Wide_Maps.To_Set(Alphabet);
|
Vowel_Set := Wide_Maps.To_Set(Vowels);
|
Vowel_Set := Wide_Maps.To_Set(Vowels);
|
Full_Vowel_Set := Vowel_Set OR Wide_Maps.To_Set(Quasi_Vowel);
|
Full_Vowel_Set := Vowel_Set OR Wide_Maps.To_Set(Quasi_Vowel);
|
Consonant_Set := Vowel_Set XOR Alphabet_Set;
|
Consonant_Set := Vowel_Set XOR Alphabet_Set;
|
|
|
First_Half_Set := Wide_Maps.To_Set(Half_Alphabet);
|
First_Half_Set := Wide_Maps.To_Set(Half_Alphabet);
|
Second_Half_Set := Alphabet_Set XOR First_Half_Set;
|
Second_Half_Set := Alphabet_Set XOR First_Half_Set;
|
|
|
|
|
-- Evaluation of Set objects, operators, and functions.
|
-- Evaluation of Set objects, operators, and functions.
|
|
|
if Alphabet_Set /= (Vowel_Set OR Consonant_Set) then
|
if Alphabet_Set /= (Vowel_Set OR Consonant_Set) then
|
Report.Failed("Incorrect set combinations using OR operator");
|
Report.Failed("Incorrect set combinations using OR operator");
|
end if;
|
end if;
|
|
|
|
|
for i in Vowels'First .. Vowels'Last loop
|
for i in Vowels'First .. Vowels'Last loop
|
if not Wide_Maps.Is_In(Vowels(i), Vowel_Set) or
|
if not Wide_Maps.Is_In(Vowels(i), Vowel_Set) or
|
not Wide_Maps.Is_In(Vowels(i), Alphabet_Set) or
|
not Wide_Maps.Is_In(Vowels(i), Alphabet_Set) or
|
Wide_Maps.Is_In(Vowels(i), Consonant_Set)
|
Wide_Maps.Is_In(Vowels(i), Consonant_Set)
|
then
|
then
|
Report.Failed("Incorrect function Is_In use with set " &
|
Report.Failed("Incorrect function Is_In use with set " &
|
"combinations - " & Integer'Image(i));
|
"combinations - " & Integer'Image(i));
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
|
|
if Wide_Maps.Is_Subset(Vowel_Set, First_Half_Set) or
|
if Wide_Maps.Is_Subset(Vowel_Set, First_Half_Set) or
|
Wide_Maps."<="(Vowel_Set, Second_Half_Set) or
|
Wide_Maps."<="(Vowel_Set, Second_Half_Set) or
|
not Wide_Maps.Is_Subset(Vowel_Set, Alphabet_Set)
|
not Wide_Maps.Is_Subset(Vowel_Set, Alphabet_Set)
|
then
|
then
|
Report.Failed
|
Report.Failed
|
("Incorrect set evaluation using Is_Subset function");
|
("Incorrect set evaluation using Is_Subset function");
|
end if;
|
end if;
|
|
|
|
|
if not (Full_Vowel_Set = Wide_Maps.To_Set(Equiv("aeiouy"))) then
|
if not (Full_Vowel_Set = Wide_Maps.To_Set(Equiv("aeiouy"))) then
|
Report.Failed("Incorrect result for ""="" set operator");
|
Report.Failed("Incorrect result for ""="" set operator");
|
end if;
|
end if;
|
|
|
|
|
if not ((Vowel_Set AND First_Half_Set) OR
|
if not ((Vowel_Set AND First_Half_Set) OR
|
(Full_Vowel_Set AND Second_Half_Set)) = Full_Vowel_Set then
|
(Full_Vowel_Set AND Second_Half_Set)) = Full_Vowel_Set then
|
Report.Failed
|
Report.Failed
|
("Incorrect result for AND, OR, or ""="" set operators");
|
("Incorrect result for AND, OR, or ""="" set operators");
|
end if;
|
end if;
|
|
|
|
|
if (Alphabet_Set AND Wide_Maps.Null_Set) /= Wide_Maps.Null_Set or
|
if (Alphabet_Set AND Wide_Maps.Null_Set) /= Wide_Maps.Null_Set or
|
(Alphabet_Set OR Wide_Maps.Null_Set) /= Alphabet_Set
|
(Alphabet_Set OR Wide_Maps.Null_Set) /= Alphabet_Set
|
then
|
then
|
Report.Failed("Incorrect result for AND or OR set operators");
|
Report.Failed("Incorrect result for AND or OR set operators");
|
end if;
|
end if;
|
|
|
|
|
Vowel_Set := Full_Vowel_Set;
|
Vowel_Set := Full_Vowel_Set;
|
Vowel_Set := Vowel_Set AND (NOT Wide_Maps.To_Set(Quasi_Vowel));
|
Vowel_Set := Vowel_Set AND (NOT Wide_Maps.To_Set(Quasi_Vowel));
|
|
|
if not (Vowels = Wide_Maps.To_Sequence(Vowel_Set)) then
|
if not (Vowels = Wide_Maps.To_Sequence(Vowel_Set)) then
|
Report.Failed("Incorrect Set to Sequence translation");
|
Report.Failed("Incorrect Set to Sequence translation");
|
end if;
|
end if;
|
|
|
|
|
for i in 0..Last_Letter-1 loop
|
for i in 0..Last_Letter-1 loop
|
Inverse_Alphabet(i+1) := Alphabet(Last_Letter-i);
|
Inverse_Alphabet(i+1) := Alphabet(Last_Letter-i);
|
end loop;
|
end loop;
|
|
|
|
|
-- Wide_Character_Mapping
|
-- Wide_Character_Mapping
|
|
|
declare
|
declare
|
Inverse_Map : Wide_Maps.Wide_Character_Mapping :=
|
Inverse_Map : Wide_Maps.Wide_Character_Mapping :=
|
Wide_Maps.To_Mapping(Alphabet, Inverse_Alphabet);
|
Wide_Maps.To_Mapping(Alphabet, Inverse_Alphabet);
|
begin
|
begin
|
if Wide_Maps.Value(Wide_Maps.Identity, Equiv('b')) /=
|
if Wide_Maps.Value(Wide_Maps.Identity, Equiv('b')) /=
|
Wide_Maps.Value(Inverse_Map, Equiv('y'))
|
Wide_Maps.Value(Inverse_Map, Equiv('y'))
|
then
|
then
|
Report.Failed("Incorrect Inverse mapping");
|
Report.Failed("Incorrect Inverse mapping");
|
end if;
|
end if;
|
end;
|
end;
|
|
|
|
|
-- Check that Translation_Error is raised when a character is
|
-- Check that Translation_Error is raised when a character is
|
-- repeated in the parameter "From" string.
|
-- repeated in the parameter "From" string.
|
declare
|
declare
|
Bad_Map : Wide_Maps.Wide_Character_Mapping;
|
Bad_Map : Wide_Maps.Wide_Character_Mapping;
|
begin
|
begin
|
Bad_Map := Wide_Maps.To_Mapping(From => Equiv("aa"),
|
Bad_Map := Wide_Maps.To_Mapping(From => Equiv("aa"),
|
To => Equiv("yz"));
|
To => Equiv("yz"));
|
Report.Failed("Exception not raised with repeated character");
|
Report.Failed("Exception not raised with repeated character");
|
exception
|
exception
|
when Translation_Error => null; -- OK
|
when Translation_Error => null; -- OK
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception raised in To_Mapping with " &
|
Report.Failed("Incorrect exception raised in To_Mapping with " &
|
"a repeated character");
|
"a repeated character");
|
end;
|
end;
|
|
|
|
|
-- Check that Translation_Error is raised when the parameters of the
|
-- Check that Translation_Error is raised when the parameters of the
|
-- function To_Mapping are of unequal lengths.
|
-- function To_Mapping are of unequal lengths.
|
declare
|
declare
|
Bad_Map : Wide_Maps.Wide_Character_Mapping;
|
Bad_Map : Wide_Maps.Wide_Character_Mapping;
|
begin
|
begin
|
Bad_Map := Wide_Maps.To_Mapping(Equiv("abc"), Equiv("yz"));
|
Bad_Map := Wide_Maps.To_Mapping(Equiv("abc"), Equiv("yz"));
|
Report.Failed
|
Report.Failed
|
("Exception not raised with unequal parameter lengths");
|
("Exception not raised with unequal parameter lengths");
|
exception
|
exception
|
when Translation_Error => null; -- OK
|
when Translation_Error => null; -- OK
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception raised in To_Mapping with " &
|
Report.Failed("Incorrect exception raised in To_Mapping with " &
|
"unequal parameter lengths");
|
"unequal parameter lengths");
|
end;
|
end;
|
|
|
|
|
-- Check that the access-to-subprogram type is defined and available.
|
-- Check that the access-to-subprogram type is defined and available.
|
-- This provides for one Wide_Character mapping capability only.
|
-- This provides for one Wide_Character mapping capability only.
|
-- The actual mapping functionality will be tested in conjunction with
|
-- The actual mapping functionality will be tested in conjunction with
|
-- the tests of subprograms defined for Wide_String handling.
|
-- the tests of subprograms defined for Wide_String handling.
|
|
|
declare
|
declare
|
|
|
X_Map_Ptr : Wide_Maps.Wide_Character_Mapping_Function :=
|
X_Map_Ptr : Wide_Maps.Wide_Character_Mapping_Function :=
|
X_Map'Access;
|
X_Map'Access;
|
|
|
begin
|
begin
|
if X_Map_Ptr(Equiv('A')) /= -- both return 'X'
|
if X_Map_Ptr(Equiv('A')) /= -- both return 'X'
|
X_Map_Ptr.all(Equiv('Q'))
|
X_Map_Ptr.all(Equiv('Q'))
|
then
|
then
|
Report.Failed
|
Report.Failed
|
("Incorrect result using access-to-subprogram values");
|
("Incorrect result using access-to-subprogram values");
|
end if;
|
end if;
|
end;
|
end;
|
|
|
|
|
exception
|
exception
|
when others => Report.Failed ("Exception raised in Test_Block");
|
when others => Report.Failed ("Exception raised in Test_Block");
|
end Test_Block;
|
end Test_Block;
|
|
|
|
|
Report.Result;
|
Report.Result;
|
|
|
end CXA4012;
|
end CXA4012;
|
|
|