Nicolas Geoffray | 98e6ce4 | 2016-02-16 18:42:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | import java.lang.reflect.Field; |
| 18 | import java.lang.reflect.Method; |
| 19 | import java.lang.reflect.InvocationTargetException; |
| 20 | |
| 21 | public class Main { |
| 22 | // Workaround for b/18051191. |
| 23 | class Inner {} |
| 24 | |
| 25 | public static native void assertIsInterpreted(); |
| 26 | |
| 27 | private static void assertEqual(String expected, String actual) { |
| 28 | if (!expected.equals(actual)) { |
| 29 | throw new Error("Assertion failed: " + expected + " != " + actual); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | public static void main(String[] args) throws Throwable { |
| 34 | System.loadLibrary(args[0]); |
| 35 | Class<?> c = Class.forName("TestCase"); |
| 36 | int[] array = new int[1]; |
| 37 | |
| 38 | { |
| 39 | Method m = c.getMethod("testNoAlias", int[].class, String.class); |
| 40 | try { |
| 41 | m.invoke(null, new Object[] { array , "foo" }); |
| 42 | throw new Error("Expected AIOOBE"); |
| 43 | } catch (InvocationTargetException e) { |
| 44 | if (!(e.getCause() instanceof ArrayIndexOutOfBoundsException)) { |
| 45 | throw new Error("Expected AIOOBE"); |
| 46 | } |
| 47 | // Ignore |
| 48 | } |
| 49 | Field field = c.getField("staticField"); |
| 50 | assertEqual("foo", (String)field.get(null)); |
| 51 | } |
| 52 | |
| 53 | { |
| 54 | Method m = c.getMethod("testAlias", int[].class, String.class); |
| 55 | try { |
| 56 | m.invoke(null, new Object[] { array, "bar" }); |
| 57 | throw new Error("Expected AIOOBE"); |
| 58 | } catch (InvocationTargetException e) { |
| 59 | if (!(e.getCause() instanceof ArrayIndexOutOfBoundsException)) { |
| 60 | throw new Error("Expected AIOOBE"); |
| 61 | } |
| 62 | // Ignore |
| 63 | } |
| 64 | Field field = c.getField("staticField"); |
| 65 | assertEqual("bar", (String)field.get(null)); |
| 66 | } |
| 67 | } |
| 68 | } |