annotate gcc/testsuite/ada/acats/tests/cxb/cxb3016.a @ 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 -- CXB3016.A
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 function Virtual_Length returns the number of elements
kono
parents:
diff changeset
28 -- in the array referenced by the Pointer parameter Ref, up to (but
kono
parents:
diff changeset
29 -- not including) the (first) instance of the element specified in
kono
parents:
diff changeset
30 -- the Terminator parameter.
kono
parents:
diff changeset
31 --
kono
parents:
diff changeset
32 -- Check that the procedure Copy_Terminated_Array copies the array of
kono
parents:
diff changeset
33 -- elements referenced by Pointer parameter Source, into the array
kono
parents:
diff changeset
34 -- pointed to by parameter Target, based on which of the following
kono
parents:
diff changeset
35 -- two scenarios occurs first:
kono
parents:
diff changeset
36 -- 1) copying the Terminator element, or
kono
parents:
diff changeset
37 -- 2) copying the number of elements specified in parameter Limit.
kono
parents:
diff changeset
38 --
kono
parents:
diff changeset
39 -- Check that procedure Copy_Terminated_Array will propagate
kono
parents:
diff changeset
40 -- Dereference_Error if either the Source or Target parameter is null.
kono
parents:
diff changeset
41 --
kono
parents:
diff changeset
42 -- Check that procedure Copy_Array will copy an array of elements
kono
parents:
diff changeset
43 -- of length specified in parameter Length, referenced by the
kono
parents:
diff changeset
44 -- Pointer parameter Source, into the array pointed to by parameter
kono
parents:
diff changeset
45 -- Target.
kono
parents:
diff changeset
46 --
kono
parents:
diff changeset
47 -- Check that procedure Copy_Array will propagate Dereference_Error
kono
parents:
diff changeset
48 -- if either the Source or Target parameter is null.
kono
parents:
diff changeset
49 --
kono
parents:
diff changeset
50 -- TEST DESCRIPTION:
kono
parents:
diff changeset
51 -- This test checks that the function Virtual_Length and the procedures
kono
parents:
diff changeset
52 -- Copy_Terminated_Array and Copy_Array in the generic package
kono
parents:
diff changeset
53 -- Interfaces.C.Pointers will allow the user to manipulate arrays of
kono
parents:
diff changeset
54 -- char and short values through the pointers that reference the
kono
parents:
diff changeset
55 -- arrays.
kono
parents:
diff changeset
56 --
kono
parents:
diff changeset
57 -- Package Interfaces.C.Pointers is instantiated twice, once for
kono
parents:
diff changeset
58 -- short values and once for chars. Pointers from each instantiated
kono
parents:
diff changeset
59 -- package are then used to reference arrays of the appropriate
kono
parents:
diff changeset
60 -- element type. The subprograms under test are used to determine the
kono
parents:
diff changeset
61 -- length, and to copy, either portions or the entire content of the
kono
parents:
diff changeset
62 -- arrays. The results of these operations are then compared against
kono
parents:
diff changeset
63 -- expected results.
kono
parents:
diff changeset
64 --
kono
parents:
diff changeset
65 -- The propagation of Dereference_Error is checked for when either
kono
parents:
diff changeset
66 -- of the two procedures is supplied with a null Pointer parameter.
kono
parents:
diff changeset
67 --
kono
parents:
diff changeset
68 -- This test assumes that the following characters are all included
kono
parents:
diff changeset
69 -- in the implementation defined type Interfaces.C.char:
kono
parents:
diff changeset
70 -- ' ', and 'a'..'z'.
kono
parents:
diff changeset
71 --
kono
parents:
diff changeset
72 -- APPLICABILITY CRITERIA:
kono
parents:
diff changeset
73 -- This test is applicable to all implementations that provide
kono
parents:
diff changeset
74 -- packages Interfaces.C, Interfaces.C.Strings, and
kono
parents:
diff changeset
75 -- Interfaces.C.Pointers. If an implementation provides these packages,
kono
parents:
diff changeset
76 -- this test must compile, execute, and report "PASSED".
kono
parents:
diff changeset
77 --
kono
parents:
diff changeset
78 --
kono
parents:
diff changeset
79 -- CHANGE HISTORY:
kono
parents:
diff changeset
80 -- 01 Feb 96 SAIC Initial release for 2.1
kono
parents:
diff changeset
81 -- 13 May 96 SAIC Incorporated reviewer comments for ACVC 2.1.
kono
parents:
diff changeset
82 -- 26 Oct 96 SAIC Incorporated reviewer comments.
kono
parents:
diff changeset
83 -- 26 Feb 97 PWB.CTA Moved code using null pointer to avoid errors
kono
parents:
diff changeset
84 --!
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 with Report;
kono
parents:
diff changeset
87 with Ada.Exceptions;
kono
parents:
diff changeset
88 with Interfaces.C; -- N/A => ERROR
kono
parents:
diff changeset
89 with Interfaces.C.Pointers; -- N/A => ERROR
kono
parents:
diff changeset
90 with Interfaces.C.Strings; -- N/A => ERROR
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 procedure CXB3016 is
kono
parents:
diff changeset
93 begin
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 Report.Test ("CXB3016", "Check that subprograms Virtual_Length, " &
kono
parents:
diff changeset
96 "Copy_Terminated_Array, and Copy_Array " &
kono
parents:
diff changeset
97 "produce correct results");
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 Test_Block:
kono
parents:
diff changeset
100 declare
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 use Ada.Exceptions;
kono
parents:
diff changeset
103 use Interfaces.C.Strings;
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 use type Interfaces.C.char,
kono
parents:
diff changeset
106 Interfaces.C.char_array,
kono
parents:
diff changeset
107 Interfaces.C.ptrdiff_t,
kono
parents:
diff changeset
108 Interfaces.C.short,
kono
parents:
diff changeset
109 Interfaces.C.size_t;
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 TC_char : Interfaces.C.char := 'a';
kono
parents:
diff changeset
112 TC_ptrdiff_t : Interfaces.C.ptrdiff_t;
kono
parents:
diff changeset
113 TC_Short : Interfaces.C.short := 0;
kono
parents:
diff changeset
114 Min_Array_Size : Interfaces.C.size_t := 0;
kono
parents:
diff changeset
115 Max_Array_Size : Interfaces.C.size_t := 20;
kono
parents:
diff changeset
116 Short_Terminator : Interfaces.C.short := Interfaces.C.short'Last;
kono
parents:
diff changeset
117 Alphabet : constant String := "abcdefghijklmnopqrstuvwxyz";
kono
parents:
diff changeset
118 Blank_String : constant String := " ";
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 type Short_Array_Type is
kono
parents:
diff changeset
121 array (Interfaces.C.size_t range <>) of aliased Interfaces.C.short;
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 Ch_Array : Interfaces.C.char_array
kono
parents:
diff changeset
124 (0..Interfaces.C.size_t(Alphabet'Length)) :=
kono
parents:
diff changeset
125 Interfaces.C.To_C(Alphabet, True);
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 TC_Ch_Array : Interfaces.C.char_array
kono
parents:
diff changeset
128 (0..Interfaces.C.size_t(Blank_String'Length)) :=
kono
parents:
diff changeset
129 Interfaces.C.To_C(Blank_String, True);
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 Short_Array : Short_Array_Type(Min_Array_Size..Max_Array_Size);
kono
parents:
diff changeset
132 TC_Short_Array : Short_Array_Type(Min_Array_Size..Max_Array_Size);
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 package Char_Pointers is new
kono
parents:
diff changeset
136 Interfaces.C.Pointers (Index => Interfaces.C.size_t,
kono
parents:
diff changeset
137 Element => Interfaces.C.char,
kono
parents:
diff changeset
138 Element_Array => Interfaces.C.char_array,
kono
parents:
diff changeset
139 Default_Terminator => Interfaces.C.nul);
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 package Short_Pointers is new
kono
parents:
diff changeset
142 Interfaces.C.Pointers (Index => Interfaces.C.size_t,
kono
parents:
diff changeset
143 Element => Interfaces.C.short,
kono
parents:
diff changeset
144 Element_Array => Short_Array_Type,
kono
parents:
diff changeset
145 Default_Terminator => Short_Terminator);
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 use Short_Pointers, Char_Pointers;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 Short_Ptr : Short_Pointers.Pointer := Short_Array(0)'Access;
kono
parents:
diff changeset
150 TC_Short_Ptr : Short_Pointers.Pointer := TC_Short_Array(0)'Access;
kono
parents:
diff changeset
151 Char_Ptr : Char_Pointers.Pointer := Ch_Array(0)'Access;
kono
parents:
diff changeset
152 TC_Char_Ptr : Char_Pointers.Pointer := TC_Ch_Array(0)'Access;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 begin
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 -- Provide initial values for the array that holds short int values.
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 for i in Min_Array_Size..Max_Array_Size loop
kono
parents:
diff changeset
159 Short_Array(i) := Interfaces.C.short(i);
kono
parents:
diff changeset
160 TC_Short_Array(i) := 100;
kono
parents:
diff changeset
161 end loop;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 -- Set the final element of the short array object to be the "terminator"
kono
parents:
diff changeset
164 -- element used in the instantiation above.
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 Short_Array(Max_Array_Size) := Short_Terminator;
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 -- Check starting pointer positions.
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 if Short_Ptr.all /= 0 or
kono
parents:
diff changeset
171 Char_Ptr.all /= Ch_Array(0)
kono
parents:
diff changeset
172 then
kono
parents:
diff changeset
173 Report.Failed("Incorrect initial value for the first " &
kono
parents:
diff changeset
174 "Char_Array or Short_Array values");
kono
parents:
diff changeset
175 end if;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 -- Check that function Virtual_Length returns the number of elements
kono
parents:
diff changeset
180 -- in the array referenced by the Pointer parameter Ref, up to (but
kono
parents:
diff changeset
181 -- not including) the (first) instance of the element specified in
kono
parents:
diff changeset
182 -- the Terminator parameter.
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 TC_char := 'j';
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 TC_ptrdiff_t := Char_Pointers.Virtual_Length(Ref => Char_Ptr,
kono
parents:
diff changeset
187 Terminator => TC_char);
kono
parents:
diff changeset
188 if TC_ptrdiff_t /= 9 then
kono
parents:
diff changeset
189 Report.Failed("Incorrect result from function Virtual_Length " &
kono
parents:
diff changeset
190 "with Char_ptr parameter - 1");
kono
parents:
diff changeset
191 end if;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 TC_char := Interfaces.C.nul;
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 TC_ptrdiff_t := Char_Pointers.Virtual_Length(Char_Ptr,
kono
parents:
diff changeset
196 Terminator => TC_char);
kono
parents:
diff changeset
197 if TC_ptrdiff_t /= Interfaces.C.ptrdiff_t(Alphabet'Length) then
kono
parents:
diff changeset
198 Report.Failed("Incorrect result from function Virtual_Length " &
kono
parents:
diff changeset
199 "with Char_ptr parameter - 2");
kono
parents:
diff changeset
200 end if;
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 TC_Short := 10;
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 TC_ptrdiff_t := Short_Pointers.Virtual_Length(Short_Ptr, TC_Short);
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 if TC_ptrdiff_t /= 10 then
kono
parents:
diff changeset
207 Report.Failed("Incorrect result from function Virtual_Length " &
kono
parents:
diff changeset
208 "with Short_ptr parameter - 1");
kono
parents:
diff changeset
209 end if;
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 -- Replace an element of the Short_Array with the element used as the
kono
parents:
diff changeset
212 -- terminator of the entire array; now there are two occurrences of the
kono
parents:
diff changeset
213 -- terminator element in the array. The call to Virtual_Length should
kono
parents:
diff changeset
214 -- return the number of array elements prior to the first terminator.
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 Short_Array(5) := Short_Terminator;
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 if Short_Pointers.Virtual_Length(Short_Ptr, Short_Terminator) /= 5
kono
parents:
diff changeset
219 then
kono
parents:
diff changeset
220 Report.Failed("Incorrect result from function Virtual_Length " &
kono
parents:
diff changeset
221 "with Short_ptr parameter - 2");
kono
parents:
diff changeset
222 end if;
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 -- Check that the procedure Copy_Terminated_Array copies the array of
kono
parents:
diff changeset
227 -- elements referenced by Pointer parameter Source, into the array
kono
parents:
diff changeset
228 -- pointed to by parameter Target, based on which of the following
kono
parents:
diff changeset
229 -- two scenarios occurs first:
kono
parents:
diff changeset
230 -- 1) copying the Terminator element, or
kono
parents:
diff changeset
231 -- 2) copying the number of elements specified in parameter Limit.
kono
parents:
diff changeset
232 -- Note: Terminator element must be copied to Target, as well as
kono
parents:
diff changeset
233 -- all array elements prior to the terminator element.
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 if TC_Ch_Array = Ch_Array then
kono
parents:
diff changeset
236 Report.Failed("The two char arrays are equivalent prior to the " &
kono
parents:
diff changeset
237 "call to Copy_Terminated_Array - 1");
kono
parents:
diff changeset
238 end if;
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 -- Case 1: Copying the Terminator Element. (Default terminator)
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 Char_Pointers.Copy_Terminated_Array(Source => Char_Ptr,
kono
parents:
diff changeset
244 Target => TC_Char_Ptr);
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 if TC_Ch_Array /= Ch_Array then
kono
parents:
diff changeset
247 Report.Failed("The two char arrays are not equal following the " &
kono
parents:
diff changeset
248 "call to Copy_Terminated_Array, case of copying " &
kono
parents:
diff changeset
249 "the Terminator Element, using default terminator");
kono
parents:
diff changeset
250 end if;
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 -- Reset the Target Pointer array.
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 TC_Ch_Array := Interfaces.C.To_C(Blank_String, True);
kono
parents:
diff changeset
255 TC_Char_Ptr := TC_Ch_Array(0)'Access;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 if TC_Ch_Array = Ch_Array then
kono
parents:
diff changeset
258 Report.Failed("The two char arrays are equivalent prior to the " &
kono
parents:
diff changeset
259 "call to Copy_Terminated_Array - 2");
kono
parents:
diff changeset
260 end if;
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 -- Case 2: Copying the Terminator Element. (Non-Default terminator)
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 TC_char := 'b'; -- Second char in char_array pointed to by Char_Ptr
kono
parents:
diff changeset
266 Char_Pointers.Copy_Terminated_Array(Source => Char_Ptr,
kono
parents:
diff changeset
267 Target => TC_Char_Ptr,
kono
parents:
diff changeset
268 Terminator => TC_char);
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 if TC_Ch_Array(0) /= Ch_Array(0) or -- Initial value modified.
kono
parents:
diff changeset
271 TC_Ch_Array(1) /= Ch_Array(1) or -- Initial value modified.
kono
parents:
diff changeset
272 TC_Ch_Array(2) = Ch_Array(2) or -- Initial value not modified.
kono
parents:
diff changeset
273 TC_Ch_Array(5) = Ch_Array(5) or -- Initial value not modified.
kono
parents:
diff changeset
274 TC_Ch_Array(15) = Ch_Array(15) or -- Initial value not modified.
kono
parents:
diff changeset
275 TC_Ch_Array(25) = Ch_Array(25) -- Initial value not modified.
kono
parents:
diff changeset
276 then
kono
parents:
diff changeset
277 Report.Failed("The appropriate portions of the two char arrays " &
kono
parents:
diff changeset
278 "are not equal following the call to " &
kono
parents:
diff changeset
279 "Copy_Terminated_Array, case of copying the " &
kono
parents:
diff changeset
280 "Terminator Element, using non-default terminator");
kono
parents:
diff changeset
281 end if;
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 if TC_Short_Array = Short_Array then
kono
parents:
diff changeset
285 Report.Failed("The two short int arrays are equivalent prior " &
kono
parents:
diff changeset
286 "to the call to Copy_Terminated_Array - 1");
kono
parents:
diff changeset
287 end if;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 Short_Pointers.Copy_Terminated_Array(Source => Short_Ptr,
kono
parents:
diff changeset
290 Target => TC_Short_Ptr,
kono
parents:
diff changeset
291 Terminator => 2);
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 if TC_Short_Array(0) /= Short_Array(0) or
kono
parents:
diff changeset
294 TC_Short_Array(1) /= Short_Array(1) or
kono
parents:
diff changeset
295 TC_Short_Array(2) /= Short_Array(2) or
kono
parents:
diff changeset
296 TC_Short_Array(3) /= 100 -- Initial value not modified.
kono
parents:
diff changeset
297 then
kono
parents:
diff changeset
298 Report.Failed("The appropriate portions of the two short int " &
kono
parents:
diff changeset
299 "arrays are not equal following the call to " &
kono
parents:
diff changeset
300 "Copy_Terminated_Array, case of copying the " &
kono
parents:
diff changeset
301 "Terminator Element, using non-default terminator");
kono
parents:
diff changeset
302 end if;
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 -- Case 3: Copying the number of elements specified in parameter Limit.
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 if TC_Short_Array = Short_Array then
kono
parents:
diff changeset
308 Report.Failed("The two short int arrays are equivalent prior " &
kono
parents:
diff changeset
309 "to the call to Copy_Terminated_Array - 2");
kono
parents:
diff changeset
310 end if;
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 TC_ptrdiff_t := 5;
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 Short_Pointers.Copy_Terminated_Array(Source => Short_Ptr,
kono
parents:
diff changeset
315 Target => TC_Short_Ptr,
kono
parents:
diff changeset
316 Limit => TC_ptrdiff_t,
kono
parents:
diff changeset
317 Terminator => Short_Terminator);
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 if TC_Short_Array(0) /= Short_Array(0) or
kono
parents:
diff changeset
320 TC_Short_Array(1) /= Short_Array(1) or
kono
parents:
diff changeset
321 TC_Short_Array(2) /= Short_Array(2) or
kono
parents:
diff changeset
322 TC_Short_Array(3) /= Short_Array(3) or
kono
parents:
diff changeset
323 TC_Short_Array(4) /= Short_Array(4) or
kono
parents:
diff changeset
324 TC_Short_Array(5) /= 100 -- Initial value not modified.
kono
parents:
diff changeset
325 then
kono
parents:
diff changeset
326 Report.Failed("The appropriate portions of the two Short arrays " &
kono
parents:
diff changeset
327 "are not equal following the call to " &
kono
parents:
diff changeset
328 "Copy_Terminated_Array, case of copying the number " &
kono
parents:
diff changeset
329 "of elements specified in parameter Limit");
kono
parents:
diff changeset
330 end if;
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 -- Case 4: Copying the number of elements specified in parameter Limit,
kono
parents:
diff changeset
334 -- which also happens to be the number of elements up to and
kono
parents:
diff changeset
335 -- including the first terminator.
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 -- Reset initial values for the array that holds short int values.
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 for i in Min_Array_Size..Max_Array_Size loop
kono
parents:
diff changeset
340 Short_Array(i) := Interfaces.C.short(i);
kono
parents:
diff changeset
341 TC_Short_Array(i) := 100;
kono
parents:
diff changeset
342 end loop;
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 if TC_Short_Array = Short_Array then
kono
parents:
diff changeset
345 Report.Failed("The two short int arrays are equivalent prior " &
kono
parents:
diff changeset
346 "to the call to Copy_Terminated_Array - 3");
kono
parents:
diff changeset
347 end if;
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 TC_ptrdiff_t := 3; -- Specifies three elements to be copied.
kono
parents:
diff changeset
350 Short_Terminator := 2; -- Value held in Short_Array third element,
kono
parents:
diff changeset
351 -- will serve as the "terminator" element.
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 Short_Pointers.Copy_Terminated_Array(Source => Short_Ptr,
kono
parents:
diff changeset
354 Target => TC_Short_Ptr,
kono
parents:
diff changeset
355 Limit => TC_ptrdiff_t,
kono
parents:
diff changeset
356 Terminator => Short_Terminator);
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 if TC_Short_Array(0) /= Short_Array(0) or -- First element copied.
kono
parents:
diff changeset
359 TC_Short_Array(1) /= Short_Array(1) or -- Second element copied.
kono
parents:
diff changeset
360 TC_Short_Array(2) /= Short_Array(2) or -- Third element copied.
kono
parents:
diff changeset
361 TC_Short_Array(3) /= 100 -- Initial value of fourth element
kono
parents:
diff changeset
362 then -- not modified.
kono
parents:
diff changeset
363 Report.Failed("The appropriate portions of the two Short arrays " &
kono
parents:
diff changeset
364 "are not equal following the call to " &
kono
parents:
diff changeset
365 "Copy_Terminated_Array, case of copying the number " &
kono
parents:
diff changeset
366 "of elements specified in parameter " &
kono
parents:
diff changeset
367 "Limit, which also happens to be the number of " &
kono
parents:
diff changeset
368 "elements up to and including the first terminator");
kono
parents:
diff changeset
369 end if;
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 -- Check that procedure Copy_Terminated_Array will propagate
kono
parents:
diff changeset
374 -- Dereference_Error if either the Source or Target parameter is null.
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 Char_Ptr := null;
kono
parents:
diff changeset
377 begin
kono
parents:
diff changeset
378 Char_Pointers.Copy_Terminated_Array(Char_Ptr, TC_Char_Ptr);
kono
parents:
diff changeset
379 Report.Failed("Dereference_Error not raised by call to " &
kono
parents:
diff changeset
380 "Copy_Terminated_Array with null Source parameter");
kono
parents:
diff changeset
381 if TC_Char_Ptr = null then -- To avoid optimization.
kono
parents:
diff changeset
382 Report.Comment("This should never be printed");
kono
parents:
diff changeset
383 end if;
kono
parents:
diff changeset
384 exception
kono
parents:
diff changeset
385 when Dereference_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
386 when others =>
kono
parents:
diff changeset
387 Report.Failed("Incorrect exception raised by call to " &
kono
parents:
diff changeset
388 "Copy_Terminated_Array with null Source parameter");
kono
parents:
diff changeset
389 end;
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 TC_Short_Ptr := null;
kono
parents:
diff changeset
392 begin
kono
parents:
diff changeset
393 Short_Pointers.Copy_Terminated_Array(Short_Ptr, TC_Short_Ptr);
kono
parents:
diff changeset
394 Report.Failed("Dereference_Error not raised by call to " &
kono
parents:
diff changeset
395 "Copy_Terminated_Array with null Target parameter");
kono
parents:
diff changeset
396 if Short_Ptr = null then -- To avoid optimization.
kono
parents:
diff changeset
397 Report.Comment("This should never be printed");
kono
parents:
diff changeset
398 end if;
kono
parents:
diff changeset
399 exception
kono
parents:
diff changeset
400 when Dereference_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
401 when others =>
kono
parents:
diff changeset
402 Report.Failed("Incorrect exception raised by call to " &
kono
parents:
diff changeset
403 "Copy_Terminated_Array with null Target parameter");
kono
parents:
diff changeset
404 end;
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 -- Check that the procedure Copy_Array will copy the array of
kono
parents:
diff changeset
409 -- elements of length specified in parameter Length, referenced by
kono
parents:
diff changeset
410 -- the Pointer parameter Source, into the array pointed to by
kono
parents:
diff changeset
411 -- parameter Target.
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 -- Reinitialize Target arrays prior to test cases below.
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415 TC_Ch_Array := Interfaces.C.To_C(Blank_String, True);
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 for i in Min_Array_Size..Max_Array_Size loop
kono
parents:
diff changeset
418 TC_Short_Array(i) := 100;
kono
parents:
diff changeset
419 end loop;
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 Char_Ptr := Ch_Array(0)'Access;
kono
parents:
diff changeset
422 TC_Char_Ptr := TC_Ch_Array(0)'Access;
kono
parents:
diff changeset
423 Short_Ptr := Short_Array(0)'Access;
kono
parents:
diff changeset
424 TC_Short_Ptr := TC_Short_Array(0)'Access;
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 TC_ptrdiff_t := 4;
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 Char_Pointers.Copy_Array(Source => Char_Ptr,
kono
parents:
diff changeset
429 Target => TC_Char_Ptr,
kono
parents:
diff changeset
430 Length => TC_ptrdiff_t);
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 if TC_Ch_Array(0) /= Ch_Array(0) or
kono
parents:
diff changeset
433 TC_Ch_Array(1) /= Ch_Array(1) or
kono
parents:
diff changeset
434 TC_Ch_Array(2) /= Ch_Array(2) or
kono
parents:
diff changeset
435 TC_Ch_Array(3) /= Ch_Array(3) or
kono
parents:
diff changeset
436 TC_Ch_Array(4) = Ch_Array(4)
kono
parents:
diff changeset
437 then
kono
parents:
diff changeset
438 Report.Failed("Incorrect result from Copy_Array when using " &
kono
parents:
diff changeset
439 "char pointer arguments, partial array copied");
kono
parents:
diff changeset
440 end if;
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 TC_ptrdiff_t := Interfaces.C.ptrdiff_t(Max_Array_Size) + 1;
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 Short_Pointers.Copy_Array(Short_Ptr, TC_Short_Ptr, TC_ptrdiff_t);
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 if TC_Short_Array /= Short_Array then
kono
parents:
diff changeset
448 Report.Failed("Incorrect result from Copy_Array when using Short " &
kono
parents:
diff changeset
449 "pointer arguments, entire array copied");
kono
parents:
diff changeset
450 end if;
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 -- Check that procedure Copy_Array will propagate Dereference_Error
kono
parents:
diff changeset
455 -- if either the Source or Target parameter is null.
kono
parents:
diff changeset
456
kono
parents:
diff changeset
457 Char_Ptr := null;
kono
parents:
diff changeset
458 begin
kono
parents:
diff changeset
459 Char_Pointers.Copy_Array(Char_Ptr, TC_Char_Ptr, TC_ptrdiff_t);
kono
parents:
diff changeset
460 Report.Failed("Dereference_Error not raised by call to " &
kono
parents:
diff changeset
461 "Copy_Array with null Source parameter");
kono
parents:
diff changeset
462 if TC_Char_Ptr = null then -- To avoid optimization.
kono
parents:
diff changeset
463 Report.Comment("This should never be printed");
kono
parents:
diff changeset
464 end if;
kono
parents:
diff changeset
465 exception
kono
parents:
diff changeset
466 when Dereference_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
467 when others =>
kono
parents:
diff changeset
468 Report.Failed("Incorrect exception raised by call to " &
kono
parents:
diff changeset
469 "Copy_Array with null Source parameter");
kono
parents:
diff changeset
470 end;
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 TC_Short_Ptr := null;
kono
parents:
diff changeset
473 begin
kono
parents:
diff changeset
474 Short_Pointers.Copy_Array(Short_Ptr, TC_Short_Ptr, TC_ptrdiff_t);
kono
parents:
diff changeset
475 Report.Failed("Dereference_Error not raised by call to " &
kono
parents:
diff changeset
476 "Copy_Array with null Target parameter");
kono
parents:
diff changeset
477 if Short_Ptr = null then -- To avoid optimization.
kono
parents:
diff changeset
478 Report.Comment("This should never be printed");
kono
parents:
diff changeset
479 end if;
kono
parents:
diff changeset
480 exception
kono
parents:
diff changeset
481 when Dereference_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
482 when others =>
kono
parents:
diff changeset
483 Report.Failed("Incorrect exception raised by call to " &
kono
parents:
diff changeset
484 "Copy_Array with null Target parameter");
kono
parents:
diff changeset
485 end;
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 -- Check that function Virtual_Length will propagate Dereference_Error
kono
parents:
diff changeset
489 -- if the Source parameter is null.
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 Char_Ptr := null;
kono
parents:
diff changeset
492 begin
kono
parents:
diff changeset
493 TC_ptrdiff_t := Char_Pointers.Virtual_Length(Char_Ptr,
kono
parents:
diff changeset
494 Terminator => TC_char);
kono
parents:
diff changeset
495 Report.Failed("Dereference_Error not raised by call to " &
kono
parents:
diff changeset
496 "Virtual_Length with null Source parameter");
kono
parents:
diff changeset
497 if TC_ptrdiff_t = 100 then -- To avoid optimization.
kono
parents:
diff changeset
498 Report.Comment("This should never be printed");
kono
parents:
diff changeset
499 end if;
kono
parents:
diff changeset
500 exception
kono
parents:
diff changeset
501 when Dereference_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
502 when others =>
kono
parents:
diff changeset
503 Report.Failed("Incorrect exception raised by call to " &
kono
parents:
diff changeset
504 "Virtual_Length with null Source parameter");
kono
parents:
diff changeset
505 end;
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 exception
kono
parents:
diff changeset
509 when The_Error : others =>
kono
parents:
diff changeset
510 Report.Failed ("The following exception was raised in the " &
kono
parents:
diff changeset
511 "Test_Block: " & Exception_Name(The_Error));
kono
parents:
diff changeset
512 end Test_Block;
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 Report.Result;
kono
parents:
diff changeset
515
kono
parents:
diff changeset
516 end CXB3016;