aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Domurad <[email protected]>2013-05-02 10:56:15 -0400
committerAdam Domurad <[email protected]>2013-05-02 10:56:15 -0400
commit41703448b3c6a3ea9ecfc1e622040e977616a2e3 (patch)
tree2d1b987f9ad0d019d19eea737e385ee0c6e9fe3c
parent39eca3bd8d4767bd6e92e29abaaf18b2153d32e1 (diff)
MethodOverloadResolve array casting tests
-rw-r--r--ChangeLog11
-rw-r--r--plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java4
-rw-r--r--tests/netx/unit/sun/applet/MethodOverloadResolverTest.java87
3 files changed, 92 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 8844e39..35ff53e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,17 @@
2013-05-02 Adam Domurad <[email protected]>
* plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java
+ (getBestOverloadMatch): Return null if a valid method was not found.
+ * tests/netx/unit/sun/applet/MethodOverloadResolverTest.java
+ (getResolvedMethod): New, gets ResolvedMethod from array of bundled class,
+ string, and parameters
+ (assertExpectedOverload): New variant that tests exact received values
+ (testArrayToStringResolve): Tests array conversion to String
+ (testArrayToArrayResolve): Tests array conversion to other arrays
+
+2013-05-02 Adam Domurad <[email protected]>
+
+ * plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java
(getCostAndCastedObject): Remove code that had no effect before refactoring.
(getBestOverloadMatch): Move debug-only code to debug if-block.
diff --git a/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java b/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java
index 827f22e..bba1e8a 100644
--- a/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java
+++ b/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java
@@ -227,6 +227,10 @@ public class MethodOverloadResolver {
PluginDebug.debug("*** Warning: Ambiguous overload of ", c.getClass(), "#", cheapestMethod, "!");
}
+ if (cheapestMethod == null) {
+ return null;
+ }
+
return new ResolvedMethod(lowestCost, cheapestMethod, cheapestArgs);
}
diff --git a/tests/netx/unit/sun/applet/MethodOverloadResolverTest.java b/tests/netx/unit/sun/applet/MethodOverloadResolverTest.java
index 8a35045..9917b39 100644
--- a/tests/netx/unit/sun/applet/MethodOverloadResolverTest.java
+++ b/tests/netx/unit/sun/applet/MethodOverloadResolverTest.java
@@ -272,25 +272,41 @@ public class MethodOverloadResolverTest {
return objects.toArray( new Object[0]);
}
- static private void assertExpectedOverload(Object[] params,
- String expectedSignature, int expectedCost) {
- Class<?> c = (Class<?>)params[0];
- String methodName = (String)params[1];
- Object[] args = Arrays.copyOfRange(params, 2, params.length);
+ // Takes {class, method, arguments...} bundled in one array
+ static private ResolvedMethod getResolvedMethod(Object[] methodAndParams) {
+ /* Copy over argument portion (class and method are bundled in same array for convenience) */
+ Class<?> c = (Class<?>)methodAndParams[0];
+ String methodName = (String)methodAndParams[1];
+ /* Copy over argument portion (class and method are bundled in same array for convenience) */
+ Object[] params = Arrays.copyOfRange(methodAndParams, 2, methodAndParams.length);
+
+ return MethodOverloadResolver.getBestMatchMethod(c, methodName, params);
+ }
- ResolvedMethod result = MethodOverloadResolver.getBestMatchMethod(c, methodName, args);
+ /* Assert that the overload completed properly by simply providing a type signature*/
+ static private void assertExpectedOverload(Object[] methodAndParams,
+ String expectedSignature, int expectedCost) {
+ ResolvedMethod result = getResolvedMethod(methodAndParams);
// Check signature array as string for convenience
assertEquals(expectedSignature, simpleSignature(result.getAccessibleObject()));
assertEquals(expectedCost, result.getCost());
}
+ /* Assert that the overload completed by providing the expected objects */
+ static private void assertExpectedOverload(Object[] methodAndParams,
+ Object[] expectedCasts, int expectedCost) {
+
+ ResolvedMethod result = getResolvedMethod(methodAndParams);
+ assertArrayEquals(expectedCasts, result.getCastedParameters());
+ assertEquals(expectedCost, result.getCost());
+ }
+
// Test methods
@Test
public void testMultipleArgResolve() {
- @SuppressWarnings("unused")
abstract class MultipleArg {
public abstract void testmethod(String s, int i);
public abstract void testmethod(String s, Integer i);
@@ -318,7 +334,6 @@ public class MethodOverloadResolverTest {
@Test
public void testBoxedNumberResolve() {
- @SuppressWarnings("unused")
abstract class BoxedNumber {
public abstract void testmethod(Number n);
public abstract void testmethod(Integer i);
@@ -336,7 +351,6 @@ public class MethodOverloadResolverTest {
@Test
public void testPrimitivesResolve() {
- @SuppressWarnings("unused")
abstract class Primitives {
public abstract void testmethod(int i);
public abstract void testmethod(long l);
@@ -365,7 +379,6 @@ public class MethodOverloadResolverTest {
@Test
public void testComplexResolve() {
- @SuppressWarnings("unused")
abstract class Complex {
public abstract void testmethod(float f);
public abstract void testmethod(String s);
@@ -417,4 +430,58 @@ public class MethodOverloadResolverTest {
"FooChild", MethodOverloadResolver.CLASS_SUPERCLASS_COST);
}
+ /*
+ * Test that arrays are casted to strings by using Javascript rules.
+ * Notably, commas have no spacing, and null values are printed as empty strings.
+ */
+ @Test
+ public void testArrayToStringResolve() {
+ abstract class ArrayAsStringResolve {
+ public abstract void testmethod(String stringRepr);
+ }
+
+ final Object[] asStringExpectedResult = {"foo,,bar"};
+
+ assertExpectedOverload(
+ args( ArrayAsStringResolve.class, (Object) new String[] {"foo", null, "bar"}),
+ asStringExpectedResult, MethodOverloadResolver.ARRAY_CAST_COST);
+ }
+
+ /*
+ * Test that arrays are casted to other arrays by recursively invoking the
+ * casting rules on each element.
+ */
+ @Test
+ public void testArrayToArrayResolve() {
+
+ abstract class IntArrayResolve {
+ public abstract void testmethod(int[] intArray);
+ }
+
+ // Note that currently, the only array actually received from the Javascript side is
+ // a String[] array, but this may change.
+ final Object[] intArrayExpectedResult = {new int[] {0, 1, 2}};
+
+ assertExpectedOverload(
+ args(IntArrayResolve.class, (Object) new String[] {null, "1", "2.1"}),
+ intArrayExpectedResult, MethodOverloadResolver.ARRAY_CAST_COST);
+
+ assertExpectedOverload(
+ args(IntArrayResolve.class, new int[] {0, 1, 2}),
+ intArrayExpectedResult, MethodOverloadResolver.ARRAY_CAST_COST);
+
+ assertExpectedOverload(
+ args(IntArrayResolve.class, new double[] {0, 1, 2.1}),
+ intArrayExpectedResult, MethodOverloadResolver.ARRAY_CAST_COST);
+
+ abstract class NestedArrayResolve {
+ public abstract void testmethod(int[][] nestedArray);
+ }
+
+ final Object[] nestedArrayExpectedResult = { new int[][] { {1,1}, {2,2} } };
+
+ assertExpectedOverload(
+ args(NestedArrayResolve.class, (Object) new String[][] { {"1", "1"}, {"2", "2"} }),
+ nestedArrayExpectedResult, MethodOverloadResolver.ARRAY_CAST_COST);
+ }
}