diff options
author | 2018-02-27 20:33:09 -0800 | |
---|---|---|
committer | 2018-03-02 00:10:53 +0000 | |
commit | 74fa8882f6de4d2755917554ab368f9859a5f995 (patch) | |
tree | 007df695b3395c18eaa58bb2a002178faa1d82cf | |
parent | 8dcb3527d416fb63f936a8fbeb7b59abfc2ac446 (diff) |
ART: harden test 044
Ensure that spec-required methods are correctly passed to the
invocation handler.
Do not rely on undefined ordering of methods (and unify the
handling).
Bug: 73888836
Bug: 73901493
Test: art/test/testrunner/testrunner.py -b --host -t 044
Change-Id: I0886bd78f7a45588384c745e38b4a12de4b81934
-rw-r--r-- | test/044-proxy/expected.txt | 8 | ||||
-rw-r--r-- | test/044-proxy/src/BasicTest.java | 19 | ||||
-rw-r--r-- | test/044-proxy/src/MethodComparator.java | 24 | ||||
-rw-r--r-- | test/044-proxy/src/NarrowingTest.java | 1 |
4 files changed, 39 insertions, 13 deletions
diff --git a/test/044-proxy/expected.txt b/test/044-proxy/expected.txt index eed7b7ea6d..9b16113484 100644 --- a/test/044-proxy/expected.txt +++ b/test/044-proxy/expected.txt @@ -42,7 +42,11 @@ Invoke public abstract java.lang.String Shapes.blob() (no args) --- blob Success: method blob res=mix +Invoke public abstract void Trace.getTrace() $PROXY_CLASS_NAME0$.getTrace null:-1 +Invoke public int java.lang.Object.hashCode() +Invoke public boolean java.lang.Object.equals(java.lang.Object) +Invoke public java.lang.String java.lang.Object.toString() Invoke public abstract void Shapes.upChuck() (no args) Got expected ioobe @@ -51,7 +55,7 @@ Invoke public abstract void Shapes.upCheck() throws java.lang.InterruptedExcepti Got expected ie Proxy interfaces: [interface Quads, interface Colors, interface Trace] -Proxy methods: [public final java.lang.String $PROXY_CLASS_NAME0$.blob(), public final double $PROXY_CLASS_NAME0$.blue(int), public final R0a $PROXY_CLASS_NAME0$.checkMe(), public final R0aa $PROXY_CLASS_NAME0$.checkMe(), public final R0base $PROXY_CLASS_NAME0$.checkMe(), public final void $PROXY_CLASS_NAME0$.circle(int), public final boolean $PROXY_CLASS_NAME0$.equals(java.lang.Object), public final void $PROXY_CLASS_NAME0$.getTrace(), public final int $PROXY_CLASS_NAME0$.green(double), public final int $PROXY_CLASS_NAME0$.hashCode(), public final int $PROXY_CLASS_NAME0$.mauve(java.lang.String), public final int $PROXY_CLASS_NAME0$.rectangle(int,int), public final int $PROXY_CLASS_NAME0$.red(float), public final int $PROXY_CLASS_NAME0$.square(int,int), public final java.lang.String $PROXY_CLASS_NAME0$.toString(), public final int $PROXY_CLASS_NAME0$.trapezoid(int,double,int), public final void $PROXY_CLASS_NAME0$.upCheck() throws java.lang.InterruptedException, public final void $PROXY_CLASS_NAME0$.upChuck()] +Proxy methods: [public final R0a $PROXY_CLASS_NAME0$.checkMe(), public final R0aa $PROXY_CLASS_NAME0$.checkMe(), public final R0base $PROXY_CLASS_NAME0$.checkMe(), public final boolean $PROXY_CLASS_NAME0$.equals(java.lang.Object), public final double $PROXY_CLASS_NAME0$.blue(int), public final int $PROXY_CLASS_NAME0$.green(double), public final int $PROXY_CLASS_NAME0$.hashCode(), public final int $PROXY_CLASS_NAME0$.mauve(java.lang.String), public final int $PROXY_CLASS_NAME0$.rectangle(int,int), public final int $PROXY_CLASS_NAME0$.red(float), public final int $PROXY_CLASS_NAME0$.square(int,int), public final int $PROXY_CLASS_NAME0$.trapezoid(int,double,int), public final java.lang.String $PROXY_CLASS_NAME0$.blob(), public final java.lang.String $PROXY_CLASS_NAME0$.toString(), public final void $PROXY_CLASS_NAME0$.circle(int), public final void $PROXY_CLASS_NAME0$.getTrace(), public final void $PROXY_CLASS_NAME0$.upCheck() throws java.lang.InterruptedException, public final void $PROXY_CLASS_NAME0$.upChuck()] Decl annos: [] Param annos (0) : [] Modifiers: 17 @@ -84,7 +88,7 @@ Got expected exception Invoke public abstract void InterfaceW1.bothThrowBase() throws BaseException,SubException,SubSubException (no args) Got expected exception -Proxy methods: [public final boolean $PROXY_CLASS_NAME1$.equals(java.lang.Object), public final java.lang.Object $PROXY_CLASS_NAME1$.foo(), public final java.lang.String $PROXY_CLASS_NAME1$.foo(), public final int $PROXY_CLASS_NAME1$.hashCode(), public final java.lang.String $PROXY_CLASS_NAME1$.toString()] +Proxy methods: [public final boolean $PROXY_CLASS_NAME1$.equals(java.lang.Object), public final int $PROXY_CLASS_NAME1$.hashCode(), public final java.lang.Object $PROXY_CLASS_NAME1$.foo(), public final java.lang.String $PROXY_CLASS_NAME1$.foo(), public final java.lang.String $PROXY_CLASS_NAME1$.toString()] Invocation of public abstract java.lang.String NarrowingTest$I2.foo() Invoking foo using I2 type: hello Invocation of public default java.lang.Object NarrowingTest$I2.foo() diff --git a/test/044-proxy/src/BasicTest.java b/test/044-proxy/src/BasicTest.java index 7f301f667b..c23576c699 100644 --- a/test/044-proxy/src/BasicTest.java +++ b/test/044-proxy/src/BasicTest.java @@ -22,7 +22,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Arrays; -import java.util.Comparator; /** * Do some basic tests. @@ -54,6 +53,11 @@ public class BasicTest { Trace trace = (Trace) proxy; trace.getTrace(); + // Test the proxy spec: These Object functions are supposed to be given to the handler. + int unusedHashCode = ((Object)trace).hashCode(); + boolean unusedEquals = ((Object)trace).equals(trace); + String unusedString = ((Object)trace).toString(); + try { shapes.upChuck(); System.out.println("Didn't get expected exception"); @@ -73,15 +77,7 @@ public class BasicTest { */ System.out.println(""); Method[] methods = proxy.getClass().getDeclaredMethods(); - Arrays.sort(methods, new Comparator<Method>() { - public int compare(Method o1, Method o2) { - int result = o1.getName().compareTo(o2.getName()); - if (result != 0) { - return result; - } - return o1.getReturnType().getName().compareTo(o2.getReturnType().getName()); - } - }); + Arrays.sort(methods, new MethodComparator()); System.out.println("Proxy interfaces: " + Arrays.deepToString(proxy.getClass().getInterfaces())); System.out.println("Proxy methods: " + @@ -239,6 +235,8 @@ class MyInvocationHandler implements InvocationHandler { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + System.out.println("Invoke " + method); + Object result = null; // Trap Object calls. This is important here to avoid a recursive @@ -286,7 +284,6 @@ class MyInvocationHandler implements InvocationHandler { } } - System.out.println("Invoke " + method); if (args == null || args.length == 0) { System.out.println(" (no args)"); } else { diff --git a/test/044-proxy/src/MethodComparator.java b/test/044-proxy/src/MethodComparator.java new file mode 100644 index 0000000000..05583c19fd --- /dev/null +++ b/test/044-proxy/src/MethodComparator.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.lang.reflect.Method; +import java.util.Comparator; + +public class MethodComparator implements Comparator<Method> { + public int compare(Method m1, Method m2) { + return m1.toString().compareTo(m2.toString()); + } +} diff --git a/test/044-proxy/src/NarrowingTest.java b/test/044-proxy/src/NarrowingTest.java index 5b80d7284f..8c597c3786 100644 --- a/test/044-proxy/src/NarrowingTest.java +++ b/test/044-proxy/src/NarrowingTest.java @@ -48,6 +48,7 @@ class NarrowingTest { Main.registerProxyClassName(proxy.getClass().getCanonicalName()); Method[] methods = proxy.getClass().getDeclaredMethods(); + Arrays.sort(methods, new MethodComparator()); System.out.println("Proxy methods: " + Main.replaceProxyClassNamesForOutput(Arrays.deepToString(methods))); |