author | jrose |
Wed, 18 Jan 2012 17:34:29 -0800 | |
changeset 11534 | 9949ffb8eb3a |
parent 9646 | 5ebbe5ab084f |
child 13423 | 17843fff200d |
permissions | -rw-r--r-- |
9646 | 1 |
/* |
2 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
package test.sun.invoke.util; |
|
25 |
||
26 |
import sun.invoke.util.ValueConversions; |
|
27 |
import sun.invoke.util.Wrapper; |
|
28 |
import java.lang.invoke.MethodType; |
|
29 |
import java.lang.invoke.MethodHandle; |
|
30 |
import java.io.Serializable; |
|
31 |
import java.util.Arrays; |
|
32 |
import java.util.Collections; |
|
33 |
import org.junit.Test; |
|
34 |
import static org.junit.Assert.*; |
|
35 |
||
36 |
/* @test |
|
37 |
* @summary unit tests for value-type conversion utilities |
|
38 |
* @ignore This test requires a special compilation environment to access sun.inovke.util. Run by hand. |
|
39 |
* @run junit/othervm test.sun.invoke.util.ValueConversionsTest |
|
40 |
* @run junit/othervm |
|
41 |
* -DValueConversionsTest.MAX_ARITY=255 -DValueConversionsTest.START_ARITY=250 |
|
42 |
* test.sun.invoke.util.ValueConversionsTest |
|
43 |
*/ |
|
44 |
||
45 |
// This might take a while and burn lots of metadata: |
|
46 |
// @run junit/othervm -DValueConversionsTest.MAX_ARITY=255 -DValueConversionsTest.EXHAUSTIVE=true test.sun.invoke.util.ValueConversionsTest |
|
47 |
||
48 |
/** |
|
49 |
* |
|
50 |
* @author jrose |
|
51 |
*/ |
|
52 |
public class ValueConversionsTest { |
|
11534
9949ffb8eb3a
7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents:
9646
diff
changeset
|
53 |
private static final Class<?> CLASS = ValueConversionsTest.class; |
9646 | 54 |
private static final int MAX_ARITY = Integer.getInteger(CLASS.getSimpleName()+".MAX_ARITY", 40); |
55 |
private static final int START_ARITY = Integer.getInteger(CLASS.getSimpleName()+".START_ARITY", 0); |
|
56 |
private static final boolean EXHAUSTIVE = Boolean.getBoolean(CLASS.getSimpleName()+".EXHAUSTIVE"); |
|
57 |
||
58 |
@Test |
|
59 |
public void testUnbox() throws Throwable { |
|
60 |
testUnbox(false); |
|
61 |
} |
|
62 |
||
63 |
@Test |
|
64 |
public void testUnboxCast() throws Throwable { |
|
65 |
testUnbox(true); |
|
66 |
} |
|
67 |
||
68 |
private void testUnbox(boolean doCast) throws Throwable { |
|
69 |
//System.out.println("unbox"); |
|
70 |
for (Wrapper dst : Wrapper.values()) { |
|
71 |
//System.out.println(dst); |
|
72 |
for (Wrapper src : Wrapper.values()) { |
|
73 |
testUnbox(doCast, dst, src); |
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { |
|
79 |
boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); |
|
80 |
if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims |
|
81 |
if (dst == Wrapper.OBJECT) |
|
82 |
expectThrow = false; // everything (even VOID==null here) converts to OBJECT |
|
83 |
try { |
|
84 |
for (int n = -5; n < 10; n++) { |
|
85 |
Object box = src.wrap(n); |
|
86 |
switch (src) { |
|
87 |
case VOID: assertEquals(box, null); break; |
|
88 |
case OBJECT: box = box.toString(); break; |
|
89 |
case SHORT: assertEquals(box.getClass(), Short.class); break; |
|
90 |
default: assertEquals(box.getClass(), src.wrapperType()); break; |
|
91 |
} |
|
92 |
MethodHandle unboxer; |
|
93 |
if (doCast) |
|
94 |
unboxer = ValueConversions.unboxCast(dst.primitiveType()); |
|
95 |
else |
|
96 |
unboxer = ValueConversions.unbox(dst.primitiveType()); |
|
97 |
Object expResult = (box == null) ? dst.zero() : dst.wrap(box); |
|
98 |
Object result = null; |
|
99 |
switch (dst) { |
|
100 |
case INT: result = (int) unboxer.invokeExact(box); break; |
|
101 |
case LONG: result = (long) unboxer.invokeExact(box); break; |
|
102 |
case FLOAT: result = (float) unboxer.invokeExact(box); break; |
|
103 |
case DOUBLE: result = (double) unboxer.invokeExact(box); break; |
|
104 |
case CHAR: result = (char) unboxer.invokeExact(box); break; |
|
105 |
case BYTE: result = (byte) unboxer.invokeExact(box); break; |
|
106 |
case SHORT: result = (short) unboxer.invokeExact(box); break; |
|
107 |
case OBJECT: result = (Object) unboxer.invokeExact(box); break; |
|
108 |
case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; |
|
109 |
case VOID: result = null; unboxer.invokeExact(box); break; |
|
110 |
} |
|
111 |
if (expectThrow) { |
|
112 |
expResult = "(need an exception)"; |
|
113 |
} |
|
114 |
assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), |
|
115 |
expResult, result); |
|
116 |
} |
|
117 |
} catch (RuntimeException ex) { |
|
118 |
if (expectThrow) return; |
|
119 |
System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); |
|
120 |
throw ex; |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
@Test |
|
125 |
public void testUnboxRaw() throws Throwable { |
|
126 |
//System.out.println("unboxRaw"); |
|
127 |
for (Wrapper w : Wrapper.values()) { |
|
128 |
if (w == Wrapper.OBJECT) continue; // skip this; no raw form |
|
129 |
//System.out.println(w); |
|
130 |
for (int n = -5; n < 10; n++) { |
|
131 |
Object box = w.wrap(n); |
|
132 |
long expResult = w.unwrapRaw(box); |
|
133 |
Object box2 = w.wrapRaw(expResult); |
|
134 |
assertEquals(box, box2); |
|
135 |
MethodHandle unboxer = ValueConversions.unboxRaw(w.primitiveType()); |
|
136 |
long result = -1; |
|
137 |
switch (w) { |
|
138 |
case INT: result = (int) unboxer.invokeExact(box); break; |
|
139 |
case LONG: result = (long) unboxer.invokeExact(box); break; |
|
140 |
case FLOAT: result = (int) unboxer.invokeExact(box); break; |
|
141 |
case DOUBLE: result = (long) unboxer.invokeExact(box); break; |
|
142 |
case CHAR: result = (int) unboxer.invokeExact(box); break; |
|
143 |
case BYTE: result = (int) unboxer.invokeExact(box); break; |
|
144 |
case SHORT: result = (int) unboxer.invokeExact(box); break; |
|
145 |
case BOOLEAN: result = (int) unboxer.invokeExact(box); break; |
|
146 |
case VOID: result = (int) unboxer.invokeExact(box); break; |
|
147 |
} |
|
148 |
assertEquals("(w,n,box)="+Arrays.asList(w,n,box), |
|
149 |
expResult, result); |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
@Test |
|
155 |
public void testBox() throws Throwable { |
|
156 |
//System.out.println("box"); |
|
157 |
for (Wrapper w : Wrapper.values()) { |
|
158 |
if (w == Wrapper.VOID) continue; // skip this; no unboxed form |
|
159 |
//System.out.println(w); |
|
160 |
for (int n = -5; n < 10; n++) { |
|
161 |
Object box = w.wrap(n); |
|
162 |
MethodHandle boxer = ValueConversions.box(w.primitiveType()); |
|
163 |
Object expResult = box; |
|
164 |
Object result = null; |
|
165 |
switch (w) { |
|
11534
9949ffb8eb3a
7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents:
9646
diff
changeset
|
166 |
case INT: result = boxer.invokeExact(/*int*/n); break; |
9646 | 167 |
case LONG: result = boxer.invokeExact((long)n); break; |
168 |
case FLOAT: result = boxer.invokeExact((float)n); break; |
|
169 |
case DOUBLE: result = boxer.invokeExact((double)n); break; |
|
170 |
case CHAR: result = boxer.invokeExact((char)n); break; |
|
171 |
case BYTE: result = boxer.invokeExact((byte)n); break; |
|
172 |
case SHORT: result = boxer.invokeExact((short)n); break; |
|
173 |
case OBJECT: result = boxer.invokeExact((Object)n); break; |
|
174 |
case BOOLEAN: result = boxer.invokeExact((n & 1) != 0); break; |
|
175 |
} |
|
176 |
assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box), |
|
177 |
expResult, result); |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
@Test |
|
183 |
public void testBoxRaw() throws Throwable { |
|
184 |
//System.out.println("boxRaw"); |
|
185 |
for (Wrapper w : Wrapper.values()) { |
|
186 |
if (w == Wrapper.VOID) continue; // skip this; no unboxed form |
|
187 |
if (w == Wrapper.OBJECT) continue; // skip this; no raw form |
|
188 |
//System.out.println(w); |
|
189 |
for (int n = -5; n < 10; n++) { |
|
190 |
Object box = w.wrap(n); |
|
191 |
long raw = w.unwrapRaw(box); |
|
192 |
Object expResult = box; |
|
193 |
MethodHandle boxer = ValueConversions.boxRaw(w.primitiveType()); |
|
194 |
Object result = null; |
|
195 |
switch (w) { |
|
196 |
case INT: result = boxer.invokeExact((int)raw); break; |
|
197 |
case LONG: result = boxer.invokeExact(raw); break; |
|
198 |
case FLOAT: result = boxer.invokeExact((int)raw); break; |
|
199 |
case DOUBLE: result = boxer.invokeExact(raw); break; |
|
200 |
case CHAR: result = boxer.invokeExact((int)raw); break; |
|
201 |
case BYTE: result = boxer.invokeExact((int)raw); break; |
|
202 |
case SHORT: result = boxer.invokeExact((int)raw); break; |
|
203 |
case BOOLEAN: result = boxer.invokeExact((int)raw); break; |
|
204 |
} |
|
205 |
assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box), |
|
206 |
expResult, result); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
@Test |
|
212 |
public void testReboxRaw() throws Throwable { |
|
213 |
//System.out.println("reboxRaw"); |
|
214 |
for (Wrapper w : Wrapper.values()) { |
|
215 |
Wrapper pw = Wrapper.forPrimitiveType(w.rawPrimitiveType()); |
|
216 |
if (w == Wrapper.VOID) continue; // skip this; no unboxed form |
|
217 |
if (w == Wrapper.OBJECT) continue; // skip this; no raw form |
|
218 |
//System.out.println(w); |
|
219 |
for (int n = -5; n < 10; n++) { |
|
220 |
Object box = w.wrap(n); |
|
221 |
Object raw = pw.wrap(w.unwrapRaw(box)); |
|
222 |
Object expResult = box; |
|
223 |
MethodHandle boxer = ValueConversions.rebox(w.primitiveType()); |
|
224 |
Object result = null; |
|
225 |
switch (w) { |
|
226 |
case INT: result = boxer.invokeExact(raw); break; |
|
227 |
case LONG: result = boxer.invokeExact(raw); break; |
|
228 |
case FLOAT: result = boxer.invokeExact(raw); break; |
|
229 |
case DOUBLE: result = boxer.invokeExact(raw); break; |
|
230 |
case CHAR: result = boxer.invokeExact(raw); break; |
|
231 |
case BYTE: result = boxer.invokeExact(raw); break; |
|
232 |
case SHORT: result = boxer.invokeExact(raw); break; |
|
233 |
case BOOLEAN: result = boxer.invokeExact(raw); break; |
|
234 |
} |
|
235 |
assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box), |
|
236 |
expResult, result); |
|
237 |
} |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
@Test |
|
242 |
public void testCast() throws Throwable { |
|
243 |
//System.out.println("cast"); |
|
244 |
Class<?>[] types = { Object.class, Serializable.class, String.class, Number.class, Integer.class }; |
|
245 |
Object[] objects = { new Object(), Boolean.FALSE, "hello", (Long)12L, (Integer)6 }; |
|
246 |
for (Class<?> dst : types) { |
|
247 |
MethodHandle caster = ValueConversions.cast(dst); |
|
248 |
assertEquals(caster.type(), ValueConversions.identity().type()); |
|
249 |
for (Object obj : objects) { |
|
250 |
Class<?> src = obj.getClass(); |
|
251 |
boolean canCast; |
|
252 |
if (dst.isInterface()) { |
|
253 |
canCast = true; |
|
254 |
} else { |
|
255 |
canCast = dst.isAssignableFrom(src); |
|
256 |
assertEquals(canCast, dst.isInstance(obj)); |
|
257 |
} |
|
258 |
//System.out.println("obj="+obj+" <: dst="+dst); |
|
259 |
try { |
|
260 |
Object result = caster.invokeExact(obj); |
|
261 |
if (canCast) |
|
262 |
assertEquals(obj, result); |
|
263 |
else |
|
264 |
assertEquals("cast should not have succeeded", dst, obj); |
|
265 |
} catch (ClassCastException ex) { |
|
266 |
if (canCast) |
|
267 |
throw ex; |
|
268 |
} |
|
269 |
} |
|
270 |
} |
|
271 |
} |
|
272 |
||
273 |
@Test |
|
274 |
public void testIdentity() throws Throwable { |
|
275 |
//System.out.println("identity"); |
|
276 |
MethodHandle id = ValueConversions.identity(); |
|
277 |
Object expResult = "foo"; |
|
278 |
Object result = id.invokeExact(expResult); |
|
279 |
// compiler bug: ValueConversions.identity().invokeExact("bar"); |
|
280 |
assertEquals(expResult, result); |
|
281 |
} |
|
282 |
||
283 |
@Test |
|
284 |
public void testVarargsArray() throws Throwable { |
|
285 |
//System.out.println("varargsArray"); |
|
286 |
final int MIN = START_ARITY; |
|
287 |
final int MAX = MAX_ARITY-2; // 253+1 would cause parameter overflow with 'this' added |
|
288 |
for (int nargs = MIN; nargs <= MAX; nargs = nextArgCount(nargs, 17, MAX)) { |
|
289 |
MethodHandle target = ValueConversions.varargsArray(nargs); |
|
290 |
Object[] args = new Object[nargs]; |
|
291 |
for (int i = 0; i < nargs; i++) |
|
292 |
args[i] = "#"+i; |
|
293 |
Object res = target.invokeWithArguments(args); |
|
294 |
assertArrayEquals(args, (Object[])res); |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
@Test |
|
299 |
public void testVarargsReferenceArray() throws Throwable { |
|
300 |
//System.out.println("varargsReferenceArray"); |
|
301 |
testTypedVarargsArray(Object[].class); |
|
302 |
testTypedVarargsArray(String[].class); |
|
303 |
testTypedVarargsArray(Number[].class); |
|
304 |
} |
|
305 |
||
306 |
@Test |
|
307 |
public void testVarargsPrimitiveArray() throws Throwable { |
|
308 |
//System.out.println("varargsPrimitiveArray"); |
|
309 |
testTypedVarargsArray(int[].class); |
|
310 |
testTypedVarargsArray(long[].class); |
|
311 |
testTypedVarargsArray(byte[].class); |
|
312 |
testTypedVarargsArray(boolean[].class); |
|
313 |
testTypedVarargsArray(short[].class); |
|
314 |
testTypedVarargsArray(char[].class); |
|
315 |
testTypedVarargsArray(float[].class); |
|
316 |
testTypedVarargsArray(double[].class); |
|
317 |
} |
|
318 |
||
319 |
private static int nextArgCount(int nargs, int density, int MAX) { |
|
320 |
if (EXHAUSTIVE) return nargs + 1; |
|
321 |
if (nargs >= MAX) return Integer.MAX_VALUE; |
|
322 |
int BOT = 20, TOP = MAX-5; |
|
323 |
if (density < 10) { BOT = 10; MAX = TOP-2; } |
|
324 |
if (nargs <= BOT || nargs >= TOP) { |
|
325 |
++nargs; |
|
326 |
} else { |
|
327 |
int bump = Math.max(1, 100 / density); |
|
328 |
nargs += bump; |
|
329 |
if (nargs > TOP) nargs = TOP; |
|
330 |
} |
|
331 |
return nargs; |
|
332 |
} |
|
333 |
||
334 |
private void testTypedVarargsArray(Class<?> arrayType) throws Throwable { |
|
335 |
System.out.println(arrayType.getSimpleName()); |
|
336 |
Class<?> elemType = arrayType.getComponentType(); |
|
337 |
int MIN = START_ARITY; |
|
338 |
int MAX = MAX_ARITY-2; // 253+1 would cause parameter overflow with 'this' added |
|
339 |
int density = 3; |
|
340 |
if (elemType == int.class || elemType == long.class) density = 7; |
|
341 |
if (elemType == long.class || elemType == double.class) { MAX /= 2; MIN /= 2; } |
|
342 |
for (int nargs = MIN; nargs <= MAX; nargs = nextArgCount(nargs, density, MAX)) { |
|
343 |
Object[] args = makeTestArray(elemType, nargs); |
|
344 |
MethodHandle varargsArray = ValueConversions.varargsArray(arrayType, nargs); |
|
345 |
MethodType vaType = varargsArray.type(); |
|
346 |
assertEquals(arrayType, vaType.returnType()); |
|
347 |
if (nargs != 0) { |
|
348 |
assertEquals(elemType, vaType.parameterType(0)); |
|
349 |
assertEquals(elemType, vaType.parameterType(vaType.parameterCount()-1)); |
|
350 |
} |
|
351 |
assertEquals(MethodType.methodType(arrayType, Collections.<Class<?>>nCopies(nargs, elemType)), |
|
352 |
vaType); |
|
353 |
Object res = varargsArray.invokeWithArguments(args); |
|
354 |
String resString = toArrayString(res); |
|
355 |
assertEquals(Arrays.toString(args), resString); |
|
356 |
||
357 |
MethodHandle spreader = varargsArray.asSpreader(arrayType, nargs); |
|
358 |
MethodType stype = spreader.type(); |
|
359 |
assert(stype == MethodType.methodType(arrayType, arrayType)); |
|
360 |
if (nargs <= 5) { |
|
361 |
// invoke target as a spreader also: |
|
11534
9949ffb8eb3a
7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents:
9646
diff
changeset
|
362 |
@SuppressWarnings("cast") |
9646 | 363 |
Object res2 = spreader.invokeWithArguments((Object)res); |
364 |
String res2String = toArrayString(res2); |
|
365 |
assertEquals(Arrays.toString(args), res2String); |
|
366 |
// invoke the spreader on a generic Object[] array; check for error |
|
367 |
try { |
|
368 |
Object res3 = spreader.invokeWithArguments((Object)args); |
|
369 |
String res3String = toArrayString(res3); |
|
370 |
assertTrue(arrayType.getName(), arrayType.isAssignableFrom(Object[].class)); |
|
371 |
assertEquals(Arrays.toString(args), res3String); |
|
372 |
} catch (ClassCastException ex) { |
|
373 |
assertFalse(arrayType.getName(), arrayType.isAssignableFrom(Object[].class)); |
|
374 |
} |
|
375 |
} |
|
376 |
if (nargs == 0) { |
|
377 |
// invoke spreader on null arglist |
|
378 |
Object res3 = spreader.invokeWithArguments((Object)null); |
|
379 |
String res3String = toArrayString(res3); |
|
380 |
assertEquals(Arrays.toString(args), res3String); |
|
381 |
} |
|
382 |
} |
|
383 |
} |
|
384 |
||
385 |
private static Object[] makeTestArray(Class<?> elemType, int len) { |
|
386 |
Wrapper elem = null; |
|
387 |
if (elemType.isPrimitive()) |
|
388 |
elem = Wrapper.forPrimitiveType(elemType); |
|
389 |
else if (Wrapper.isWrapperType(elemType)) |
|
390 |
elem = Wrapper.forWrapperType(elemType); |
|
391 |
Object[] args = new Object[len]; |
|
392 |
for (int i = 0; i < len; i++) { |
|
393 |
Object arg = i * 100; |
|
394 |
if (elem == null) { |
|
395 |
if (elemType == String.class) |
|
396 |
arg = "#"+arg; |
|
397 |
arg = elemType.cast(arg); // just to make sure |
|
398 |
} else { |
|
399 |
switch (elem) { |
|
400 |
case BOOLEAN: arg = (i % 3 == 0); break; |
|
401 |
case CHAR: arg = 'a' + i; break; |
|
402 |
case LONG: arg = (long)i * 1000_000_000; break; |
|
403 |
case FLOAT: arg = (float)i / 100; break; |
|
404 |
case DOUBLE: arg = (double)i / 1000_000; break; |
|
405 |
} |
|
406 |
arg = elem.cast(arg, elemType); |
|
407 |
} |
|
408 |
args[i] = arg; |
|
409 |
} |
|
410 |
//System.out.println(elemType.getName()+Arrays.toString(args)); |
|
411 |
return args; |
|
412 |
} |
|
413 |
||
414 |
private static String toArrayString(Object a) { |
|
415 |
if (a == null) return "null"; |
|
416 |
Class<?> elemType = a.getClass().getComponentType(); |
|
417 |
if (elemType == null) return a.toString(); |
|
418 |
if (elemType.isPrimitive()) { |
|
419 |
switch (Wrapper.forPrimitiveType(elemType)) { |
|
420 |
case INT: return Arrays.toString((int[])a); |
|
421 |
case BYTE: return Arrays.toString((byte[])a); |
|
422 |
case BOOLEAN: return Arrays.toString((boolean[])a); |
|
423 |
case SHORT: return Arrays.toString((short[])a); |
|
424 |
case CHAR: return Arrays.toString((char[])a); |
|
425 |
case FLOAT: return Arrays.toString((float[])a); |
|
426 |
case LONG: return Arrays.toString((long[])a); |
|
427 |
case DOUBLE: return Arrays.toString((double[])a); |
|
428 |
} |
|
429 |
} |
|
430 |
return Arrays.toString((Object[])a); |
|
431 |
} |
|
432 |
||
433 |
@Test |
|
434 |
public void testVarargsList() throws Throwable { |
|
435 |
//System.out.println("varargsList"); |
|
436 |
final int MIN = START_ARITY; |
|
437 |
final int MAX = MAX_ARITY-2; // 253+1 would cause parameter overflow with 'this' added |
|
438 |
for (int nargs = MIN; nargs <= MAX; nargs = nextArgCount(nargs, 7, MAX)) { |
|
439 |
MethodHandle target = ValueConversions.varargsList(nargs); |
|
440 |
Object[] args = new Object[nargs]; |
|
441 |
for (int i = 0; i < nargs; i++) |
|
442 |
args[i] = "#"+i; |
|
443 |
Object res = target.invokeWithArguments(args); |
|
444 |
assertEquals(Arrays.asList(args), res); |
|
445 |
} |
|
446 |
} |
|
447 |
} |