annotate gcc/testsuite/ada/acats/tests/cxb/cxb30132.am @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- CXB30132.AM
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that imported, user-defined C language functions can be
kono
parents:
diff changeset
28 -- called from an Ada program.
kono
parents:
diff changeset
29 --
kono
parents:
diff changeset
30 -- TEST DESCRIPTION:
kono
parents:
diff changeset
31 -- This test checks that user-defined C language functions can be
kono
parents:
diff changeset
32 -- imported and referenced from an Ada program. Two C language
kono
parents:
diff changeset
33 -- functions are specified in files CXB30130.C and CXB30131.C.
kono
parents:
diff changeset
34 -- These two functions are imported to this test program, using two
kono
parents:
diff changeset
35 -- calls to Pragma Import. Each function is then called in this test,
kono
parents:
diff changeset
36 -- and the results of the call are verified.
kono
parents:
diff changeset
37 --
kono
parents:
diff changeset
38 -- This test assumes that the following characters are all included
kono
parents:
diff changeset
39 -- in the implementation defined type Interfaces.C.char:
kono
parents:
diff changeset
40 -- ' ', 'a'..'z', and 'A'..'Z'.
kono
parents:
diff changeset
41 --
kono
parents:
diff changeset
42 -- APPLICABILITY CRITERIA:
kono
parents:
diff changeset
43 -- This test is applicable to all implementations that provide
kono
parents:
diff changeset
44 -- packages Interfaces.C and Interfaces.C.Strings. If an
kono
parents:
diff changeset
45 -- implementation provides packages Interfaces.C and
kono
parents:
diff changeset
46 -- Interfaces.C.Strings, this test must compile, execute, and
kono
parents:
diff changeset
47 -- report "PASSED".
kono
parents:
diff changeset
48 --
kono
parents:
diff changeset
49 -- SPECIAL REQUIREMENTS:
kono
parents:
diff changeset
50 -- The files CXB30130.C and CXB30131.C must be compiled with a C
kono
parents:
diff changeset
51 -- compiler. Implementation dialects of C may require alteration of
kono
parents:
diff changeset
52 -- the C program syntax (see individual C files).
kono
parents:
diff changeset
53 --
kono
parents:
diff changeset
54 -- Note that the compiled C code must be bound with the compiled Ada
kono
parents:
diff changeset
55 -- code to create an executable image. An implementation must provide
kono
parents:
diff changeset
56 -- the necessary commands to accomplish this.
kono
parents:
diff changeset
57 --
kono
parents:
diff changeset
58 -- Note that the C code included in CXB30130.C and CXB30131.C conforms
kono
parents:
diff changeset
59 -- to ANSI-C. Modifications to these files may be required for other
kono
parents:
diff changeset
60 -- C compilers. An implementation must provide the necessary
kono
parents:
diff changeset
61 -- modifications to satisfy the function requirements.
kono
parents:
diff changeset
62 --
kono
parents:
diff changeset
63 -- TEST FILES:
kono
parents:
diff changeset
64 -- The following files comprise this test:
kono
parents:
diff changeset
65 --
kono
parents:
diff changeset
66 -- CXB30130.C
kono
parents:
diff changeset
67 -- CXB30131.C
kono
parents:
diff changeset
68 -- CXB30132.AM
kono
parents:
diff changeset
69 --
kono
parents:
diff changeset
70 --
kono
parents:
diff changeset
71 -- CHANGE HISTORY:
kono
parents:
diff changeset
72 -- 13 Oct 95 SAIC Initial prerelease version.
kono
parents:
diff changeset
73 -- 13 May 96 SAIC Incorporated reviewer comments for ACVC 2.1.
kono
parents:
diff changeset
74 -- 26 Oct 96 SAIC Incorporated reviewer comments.
kono
parents:
diff changeset
75 --
kono
parents:
diff changeset
76 --!
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 with Report;
kono
parents:
diff changeset
79 with Impdef;
kono
parents:
diff changeset
80 with Interfaces.C; -- N/A => ERROR
kono
parents:
diff changeset
81 with Interfaces.C.Strings; -- N/A => ERROR
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 procedure CXB30132 is
kono
parents:
diff changeset
84 begin
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 Report.Test ("CXB3013", "Check that user-defined C functions can " &
kono
parents:
diff changeset
87 "be imported into an Ada program");
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 Test_Block:
kono
parents:
diff changeset
90 declare
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 package IC renames Interfaces.C;
kono
parents:
diff changeset
93 package ICS renames Interfaces.C.Strings;
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 use type IC.char_array;
kono
parents:
diff changeset
96 use type IC.int;
kono
parents:
diff changeset
97 use type IC.short;
kono
parents:
diff changeset
98 use type IC.C_float;
kono
parents:
diff changeset
99 use type IC.double;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 type Short_Ptr is access all IC.short;
kono
parents:
diff changeset
102 type Float_Ptr is access all IC.C_float;
kono
parents:
diff changeset
103 type Double_Ptr is access all IC.double;
kono
parents:
diff changeset
104 subtype Char_Array_Type is IC.char_array(0..20);
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 TC_Default_int : IC.int := 49;
kono
parents:
diff changeset
107 TC_Default_short : IC.short := 3;
kono
parents:
diff changeset
108 TC_Default_float : IC.C_float := 50.0;
kono
parents:
diff changeset
109 TC_Default_double : IC.double := 1209.0;
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 An_Int_Value : IC.int := TC_Default_int;
kono
parents:
diff changeset
112 A_Short_Value : aliased IC.short := TC_Default_short;
kono
parents:
diff changeset
113 A_Float_Value : aliased IC.C_float := TC_Default_float;
kono
parents:
diff changeset
114 A_Double_Value : aliased IC.double := TC_Default_double;
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 A_Short_Int_Pointer : Short_Ptr := A_Short_Value'access;
kono
parents:
diff changeset
117 A_Float_Pointer : Float_Ptr := A_Float_Value'access;
kono
parents:
diff changeset
118 A_Double_Pointer : Double_Ptr := A_Double_Value'access;
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 Char_Array_1 : Char_Array_Type;
kono
parents:
diff changeset
121 Char_Array_2 : Char_Array_Type;
kono
parents:
diff changeset
122 Char_Pointer : ICS.chars_ptr;
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 TC_Char_Array : constant Char_Array_Type :=
kono
parents:
diff changeset
125 "Look before you leap" & IC.nul;
kono
parents:
diff changeset
126 TC_Return_int : IC.int := 0;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 -- The Square_It function returns the square of the value The_Int
kono
parents:
diff changeset
129 -- through the function name, and returns the square of the other
kono
parents:
diff changeset
130 -- parameters through the parameter list (the last three parameters
kono
parents:
diff changeset
131 -- are access values).
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 function Square_It (The_Int : in IC.int;
kono
parents:
diff changeset
134 The_Short : in Short_Ptr;
kono
parents:
diff changeset
135 The_Float : in Float_Ptr;
kono
parents:
diff changeset
136 The_Double : in Double_Ptr) return IC.int;
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 -- The Combine_Strings function returns the result of the catenation
kono
parents:
diff changeset
139 -- of the two string parameters through the function name.
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 function Combine_Strings (First_Part : in IC.char_array;
kono
parents:
diff changeset
142 Second_Part : in IC.char_array)
kono
parents:
diff changeset
143 return ICS.chars_ptr;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 -- Use the user-defined C function square_it as a completion to the
kono
parents:
diff changeset
147 -- function specification above.
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 pragma Import (Convention => C,
kono
parents:
diff changeset
150 Entity => Square_It,
kono
parents:
diff changeset
151 External_Name => Impdef.CXB30130_External_Name);
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 -- Use the user-defined C function combine_two_strings as a completion
kono
parents:
diff changeset
154 -- to the function specification above.
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 pragma Import (C, Combine_Strings, Impdef.CXB30131_External_Name);
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 begin
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 -- Check that the imported version of C function CXB30130 produces
kono
parents:
diff changeset
162 -- the correct results.
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 TC_Return_int := Square_It (The_Int => An_Int_Value,
kono
parents:
diff changeset
165 The_Short => A_Short_Int_Pointer,
kono
parents:
diff changeset
166 The_Float => A_Float_Pointer,
kono
parents:
diff changeset
167 The_Double => A_Double_Pointer);
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 -- Compare the results with the expected results. Note that in the
kono
parents:
diff changeset
170 -- case of the three "pointer" parameters, the objects being pointed
kono
parents:
diff changeset
171 -- to have been modified as a result of the function.
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 if TC_Return_int /= An_Int_Value * An_Int_Value or
kono
parents:
diff changeset
174 A_Short_Int_Pointer.all /= TC_Default_short * TC_Default_Short or
kono
parents:
diff changeset
175 A_Short_Value /= TC_Default_short * TC_Default_Short or
kono
parents:
diff changeset
176 A_Float_Pointer.all /= TC_Default_float * TC_Default_float or
kono
parents:
diff changeset
177 A_Float_Value /= TC_Default_float * TC_Default_float or
kono
parents:
diff changeset
178 A_Double_Pointer.all /= TC_Default_double * TC_Default_double or
kono
parents:
diff changeset
179 A_Double_Value /= TC_Default_double * TC_Default_double
kono
parents:
diff changeset
180 then
kono
parents:
diff changeset
181 Report.Failed("Incorrect results returned from function square_it");
kono
parents:
diff changeset
182 end if;
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 -- Check that two char_array values are combined by the imported
kono
parents:
diff changeset
186 -- C function CXB30131.
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 Char_Array_1(0..12) := "Look before " & IC.nul;
kono
parents:
diff changeset
189 Char_Array_2(0..8) := "you leap" & IC.nul;
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 Char_Pointer := Combine_Strings (Char_Array_1, Char_Array_2);
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 if ICS.Value(Char_Pointer) /= TC_Char_Array then
kono
parents:
diff changeset
194 Report.Failed("Incorrect value returned from imported function " &
kono
parents:
diff changeset
195 "combine_two_strings");
kono
parents:
diff changeset
196 end if;
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 exception
kono
parents:
diff changeset
200 when others => Report.Failed ("Exception raised in Test_Block");
kono
parents:
diff changeset
201 end Test_Block;
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 Report.Result;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 end CXB30132;