OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [cxb/] [cxb3008.a] - Diff between revs 294 and 338

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

Rev 294 Rev 338
-- CXB3008.A
-- CXB3008.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 functions imported from the C language  and
--      Check that functions imported from the C language  and
--       libraries can be called from an Ada program.
--       libraries can be called from an Ada program.
--
--
-- TEST DESCRIPTION:
-- TEST DESCRIPTION:
--      This test checks that C language functions from the  and
--      This test checks that C language functions from the  and
--       libraries can be used as completions of Ada subprograms.
--       libraries can be used as completions of Ada subprograms.
--      A pragma Import with convention identifier "C" is used to complete
--      A pragma Import with convention identifier "C" is used to complete
--      the Ada subprogram specifications.
--      the Ada subprogram specifications.
--      The three subprogram cases tested are as follows:
--      The three subprogram cases tested are as follows:
--      1) A C function that returns an int value (strcpy) is used as the
--      1) A C function that returns an int value (strcpy) is used as the
--         completion of an Ada procedure specification.  The return value
--         completion of an Ada procedure specification.  The return value
--         is discarded; parameter modification is the desired effect.
--         is discarded; parameter modification is the desired effect.
--      2) A C function that returns an int value (strlen) is used as the
--      2) A C function that returns an int value (strlen) is used as the
--         completion of an Ada function specification.
--         completion of an Ada function specification.
--      3) A C function that returns a double value (strtod) is used as the
--      3) A C function that returns a double value (strtod) is used as the
--         completion of an Ada function specification.
--         completion of an Ada function specification.
--
--
--      This test assumes that the following characters are all included
--      This test assumes that the following characters are all included
--      in the implementation defined type Interfaces.C.char:
--      in the implementation defined type Interfaces.C.char:
--      ' ', 'a'..'z', 'A'..'Z', '0'..'9', and '$'.
--      ' ', 'a'..'z', 'A'..'Z', '0'..'9', and '$'.
--
--
-- APPLICABILITY CRITERIA:
-- APPLICABILITY CRITERIA:
--      This test is applicable to all implementations that provide
--      This test is applicable to all implementations that provide
--      packages Interfaces.C and Interfaces.C.Strings.  If an
--      packages Interfaces.C and Interfaces.C.Strings.  If an
--      implementation provides these packages, this test must compile,
--      implementation provides these packages, this test must compile,
--      execute, and report "PASSED".
--      execute, and report "PASSED".
--
--
-- SPECIAL REQUIREMENTS:
-- SPECIAL REQUIREMENTS:
--      The C language library functions used by this test must be
--      The C language library functions used by this test must be
--      available for importing into the test.
--      available for importing into the test.
--
--
--
--
-- CHANGE HISTORY:
-- CHANGE HISTORY:
--      12 Oct 95   SAIC    Initial prerelease version.
--      12 Oct 95   SAIC    Initial prerelease version.
--      09 May 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--      09 May 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--      01 DEC 97   EDS     Replaced all references of C function atof with
--      01 DEC 97   EDS     Replaced all references of C function atof with
--                          C function strtod.
--                          C function strtod.
--      29 JUN 98   EDS     Give Ada function corresponding to strtod a
--      29 JUN 98   EDS     Give Ada function corresponding to strtod a
--                          second parameter.
--                          second parameter.
--!
--!
with Report;
with Report;
with Ada.Exceptions;
with Ada.Exceptions;
with Interfaces.C;                                            -- N/A => ERROR
with Interfaces.C;                                            -- N/A => ERROR
with Interfaces.C.Strings;                                    -- N/A => ERROR
with Interfaces.C.Strings;                                    -- N/A => ERROR
with Interfaces.C.Pointers;
with Interfaces.C.Pointers;
procedure CXB3008 is
procedure CXB3008 is
begin
begin
   Report.Test ("CXB3008", "Check that functions imported from the " &
   Report.Test ("CXB3008", "Check that functions imported from the " &
                           "C language predefined libraries can be " &
                           "C language predefined libraries can be " &
                           "called from an Ada program");
                           "called from an Ada program");
   Test_Block:
   Test_Block:
   declare
   declare
      package IC  renames Interfaces.C;
      package IC  renames Interfaces.C;
      package ICS renames Interfaces.C.Strings;
      package ICS renames Interfaces.C.Strings;
      package ICP is new Interfaces.C.Pointers
      package ICP is new Interfaces.C.Pointers
         ( Index => IC.size_t,
         ( Index => IC.size_t,
           Element => IC.char,
           Element => IC.char,
           Element_Array => IC.char_array,
           Element_Array => IC.char_array,
           Default_Terminator => IC.nul );
           Default_Terminator => IC.nul );
      use Ada.Exceptions;
      use Ada.Exceptions;
      use type IC.char;
      use type IC.char;
      use type IC.char_array;
      use type IC.char_array;
      use type IC.size_t;
      use type IC.size_t;
      use type IC.double;
      use type IC.double;
      -- The String_Copy procedure copies the string pointed to by Source,
      -- The String_Copy procedure copies the string pointed to by Source,
      -- including the terminating nul char, into the char_array pointed
      -- including the terminating nul char, into the char_array pointed
      -- to by Target.
      -- to by Target.
      procedure String_Copy (Target : out IC.char_array;
      procedure String_Copy (Target : out IC.char_array;
                             Source : in  IC.char_array);
                             Source : in  IC.char_array);
      -- The String_Length function returns the length of the nul-terminated
      -- The String_Length function returns the length of the nul-terminated
      -- string pointed to by The_String.  The nul is not included in
      -- string pointed to by The_String.  The nul is not included in
      -- the count.
      -- the count.
      function String_Length (The_String : in IC.char_array)
      function String_Length (The_String : in IC.char_array)
        return IC.size_t;
        return IC.size_t;
      -- The String_To_Double function converts the char_array pointed to
      -- The String_To_Double function converts the char_array pointed to
      -- by The_String into a double value returned through the function
      -- by The_String into a double value returned through the function
      -- name.  The_String must contain a valid floating-point number; if
      -- name.  The_String must contain a valid floating-point number; if
      -- not, the value returned is zero.
      -- not, the value returned is zero.
--      type Acc_ptr is access IC.char_array;
--      type Acc_ptr is access IC.char_array;
      function String_To_Double (The_String : in IC.char_array ;
      function String_To_Double (The_String : in IC.char_array ;
                                 End_Ptr    : ICP.Pointer := null)
                                 End_Ptr    : ICP.Pointer := null)
        return IC.double;
        return IC.double;
      -- Use the  strcpy function as a completion to the procedure
      -- Use the  strcpy function as a completion to the procedure
      -- specification.  Note that the Ada interface to this C function is
      -- specification.  Note that the Ada interface to this C function is
      -- in the form of a procedure (C function return value is not used).
      -- in the form of a procedure (C function return value is not used).
      pragma Import (C, String_Copy, "strcpy");
      pragma Import (C, String_Copy, "strcpy");
      -- Use the  strlen function as a completion to the
      -- Use the  strlen function as a completion to the
      -- String_Length function specification.
      -- String_Length function specification.
      pragma Import (C, String_Length, "strlen");
      pragma Import (C, String_Length, "strlen");
      -- Use the  strtod function as a completion to the
      -- Use the  strtod function as a completion to the
      -- String_To_Double function specification.
      -- String_To_Double function specification.
      pragma Import (C, String_To_Double, "strtod");
      pragma Import (C, String_To_Double, "strtod");
      TC_String     : constant String := "Just a Test";
      TC_String     : constant String := "Just a Test";
      Char_Source   : IC.char_array(0..30);
      Char_Source   : IC.char_array(0..30);
      Char_Target   : IC.char_array(0..30);
      Char_Target   : IC.char_array(0..30);
      Double_Result : IC.double;
      Double_Result : IC.double;
      Source_Ptr,
      Source_Ptr,
      Target_Ptr    : ICS.chars_ptr;
      Target_Ptr    : ICS.chars_ptr;
   begin
   begin
      -- Check that the imported version of C function strcpy produces
      -- Check that the imported version of C function strcpy produces
      -- the correct results.
      -- the correct results.
      Char_Source(0..21) := "Test of Pragma Import" & IC.nul;
      Char_Source(0..21) := "Test of Pragma Import" & IC.nul;
      String_Copy(Char_Target, Char_Source);
      String_Copy(Char_Target, Char_Source);
      if Char_Target(0..21) /= Char_Source(0..21) then
      if Char_Target(0..21) /= Char_Source(0..21) then
         Report.Failed("Incorrect result from the imported version of " &
         Report.Failed("Incorrect result from the imported version of " &
                       "strcpy - 1");
                       "strcpy - 1");
      end if;
      end if;
      if String_Length(Char_Target) /= 21 then
      if String_Length(Char_Target) /= 21 then
         Report.Failed("Incorrect result from the imported version of " &
         Report.Failed("Incorrect result from the imported version of " &
                       "strlen - 1");
                       "strlen - 1");
      end if;
      end if;
      Char_Source(0) := IC.nul;
      Char_Source(0) := IC.nul;
      String_Copy(Char_Target, Char_Source);
      String_Copy(Char_Target, Char_Source);
      if Char_Target(0) /= Char_Source(0) then
      if Char_Target(0) /= Char_Source(0) then
         Report.Failed("Incorrect result from the imported version of " &
         Report.Failed("Incorrect result from the imported version of " &
                       "strcpy - 2");
                       "strcpy - 2");
      end if;
      end if;
      if String_Length(Char_Target) /= 0 then
      if String_Length(Char_Target) /= 0 then
         Report.Failed("Incorrect result from the imported version of " &
         Report.Failed("Incorrect result from the imported version of " &
                       "strlen - 2");
                       "strlen - 2");
      end if;
      end if;
      -- The following chars_ptr designates a char_array of 12 chars
      -- The following chars_ptr designates a char_array of 12 chars
      -- (including the terminating nul char).
      -- (including the terminating nul char).
      Source_Ptr := ICS.New_Char_Array(IC.To_C(TC_String));
      Source_Ptr := ICS.New_Char_Array(IC.To_C(TC_String));
      String_Copy(Char_Target, ICS.Value(Source_Ptr));
      String_Copy(Char_Target, ICS.Value(Source_Ptr));
      Target_Ptr := ICS.New_Char_Array(Char_Target);
      Target_Ptr := ICS.New_Char_Array(Char_Target);
      if ICS.Value(Target_Ptr) /= TC_String then
      if ICS.Value(Target_Ptr) /= TC_String then
         Report.Failed("Incorrect result from the imported version of " &
         Report.Failed("Incorrect result from the imported version of " &
                       "strcpy - 3");
                       "strcpy - 3");
      end if;
      end if;
      if String_Length(ICS.Value(Target_Ptr)) /= TC_String'Length then
      if String_Length(ICS.Value(Target_Ptr)) /= TC_String'Length then
         Report.Failed("Incorrect result from the imported version of " &
         Report.Failed("Incorrect result from the imported version of " &
                       "strlen - 3");
                       "strlen - 3");
      end if;
      end if;
      Char_Source(0..9) := "100.00only";
      Char_Source(0..9) := "100.00only";
      Double_Result := String_To_Double(Char_Source);
      Double_Result := String_To_Double(Char_Source);
      Char_Source(0..13) := "5050.00$$$$$$$";
      Char_Source(0..13) := "5050.00$$$$$$$";
      if Double_Result + String_To_Double(Char_Source) /= 5150.00 then
      if Double_Result + String_To_Double(Char_Source) /= 5150.00 then
         Report.Failed("Incorrect result returned from the imported " &
         Report.Failed("Incorrect result returned from the imported " &
                       "version of function strtod - 1");
                       "version of function strtod - 1");
      end if;
      end if;
      Char_Source(0..9) := "xxx$10.00x";  -- String doesn't contain a
      Char_Source(0..9) := "xxx$10.00x";  -- String doesn't contain a
                                          -- valid floating point value.
                                          -- valid floating point value.
      if String_To_Double(Char_Source) /= 0.0 then
      if String_To_Double(Char_Source) /= 0.0 then
         Report.Failed("Incorrect result returned from the imported " &
         Report.Failed("Incorrect result returned from the imported " &
                       "version of function strtod - 2");
                       "version of function strtod - 2");
      end if;
      end if;
   exception
   exception
      when The_Error : others =>
      when The_Error : others =>
         Report.Failed ("The following exception was raised in the " &
         Report.Failed ("The following exception was raised in the " &
                        "Test_Block: " & Exception_Name(The_Error));
                        "Test_Block: " & Exception_Name(The_Error));
   end Test_Block;
   end Test_Block;
   Report.Result;
   Report.Result;
end CXB3008;
end CXB3008;
 
 

powered by: WebSVN 2.1.0

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