Home | History | Annotate | Download | only in check_cast
      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.check_cast;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.check_cast.d.T_check_cast_1;
     22 import dot.junit.opcodes.check_cast.d.T_check_cast_2;
     23 import dot.junit.opcodes.check_cast.d.T_check_cast_3;
     24 import dot.junit.opcodes.check_cast.d.T_check_cast_7;
     25 
     26 
     27 public class Test_check_cast extends DxTestCase {
     28 
     29 
     30     /**
     31      * @title (String)(Object)String
     32      */
     33     public void testN1() {
     34         T_check_cast_1 t = new T_check_cast_1();
     35         String s = "";
     36         assertEquals(s, t.run(s));
     37     }
     38 
     39     /**
     40      * @title (String)(Object)null
     41      */
     42     public void testN2() {
     43         T_check_cast_1 t = new T_check_cast_1();
     44         assertNull(t.run(null));
     45     }
     46 
     47     /**
     48      * @title check assignment compatibility rules
     49      */
     50     public void testN4() {
     51         T_check_cast_2 t = new T_check_cast_2();
     52         assertEquals(5, t.run());
     53     }
     54 
     55     /**
     56      * @title expected ClassCastException
     57      */
     58     public void testE1() {
     59         T_check_cast_1 t = new T_check_cast_1();
     60         try {
     61             t.run(t);
     62             fail("expected ClassCastException");
     63         } catch (ClassCastException iae) {
     64             // expected
     65         }
     66     }
     67 
     68     /**
     69      * @constraint A18
     70      * @title  constant pool index
     71      */
     72     public void testVFE1() {
     73         try {
     74             Class.forName("dot.junit.opcodes.check_cast.d.T_check_cast_4");
     75             fail("expected a verification exception");
     76         } catch (Throwable t) {
     77             DxUtil.checkVerifyException(t);
     78         }
     79     }
     80 
     81     /**
     82      *
     83      * @constraint B1
     84      * @title  type of argument - int
     85      */
     86     public void testVFE2() {
     87         try {
     88             Class.forName("dot.junit.opcodes.check_cast.d.T_check_cast_5");
     89             fail("expected a verification exception");
     90         } catch (Throwable t) {
     91             DxUtil.checkVerifyException(t);
     92         }
     93     }
     94 
     95     /**
     96      *
     97      * @constraint B1
     98      * @title  type of argument - long
     99      */
    100     public void testVFE3() {
    101         try {
    102             Class.forName("dot.junit.opcodes.check_cast.d.T_check_cast_8");
    103             fail("expected a verification exception");
    104         } catch (Throwable t) {
    105             DxUtil.checkVerifyException(t);
    106         }
    107     }
    108 
    109     /**
    110      *
    111      * @constraint B1
    112      * @title  number of registers
    113      */
    114     public void testVFE4() {
    115         try {
    116             Class.forName("dot.junit.opcodes.check_cast.d.T_check_cast_6");
    117             fail("expected a verification exception");
    118         } catch (Throwable t) {
    119             DxUtil.checkVerifyException(t);
    120         }
    121     }
    122 
    123     /**
    124      * @constraint n/a
    125      * @title Attempt to access inaccessible class, expect throws IllegalAccessError
    126      */
    127     public void testVFE5() {
    128         //@uses dot.junit.opcodes.check_cast.TestStubs
    129         //@uses dot.junit.opcodes.check_cast.d.T_check_cast_3
    130         T_check_cast_3 t = new T_check_cast_3();
    131         try {
    132             t.run();
    133             fail("expected IllegalAccessError");
    134         } catch (IllegalAccessError iae) {
    135             // expected
    136         }
    137     }
    138 
    139     /**
    140      * @constraint n/a
    141      * @title Attempt to access undefined class, expect throws NoClassDefFoundError on
    142      * first access
    143      */
    144     public void testVFE6() {
    145         T_check_cast_7 t = new T_check_cast_7();
    146         try {
    147             t.run();
    148             fail("expected NoClassDefFoundError");
    149         } catch (NoClassDefFoundError iae) {
    150             // expected
    151         }
    152     }
    153 
    154     /**
    155      * @constraint A18
    156      * @title  constant pool type
    157      */
    158     public void testVFE7() {
    159         try {
    160             Class.forName("dot.junit.opcodes.check_cast.d.T_check_cast_9");
    161             fail("expected a verification exception");
    162         } catch (Throwable t) {
    163             DxUtil.checkVerifyException(t);
    164         }
    165     }
    166 
    167 }
    168