-- CXA4031.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.Unbounded
--      are available, and that they produce correct results. Specifically,
--      check the functions To_Unbounded_String (version with Length
--      parameter), "=", "<", "<=", ">", ">=" (all with String-Unbounded
--      String parameter mix), as well as three versions of Procedure Append.
--
-- TEST DESCRIPTION:
--      This test demonstrates the uses of many of the subprograms defined
--      in package Ada.Strings.Unbounded for use with unbounded strings.
--      The test simulates how unbounded strings could be processed in a
--      user environment, using the subprograms provided in this package.
--
--      This test, when taken in conjunction with tests CXA4010, CXA4011,
--      CXA4030, and CXA4032 will constitute a test of all the functionality
--      contained in package Ada.Strings.Unbounded.  This test uses a variety
--      of the subprograms defined in the unbounded string package in ways
--      typical of common usage.
--
--
-- CHANGE HISTORY:
--      27 Feb 95   SAIC    Initial prerelease version.
--      18 Apr 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--
--!

with Report;
with Ada.Exceptions;
with Ada.Strings.Maps;
with Jwa.Strings;

procedure Test_Jwa_CXA4031 is
begin

   Report.Test ("CXA4031", "Check that the subprograms defined in "        &
                           "package Ada.Strings.Unbounded are available, " &
                           "and that they produce correct results");

   Test_Block:
   declare

      package JS renames Jwa.Strings;
      use JS;
      use Ada.Exceptions;

      subtype LC_Characters is Character range 'a'..'z';

      Null_String       : constant String := "";
      TC_String         : constant String := "A Standard String";

      TC_Unb_String,
      TC_New_Unb_String : JS.String_8 := JS.Null_String_8;

   begin

      -- Function To_Unbounded_String (version with Length parameter)
      -- returns an unbounded string that represents an uninitialized String
      -- whose length is Length.
      -- Note: Unbounded_String length can vary conceptually between 0 and
      --       Natural'Last.

      if JS.Length(JS.Create(Length => 10)) /= 10 or
         JS.Length(JS.Create(1))            /=  1 or
         JS.Length(JS.Create(0))            /=  0 or
         JS.Length(JS."&"(JS.Create(Length => 10),
                   JS."&"(JS.Create(1),
                            JS.Create(0) ))) /= 10+1+0
      then
         Report.Failed
           ("Incorrect results from Function To_Unbounded_String with " &
            "Length parameter");
      end if;


      -- Procedure Append (Unbounded - Unbounded)
      -- Note: For each of the Append procedures, the resulting string
      --       represented by the Source parameter is given by the
      --       concatenation of the original value of Source and the value
      --       of New_Item.

      TC_Unb_String := JS.To_String_8("Sample string of length L");
      TC_New_Unb_String := JS.To_String_8(" and then some");

      JS.Append(Source => TC_Unb_String, New_Item => TC_New_Unb_String);

      if TC_Unb_String /=
         JS.To_String_8("Sample string of length L and then some")
      then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "unbounded string parameters - 1");
      end if;


      TC_Unb_String := JS.To_String_8("Sample string of length L");
      TC_New_Unb_String := JS.Null_String_8;

      JS.Append(TC_Unb_String, TC_New_Unb_String);

      if TC_Unb_String /=
         JS.To_String_8("Sample string of length L")
      then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "unbounded string parameters - 2");
      end if;


      TC_Unb_String := JS.Null_String_8;

      JS.Append(TC_Unb_String,
                 JS.To_String_8("New Unbounded String"));

      if TC_Unb_String /=
         JS.To_String_8("New Unbounded String")
      then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "unbounded string parameters - 3");
      end if;


      -- Procedure Append (Unbounded - String)

      TC_Unb_String := JS.To_String_8("An Unbounded String and ");

      JS.Append(Source => TC_Unb_String, New_Item => TC_String);

      if TC_Unb_String /=
         JS.To_String_8("An Unbounded String and A Standard String")
      then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "an unbounded string parameter and a string "   &
                       "parameter - 1");
      end if;


      TC_Unb_String := JS.To_String_8("An Unbounded String");

      JS.Append(TC_Unb_String, New_Item => Null_String);

      if TC_Unb_String /=
         JS.To_String_8("An Unbounded String")
      then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "an unbounded string parameter and a string "   &
                       "parameter - 2");
      end if;


      TC_Unb_String := JS.Null_String_8;

      JS.Append(TC_Unb_String, TC_String);

      if TC_Unb_String /= JS.To_String_8("A Standard String") then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "an unbounded string parameter and a string "   &
                       "parameter - 3");
      end if;


      -- Procedure Append (Unbounded - Character)

      TC_Unb_String := JS.To_String_8("Lower Case = ");

      for i in LC_Characters'Range loop
         JS.Append(Source => TC_Unb_String, New_Item => LC_Characters(i));
      end loop;

      if TC_Unb_String /=
         JS.To_String_8("Lower Case = abcdefghijklmnopqrstuvwxyz")
      then
         Report.Failed("Incorrect results from Procedure Append with "  &
                       "an unbounded string parameter and a character " &
                       "parameter - 1");
      end if;


      TC_Unb_String := JS.Null_String_8;

      JS.Append(TC_Unb_String, New_Item => 'a');

      if TC_Unb_String /= JS.To_String_8("a") then
         Report.Failed("Incorrect results from Procedure Append with "  &
                       "an unbounded string parameter and a character " &
                       "parameter - 2");
      end if;


      -- Function "="

      TC_Unb_String := JS.To_String_8(TC_String);

      if not (TC_Unb_String = TC_String)                 or  -- (Unb_Str, Str)
         not JS."="("A Standard String", TC_Unb_String) or  -- (Str, Unb_Str)
         not ((JS.Null_String_8 = "") and           -- (Unb_Str, Str)
              ("Test String" =                               -- (Str, Unb_Str)
               JS.To_String_8("Test String")))
      then
         Report.Failed("Incorrect results from function ""="" with " &
                       "string - unbounded string parameter combinations");
      end if;


      -- Function "<"

      if not ("Extra Space" < JS.To_String_8("Extra Space ") and
              JS.To_String_8("tess") < "test"                and
              JS.To_String_8("best") < "test")                or
         JS.Null_String_8            < Null_String            or
         " leading blank"  < JS.To_String_8(" leading blank") or
         "ending blank "   < JS.To_String_8("ending blank ")
      then
         Report.Failed("Incorrect results from function ""<"" with " &
                       "string - unbounded string parameter combinations");
      end if;


      -- Function "<="

      TC_Unb_String := JS.To_String_8("Sample string");

      if TC_Unb_String                 <= "Sample strin" or  -- (Unb_Str, Str)
         "sample string"               <= TC_Unb_String  or  -- (Str, Unb_Str)
         not(JS.Null_String_8 <= "")            or  -- (Unb_Str, Str)
         not("Sample string"           <= TC_Unb_String)     -- (Str, Unb_Str)
      then
         Report.Failed("Incorrect results from function ""<="" with " &
                       "string - unbounded string parameter combinations");
      end if;


      -- Function ">"

      TC_Unb_String := JS.To_String_8("A MUCH LONGER STRING");

      if not ("A much longer string" > TC_Unb_String                  and
              JS.To_String_8(TC_String) > "A Standard Strin" and
              "abcdefgh" > JS.To_String_8("ABCDEFGH"))        or
         JS.Null_String_8 > Null_String
      then
         Report.Failed("Incorrect results from function "">"" with " &
                       "string - unbounded string parameter combinations");
      end if;


      -- Function ">="

      TC_Unb_String := JS.To_String_8(TC_String);

      if not (TC_Unb_String >= TC_String                       and
              Null_String   >= JS.Null_String_8       and
              "test"        >= JS.To_String_8("tess") and
              JS.To_String_8("Programming") >= "PROGRAMMING")
      then
         Report.Failed("Incorrect results from function "">="" with " &
                       "string - unbounded string parameter combinations");
      end if;


   exception
      when The_Error : others =>
         Report.Failed ("The following exception was raised in the " &
                        "Test_Block: " & Exception_Name(The_Error));
   end Test_Block;

   Report.Result;

end Test_Jwa_CXA4031;
