Home | History | Annotate | Download | only in junit
      1 /*
      2  * Copyright (C) 2008 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 package dot.junit;
     18 
     19 public class DxUtil {
     20     private static boolean isDalvik = false;
     21 
     22     static {
     23         /**
     24          * whether in case of a failure, also ClassNotFoundException is accepted.
     25          * this makes sense for invalid classes that got rejected by the dx tools
     26          * and thus do not exist in .dex format, so that this class missing means a
     27          * the expected verify error (though at the dx tool level)
     28          */
     29 //        String acnfS = System.getProperty("acceptCNF");
     30 //        isDalvik = (acnfS != null && acnfS.equals("true"));
     31         //System.out.println("@DX:DxUtil:isDalik="+isDalvik);
     32     }
     33 
     34     public static void checkVerifyException(Throwable t) {
     35         // the dalvik vm and other vm handle verify errors differently (see the dalvik verifier)
     36         // the dalvik vm only throws a VerifyError, whereas other vm can throw all subclasses of
     37         // LinkageError:
     38         // - ClassCircularityError
     39         // - ClassFormatError
     40         // - ExceptionInInitializerError
     41         // - IncompatibleClassChangeError
     42         // - NoClassDefFoundError
     43         // - UnsatisfiedLinkError
     44         // - VerifyError
     45 
     46         // in case we are testing the dalvik, we also accept a ClassNotFoundException,
     47         // since that may happen when a verify error was thrown by the dx tool and thus no
     48         // classes.dex was written at all.
     49         //System.out.println("@dx:debug:isDalvik:"+isDalvik);
     50         /*
     51         if ((t instanceof VerifyError ||
     52                 (isDalvik && t instanceof ClassNotFoundException) ||
     53                 (!isDalvik && !(t instanceof NoClassDefFoundError)
     54                         && t instanceof LinkageError))) {
     55                 // ok, this is what we expected
     56             System.out.println("@dx:debug:vfe-ok: vfe was:"+t.getClass().getName()+", msg:"+t.getMessage());
     57             return;
     58         } else {
     59             throw new RuntimeException("test did not cause the expected verify error, but:"+t.getClass().getName()+", msg:"+t.getMessage());
     60         }
     61 */
     62         if (t instanceof VerifyError || t instanceof java.lang.IncompatibleClassChangeError ||t instanceof ClassNotFoundException) {
     63                 // ok, this is what we expected
     64         } else {
     65             throw new RuntimeException("VerifyError expected", t);
     66         }
     67 
     68     }
     69 }
     70