Home | History | Annotate | Download | only in const_class
      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.opcodes.const_class;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.const_class.d.T_const_class_1;
     22 import dot.junit.opcodes.const_class.d.T_const_class_2;
     23 import dot.junit.opcodes.const_class.d.T_const_class_6;
     24 import dot.junit.opcodes.const_class.d.T_const_class_7;
     25 
     26 public class Test_const_class extends DxTestCase {
     27     /**
     28      * @title const-class v254, java/lang/String
     29      */
     30     public void testN1() {
     31         T_const_class_1 t = new T_const_class_1();
     32         Class c = t.run();
     33         assertEquals(0, c.getCanonicalName().compareTo("java.lang.String"));
     34     }
     35 
     36     /**
     37      * @title const-class v254, I
     38      */
     39     public void testN2() {
     40         T_const_class_2 t = new T_const_class_2();
     41         Class c = t.run();
     42         assertEquals(c.getCanonicalName(), "int");
     43     }
     44 
     45     /**
     46      * @title Class definition not found
     47      */
     48     public void testE1() {
     49         try {
     50             T_const_class_6 t = new T_const_class_6();
     51             t.run();
     52             fail("expected a verification exception");
     53         } catch (NoClassDefFoundError e) {
     54             // expected
     55         } catch(VerifyError e) {
     56             // expected
     57         }
     58     }
     59 
     60     /**
     61      * @title Class is not accessible
     62      */
     63     public void testE2() {
     64         //@uses dot.junit.opcodes.const_class.TestStubs
     65         //@uses dot.junit.opcodes.const_class.d.T_const_class_7
     66         try {
     67             T_const_class_7 t = new T_const_class_7();
     68             t.run();
     69             fail("expected an IllegalAccessError exception");
     70         } catch (IllegalAccessError e) {
     71             // expected
     72         }
     73     }
     74 
     75     /**
     76      * @constraint A23
     77      * @title  number of registers
     78      */
     79     public void testVFE1() {
     80         try {
     81             Class.forName("dot.junit.opcodes.const_class.d.T_const_class_3");
     82             fail("expected a verification exception");
     83         } catch (Throwable t) {
     84             DxUtil.checkVerifyException(t);
     85         }
     86     }
     87 
     88     /**
     89      * @constraint B11
     90      * @title  When writing to a register that is one half of a register
     91      * pair, but not touching the other half, the old register pair gets broken up, and the
     92      * other register involved in it becomes undefined
     93      */
     94     public void testVFE2() {
     95         try {
     96             Class.forName("dot.junit.opcodes.const_class.d.T_const_class_4");
     97             fail("expected a verification exception");
     98         } catch (Throwable t) {
     99             DxUtil.checkVerifyException(t);
    100         }
    101     }
    102 
    103     /**
    104      * @constraint A18
    105      * @title  constant pool index
    106      */
    107     public void testVFE3() {
    108         try {
    109             Class.forName("dot.junit.opcodes.const_class.d.T_const_class_5");
    110             fail("expected a verification exception");
    111         } catch (Throwable t) {
    112             DxUtil.checkVerifyException(t);
    113         }
    114     }
    115 
    116 }
    117