cxa4015.a
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· A 代码 · 共 581 行 · 第 1/2 页
A
581 行
-- CXA4015.A---- Grant of Unlimited Rights---- 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 -- unlimited rights in the software and documentation contained herein.-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- 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 -- to do so.---- DISCLAIMER---- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A-- PARTICULAR PURPOSE OF SAID MATERIAL.--*---- OBJECTIVE:-- Check that the subprograms defined in package Ada.Strings.Wide_Fixed-- are available, and that they produce correct results. Specifically, -- check the subprograms Count, Find_Token, Index, Index_Non_Blank, and-- Move.-- -- TEST DESCRIPTION:-- This test, when combined with tests CXA4013,14,16 will provide -- coverage of the functionality found in Ada.Strings.Wide_Fixed. -- This test contains many small, specific test cases, situations that -- although common in user environments, are often difficult to generate -- in large numbers in a application-based test.---- -- CHANGE HISTORY:-- 06 Dec 94 SAIC ACVC 2.0-- 02 Nov 95 SAIC Corrected various accesssibility problems and-- expected result strings for ACVC 2.0.1.----!package CXA40150 is -- Wide Character mapping function defined for use with specific -- versions of functions Index and Count. function AK_to_ZQ_Mapping (From : Wide_Character) return Wide_Character;end CXA40150;package body CXA40150 is function AK_to_ZQ_Mapping (From : Wide_Character) return Wide_Character is begin if From = 'a' then return 'z'; elsif From = 'k' then return 'q'; else return From; end if; end AK_to_ZQ_Mapping;end CXA40150;with CXA40150;with Report;with Ada.Strings;with Ada.Strings.Wide_Fixed;with Ada.Strings.Wide_Maps;procedure CXA4015 isbegin Report.Test("CXA4015", "Check that the subprograms defined in " & "package Ada.Strings.Wide_Fixed are available, " & "and that they produce correct results"); Test_Block: declare use CXA40150; package ASF renames Ada.Strings.Wide_Fixed; package Maps renames Ada.Strings.Wide_Maps; Result_String : Wide_String(1..10) := (others => Ada.Strings.Wide_Space); Source_String1 : Wide_String(1..5) := "abcde"; -- odd len Wide_String Source_String2 : Wide_String(1..6) := "abcdef"; -- even len Wide_String Source_String3 : Wide_String(1..12) := "abcdefghijkl"; Source_String4 : Wide_String(1..12) := "abcdefghij "; -- last 2 ch pad Source_String5 : Wide_String(1..12) := " cdefghijkl"; -- first 2 ch pad Source_String6 : Wide_String(1..12) := "abcdefabcdef"; Location : Natural := 0; Slice_Start : Positive; Slice_End, Slice_Count : Natural := 0; CD_Set : Maps.Wide_Character_Set := Maps.To_Set("cd"); ABCD_Set : Maps.Wide_Character_Set := Maps.To_Set("abcd"); A_to_F_Set : Maps.Wide_Character_Set := Maps.To_Set("abcdef"); CD_to_XY_Map : Maps.Wide_Character_Mapping := Maps.To_Mapping(From => "cd", To => "xy"); -- Access-to-Subprogram object defined for use with specific versions of -- functions Index and Count. Map_Ptr : Maps.Wide_Character_Mapping_Function := AK_to_ZQ_Mapping'Access; begin -- Procedure Move -- Evaluate the Procedure Move with various combinations of -- parameters. -- Justify = Left (default case) ASF.Move(Source => Source_String1, -- "abcde" Target => Result_String); if Result_String /= "abcde " then Report.Failed("Incorrect result from Move with Justify = Left"); end if; -- Justify = Right ASF.Move(Source => Source_String2, -- "abcdef" Target => Result_String, Drop => Ada.Strings.Error, Justify => Ada.Strings.Right); if Result_String /= " abcdef" then Report.Failed("Incorrect result from Move with Justify = Right"); end if; -- Justify = Center (two cases, odd and even pad lengths) ASF.Move(Source_String1, -- "abcde" Result_String, Ada.Strings.Error, Ada.Strings.Center, 'x'); -- non-default padding. if Result_String /= "xxabcdexxx" then -- Unequal padding added right Report.Failed("Incorrect result from Move with Justify = Center-1"); end if; ASF.Move(Source_String2, -- "abcdef" Result_String, Ada.Strings.Error, Ada.Strings.Center); if Result_String /= " abcdef " then -- Equal padding added on L/R. Report.Failed("Incorrect result from Move with Justify = Center-2"); end if; -- When the source Wide_String is longer than the target Wide_String, -- several cases can be examined, with the results depending on the -- value of the Drop parameter. -- Drop = Left ASF.Move(Source => Source_String3, -- "abcdefghijkl" Target => Result_String, Drop => Ada.Strings.Left); if Result_String /= "cdefghijkl" then Report.Failed("Incorrect result from Move with Drop = Left"); end if; -- Drop = Right ASF.Move(Source_String3, Result_String, Ada.Strings.Right); if Result_String /= "abcdefghij" then Report.Failed("Incorrect result from Move with Drop = Right"); end if; -- Drop = Error -- The effect in this case depends on the value of the justify -- parameter, and on whether any characters in Source other than -- Pad would fail to be copied. -- Drop = Error, Justify = Left, right overflow characters are pad. ASF.Move(Source => Source_String4, -- "abcdefghij " Target => Result_String, Drop => Ada.Strings.Error, Justify => Ada.Strings.Left); if not(Result_String = "abcdefghij") then -- leftmost 10 characters Report.Failed("Incorrect result from Move with Drop = Error - 1"); end if; -- Drop = Error, Justify = Right, left overflow characters are pad. ASF.Move(Source_String5, -- " cdefghijkl" Result_String, Ada.Strings.Error, Ada.Strings.Right); if Result_String /= "cdefghijkl" then -- rightmost 10 characters Report.Failed("Incorrect result from Move with Drop = Error - 2"); end if; -- In other cases of Drop=Error, Length_Error is propagated, such as: begin ASF.Move(Source_String3, -- 12 characters, no Pad. Result_String, -- 10 characters Ada.Strings.Error, Ada.Strings.Left); Report.Failed("Length_Error not raised by Move - 1"); exception when Ada.Strings.Length_Error => null; -- OK when others => Report.Failed("Incorrect exception raised by Move - 1"); end; -- Function Index -- (Other usage examples of this function found in CXA4013-14.) -- Check when the pattern is not found in the source. if ASF.Index("abcdef", "gh") /= 0 or ASF.Index("abcde", "abcdef") /= 0 or -- pattern > source ASF.Index("xyz", "abcde", Ada.Strings.Backward) /= 0 or ASF.Index("", "ab") /= 0 or -- null source Wide_String. ASF.Index("abcde", " ") /= 0 -- blank pattern. then Report.Failed("Incorrect result from Index, no pattern match"); end if; -- Check that Pattern_Error is raised when the pattern is the -- null Wide_String. begin Location := ASF.Index(Source_String6, -- "abcdefabcdef" "", -- null pattern Wide_String. Ada.Strings.Forward); Report.Failed("Pattern_Error not raised by Index"); exception when Ada.Strings.Pattern_Error => null; -- OK, expected exception. when others => Report.Failed("Incorrect exception raised by Index, null pattern"); end; -- Use the search direction "backward" to locate the particular -- pattern within the source Wide_String. Location := ASF.Index(Source_String6, -- "abcdefabcdef" "de", -- slice 4..5, 10..11 Ada.Strings.Backward); -- search from right end. if Location /= 10 then Report.Failed("Incorrect result from Index going Backward"); end if; -- Function Index -- Use the version of Index that takes a Wide_Character_Mapping_Function -- parameter. -- Use the search directions Forward and Backward to locate the -- particular pattern wide string within the source wide string. Location := ASF.Index("akzqefakzqef", "qzq", -- slice 8..10 Ada.Strings.Backward, Map_Ptr); -- perform 'a' to 'z', 'k' to 'q'
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?