Home | History | Annotate | Download | only in src
      1 /*
      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 
     17 import java.lang.reflect.Method;
     18 
     19 public class Main {
     20 
     21   // Workaround for b/18051191.
     22   class InnerClass {}
     23 
     24   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");
     42     Method m = c.getMethod(method, new Class[] { boolean.class, boolean.class });
     43 
     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   }
     68 }
     69