cxa4008.a
来自「linux下编程用 编译软件」· A 代码 · 共 663 行 · 第 1/2 页
A
663 行
-- CXA4008.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.Bounded are-- available, and that they produce correct results, especially under-- conditions where truncation of the result is required. Specifically, -- check the subprograms Append, Count with non-Identity maps, Index with -- non-Identity maps, Index with Set parameters, Insert (function and-- procedure), Replace_Slice (function and procedure), To_Bounded_String, -- and Translate.---- TEST DESCRIPTION:-- This test, in conjunction with tests CXA4006, CXA4007, and CXA4009, -- will provide coverage of the most common usages of the functionality-- found in the Ada.Strings.Bounded package. It deals in large part-- with truncation effects and options. This test contains many small, -- specific test cases, situations that are often difficult to generate -- in large numbers in an application-based test. These cases represent -- specific usage paradigms in-the-small.---- -- CHANGE HISTORY:-- 06 Dec 94 SAIC ACVC 2.0-- 10 Apr 95 SAIC Corrected acceptance condition of subtest for-- Function Append with Truncation = Left.-- 31 Oct 95 SAIC Update and repair for ACVC 2.0.1.----!with Report;with Ada.Strings.Maps.Constants;with Ada.Strings.Bounded;with Ada.Strings.Maps;procedure CXA4008 isbegin Report.Test("CXA4008", "Check that the subprograms defined in " & "package Ada.Strings.Bounded are available, " & "and that they produce correct results, " & "especially under conditions where " & "truncation of the result is required"); Test_Block: declare package AS renames Ada.Strings; package ASB renames Ada.Strings.Bounded; package ASC renames Ada.Strings.Maps.Constants; package Maps renames Ada.Strings.Maps; package B10 is new ASB.Generic_Bounded_Length(Max => 10); use type B10.Bounded_String; Result_String : B10.Bounded_String; Test_String : B10.Bounded_String; AtoE_Bnd_Str : B10.Bounded_String := B10.To_Bounded_String("abcde"); FtoJ_Bnd_Str : B10.Bounded_String := B10.To_Bounded_String("fghij"); AtoJ_Bnd_Str : B10.Bounded_String := B10.To_Bounded_String("abcdefghij"); Location : Natural := 0; Total_Count : Natural := 0; CD_Set : Maps.Character_Set := Maps.To_Set("cd"); AB_to_YZ_Map : Maps.Character_Mapping := Maps.To_Mapping(From => "ab", To => "yz"); CD_to_XY_Map : Maps.Character_Mapping := Maps.To_Mapping(From => "cd", To => "xy"); begin -- Function To_Bounded_String with Truncation -- Evaluate the function Append with parameters that will -- cause the truncation of the result. -- Drop = Error (default case, Length_Error will be raised) begin Test_String := B10.To_Bounded_String("Much too long for this bounded string"); Report.Failed("Length Error not raised by To_Bounded_String"); exception when AS.Length_Error => null; -- Expected exception raised. when others => Report.Failed("Incorrect exception raised by To_Bounded_String"); end; -- Drop = Left Test_String := B10.To_Bounded_String(Source => "abcdefghijklmn", Drop => Ada.Strings.Left); if Test_String /= B10.To_Bounded_String("efghijklmn") then Report.Failed ("Incorrect result from To_Bounded_String, Drop = Left"); end if; -- Drop = Right Test_String := B10.To_Bounded_String(Source => "abcdefghijklmn", Drop => Ada.Strings.Right); if not(Test_String = AtoJ_Bnd_Str) then Report.Failed ("Incorrect result from To_Bounded_String, Drop = Right"); end if; -- Function Append with Truncation -- Evaluate the function Append with parameters that will -- cause the truncation of the result. -- Drop = Error (default case, Length_Error will be raised) begin -- Append (Bnd Str, Bnd Str); Result_String := B10.Append(B10.To_Bounded_String("abcde"), B10.To_Bounded_String("fghijk")); -- 11 char Report.Failed("Length_Error not raised by Append - 1"); exception when AS.Length_Error => null; -- OK, correct exception raised. when others => Report.Failed("Incorrect exception raised by Append - 1"); end; begin -- Append (Str, Bnd Str); Result_String := B10.Append(B10.To_String(AtoE_Bnd_Str), B10.To_Bounded_String("fghijk"), AS.Error); Report.Failed("Length_Error not raised by Append - 2"); exception when AS.Length_Error => null; -- OK, correct exception raised. when others => Report.Failed("Incorrect exception raised by Append - 2"); end; begin -- Append (Bnd Str, Char); Result_String := B10.Append(B10.To_Bounded_String("abcdefghij"), 'k'); Report.Failed("Length_Error not raised by Append - 3"); exception when AS.Length_Error => null; -- OK, correct exception raised. when others => Report.Failed("Incorrect exception raised by Append - 3"); end; -- Drop = Left -- Append (Bnd Str, Bnd Str) Result_String := B10.Append(B10.To_Bounded_String("abcdefgh"), -- 8 chs B10.To_Bounded_String("ijklmn"), -- 6 chs Ada.Strings.Left); if Result_String /= B10.To_Bounded_String("efghijklmn") then -- 10 chars Report.Failed("Incorrect truncation performed by Append - 4"); end if; -- Append (Bnd Str, Str) Result_String := B10.Append(B10.To_Bounded_String("abcdefghij"), "xyz", Ada.Strings.Left); if Result_String /= B10.To_Bounded_String("defghijxyz") then Report.Failed("Incorrect truncation performed by Append - 5"); end if; -- Append (Char, Bnd Str) Result_String := B10.Append('A', B10.To_Bounded_String("abcdefghij"), Ada.Strings.Left); if Result_String /= B10.To_Bounded_String("abcdefghij") then Report.Failed("Incorrect truncation performed by Append - 6"); end if; -- Drop = Right -- Append (Bnd Str, Bnd Str) Result_String := B10.Append(FtoJ_Bnd_Str, AtoJ_Bnd_Str, Ada.Strings.Right); if Result_String /= B10.To_Bounded_String("fghijabcde") then Report.Failed("Incorrect truncation performed by Append - 7"); end if; -- Append (Str, Bnd Str) Result_String := B10.Append(B10.To_String(AtoE_Bnd_Str), AtoJ_Bnd_Str, Ada.Strings.Right); if Result_String /= B10.To_Bounded_String("abcdeabcde") then Report.Failed("Incorrect truncation performed by Append - 8"); end if; -- Append (Char, Bnd Str) Result_String := B10.Append('A', AtoJ_Bnd_Str, Ada.Strings.Right); if Result_String /= B10.To_Bounded_String("Aabcdefghi") then Report.Failed("Incorrect truncation performed by Append - 9"); end if; -- Function Index with non-Identity map. -- Evaluate the function Index with a non-identity map -- parameter which will cause mapping of the source parameter -- prior to the evaluation of the index position search. Location := B10.Index(Source => AtoJ_Bnd_Str, -- "abcdefghij" Pattern => "xy", Going => Ada.Strings.Forward, Mapping => CD_to_XY_Map); -- change "cd" to "xy" if Location /= 3 then Report.Failed("Incorrect result from Index, non-Identity map - 1"); end if; Location := B10.Index(B10.To_Bounded_String("AND IF MAN"), "an", Ada.Strings.Backward, ASC.Lower_Case_Map); if Location /= 9 then Report.Failed("Incorrect result from Index, non-Identity map - 2"); end if; Location := B10.Index(Source => B10.To_Bounded_String("The the"), Pattern => "the", Going => Ada.Strings.Forward, Mapping => ASC.Lower_Case_Map); if Location /= 1 then Report.Failed("Incorrect result from Index, non-Identity map - 3"); end if; if B10.Index(B10.To_Bounded_String("abcd"), -- Pattern = Source "abcd") /= 1 or B10.Index(B10.To_Bounded_String("abc"), -- Pattern < Source "abcd") /= 0 or B10.Index(B10.Null_Bounded_String, -- Source = Null "abc") /= 0 then Report.Failed("Incorrect result from Index with string patterns"); end if; -- Function Index (for Sets). -- This version of Index uses Sets as the basis of the search. -- Test = Inside, Going = Forward (Default case). Location := B10.Index(Source => B10.To_Bounded_String("abcdeabcde"), Set => CD_Set, -- set containing 'c' and 'd' Test => Ada.Strings.Inside, Going => Ada.Strings.Forward); if not (Location = 3) then -- position of first 'c' in source. Report.Failed("Incorrect result from Index using Sets - 1"); end if; -- Test = Inside, Going = Backward. Location := B10.Index(Source => B10."&"(AtoE_Bnd_Str, AtoE_Bnd_Str), Set => CD_Set, -- set containing 'c' and 'd' Test => Ada.Strings.Inside, Going => Ada.Strings.Backward); if not (Location = 9) then -- position of last 'd' in source. Report.Failed("Incorrect result from Index using Sets - 2"); end if; -- Test = Outside, Going = Forward. Location := B10.Index(B10.To_Bounded_String("deddacd"), CD_Set, Test => Ada.Strings.Outside, Going => Ada.Strings.Forward); if Location /= 2 then -- position of 'e' in source. Report.Failed("Incorrect result from Index using Sets - 3"); end if; -- Test = Outside, Going = Backward. Location := B10.Index(B10.To_Bounded_String("deddacd"), CD_Set, Ada.Strings.Outside, Ada.Strings.Backward); if Location /= 5 then -- correct position of 'a'. Report.Failed("Incorrect result from Index using Sets - 4"); end if; if B10.Index(B10.To_Bounded_String("cd"), -- Source = Set CD_Set) /= 1 or B10.Index(B10.To_Bounded_String("c"), -- Source < Set CD_Set) /= 1 or B10.Index(B10.Null_Bounded_String, -- Source = Null CD_Set) /= 0 or
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?