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