OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [cxa/] [cxa4002.a] - Diff between revs 154 and 816

Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
-- CXA4002.A
-- CXA4002.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.Fixed are
--      Check that the subprograms defined in package Ada.Strings.Fixed are
--      available, and that they produce correct results.  Specifically,
--      available, and that they produce correct results.  Specifically,
--      check the subprograms Index, "*" (string constructor function),
--      check the subprograms Index, "*" (string constructor function),
--      Count, Trim, and Replace_Slice.
--      Count, Trim, and Replace_Slice.
--
--
-- TEST DESCRIPTION:
-- TEST DESCRIPTION:
--      This test demonstrates how certain Fixed string functions are used
--      This test demonstrates how certain Fixed string functions are used
--      to eliminate specific substrings from portions of text.  A procedure
--      to eliminate specific substrings from portions of text.  A procedure
--      is defined that will take as parameters a source string along with
--      is defined that will take as parameters a source string along with
--      a substring that is to be completely removed from the source string.
--      a substring that is to be completely removed from the source string.
--      The source string is parsed using the Index function, and any substring
--      The source string is parsed using the Index function, and any substring
--      slices are replaced in the source string by a series of X's (based on
--      slices are replaced in the source string by a series of X's (based on
--      the length of the substring.)
--      the length of the substring.)
--      Three lines of text are provided to this procedure, and the resulting
--      Three lines of text are provided to this procedure, and the resulting
--      substitutions are compared with expected results to validate the
--      substitutions are compared with expected results to validate the
--      string processing.
--      string processing.
--      A global accumulator is updated with the number of occurrences of the
--      A global accumulator is updated with the number of occurrences of the
--      substring in the source string.
--      substring in the source string.
--
--
--
--
-- CHANGE HISTORY:
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--      06 Dec 94   SAIC    ACVC 2.0
--
--
--!
--!
with Ada.Strings;
with Ada.Strings;
with Ada.Strings.Fixed;
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
with Ada.Strings.Maps;
with Report;
with Report;
procedure CXA4002 is
procedure CXA4002 is
begin
begin
   Report.Test ("CXA4002", "Check that the subprograms defined in package "  &
   Report.Test ("CXA4002", "Check that the subprograms defined in package "  &
                           "Ada.Strings.Fixed are available, and that "      &
                           "Ada.Strings.Fixed are available, and that "      &
                           "they produce correct results");
                           "they produce correct results");
   Test_Block:
   Test_Block:
   declare
   declare
      TC_Total : Natural := 0;
      TC_Total : Natural := 0;
      Number_Of_Lines : constant := 3;
      Number_Of_Lines : constant := 3;
      type Restricted_Words_Array_Type is array (1..10) of String (1..10);
      type Restricted_Words_Array_Type is array (1..10) of String (1..10);
      Restricted_Words : Restricted_Words_Array_Type :=
      Restricted_Words : Restricted_Words_Array_Type :=
                           ("   platoon", " marines  ", "  Marines ",
                           ("   platoon", " marines  ", "  Marines ",
                            "north     ", "south     ", "      east",
                            "north     ", "south     ", "      east",
                            "  beach   ", "   airport", "airfield  ",
                            "  beach   ", "   airport", "airfield  ",
                            "     road ");
                            "     road ");
      subtype Line_Of_Text_Type is String(1..25);
      subtype Line_Of_Text_Type is String(1..25);
      type    Page_Of_Text_Type is array (1..Number_Of_Lines)
      type    Page_Of_Text_Type is array (1..Number_Of_Lines)
        of Line_Of_Text_Type;
        of Line_Of_Text_Type;
      Text_Page : Page_Of_Text_Type := ("The platoon of Marines   ",
      Text_Page : Page_Of_Text_Type := ("The platoon of Marines   ",
                                        "moved south on the south ",
                                        "moved south on the south ",
                                        "road to the airfield.    ");
                                        "road to the airfield.    ");
      TC_Revised_Line_1 : constant String := "The XXXXXXX of XXXXXXX   ";
      TC_Revised_Line_1 : constant String := "The XXXXXXX of XXXXXXX   ";
      TC_Revised_Line_2 : constant String := "moved XXXXX on the XXXXX ";
      TC_Revised_Line_2 : constant String := "moved XXXXX on the XXXXX ";
      TC_Revised_Line_3 : constant String := "XXXX to the XXXXXXXX.    ";
      TC_Revised_Line_3 : constant String := "XXXX to the XXXXXXXX.    ";
      ---
      ---
      procedure Censor (Source_String  : in out String;
      procedure Censor (Source_String  : in out String;
                        Pattern_String : in     String) is
                        Pattern_String : in     String) is
         -- Create a replacement string that is the same length as the
         -- Create a replacement string that is the same length as the
         -- pattern string being removed.
         -- pattern string being removed.
         Replacement : constant String :=                              -- "*"
         Replacement : constant String :=                              -- "*"
                         Ada.Strings.Fixed."*"(Pattern_String'Length, 'X');
                         Ada.Strings.Fixed."*"(Pattern_String'Length, 'X');
         Going       : Ada.Strings.Direction := Ada.Strings.Forward;
         Going       : Ada.Strings.Direction := Ada.Strings.Forward;
         Map         : constant Ada.Strings.Maps.Character_Mapping :=
         Map         : constant Ada.Strings.Maps.Character_Mapping :=
                         Ada.Strings.Maps.Identity;
                         Ada.Strings.Maps.Identity;
         Start_Pos,
         Start_Pos,
         Index       : Natural := Source_String'First;
         Index       : Natural := Source_String'First;
      begin  -- Censor
      begin  -- Censor
         -- Accumulate count of total replacement operations.
         -- Accumulate count of total replacement operations.
         TC_Total := TC_Total +                                     -- Count
         TC_Total := TC_Total +                                     -- Count
                       Ada.Strings.Fixed.Count (Source  => Source_String,
                       Ada.Strings.Fixed.Count (Source  => Source_String,
                                                Pattern => Pattern_String,
                                                Pattern => Pattern_String,
                                                Mapping => Map);
                                                Mapping => Map);
         loop
         loop
            Index := Ada.Strings.Fixed.Index                        -- Index
            Index := Ada.Strings.Fixed.Index                        -- Index
                       (Source_String(Start_Pos..Source_String'Last),
                       (Source_String(Start_Pos..Source_String'Last),
                        Pattern_String,
                        Pattern_String,
                        Going,
                        Going,
                        Map);
                        Map);
            exit when Index = 0;   -- No matches, exit loop.
            exit when Index = 0;   -- No matches, exit loop.
            -- if a match was found, modify the substring.
            -- if a match was found, modify the substring.
            Ada.Strings.Fixed.Replace_Slice                   -- Replace_Slice
            Ada.Strings.Fixed.Replace_Slice                   -- Replace_Slice
                                (Source_String,
                                (Source_String,
                                 Index,
                                 Index,
                                 Index + Pattern_String'Length - 1,
                                 Index + Pattern_String'Length - 1,
                                 Replacement);
                                 Replacement);
            Start_Pos := Index + Pattern_String'Length;
            Start_Pos := Index + Pattern_String'Length;
         end loop;
         end loop;
      end Censor;
      end Censor;
   begin
   begin
      -- Invoke Censor subprogram to cleanse text.
      -- Invoke Censor subprogram to cleanse text.
      -- Loop through each line of text, and check for the presence of each
      -- Loop through each line of text, and check for the presence of each
      -- restricted word.
      -- restricted word.
      -- Use the Trim function to eliminate leading or trailing blanks from
      -- Use the Trim function to eliminate leading or trailing blanks from
      -- the restricted word parameters.
      -- the restricted word parameters.
      for Line in 1..Number_Of_Lines loop
      for Line in 1..Number_Of_Lines loop
         for Word in Restricted_Words'Range loop
         for Word in Restricted_Words'Range loop
             Censor (Text_Page(Line),
             Censor (Text_Page(Line),
                     Ada.Strings.Fixed.Trim(Restricted_Words(Word),   -- Trim
                     Ada.Strings.Fixed.Trim(Restricted_Words(Word),   -- Trim
                                            Ada.Strings.Both));
                                            Ada.Strings.Both));
         end loop;
         end loop;
      end loop;
      end loop;
      -- Validate results.
      -- Validate results.
      if TC_Total /= 6 then
      if TC_Total /= 6 then
         Report.Failed ("Incorrect number of substitutions performed");
         Report.Failed ("Incorrect number of substitutions performed");
      end if;
      end if;
      if Text_Page(1) /= TC_Revised_Line_1 then
      if Text_Page(1) /= TC_Revised_Line_1 then
         Report.Failed ("Incorrect substitutions on Line 1");
         Report.Failed ("Incorrect substitutions on Line 1");
      end if;
      end if;
      if Text_Page(2) /= TC_Revised_Line_2 then
      if Text_Page(2) /= TC_Revised_Line_2 then
         Report.Failed ("Incorrect substitutions on Line 2");
         Report.Failed ("Incorrect substitutions on Line 2");
      end if;
      end if;
      if Text_Page(3) /= TC_Revised_Line_3 then
      if Text_Page(3) /= TC_Revised_Line_3 then
         Report.Failed ("Incorrect substitutions on Line 3");
         Report.Failed ("Incorrect substitutions on Line 3");
      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 CXA4002;
end CXA4002;
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.