blob: 636f047195ed0966d251624e6155c684d57dc129 [file] [log] [blame]
Vladimir Marko606c8f02016-11-03 13:01:28 +00001/*
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
17import java.lang.reflect.Method;
18import java.lang.reflect.InvocationTargetException;
19
20public class Main {
21 public static void main(String[] args) throws Exception {
22 Class<?> c = Class.forName("Test");
23 Method test = c.getDeclaredMethod("test", int[].class);
24 assertIntEquals(-2, (int)test.invoke(null, new Object[] { null }));
25 assertIntEquals(-1, (int)test.invoke(null, new Object[] { new int[0] }));
26 assertIntEquals(42, (int)test.invoke(null, new Object[] { new int[] { 42 } }));
27
28 Method test2 = c.getDeclaredMethod("test2", int[].class, int.class);
29 assertIntEquals(-2, (int)test2.invoke(null, new Object[] { null, 0 }));
30 assertIntEquals(-1, (int)test2.invoke(null, new Object[] { new int[0], 0 }));
31 assertIntEquals(-1, (int)test2.invoke(null, new Object[] { new int[0], 1 }));
32 assertIntEquals(3, (int)test2.invoke(null, new Object[] { new int[] { 42 }, 0 }));
33 }
34
35 public static void assertIntEquals(int expected, int result) {
36 if (expected != result) {
37 throw new Error("Expected: " + expected + ", found: " + result);
38 }
39 }
40
41 // Workaround for non-zero field ids offset in dex file with no fields. Bug: 18051191
42 static final boolean dummy = false;
43}