changeset 11:16e8d2a2f373

meth: MethodHandles.spreadArguments passes unit test
author jrose
date Wed, 27 May 2009 02:15:28 -0700
parents 663ab03c3b69
children d6e69f64cd3e
files netbeans/meth/test/jdk/java/dyn/MethodHandlesTest.java
diffstat 1 files changed, 32 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/netbeans/meth/test/jdk/java/dyn/MethodHandlesTest.java	Tue May 26 18:14:49 2009 -0700
+++ b/netbeans/meth/test/jdk/java/dyn/MethodHandlesTest.java	Wed May 27 02:15:28 2009 -0700
@@ -39,6 +39,7 @@
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
+import sun.dyn.util.ValueConversions;
 import static org.junit.Assert.*;
 
 /**
@@ -636,15 +637,39 @@
         System.out.print(':');
     }
 
-    @Test @Ignore("unimplemented")
+    @Test
     public void testSpreadArguments() {
+        if (CAN_SKIP_WORKING)  return;
         System.out.println("spreadArguments");
-        MethodHandle target = null;
-        MethodType newType = null;
-        MethodHandle expResult = null;
-        MethodHandle result = MethodHandles.spreadArguments(target, newType);
-        assertEquals(expResult, result);
-        fail("The test case is a prototype.");
+        for (int i = 0; i < 10; i++) {
+            Object[] args = new Object[i];
+            for (int j = 0; j < args.length; j++)
+                args[j] = randomArg(Integer.class);
+            MethodHandle target = ValueConversions.varargsArray(i);
+            // make sure the target does what we think it does:
+            if (i < 5) {
+                Object[] check = (Object[]) MethodHandles.invoke(target, args);
+                assertArrayEquals(args, check);
+                switch (i) {
+                    case 0:
+                        check = target.<Object[]>invoke();
+                        assertArrayEquals(args, check);
+                        break;
+                    case 1:
+                        check = target.<Object[]>invoke(args[0]);
+                        assertArrayEquals(args, check);
+                        break;
+                    case 2:
+                        check = target.<Object[]>invoke(args[0], args[1]);
+                        assertArrayEquals(args, check);
+                        break;
+                }
+            }
+            MethodType newType = MethodType.make(Object.class, Object[].class);
+            MethodHandle result = MethodHandles.spreadArguments(target, newType);
+            Object[] returnValue = (Object[]) result.invoke((Object)args);
+            assertArrayEquals(args, returnValue);
+        }
     }
 
     @Test @Ignore("unimplemented")