-- CXA4038.A -- -- Grant of Unlimited Rights -- -- The Ada Conformity Assessment Authority (ACAA) holds unlimited -- rights in the software and documentation contained herein. Unlimited -- rights are the same as those granted by the U.S. Government for older -- parts of the Ada Conformity Assessment Test Suite, and are defined -- in DFAR 252.227-7013(a)(19). By making this public release, the ACAA -- intends to confer upon all recipients unlimited rights equal to those -- held by the ACAA. 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 Ada.Strings.Bounded.Slice raises Index_Error if -- High > Length (Source) or Low > Length (Source) + 1. -- -- Check that the bounds of the result of Ada.Strings.Bounded.Slice are -- Low and High. Check that the bounds of the result of -- Ada.Strings.Bounded.To_String are 1 and Length. -- -- Check that Ada.Strings.Wide_Bounded.Slice raises Index_Error if -- High > Length (Source) or Low > Length (Source) + 1. -- -- Check that the bounds of the result of Ada.Strings.Wide_Bounded.Slice are -- Low and High. Check that the bounds of the result of -- Ada.Strings.Wide_Bounded.To_Wide_String are 1 and Length. -- -- TEST DESCRIPTION: -- These objectives primarily test error cases associated with the -- operations Slice, Bounded_Slice, To_String, and To_Wide_String. These -- operations are very likely to be used for any application that uses -- Bounded_String or Bounded_Wide_String objects, and errors are always -- possible, so we don't attempt to define a specific use case for these -- operations. Undetected runtime errors are a significant portability -- problem (this test was inspired by such a problem in the ARG tool -- GD2HTML). -- -- The checks for Index_Error for Slice were introduced by AI95-0128-1 -- (Defect Report 8652/0049). The bounds of Slice were clarified by -- AI95-0238-1. The Bounded_Slice function and procedure were introduced -- by AI95-0301-1. -- -- Note that To_String is the only other string returning function in -- Ada.Strings.Bounded, so we check its bounds here in order to check all -- such bounds explicitly. The bounds are explicitly defined in the -- definition of To_String (A.4.4(92)). -- -- CHANGE HISTORY: -- 12 FEB 2001 PHL Initial version -- 14 MAR 2001 RLB Added Wide_Bounded subtest. -- 06 APR 2022 RLB Added additional objectives, test cases, renamed -- test. -- --! with Ada.Exceptions; use Ada.Exceptions; with Ada.Strings.Bounded; with Ada.Strings.Wide_Bounded; use Ada.Strings; with Report; use Report; procedure CXA4038 is package Bs is new Ada.Strings.Bounded.Generic_Bounded_Length (40); package WBs is new Ada.Strings.Wide_Bounded.Generic_Bounded_Length (32); Source : String (Ident_Int (1) .. Ident_Int (30)); Wide_Source : Wide_String (Ident_Int (1) .. Ident_Int (24)); X : Bs.Bounded_String; WX : WBs.Bounded_Wide_String; begin Test ("CXA4038", "Check that Slice and Bounded_Slice raises Index_Error " & "appropriately; check the bounds of Slice, To_String, and " & "To_Wide_String; check for Ada.Strings.Bounded and " & "Ada.Strings.Wide_Bounded"); -- Fill Source with "ABC..." for I in Source'Range loop Source (I) := Ident_Char (Character'Val (I + Character'Pos ('A') - Source'First)); end loop; -- and W with "ABC..." for I in Wide_Source'Range loop Wide_Source (I) := Ident_Wide_Char (Wide_Character'Val (I + Wide_Character'Pos ('A') - Wide_Source'First)); end loop; X := Bs.To_Bounded_String (Source); begin declare S : constant String := Bs.Slice (X, Low => Ident_Int (28), High => Ident_Int (41)); begin Failed ("No exception raised by Slice - 1"); if S = Source then Comment ("Don't optimize S"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 1"); end; begin declare S : constant String := Bs.Slice (X, Low => Ident_Int (8), High => Ident_Int (31)); begin Failed ("No exception raised by Slice - 2"); if S = Source then Comment ("Don't optimize S"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 2"); end; begin declare S : constant String := Bs.Slice (X, Low => Ident_Int (15), High => Ident_Int (30)); begin if S /= Source(15..30) then Failed ("Wrong result - 3"); end if; if S'First /= 15 or else S'Last /= 30 then Failed ("Wrong bounds - 3"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 3"); end; begin declare S : constant String := Bs.Slice (X, Low => Ident_Int (42), High => Ident_Int (28)); begin Failed ("No exception raised by Slice - 4"); if S = Source then Comment ("Don't optimize S"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 4"); end; begin declare S : constant String := Bs.Slice (X, Low => Ident_Int (31), High => Ident_Int (28)); begin if S /= "" then Failed ("Wrong result - 5"); end if; if S'First /= 31 or else S'Last /= 28 then Failed ("Wrong bounds - 5"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 5"); end; begin declare S : constant String := Bs.Slice (X, Low => Ident_Int (30), High => Ident_Int (30)); begin if S /= Source(30..30) then Failed ("Wrong result - 6"); end if; if S'First /= 30 or else S'Last /= 30 then Failed ("Wrong bounds - 6"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 6"); end; begin declare B : constant Bs.Bounded_String := Bs.Bounded_Slice (X, Low => Ident_Int (20), High => Ident_Int (38)); begin Failed ("No exception raised by Bounded_Slice - 7"); if Bs.To_String(B) = Source then Comment ("Don't optimize B"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 7"); end; begin declare B : constant Bs.Bounded_String := Bs.Bounded_Slice (X, Low => Ident_Int (12), High => Ident_Int (31)); begin Failed ("No exception raised by Bounded_Slice - 8"); if Bs.To_String(B) = Source then Comment ("Don't optimize B"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 8"); end; begin declare B : constant Bs.Bounded_String := Bs.Bounded_Slice (X, Low => Ident_Int (10), High => Ident_Int (30)); S : constant String := Bs.To_String (B); begin if S /= Source(10..30) then Failed ("Wrong result - 9"); end if; if S'First /= 1 or else S'Last /= Bs.Length(B) then Failed ("Wrong bounds - 9"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 9"); end; begin declare B : constant Bs.Bounded_String := Bs.Bounded_Slice (X, Low => Ident_Int (36), High => Ident_Int (25)); begin Failed ("No exception raised by Bounded_Slice - 10"); if Bs.To_String(B) = Source then Comment ("Don't optimize B"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 10"); end; begin declare B : constant Bs.Bounded_String := Bs.Bounded_Slice (X, Low => Ident_Int (31), High => Ident_Int (25)); S : constant String := Bs.To_String (B); begin if S /= "" then Failed ("Wrong result - 11"); end if; if S'First /= 1 or else S'Last /= Bs.Length (B) then Failed ("Wrong bounds - 11"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 11"); end; begin declare B : constant Bs.Bounded_String := Bs.Bounded_Slice (X, Low => Ident_Int (30), High => Ident_Int (30)); S : constant String := Bs.To_String (B); begin if S /= Source(30..30) then Failed ("Wrong result - 12"); end if; if S'First /= 1 or else S'Last /= Bs.Length (B) then Failed ("Wrong bounds - 12"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 12"); end; declare B : Bs.Bounded_String; begin Bs.Bounded_Slice (Source => X, Target => B, Low => Ident_Int (5), High => Ident_Int (32)); Failed ("No exception raised by Bounded_Slice - 13"); if Bs.To_String(B) = Source then Comment ("Don't optimize B"); end if; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 13"); end; declare B : Bs.Bounded_String; begin Bs.Bounded_Slice (Source => X, Target => B, Low => Ident_Int (44), High => Ident_Int (3)); Failed ("No exception raised by Bounded_Slice - 14"); if Bs.To_String(B) = Source then Comment ("Don't optimize B"); end if; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 14"); end; declare B : Bs.Bounded_String; begin Bs.Bounded_Slice (Source => X, Target => B, Low => Ident_Int (18), High => Ident_Int (30)); declare S : constant String := Bs.To_String (B); begin if S /= Source(18..30) then Failed ("Wrong result - 15"); end if; if S'First /= 1 or else S'Last /= Bs.Length(B) then Failed ("Wrong bounds - 15"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 15"); end; declare B : Bs.Bounded_String; begin Bs.Bounded_Slice (Source => X, Target => B, Low => Ident_Int (31), High => Ident_Int (12)); declare S : constant String := Bs.To_String (B); begin if S /= "" then Failed ("Wrong result - 16"); end if; if S'First /= 1 or else S'Last /= Bs.Length(B) then Failed ("Wrong bounds - 16"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 16"); end; ---- WX := WBs.To_Bounded_Wide_String (Wide_Source); begin declare W : constant Wide_String := WBs.Slice (WX, Low => Ident_Int (21), High => Ident_Int (33)); begin Failed ("No exception raised by Slice - 21"); if W = Wide_Source then Comment ("Don't optimize W"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 21"); end; begin declare W : constant Wide_String := WBs.Slice (WX, Low => Ident_Int (8), High => Ident_Int (25)); begin Failed ("No exception raised by Slice - 22"); if W = Wide_Source then Comment ("Don't optimize W"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 22"); end; begin declare W : constant Wide_String := WBs.Slice (WX, Low => Ident_Int (15), High => Ident_Int (24)); begin if W /= Wide_Source(15..24) then Failed ("Wrong result - 23"); end if; if W'First /= 15 or else W'Last /= 24 then Failed ("Wrong bounds - 23"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 23"); end; begin declare W : constant Wide_String := WBs.Slice (WX, Low => Ident_Int (36), High => Ident_Int (20)); begin Failed ("No exception raised by Slice - 24"); if W = Wide_Source then Comment ("Don't optimize W"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 24"); end; begin declare W : constant Wide_String := WBs.Slice (WX, Low => Ident_Int (25), High => Ident_Int (21)); begin if W /= "" then Failed ("Wrong result - 25"); end if; if W'First /= 25 or else W'Last /= 21 then Failed ("Wrong bounds - 25"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 25"); end; begin declare W : constant Wide_String := WBs.Slice (WX, Low => Ident_Int (24), High => Ident_Int (24)); begin if W /= Wide_Source(24..24) then Failed ("Wrong result - 26"); end if; if W'First /= 24 or else W'Last /= 24 then Failed ("Wrong bounds - 26"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 26"); end; begin declare B : constant WBs.Bounded_Wide_String := WBs.Bounded_Slice (WX, Low => Ident_Int (20), High => Ident_Int (38)); begin Failed ("No exception raised by Bounded_Slice - 27"); if WBs.To_Wide_String(B) = Wide_Source then Comment ("Don't optimize B"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 27"); end; begin declare B : constant WBs.Bounded_Wide_String := WBs.Bounded_Slice (WX, Low => Ident_Int (12), High => Ident_Int (31)); begin Failed ("No exception raised by Bounded_Slice - 28"); if WBs.To_Wide_String(B) = Wide_Source then Comment ("Don't optimize B"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 28"); end; begin declare B : constant WBs.Bounded_Wide_String := WBs.Bounded_Slice (WX, Low => Ident_Int (4), High => Ident_Int (24)); W : constant Wide_String := WBs.To_Wide_String (B); begin if W /= Wide_Source(4..24) then Failed ("Wrong result - 29"); end if; if W'First /= 1 or else W'Last /= WBs.Length(B) then Failed ("Wrong bounds - 29"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 29"); end; begin declare B : constant WBs.Bounded_Wide_String := WBs.Bounded_Slice (WX, Low => Ident_Int (36), High => Ident_Int (21)); begin Failed ("No exception raised by Bounded_Slice - 30"); if WBs.To_Wide_String(B) = Wide_Source then Comment ("Don't optimize B"); end if; end; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 30"); end; begin declare B : constant WBs.Bounded_Wide_String := WBs.Bounded_Slice (WX, Low => Ident_Int (25), High => Ident_Int (20)); W : constant Wide_String := WBs.To_Wide_String (B); begin if W /= "" then Failed ("Wrong result - 31"); end if; if W'First /= 1 or else W'Last /= WBs.Length (B) then Failed ("Wrong bounds - 31"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 31"); end; begin declare B : constant WBs.Bounded_Wide_String := WBs.Bounded_Slice (WX, Low => Ident_Int (24), High => Ident_Int (24)); W : constant Wide_String := WBs.To_Wide_String (B); begin if W /= Wide_Source(24..24) then Failed ("Wrong result - 32"); end if; if W'First /= 1 or else W'Last /= WBs.Length (B) then Failed ("Wrong bounds - 32"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 32"); end; declare B : WBs.Bounded_Wide_String; begin WBs.Bounded_Slice (Source => WX, Target => B, Low => Ident_Int (5), High => Ident_Int (32)); Failed ("No exception raised by Bounded_Slice - 33"); if WBs.To_Wide_String(B) = Wide_Source then Comment ("Don't optimize B"); end if; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 33"); end; declare B : WBs.Bounded_Wide_String; begin WBs.Bounded_Slice (Source => WX, Target => B, Low => Ident_Int (44), High => Ident_Int (3)); Failed ("No exception raised by Bounded_Slice - 34"); if WBs.To_Wide_String(B) = Wide_Source then Comment ("Don't optimize B"); end if; exception when Index_Error => null; -- Expected exception. when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 34"); end; declare B : WBs.Bounded_Wide_String; begin WBs.Bounded_Slice (Source => WX, Target => B, Low => Ident_Int (18), High => Ident_Int (24)); declare W : constant Wide_String := WBs.To_Wide_String (B); begin if W /= Wide_Source(18..24) then Failed ("Wrong result - 35"); end if; if W'First /= 1 or else W'Last /= WBs.Length(B) then Failed ("Wrong bounds - 35"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 35"); end; declare B : WBs.Bounded_Wide_String; begin WBs.Bounded_Slice (Source => WX, Target => B, Low => Ident_Int (25), High => Ident_Int (24)); declare W : constant Wide_String := WBs.To_Wide_String (B); begin if W /= "" then Failed ("Wrong result - 36"); end if; if W'First /= 1 or else W'Last /= WBs.Length(B) then Failed ("Wrong bounds - 36"); end if; end; exception when E: others => Failed ("Exception raised - " & Exception_Name (E) & " - " & Exception_Message (E) & " - 36"); end; Result; end CXA4038;