-- CXA4015.A
|
-- CXA4015.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 subprograms defined in package Ada.Strings.Wide_Fixed
|
-- Check that the subprograms defined in package Ada.Strings.Wide_Fixed
|
-- are available, and that they produce correct results. Specifically,
|
-- are available, and that they produce correct results. Specifically,
|
-- check the subprograms Count, Find_Token, Index, Index_Non_Blank, and
|
-- check the subprograms Count, Find_Token, Index, Index_Non_Blank, and
|
-- Move.
|
-- Move.
|
--
|
--
|
-- TEST DESCRIPTION:
|
-- TEST DESCRIPTION:
|
-- This test, when combined with tests CXA4013,14,16 will provide
|
-- This test, when combined with tests CXA4013,14,16 will provide
|
-- coverage of the functionality found in Ada.Strings.Wide_Fixed.
|
-- coverage of the functionality found in Ada.Strings.Wide_Fixed.
|
-- This test contains many small, specific test cases, situations that
|
-- This test contains many small, specific test cases, situations that
|
-- although common in user environments, are often difficult to generate
|
-- although common in user environments, are often difficult to generate
|
-- in large numbers in a application-based test.
|
-- in large numbers in a application-based test.
|
--
|
--
|
--
|
--
|
-- CHANGE HISTORY:
|
-- CHANGE HISTORY:
|
-- 06 Dec 94 SAIC ACVC 2.0
|
-- 06 Dec 94 SAIC ACVC 2.0
|
-- 02 Nov 95 SAIC Corrected various accesssibility problems and
|
-- 02 Nov 95 SAIC Corrected various accesssibility problems and
|
-- expected result strings for ACVC 2.0.1.
|
-- expected result strings for ACVC 2.0.1.
|
--
|
--
|
--!
|
--!
|
|
|
package CXA40150 is
|
package CXA40150 is
|
|
|
-- Wide Character mapping function defined for use with specific
|
-- Wide Character mapping function defined for use with specific
|
-- versions of functions Index and Count.
|
-- versions of functions Index and Count.
|
|
|
function AK_to_ZQ_Mapping (From : Wide_Character) return Wide_Character;
|
function AK_to_ZQ_Mapping (From : Wide_Character) return Wide_Character;
|
|
|
end CXA40150;
|
end CXA40150;
|
|
|
package body CXA40150 is
|
package body CXA40150 is
|
|
|
function AK_to_ZQ_Mapping (From : Wide_Character)
|
function AK_to_ZQ_Mapping (From : Wide_Character)
|
return Wide_Character is
|
return Wide_Character is
|
begin
|
begin
|
if From = 'a' then
|
if From = 'a' then
|
return 'z';
|
return 'z';
|
elsif From = 'k' then
|
elsif From = 'k' then
|
return 'q';
|
return 'q';
|
else
|
else
|
return From;
|
return From;
|
end if;
|
end if;
|
end AK_to_ZQ_Mapping;
|
end AK_to_ZQ_Mapping;
|
|
|
end CXA40150;
|
end CXA40150;
|
|
|
|
|
with CXA40150;
|
with CXA40150;
|
with Report;
|
with Report;
|
with Ada.Strings;
|
with Ada.Strings;
|
with Ada.Strings.Wide_Fixed;
|
with Ada.Strings.Wide_Fixed;
|
with Ada.Strings.Wide_Maps;
|
with Ada.Strings.Wide_Maps;
|
|
|
procedure CXA4015 is
|
procedure CXA4015 is
|
begin
|
begin
|
|
|
Report.Test("CXA4015", "Check that the subprograms defined in " &
|
Report.Test("CXA4015", "Check that the subprograms defined in " &
|
"package Ada.Strings.Wide_Fixed are available, " &
|
"package Ada.Strings.Wide_Fixed are available, " &
|
"and that they produce correct results");
|
"and that they produce correct results");
|
|
|
|
|
Test_Block:
|
Test_Block:
|
declare
|
declare
|
|
|
use CXA40150;
|
use CXA40150;
|
|
|
package ASF renames Ada.Strings.Wide_Fixed;
|
package ASF renames Ada.Strings.Wide_Fixed;
|
package Maps renames Ada.Strings.Wide_Maps;
|
package Maps renames Ada.Strings.Wide_Maps;
|
|
|
Result_String : Wide_String(1..10) :=
|
Result_String : Wide_String(1..10) :=
|
(others => Ada.Strings.Wide_Space);
|
(others => Ada.Strings.Wide_Space);
|
|
|
Source_String1 : Wide_String(1..5) := "abcde"; -- odd len Wide_String
|
Source_String1 : Wide_String(1..5) := "abcde"; -- odd len Wide_String
|
Source_String2 : Wide_String(1..6) := "abcdef"; -- even len Wide_String
|
Source_String2 : Wide_String(1..6) := "abcdef"; -- even len Wide_String
|
Source_String3 : Wide_String(1..12) := "abcdefghijkl";
|
Source_String3 : Wide_String(1..12) := "abcdefghijkl";
|
Source_String4 : Wide_String(1..12) := "abcdefghij "; -- last 2 ch pad
|
Source_String4 : Wide_String(1..12) := "abcdefghij "; -- last 2 ch pad
|
Source_String5 : Wide_String(1..12) := " cdefghijkl"; -- first 2 ch pad
|
Source_String5 : Wide_String(1..12) := " cdefghijkl"; -- first 2 ch pad
|
Source_String6 : Wide_String(1..12) := "abcdefabcdef";
|
Source_String6 : Wide_String(1..12) := "abcdefabcdef";
|
|
|
Location : Natural := 0;
|
Location : Natural := 0;
|
Slice_Start : Positive;
|
Slice_Start : Positive;
|
Slice_End,
|
Slice_End,
|
Slice_Count : Natural := 0;
|
Slice_Count : Natural := 0;
|
|
|
CD_Set : Maps.Wide_Character_Set := Maps.To_Set("cd");
|
CD_Set : Maps.Wide_Character_Set := Maps.To_Set("cd");
|
ABCD_Set : Maps.Wide_Character_Set := Maps.To_Set("abcd");
|
ABCD_Set : Maps.Wide_Character_Set := Maps.To_Set("abcd");
|
A_to_F_Set : Maps.Wide_Character_Set := Maps.To_Set("abcdef");
|
A_to_F_Set : Maps.Wide_Character_Set := Maps.To_Set("abcdef");
|
|
|
CD_to_XY_Map : Maps.Wide_Character_Mapping :=
|
CD_to_XY_Map : Maps.Wide_Character_Mapping :=
|
Maps.To_Mapping(From => "cd", To => "xy");
|
Maps.To_Mapping(From => "cd", To => "xy");
|
|
|
|
|
-- Access-to-Subprogram object defined for use with specific versions of
|
-- Access-to-Subprogram object defined for use with specific versions of
|
-- functions Index and Count.
|
-- functions Index and Count.
|
|
|
Map_Ptr : Maps.Wide_Character_Mapping_Function :=
|
Map_Ptr : Maps.Wide_Character_Mapping_Function :=
|
AK_to_ZQ_Mapping'Access;
|
AK_to_ZQ_Mapping'Access;
|
|
|
|
|
begin
|
begin
|
|
|
|
|
-- Procedure Move
|
-- Procedure Move
|
-- Evaluate the Procedure Move with various combinations of
|
-- Evaluate the Procedure Move with various combinations of
|
-- parameters.
|
-- parameters.
|
|
|
-- Justify = Left (default case)
|
-- Justify = Left (default case)
|
|
|
ASF.Move(Source => Source_String1, -- "abcde"
|
ASF.Move(Source => Source_String1, -- "abcde"
|
Target => Result_String);
|
Target => Result_String);
|
|
|
if Result_String /= "abcde " then
|
if Result_String /= "abcde " then
|
Report.Failed("Incorrect result from Move with Justify = Left");
|
Report.Failed("Incorrect result from Move with Justify = Left");
|
end if;
|
end if;
|
|
|
-- Justify = Right
|
-- Justify = Right
|
|
|
ASF.Move(Source => Source_String2, -- "abcdef"
|
ASF.Move(Source => Source_String2, -- "abcdef"
|
Target => Result_String,
|
Target => Result_String,
|
Drop => Ada.Strings.Error,
|
Drop => Ada.Strings.Error,
|
Justify => Ada.Strings.Right);
|
Justify => Ada.Strings.Right);
|
|
|
if Result_String /= " abcdef" then
|
if Result_String /= " abcdef" then
|
Report.Failed("Incorrect result from Move with Justify = Right");
|
Report.Failed("Incorrect result from Move with Justify = Right");
|
end if;
|
end if;
|
|
|
-- Justify = Center (two cases, odd and even pad lengths)
|
-- Justify = Center (two cases, odd and even pad lengths)
|
|
|
ASF.Move(Source_String1, -- "abcde"
|
ASF.Move(Source_String1, -- "abcde"
|
Result_String,
|
Result_String,
|
Ada.Strings.Error,
|
Ada.Strings.Error,
|
Ada.Strings.Center,
|
Ada.Strings.Center,
|
'x'); -- non-default padding.
|
'x'); -- non-default padding.
|
|
|
if Result_String /= "xxabcdexxx" then -- Unequal padding added right
|
if Result_String /= "xxabcdexxx" then -- Unequal padding added right
|
Report.Failed("Incorrect result from Move with Justify = Center-1");
|
Report.Failed("Incorrect result from Move with Justify = Center-1");
|
end if;
|
end if;
|
|
|
ASF.Move(Source_String2, -- "abcdef"
|
ASF.Move(Source_String2, -- "abcdef"
|
Result_String,
|
Result_String,
|
Ada.Strings.Error,
|
Ada.Strings.Error,
|
Ada.Strings.Center);
|
Ada.Strings.Center);
|
|
|
if Result_String /= " abcdef " then -- Equal padding added on L/R.
|
if Result_String /= " abcdef " then -- Equal padding added on L/R.
|
Report.Failed("Incorrect result from Move with Justify = Center-2");
|
Report.Failed("Incorrect result from Move with Justify = Center-2");
|
end if;
|
end if;
|
|
|
-- When the source Wide_String is longer than the target Wide_String,
|
-- When the source Wide_String is longer than the target Wide_String,
|
-- several cases can be examined, with the results depending on the
|
-- several cases can be examined, with the results depending on the
|
-- value of the Drop parameter.
|
-- value of the Drop parameter.
|
|
|
-- Drop = Left
|
-- Drop = Left
|
|
|
ASF.Move(Source => Source_String3, -- "abcdefghijkl"
|
ASF.Move(Source => Source_String3, -- "abcdefghijkl"
|
Target => Result_String,
|
Target => Result_String,
|
Drop => Ada.Strings.Left);
|
Drop => Ada.Strings.Left);
|
|
|
if Result_String /= "cdefghijkl" then
|
if Result_String /= "cdefghijkl" then
|
Report.Failed("Incorrect result from Move with Drop = Left");
|
Report.Failed("Incorrect result from Move with Drop = Left");
|
end if;
|
end if;
|
|
|
-- Drop = Right
|
-- Drop = Right
|
|
|
ASF.Move(Source_String3, Result_String, Ada.Strings.Right);
|
ASF.Move(Source_String3, Result_String, Ada.Strings.Right);
|
|
|
if Result_String /= "abcdefghij" then
|
if Result_String /= "abcdefghij" then
|
Report.Failed("Incorrect result from Move with Drop = Right");
|
Report.Failed("Incorrect result from Move with Drop = Right");
|
end if;
|
end if;
|
|
|
-- Drop = Error
|
-- Drop = Error
|
-- The effect in this case depends on the value of the justify
|
-- The effect in this case depends on the value of the justify
|
-- parameter, and on whether any characters in Source other than
|
-- parameter, and on whether any characters in Source other than
|
-- Pad would fail to be copied.
|
-- Pad would fail to be copied.
|
|
|
-- Drop = Error, Justify = Left, right overflow characters are pad.
|
-- Drop = Error, Justify = Left, right overflow characters are pad.
|
|
|
ASF.Move(Source => Source_String4, -- "abcdefghij "
|
ASF.Move(Source => Source_String4, -- "abcdefghij "
|
Target => Result_String,
|
Target => Result_String,
|
Drop => Ada.Strings.Error,
|
Drop => Ada.Strings.Error,
|
Justify => Ada.Strings.Left);
|
Justify => Ada.Strings.Left);
|
|
|
if not(Result_String = "abcdefghij") then -- leftmost 10 characters
|
if not(Result_String = "abcdefghij") then -- leftmost 10 characters
|
Report.Failed("Incorrect result from Move with Drop = Error - 1");
|
Report.Failed("Incorrect result from Move with Drop = Error - 1");
|
end if;
|
end if;
|
|
|
-- Drop = Error, Justify = Right, left overflow characters are pad.
|
-- Drop = Error, Justify = Right, left overflow characters are pad.
|
|
|
ASF.Move(Source_String5, -- " cdefghijkl"
|
ASF.Move(Source_String5, -- " cdefghijkl"
|
Result_String,
|
Result_String,
|
Ada.Strings.Error,
|
Ada.Strings.Error,
|
Ada.Strings.Right);
|
Ada.Strings.Right);
|
|
|
if Result_String /= "cdefghijkl" then -- rightmost 10 characters
|
if Result_String /= "cdefghijkl" then -- rightmost 10 characters
|
Report.Failed("Incorrect result from Move with Drop = Error - 2");
|
Report.Failed("Incorrect result from Move with Drop = Error - 2");
|
end if;
|
end if;
|
|
|
-- In other cases of Drop=Error, Length_Error is propagated, such as:
|
-- In other cases of Drop=Error, Length_Error is propagated, such as:
|
|
|
begin
|
begin
|
|
|
ASF.Move(Source_String3, -- 12 characters, no Pad.
|
ASF.Move(Source_String3, -- 12 characters, no Pad.
|
Result_String, -- 10 characters
|
Result_String, -- 10 characters
|
Ada.Strings.Error,
|
Ada.Strings.Error,
|
Ada.Strings.Left);
|
Ada.Strings.Left);
|
|
|
Report.Failed("Length_Error not raised by Move - 1");
|
Report.Failed("Length_Error not raised by Move - 1");
|
|
|
exception
|
exception
|
when Ada.Strings.Length_Error => null; -- OK
|
when Ada.Strings.Length_Error => null; -- OK
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception raised by Move - 1");
|
Report.Failed("Incorrect exception raised by Move - 1");
|
end;
|
end;
|
|
|
|
|
|
|
-- Function Index
|
-- Function Index
|
-- (Other usage examples of this function found in CXA4013-14.)
|
-- (Other usage examples of this function found in CXA4013-14.)
|
-- Check when the pattern is not found in the source.
|
-- Check when the pattern is not found in the source.
|
|
|
if ASF.Index("abcdef", "gh") /= 0 or
|
if ASF.Index("abcdef", "gh") /= 0 or
|
ASF.Index("abcde", "abcdef") /= 0 or -- pattern > source
|
ASF.Index("abcde", "abcdef") /= 0 or -- pattern > source
|
ASF.Index("xyz",
|
ASF.Index("xyz",
|
"abcde",
|
"abcde",
|
Ada.Strings.Backward) /= 0 or
|
Ada.Strings.Backward) /= 0 or
|
ASF.Index("", "ab") /= 0 or -- null source Wide_String.
|
ASF.Index("", "ab") /= 0 or -- null source Wide_String.
|
ASF.Index("abcde", " ") /= 0 -- blank pattern.
|
ASF.Index("abcde", " ") /= 0 -- blank pattern.
|
then
|
then
|
Report.Failed("Incorrect result from Index, no pattern match");
|
Report.Failed("Incorrect result from Index, no pattern match");
|
end if;
|
end if;
|
|
|
-- Check that Pattern_Error is raised when the pattern is the
|
-- Check that Pattern_Error is raised when the pattern is the
|
-- null Wide_String.
|
-- null Wide_String.
|
begin
|
begin
|
Location := ASF.Index(Source_String6, -- "abcdefabcdef"
|
Location := ASF.Index(Source_String6, -- "abcdefabcdef"
|
"", -- null pattern Wide_String.
|
"", -- null pattern Wide_String.
|
Ada.Strings.Forward);
|
Ada.Strings.Forward);
|
Report.Failed("Pattern_Error not raised by Index");
|
Report.Failed("Pattern_Error not raised by Index");
|
exception
|
exception
|
when Ada.Strings.Pattern_Error => null; -- OK, expected exception.
|
when Ada.Strings.Pattern_Error => null; -- OK, expected exception.
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception raised by Index, null pattern");
|
Report.Failed("Incorrect exception raised by Index, null pattern");
|
end;
|
end;
|
|
|
-- Use the search direction "backward" to locate the particular
|
-- Use the search direction "backward" to locate the particular
|
-- pattern within the source Wide_String.
|
-- pattern within the source Wide_String.
|
|
|
Location := ASF.Index(Source_String6, -- "abcdefabcdef"
|
Location := ASF.Index(Source_String6, -- "abcdefabcdef"
|
"de", -- slice 4..5, 10..11
|
"de", -- slice 4..5, 10..11
|
Ada.Strings.Backward); -- search from right end.
|
Ada.Strings.Backward); -- search from right end.
|
|
|
if Location /= 10 then
|
if Location /= 10 then
|
Report.Failed("Incorrect result from Index going Backward");
|
Report.Failed("Incorrect result from Index going Backward");
|
end if;
|
end if;
|
|
|
|
|
|
|
-- Function Index
|
-- Function Index
|
-- Use the version of Index that takes a Wide_Character_Mapping_Function
|
-- Use the version of Index that takes a Wide_Character_Mapping_Function
|
-- parameter.
|
-- parameter.
|
-- Use the search directions Forward and Backward to locate the
|
-- Use the search directions Forward and Backward to locate the
|
-- particular pattern wide string within the source wide string.
|
-- particular pattern wide string within the source wide string.
|
|
|
Location := ASF.Index("akzqefakzqef",
|
Location := ASF.Index("akzqefakzqef",
|
"qzq", -- slice 8..10
|
"qzq", -- slice 8..10
|
Ada.Strings.Backward,
|
Ada.Strings.Backward,
|
Map_Ptr); -- perform 'a' to 'z', 'k' to 'q'
|
Map_Ptr); -- perform 'a' to 'z', 'k' to 'q'
|
-- translation.
|
-- translation.
|
if Location /= 8 then
|
if Location /= 8 then
|
Report.Failed
|
Report.Failed
|
("Incorrect result from Index w/map ptr going Backward");
|
("Incorrect result from Index w/map ptr going Backward");
|
end if;
|
end if;
|
|
|
Location := ASF.Index("ddkkddakcdakdefcadckdfzaaqd",
|
Location := ASF.Index("ddkkddakcdakdefcadckdfzaaqd",
|
"zq", -- slice 7..8
|
"zq", -- slice 7..8
|
Ada.Strings.Forward,
|
Ada.Strings.Forward,
|
Map_Ptr); -- perform 'a' to 'z', 'k' to 'q'
|
Map_Ptr); -- perform 'a' to 'z', 'k' to 'q'
|
-- translation.
|
-- translation.
|
if Location /= 7 then
|
if Location /= 7 then
|
Report.Failed
|
Report.Failed
|
("Incorrect result from Index w/map ptr going Forward");
|
("Incorrect result from Index w/map ptr going Forward");
|
end if;
|
end if;
|
|
|
|
|
if ASF.Index("aakkzq", "zq", Ada.Strings.Forward, Map_Ptr) /= 2 or
|
if ASF.Index("aakkzq", "zq", Ada.Strings.Forward, Map_Ptr) /= 2 or
|
ASF.Index("qzedka", "qz", Ada.Strings.Backward, Map_Ptr) /= 5 or
|
ASF.Index("qzedka", "qz", Ada.Strings.Backward, Map_Ptr) /= 5 or
|
ASF.Index("zazaza", "zzzz", Ada.Strings.Backward, Map_Ptr) /= 3 or
|
ASF.Index("zazaza", "zzzz", Ada.Strings.Backward, Map_Ptr) /= 3 or
|
ASF.Index("kka", "qqz", Ada.Strings.Forward, Map_Ptr) /= 1
|
ASF.Index("kka", "qqz", Ada.Strings.Forward, Map_Ptr) /= 1
|
then
|
then
|
Report.Failed("Incorrect result from Index w/map ptr");
|
Report.Failed("Incorrect result from Index w/map ptr");
|
end if;
|
end if;
|
|
|
|
|
-- Check when the pattern wide string is not found in the source.
|
-- Check when the pattern wide string is not found in the source.
|
|
|
if ASF.Index("akzqef", "kzq", Ada.Strings.Forward, Map_Ptr) /= 0 or
|
if ASF.Index("akzqef", "kzq", Ada.Strings.Forward, Map_Ptr) /= 0 or
|
ASF.Index("abcde", "abcdef", Ada.Strings.Backward, Map_Ptr) /= 0 or
|
ASF.Index("abcde", "abcdef", Ada.Strings.Backward, Map_Ptr) /= 0 or
|
ASF.Index("xyz", "akzde", Ada.Strings.Backward, Map_Ptr) /= 0 or
|
ASF.Index("xyz", "akzde", Ada.Strings.Backward, Map_Ptr) /= 0 or
|
ASF.Index("", "zq", Ada.Strings.Forward, Map_Ptr) /= 0 or
|
ASF.Index("", "zq", Ada.Strings.Forward, Map_Ptr) /= 0 or
|
ASF.Index("akcde", " ", Ada.Strings.Backward, Map_Ptr) /= 0
|
ASF.Index("akcde", " ", Ada.Strings.Backward, Map_Ptr) /= 0
|
then
|
then
|
Report.Failed
|
Report.Failed
|
("Incorrect result from Index w/map ptr, no pattern match");
|
("Incorrect result from Index w/map ptr, no pattern match");
|
end if;
|
end if;
|
|
|
-- Check that Pattern_Error is raised when the pattern is a
|
-- Check that Pattern_Error is raised when the pattern is a
|
-- null Wide_String.
|
-- null Wide_String.
|
begin
|
begin
|
Location := ASF.Index("akzqefakqzef",
|
Location := ASF.Index("akzqefakqzef",
|
"", -- null pattern Wide_String.
|
"", -- null pattern Wide_String.
|
Ada.Strings.Forward,
|
Ada.Strings.Forward,
|
Map_Ptr);
|
Map_Ptr);
|
Report.Failed("Pattern_Error not raised by Index w/map ptr");
|
Report.Failed("Pattern_Error not raised by Index w/map ptr");
|
exception
|
exception
|
when Ada.Strings.Pattern_Error => null; -- OK, expected exception.
|
when Ada.Strings.Pattern_Error => null; -- OK, expected exception.
|
when others =>
|
when others =>
|
Report.Failed
|
Report.Failed
|
("Incorrect exception raised by Index w/map ptr, null pattern");
|
("Incorrect exception raised by Index w/map ptr, null pattern");
|
end;
|
end;
|
|
|
|
|
|
|
-- Function Index
|
-- Function Index
|
-- Using the version of Index testing wide character set membership,
|
-- Using the version of Index testing wide character set membership,
|
-- check combinations of forward/backward, inside/outside parameter
|
-- check combinations of forward/backward, inside/outside parameter
|
-- configurations.
|
-- configurations.
|
|
|
if ASF.Index(Source => Source_String1, -- "abcde"
|
if ASF.Index(Source => Source_String1, -- "abcde"
|
Set => CD_Set,
|
Set => CD_Set,
|
Test => Ada.Strings.Inside,
|
Test => Ada.Strings.Inside,
|
Going => Ada.Strings.Forward) /= 3 or -- 'c' at pos 3.
|
Going => Ada.Strings.Forward) /= 3 or -- 'c' at pos 3.
|
ASF.Index(Source_String6, -- "abcdefabcdef"
|
ASF.Index(Source_String6, -- "abcdefabcdef"
|
CD_Set,
|
CD_Set,
|
Ada.Strings.Outside,
|
Ada.Strings.Outside,
|
Ada.Strings.Backward) /= 12 or -- 'f' at position 12
|
Ada.Strings.Backward) /= 12 or -- 'f' at position 12
|
ASF.Index(Source_String6, -- "abcdefabcdef"
|
ASF.Index(Source_String6, -- "abcdefabcdef"
|
CD_Set,
|
CD_Set,
|
Ada.Strings.Inside,
|
Ada.Strings.Inside,
|
Ada.Strings.Backward) /= 10 or -- 'd' at position 10
|
Ada.Strings.Backward) /= 10 or -- 'd' at position 10
|
ASF.Index("cdcdcdcdacdcdcdcd",
|
ASF.Index("cdcdcdcdacdcdcdcd",
|
CD_Set,
|
CD_Set,
|
Ada.Strings.Outside,
|
Ada.Strings.Outside,
|
Ada.Strings.Forward) /= 9 -- 'a' at position 9
|
Ada.Strings.Forward) /= 9 -- 'a' at position 9
|
then
|
then
|
Report.Failed("Incorrect result from function Index for sets - 1");
|
Report.Failed("Incorrect result from function Index for sets - 1");
|
end if;
|
end if;
|
|
|
-- Additional interesting uses/combinations using Index for sets.
|
-- Additional interesting uses/combinations using Index for sets.
|
|
|
if ASF.Index("cd", -- same size, str-set
|
if ASF.Index("cd", -- same size, str-set
|
CD_Set,
|
CD_Set,
|
Ada.Strings.Inside,
|
Ada.Strings.Inside,
|
Ada.Strings.Forward) /= 1 or -- 'c' at position 1
|
Ada.Strings.Forward) /= 1 or -- 'c' at position 1
|
ASF.Index("abcd", -- same size, str-set,
|
ASF.Index("abcd", -- same size, str-set,
|
Maps.To_Set("efgh"), -- different contents.
|
Maps.To_Set("efgh"), -- different contents.
|
Ada.Strings.Outside,
|
Ada.Strings.Outside,
|
Ada.Strings.Forward) /= 1 or
|
Ada.Strings.Forward) /= 1 or
|
ASF.Index("abccd", -- set > Wide_String
|
ASF.Index("abccd", -- set > Wide_String
|
Maps.To_Set("acegik"),
|
Maps.To_Set("acegik"),
|
Ada.Strings.Inside,
|
Ada.Strings.Inside,
|
Ada.Strings.Backward) /= 4 or -- 'c' at position 4
|
Ada.Strings.Backward) /= 4 or -- 'c' at position 4
|
ASF.Index("abcde",
|
ASF.Index("abcde",
|
Maps.Null_Set) /= 0 or
|
Maps.Null_Set) /= 0 or
|
ASF.Index("", -- Null string.
|
ASF.Index("", -- Null string.
|
CD_Set) /= 0 or
|
CD_Set) /= 0 or
|
ASF.Index("abc ab", -- blank included
|
ASF.Index("abc ab", -- blank included
|
Maps.To_Set("e "), -- in Wide_String and
|
Maps.To_Set("e "), -- in Wide_String and
|
Ada.Strings.Inside, -- set.
|
Ada.Strings.Inside, -- set.
|
Ada.Strings.Backward) /= 4 -- blank in Wide_Str.
|
Ada.Strings.Backward) /= 4 -- blank in Wide_Str.
|
then
|
then
|
Report.Failed("Incorrect result from function Index for sets - 2");
|
Report.Failed("Incorrect result from function Index for sets - 2");
|
end if;
|
end if;
|
|
|
|
|
|
|
-- Function Index_Non_Blank.
|
-- Function Index_Non_Blank.
|
-- (Other usage examples of this function found in CXA4013-14.)
|
-- (Other usage examples of this function found in CXA4013-14.)
|
|
|
|
|
if ASF.Index_Non_Blank(Source => Source_String4, -- "abcdefghij "
|
if ASF.Index_Non_Blank(Source => Source_String4, -- "abcdefghij "
|
Going => Ada.Strings.Backward) /= 10 or
|
Going => Ada.Strings.Backward) /= 10 or
|
ASF.Index_Non_Blank("abc def ghi jkl ",
|
ASF.Index_Non_Blank("abc def ghi jkl ",
|
Ada.Strings.Backward) /= 15 or
|
Ada.Strings.Backward) /= 15 or
|
ASF.Index_Non_Blank(" abcdef") /= 3 or
|
ASF.Index_Non_Blank(" abcdef") /= 3 or
|
ASF.Index_Non_Blank(" ") /= 0
|
ASF.Index_Non_Blank(" ") /= 0
|
then
|
then
|
Report.Failed("Incorrect result from Index_Non_Blank");
|
Report.Failed("Incorrect result from Index_Non_Blank");
|
end if;
|
end if;
|
|
|
|
|
|
|
-- Function Count
|
-- Function Count
|
-- (Other usage examples of this function found in CXA4013-14.)
|
-- (Other usage examples of this function found in CXA4013-14.)
|
|
|
if ASF.Count("abababa", "aba") /= 2 or
|
if ASF.Count("abababa", "aba") /= 2 or
|
ASF.Count("abababa", "ab" ) /= 3 or
|
ASF.Count("abababa", "ab" ) /= 3 or
|
ASF.Count("babababa", "ab") /= 3 or
|
ASF.Count("babababa", "ab") /= 3 or
|
ASF.Count("abaabaaba", "aba") /= 3 or
|
ASF.Count("abaabaaba", "aba") /= 3 or
|
ASF.Count("xxxxxxxxxxxxxxxxxxxy", "xy") /= 1 or
|
ASF.Count("xxxxxxxxxxxxxxxxxxxy", "xy") /= 1 or
|
ASF.Count("xxxxxxxxxxxxxxxxxxxx", "x") /= 20
|
ASF.Count("xxxxxxxxxxxxxxxxxxxx", "x") /= 20
|
then
|
then
|
Report.Failed("Incorrect result from Function Count");
|
Report.Failed("Incorrect result from Function Count");
|
end if;
|
end if;
|
|
|
-- Determine the number of slices of Source that when mapped to a
|
-- Determine the number of slices of Source that when mapped to a
|
-- non-identity map, match the pattern Wide_String.
|
-- non-identity map, match the pattern Wide_String.
|
|
|
Slice_Count := ASF.Count(Source_String6, -- "abcdefabcdef"
|
Slice_Count := ASF.Count(Source_String6, -- "abcdefabcdef"
|
"xy",
|
"xy",
|
CD_to_XY_Map); -- maps 'c' to 'x', 'd' to 'y'
|
CD_to_XY_Map); -- maps 'c' to 'x', 'd' to 'y'
|
|
|
if Slice_Count /= 2 then -- two slices "xy" in "mapped" Source_String6
|
if Slice_Count /= 2 then -- two slices "xy" in "mapped" Source_String6
|
Report.Failed("Incorrect result from Count with non-identity map");
|
Report.Failed("Incorrect result from Count with non-identity map");
|
end if;
|
end if;
|
|
|
-- If the pattern supplied to Function Count is the null Wide_String,
|
-- If the pattern supplied to Function Count is the null Wide_String,
|
-- then Pattern_Error is propagated.
|
-- then Pattern_Error is propagated.
|
declare
|
declare
|
The_Null_Wide_String : constant Wide_String := "";
|
The_Null_Wide_String : constant Wide_String := "";
|
begin
|
begin
|
Slice_Count := ASF.Count(Source_String6, The_Null_Wide_String);
|
Slice_Count := ASF.Count(Source_String6, The_Null_Wide_String);
|
Report.Failed("Pattern_Error not raised by Function Count");
|
Report.Failed("Pattern_Error not raised by Function Count");
|
exception
|
exception
|
when Ada.Strings.Pattern_Error => null; -- OK
|
when Ada.Strings.Pattern_Error => null; -- OK
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception from Count with null pattern");
|
Report.Failed("Incorrect exception from Count with null pattern");
|
end;
|
end;
|
|
|
|
|
|
|
|
|
-- Function Count
|
-- Function Count
|
-- Use the version of Count that takes a Wide_Character_Mapping_Function
|
-- Use the version of Count that takes a Wide_Character_Mapping_Function
|
-- value as the basis of its source mapping.
|
-- value as the basis of its source mapping.
|
|
|
if ASF.Count("akakaka", "zqz", Map_Ptr) /= 2 or
|
if ASF.Count("akakaka", "zqz", Map_Ptr) /= 2 or
|
ASF.Count("akakaka", "qz", Map_Ptr) /= 3 or
|
ASF.Count("akakaka", "qz", Map_Ptr) /= 3 or
|
ASF.Count("kakakaka", "q", Map_Ptr) /= 4 or
|
ASF.Count("kakakaka", "q", Map_Ptr) /= 4 or
|
ASF.Count("zzqaakzaqzzk", "zzq", Map_Ptr) /= 4 or
|
ASF.Count("zzqaakzaqzzk", "zzq", Map_Ptr) /= 4 or
|
ASF.Count(" ", "z", Map_Ptr) /= 0 or
|
ASF.Count(" ", "z", Map_Ptr) /= 0 or
|
ASF.Count("", "qz", Map_Ptr) /= 0 or
|
ASF.Count("", "qz", Map_Ptr) /= 0 or
|
ASF.Count("abbababab", "zq", Map_Ptr) /= 0 or
|
ASF.Count("abbababab", "zq", Map_Ptr) /= 0 or
|
ASF.Count("aaaaaaaaaaaaaaaaaakk", "zqq", Map_Ptr) /= 1 or
|
ASF.Count("aaaaaaaaaaaaaaaaaakk", "zqq", Map_Ptr) /= 1 or
|
ASF.Count("azaazaazzzaaaaazzzza", "z", Map_Ptr) /= 20
|
ASF.Count("azaazaazzzaaaaazzzza", "z", Map_Ptr) /= 20
|
then
|
then
|
Report.Failed("Incorrect result from Function Count w/map ptr");
|
Report.Failed("Incorrect result from Function Count w/map ptr");
|
end if;
|
end if;
|
|
|
-- If the pattern supplied to Function Count is a null Wide_String,
|
-- If the pattern supplied to Function Count is a null Wide_String,
|
-- then Pattern_Error is propagated.
|
-- then Pattern_Error is propagated.
|
declare
|
declare
|
The_Null_Wide_String : constant Wide_String := "";
|
The_Null_Wide_String : constant Wide_String := "";
|
begin
|
begin
|
Slice_Count := ASF.Count(Source_String6,
|
Slice_Count := ASF.Count(Source_String6,
|
The_Null_Wide_String,
|
The_Null_Wide_String,
|
Map_Ptr);
|
Map_Ptr);
|
Report.Failed
|
Report.Failed
|
("Pattern_Error not raised by Function Count w/map ptr");
|
("Pattern_Error not raised by Function Count w/map ptr");
|
exception
|
exception
|
when Ada.Strings.Pattern_Error => null; -- OK
|
when Ada.Strings.Pattern_Error => null; -- OK
|
when others =>
|
when others =>
|
Report.Failed
|
Report.Failed
|
("Incorrect exception from Count w/map ptr, null pattern");
|
("Incorrect exception from Count w/map ptr, null pattern");
|
end;
|
end;
|
|
|
|
|
|
|
|
|
-- Function Count returning the number of characters in a particular
|
-- Function Count returning the number of characters in a particular
|
-- set that are found in source Wide_String.
|
-- set that are found in source Wide_String.
|
|
|
if ASF.Count(Source_String6, CD_Set) /= 4 or -- 2 'c' and 'd' chars.
|
if ASF.Count(Source_String6, CD_Set) /= 4 or -- 2 'c' and 'd' chars.
|
ASF.Count("cddaccdaccdd", CD_Set) /= 10
|
ASF.Count("cddaccdaccdd", CD_Set) /= 10
|
then
|
then
|
Report.Failed("Incorrect result from Count with set");
|
Report.Failed("Incorrect result from Count with set");
|
end if;
|
end if;
|
|
|
|
|
|
|
-- Function Find_Token.
|
-- Function Find_Token.
|
-- (Other usage examples of this function found in CXA4013-14.)
|
-- (Other usage examples of this function found in CXA4013-14.)
|
|
|
ASF.Find_Token(Source => Source_String6, -- First slice with no
|
ASF.Find_Token(Source => Source_String6, -- First slice with no
|
Set => ABCD_Set, -- 'a', 'b', 'c', or 'd'
|
Set => ABCD_Set, -- 'a', 'b', 'c', or 'd'
|
Test => Ada.Strings.Outside, -- is "ef" at 5..6.
|
Test => Ada.Strings.Outside, -- is "ef" at 5..6.
|
First => Slice_Start,
|
First => Slice_Start,
|
Last => Slice_End);
|
Last => Slice_End);
|
|
|
if Slice_Start /= 5 or Slice_End /= 6 then
|
if Slice_Start /= 5 or Slice_End /= 6 then
|
Report.Failed("Incorrect result from Find_Token - 1");
|
Report.Failed("Incorrect result from Find_Token - 1");
|
end if;
|
end if;
|
|
|
-- If no appropriate slice is contained by the source Wide_String,
|
-- If no appropriate slice is contained by the source Wide_String,
|
-- then the value returned in Last is zero, and the value in First is
|
-- then the value returned in Last is zero, and the value in First is
|
-- Source'First.
|
-- Source'First.
|
|
|
ASF.Find_Token(Source_String6, -- "abcdefabcdef"
|
ASF.Find_Token(Source_String6, -- "abcdefabcdef"
|
A_to_F_Set, -- Set of characters 'a' thru 'f'.
|
A_to_F_Set, -- Set of characters 'a' thru 'f'.
|
Ada.Strings.Outside, -- No characters outside this set.
|
Ada.Strings.Outside, -- No characters outside this set.
|
Slice_Start,
|
Slice_Start,
|
Slice_End);
|
Slice_End);
|
|
|
if Slice_Start /= Source_String6'First or Slice_End /= 0 then
|
if Slice_Start /= Source_String6'First or Slice_End /= 0 then
|
Report.Failed("Incorrect result from Find_Token - 2");
|
Report.Failed("Incorrect result from Find_Token - 2");
|
end if;
|
end if;
|
|
|
-- Additional testing of Find_Token.
|
-- Additional testing of Find_Token.
|
|
|
ASF.Find_Token("eabcdabcddcab",
|
ASF.Find_Token("eabcdabcddcab",
|
ABCD_Set,
|
ABCD_Set,
|
Ada.Strings.Inside,
|
Ada.Strings.Inside,
|
Slice_Start,
|
Slice_Start,
|
Slice_End);
|
Slice_End);
|
|
|
if Slice_Start /= 2 or Slice_End /= 13 then
|
if Slice_Start /= 2 or Slice_End /= 13 then
|
Report.Failed("Incorrect result from Find_Token - 3");
|
Report.Failed("Incorrect result from Find_Token - 3");
|
end if;
|
end if;
|
|
|
ASF.Find_Token("efghijklabcdabcd",
|
ASF.Find_Token("efghijklabcdabcd",
|
ABCD_Set,
|
ABCD_Set,
|
Ada.Strings.Outside,
|
Ada.Strings.Outside,
|
Slice_Start,
|
Slice_Start,
|
Slice_End);
|
Slice_End);
|
|
|
if Slice_Start /= 1 or Slice_End /= 8 then
|
if Slice_Start /= 1 or Slice_End /= 8 then
|
Report.Failed("Incorrect result from Find_Token - 4");
|
Report.Failed("Incorrect result from Find_Token - 4");
|
end if;
|
end if;
|
|
|
ASF.Find_Token("abcdefgabcdabcd",
|
ASF.Find_Token("abcdefgabcdabcd",
|
ABCD_Set,
|
ABCD_Set,
|
Ada.Strings.Outside,
|
Ada.Strings.Outside,
|
Slice_Start,
|
Slice_Start,
|
Slice_End);
|
Slice_End);
|
|
|
if Slice_Start /= 5 or Slice_End /= 7 then
|
if Slice_Start /= 5 or Slice_End /= 7 then
|
Report.Failed("Incorrect result from Find_Token - 5");
|
Report.Failed("Incorrect result from Find_Token - 5");
|
end if;
|
end if;
|
|
|
ASF.Find_Token("abcdcbabcdcba",
|
ASF.Find_Token("abcdcbabcdcba",
|
ABCD_Set,
|
ABCD_Set,
|
Ada.Strings.Inside,
|
Ada.Strings.Inside,
|
Slice_Start,
|
Slice_Start,
|
Slice_End);
|
Slice_End);
|
|
|
if Slice_Start /= 1 or Slice_End /= 13 then
|
if Slice_Start /= 1 or Slice_End /= 13 then
|
Report.Failed("Incorrect result from Find_Token - 6");
|
Report.Failed("Incorrect result from Find_Token - 6");
|
end if;
|
end if;
|
|
|
|
|
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 CXA4015;
|
end CXA4015;
|
|
|