blob: d6dcd30f3cd1aceecdaf3e0864d480ff307a34d5 [file] [log] [blame]
David Brazdilfc6a86a2015-06-26 10:33:45 +00001/*
2 * Copyright (C) 2015 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
David Brazdil77a48ae2015-09-15 12:34:04 +000017import java.lang.reflect.Method;
18
David Brazdilfc6a86a2015-06-26 10:33:45 +000019public class Main {
20
21 // Workaround for b/18051191.
22 class InnerClass {}
23
David Brazdil77a48ae2015-09-15 12:34:04 +000024 public enum TestPath {
25 ExceptionalFlow1(true, false, 3),
26 ExceptionalFlow2(false, true, 8),
27 NormalFlow(false, false, 42);
28
29 TestPath(boolean arg1, boolean arg2, int expected) {
30 this.arg1 = arg1;
31 this.arg2 = arg2;
32 this.expected = expected;
33 }
34
35 public boolean arg1;
36 public boolean arg2;
37 public int expected;
38 }
39
40 public static void testMethod(String method) throws Exception {
41 Class<?> c = Class.forName("Runtime");
Andreas Gampe166aaee2016-07-18 08:27:23 -070042 Method m = c.getMethod(method, boolean.class, boolean.class);
David Brazdil77a48ae2015-09-15 12:34:04 +000043
44 for (TestPath path : TestPath.values()) {
45 Object[] arguments = new Object[] { path.arg1, path.arg2 };
46 int actual = (Integer) m.invoke(null, arguments);
47
48 if (actual != path.expected) {
49 throw new Error("Method: \"" + method + "\", path: " + path + ", " +
50 "expected: " + path.expected + ", actual: " + actual);
51 }
52 }
53 }
54
55 public static void main(String[] args) throws Exception {
56 testMethod("testUseAfterCatch_int");
57 testMethod("testUseAfterCatch_long");
58 testMethod("testUseAfterCatch_float");
59 testMethod("testUseAfterCatch_double");
60 testMethod("testCatchPhi_const");
61 testMethod("testCatchPhi_int");
62 testMethod("testCatchPhi_long");
63 testMethod("testCatchPhi_float");
64 testMethod("testCatchPhi_double");
65 testMethod("testCatchPhi_singleSlot");
66 testMethod("testCatchPhi_doubleSlot");
67 }
David Brazdilfc6a86a2015-06-26 10:33:45 +000068}