Home | History | Annotate | Download | only in instance_of
      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.instance_of;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.instance_of.d.T_instance_of_1;
     22 import dot.junit.opcodes.instance_of.d.T_instance_of_2;
     23 import dot.junit.opcodes.instance_of.d.T_instance_of_3;
     24 import dot.junit.opcodes.instance_of.d.T_instance_of_7;
     25 
     26 public class Test_instance_of extends DxTestCase {
     27 
     28 
     29     /**
     30      * @title (Object)String instanceof String
     31      */
     32     public void testN1() {
     33         T_instance_of_1 t = new T_instance_of_1();
     34         String s = "";
     35         assertTrue(t.run(s));
     36     }
     37 
     38     /**
     39      * @title null instanceof String
     40      */
     41     public void testN2() {
     42         T_instance_of_1 t = new T_instance_of_1();
     43         assertFalse(t.run(null));
     44     }
     45 
     46     /**
     47      * @title check assignment compatibility rules
     48      */
     49     public void testN4() {
     50         T_instance_of_2 t = new T_instance_of_2();
     51         assertTrue(t.run());
     52     }
     53 
     54     /**
     55      * @title T_instance_of_1 instanceof String
     56      */
     57     public void testE1() {
     58         T_instance_of_1 t = new T_instance_of_1();
     59         assertFalse(t.run(t));
     60     }
     61 
     62     /**
     63      * @title Attempt to access inaccessible class.
     64      */
     65     public void testE2() {
     66         //@uses dot.junit.opcodes.instance_of.TestStubs
     67         //@uses dot.junit.opcodes.instance_of.d.T_instance_of_3
     68         try {
     69             T_instance_of_3 tt = new T_instance_of_3();
     70             tt.run();
     71             fail("expected IllegalAccessError");
     72         } catch (IllegalAccessError e) {
     73         }
     74     }
     75 
     76     /**
     77      * @title Attempt to access undefined class.
     78      */
     79     public void testE3() {
     80         try {
     81             T_instance_of_7 tt = new T_instance_of_7();
     82             tt.run();
     83             fail("expected a verification exception");
     84         } catch (NoClassDefFoundError e) {
     85             // expected
     86         } catch(VerifyError e) {
     87             // expected
     88         }
     89     }
     90 
     91     /**
     92      * @constraint A19
     93      * @title constant pool index
     94      */
     95     public void testVFE1() {
     96         try {
     97             Class.forName("dot.junit.opcodes.instance_of.d.T_instance_of_4");
     98             fail("expected a verification exception");
     99         } catch (Throwable t) {
    100             DxUtil.checkVerifyException(t);
    101         }
    102     }
    103 
    104     /**
    105      *
    106      * @constraint B1
    107      * @title type of argument - int
    108      */
    109     public void testVFE2() {
    110         try {
    111             Class.forName("dot.junit.opcodes.instance_of.d.T_instance_of_5");
    112             fail("expected a verification exception");
    113         } catch (Throwable t) {
    114             DxUtil.checkVerifyException(t);
    115         }
    116     }
    117 
    118     /**
    119      *
    120      * @constraint B1
    121      * @title type of argument - long
    122      */
    123     public void testVFE3() {
    124         try {
    125             Class.forName("dot.junit.opcodes.instance_of.d.T_instance_of_8");
    126             fail("expected a verification exception");
    127         } catch (Throwable t) {
    128             DxUtil.checkVerifyException(t);
    129         }
    130     }
    131 
    132     /**
    133      *
    134      * @constraint B1
    135      * @title number of registers
    136      */
    137     public void testVFE4() {
    138         try {
    139             Class.forName("dot.junit.opcodes.instance_of.d.T_instance_of_6");
    140             fail("expected a verification exception");
    141         } catch (Throwable t) {
    142             DxUtil.checkVerifyException(t);
    143         }
    144     }
    145 
    146 
    147 }
    148