-- CXA4034.A
|
-- CXA4034.A
|
--
|
--
|
-- Grant of Unlimited Rights
|
-- Grant of Unlimited Rights
|
--
|
--
|
-- The Ada Conformity Assessment Authority (ACAA) holds unlimited
|
-- The Ada Conformity Assessment Authority (ACAA) holds unlimited
|
-- rights in the software and documentation contained herein. Unlimited
|
-- rights in the software and documentation contained herein. Unlimited
|
-- rights are the same as those granted by the U.S. Government for older
|
-- 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
|
-- 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
|
-- 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
|
-- intends to confer upon all recipients unlimited rights equal to those
|
-- held by the ACAA. These rights include rights to use, duplicate,
|
-- held by the ACAA. These rights include rights to use, duplicate,
|
-- release or disclose the released technical data and computer software
|
-- release or disclose the released technical data and computer software
|
-- in whole or in part, in any manner and for any purpose whatsoever, and
|
-- in whole or in part, in any manner and for any purpose whatsoever, and
|
-- to have or permit others to do so.
|
-- to have or permit others 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 Ada.Strings.Bounded.Slice raises Index_Error if
|
-- Check that Ada.Strings.Bounded.Slice raises Index_Error if
|
-- High > Length (Source) or Low > Length (Source) + 1.
|
-- High > Length (Source) or Low > Length (Source) + 1.
|
-- (Defect Report 8652/0049).
|
-- (Defect Report 8652/0049).
|
--
|
--
|
-- Check that Ada.Strings.Wide_Bounded.Slice raises Index_Error if
|
-- Check that Ada.Strings.Wide_Bounded.Slice raises Index_Error if
|
-- High > Length (Source) or Low > Length (Source) + 1.
|
-- High > Length (Source) or Low > Length (Source) + 1.
|
--
|
--
|
-- CHANGE HISTORY:
|
-- CHANGE HISTORY:
|
-- 12 FEB 2001 PHL Initial version
|
-- 12 FEB 2001 PHL Initial version
|
-- 14 MAR 2001 RLB Added Wide_Bounded subtest.
|
-- 14 MAR 2001 RLB Added Wide_Bounded subtest.
|
--
|
--
|
--!
|
--!
|
with Ada.Exceptions;
|
with Ada.Exceptions;
|
use Ada.Exceptions;
|
use Ada.Exceptions;
|
with Ada.Strings.Bounded;
|
with Ada.Strings.Bounded;
|
with Ada.Strings.Wide_Bounded;
|
with Ada.Strings.Wide_Bounded;
|
use Ada.Strings;
|
use Ada.Strings;
|
with Report;
|
with Report;
|
use Report;
|
use Report;
|
procedure CXA4034 is
|
procedure CXA4034 is
|
|
|
package Bs is new Ada.Strings.Bounded.Generic_Bounded_Length (40);
|
package Bs is new Ada.Strings.Bounded.Generic_Bounded_Length (40);
|
|
|
package WBs is new Ada.Strings.Wide_Bounded.Generic_Bounded_Length (32);
|
package WBs is new Ada.Strings.Wide_Bounded.Generic_Bounded_Length (32);
|
|
|
Source : String (Ident_Int (1) .. Ident_Int (30));
|
Source : String (Ident_Int (1) .. Ident_Int (30));
|
|
|
Wide_Source : Wide_String (Ident_Int (1) .. Ident_Int (24));
|
Wide_Source : Wide_String (Ident_Int (1) .. Ident_Int (24));
|
|
|
X : Bs.Bounded_String;
|
X : Bs.Bounded_String;
|
|
|
WX : WBs.Bounded_Wide_String;
|
WX : WBs.Bounded_Wide_String;
|
|
|
begin
|
begin
|
Test ("CXA4034",
|
Test ("CXA4034",
|
"Check that Slice raises Index_Error if either Low or High is " &
|
"Check that Slice raises Index_Error if either Low or High is " &
|
"greater than the Length(Source) for Ada.Strings.Bounded and " &
|
"greater than the Length(Source) for Ada.Strings.Bounded and " &
|
"Ada.Strings.Wide_Bounded");
|
"Ada.Strings.Wide_Bounded");
|
|
|
-- Fill Source with "ABC..."
|
-- Fill Source with "ABC..."
|
for I in Source'Range loop
|
for I in Source'Range loop
|
Source (I) := Ident_Char (Character'Val (I +
|
Source (I) := Ident_Char (Character'Val (I +
|
Character'Pos ('A') - Source'First));
|
Character'Pos ('A') - Source'First));
|
end loop;
|
end loop;
|
-- and W with "ABC..."
|
-- and W with "ABC..."
|
for I in Wide_Source'Range loop
|
for I in Wide_Source'Range loop
|
Wide_Source (I) := Ident_Wide_Char (Wide_Character'Val (I +
|
Wide_Source (I) := Ident_Wide_Char (Wide_Character'Val (I +
|
Wide_Character'Pos ('A') - Wide_Source'First));
|
Wide_Character'Pos ('A') - Wide_Source'First));
|
end loop;
|
end loop;
|
|
|
X := Bs.To_Bounded_String (Source);
|
X := Bs.To_Bounded_String (Source);
|
|
|
begin
|
begin
|
declare
|
declare
|
S : constant String :=
|
S : constant String :=
|
Bs.Slice (X, Low => Ident_Int (28), High => Ident_Int (41));
|
Bs.Slice (X, Low => Ident_Int (28), High => Ident_Int (41));
|
begin
|
begin
|
Failed ("No exception raised by Slice - 1");
|
Failed ("No exception raised by Slice - 1");
|
if S = Source then
|
if S = Source then
|
Comment ("Don't optimize S");
|
Comment ("Don't optimize S");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when Index_Error =>
|
when Index_Error =>
|
null; -- Expected exception.
|
null; -- Expected exception.
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 1");
|
" - " & Exception_Message (E) & " - 1");
|
end;
|
end;
|
|
|
begin
|
begin
|
declare
|
declare
|
S : constant String :=
|
S : constant String :=
|
Bs.Slice (X, Low => Ident_Int (8), High => Ident_Int (31));
|
Bs.Slice (X, Low => Ident_Int (8), High => Ident_Int (31));
|
begin
|
begin
|
Failed ("No exception raised by Slice - 2");
|
Failed ("No exception raised by Slice - 2");
|
if S = Source then
|
if S = Source then
|
Comment ("Don't optimize S");
|
Comment ("Don't optimize S");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when Index_Error =>
|
when Index_Error =>
|
null; -- Expected exception.
|
null; -- Expected exception.
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 2");
|
" - " & Exception_Message (E) & " - 2");
|
end;
|
end;
|
|
|
begin
|
begin
|
declare
|
declare
|
S : constant String :=
|
S : constant String :=
|
Bs.Slice (X, Low => Ident_Int (15), High => Ident_Int (30));
|
Bs.Slice (X, Low => Ident_Int (15), High => Ident_Int (30));
|
begin
|
begin
|
if S /= Source(15..30) then
|
if S /= Source(15..30) then
|
Failed ("Wrong result - 3");
|
Failed ("Wrong result - 3");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 3");
|
" - " & Exception_Message (E) & " - 3");
|
end;
|
end;
|
|
|
begin
|
begin
|
declare
|
declare
|
S : constant String :=
|
S : constant String :=
|
Bs.Slice (X, Low => Ident_Int (42), High => Ident_Int (28));
|
Bs.Slice (X, Low => Ident_Int (42), High => Ident_Int (28));
|
begin
|
begin
|
Failed ("No exception raised by Slice - 4");
|
Failed ("No exception raised by Slice - 4");
|
if S = Source then
|
if S = Source then
|
Comment ("Don't optimize S");
|
Comment ("Don't optimize S");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when Index_Error =>
|
when Index_Error =>
|
null; -- Expected exception.
|
null; -- Expected exception.
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 4");
|
" - " & Exception_Message (E) & " - 4");
|
end;
|
end;
|
|
|
begin
|
begin
|
declare
|
declare
|
S : constant String :=
|
S : constant String :=
|
Bs.Slice (X, Low => Ident_Int (31), High => Ident_Int (28));
|
Bs.Slice (X, Low => Ident_Int (31), High => Ident_Int (28));
|
begin
|
begin
|
if S /= "" then
|
if S /= "" then
|
Failed ("Wrong result - 5");
|
Failed ("Wrong result - 5");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 5");
|
" - " & Exception_Message (E) & " - 5");
|
end;
|
end;
|
|
|
begin
|
begin
|
declare
|
declare
|
S : constant String :=
|
S : constant String :=
|
Bs.Slice (X, Low => Ident_Int (30), High => Ident_Int (30));
|
Bs.Slice (X, Low => Ident_Int (30), High => Ident_Int (30));
|
begin
|
begin
|
if S /= Source(30..30) then
|
if S /= Source(30..30) then
|
Failed ("Wrong result - 6");
|
Failed ("Wrong result - 6");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 6");
|
" - " & Exception_Message (E) & " - 6");
|
end;
|
end;
|
|
|
WX := WBs.To_Bounded_Wide_String (Wide_Source);
|
WX := WBs.To_Bounded_Wide_String (Wide_Source);
|
|
|
begin
|
begin
|
declare
|
declare
|
W : constant Wide_String :=
|
W : constant Wide_String :=
|
WBs.Slice (WX, Low => Ident_Int (21), High => Ident_Int (33));
|
WBs.Slice (WX, Low => Ident_Int (21), High => Ident_Int (33));
|
begin
|
begin
|
Failed ("No exception raised by Slice - 7");
|
Failed ("No exception raised by Slice - 7");
|
if W = Wide_Source then
|
if W = Wide_Source then
|
Comment ("Don't optimize W");
|
Comment ("Don't optimize W");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when Index_Error =>
|
when Index_Error =>
|
null; -- Expected exception.
|
null; -- Expected exception.
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 7");
|
" - " & Exception_Message (E) & " - 7");
|
end;
|
end;
|
|
|
begin
|
begin
|
declare
|
declare
|
W : constant Wide_String :=
|
W : constant Wide_String :=
|
WBs.Slice (WX, Low => Ident_Int (8), High => Ident_Int (25));
|
WBs.Slice (WX, Low => Ident_Int (8), High => Ident_Int (25));
|
begin
|
begin
|
Failed ("No exception raised by Slice - 8");
|
Failed ("No exception raised by Slice - 8");
|
if W = Wide_Source then
|
if W = Wide_Source then
|
Comment ("Don't optimize W");
|
Comment ("Don't optimize W");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when Index_Error =>
|
when Index_Error =>
|
null; -- Expected exception.
|
null; -- Expected exception.
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 8");
|
" - " & Exception_Message (E) & " - 8");
|
end;
|
end;
|
|
|
begin
|
begin
|
declare
|
declare
|
W : constant Wide_String :=
|
W : constant Wide_String :=
|
WBs.Slice (WX, Low => Ident_Int (15), High => Ident_Int (24));
|
WBs.Slice (WX, Low => Ident_Int (15), High => Ident_Int (24));
|
begin
|
begin
|
if W /= Wide_Source(15..24) then
|
if W /= Wide_Source(15..24) then
|
Failed ("Wrong result - 8");
|
Failed ("Wrong result - 8");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 9");
|
" - " & Exception_Message (E) & " - 9");
|
end;
|
end;
|
|
|
begin
|
begin
|
declare
|
declare
|
W : constant Wide_String :=
|
W : constant Wide_String :=
|
WBs.Slice (WX, Low => Ident_Int (36), High => Ident_Int (20));
|
WBs.Slice (WX, Low => Ident_Int (36), High => Ident_Int (20));
|
begin
|
begin
|
Failed ("No exception raised by Slice - 10");
|
Failed ("No exception raised by Slice - 10");
|
if W = Wide_Source then
|
if W = Wide_Source then
|
Comment ("Don't optimize W");
|
Comment ("Don't optimize W");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when Index_Error =>
|
when Index_Error =>
|
null; -- Expected exception.
|
null; -- Expected exception.
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 10");
|
" - " & Exception_Message (E) & " - 10");
|
end;
|
end;
|
|
|
begin
|
begin
|
declare
|
declare
|
W : constant Wide_String :=
|
W : constant Wide_String :=
|
WBs.Slice (WX, Low => Ident_Int (25), High => Ident_Int (21));
|
WBs.Slice (WX, Low => Ident_Int (25), High => Ident_Int (21));
|
begin
|
begin
|
if W /= "" then
|
if W /= "" then
|
Failed ("Wrong result - 11");
|
Failed ("Wrong result - 11");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 11");
|
" - " & Exception_Message (E) & " - 11");
|
end;
|
end;
|
|
|
begin
|
begin
|
declare
|
declare
|
W : constant Wide_String :=
|
W : constant Wide_String :=
|
WBs.Slice (WX, Low => Ident_Int (24), High => Ident_Int (24));
|
WBs.Slice (WX, Low => Ident_Int (24), High => Ident_Int (24));
|
begin
|
begin
|
if W /= Wide_Source(24..24) then
|
if W /= Wide_Source(24..24) then
|
Failed ("Wrong result - 12");
|
Failed ("Wrong result - 12");
|
end if;
|
end if;
|
end;
|
end;
|
exception
|
exception
|
when E: others =>
|
when E: others =>
|
Failed ("Exception raised - " & Exception_Name (E) &
|
Failed ("Exception raised - " & Exception_Name (E) &
|
" - " & Exception_Message (E) & " - 12");
|
" - " & Exception_Message (E) & " - 12");
|
end;
|
end;
|
|
|
Result;
|
Result;
|
end CXA4034;
|
end CXA4034;
|
|
|
|
|