Home | History | Annotate | Download | only in iget
      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.iget;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.iget.d.T_iget_1;
     22 import dot.junit.opcodes.iget.d.T_iget_11;
     23 import dot.junit.opcodes.iget.d.T_iget_12;
     24 import dot.junit.opcodes.iget.d.T_iget_13;
     25 import dot.junit.opcodes.iget.d.T_iget_2;
     26 import dot.junit.opcodes.iget.d.T_iget_21;
     27 import dot.junit.opcodes.iget.d.T_iget_5;
     28 import dot.junit.opcodes.iget.d.T_iget_6;
     29 import dot.junit.opcodes.iget.d.T_iget_7;
     30 import dot.junit.opcodes.iget.d.T_iget_8;
     31 import dot.junit.opcodes.iget.d.T_iget_9;
     32 
     33 public class Test_iget extends DxTestCase {
     34 
     35     /**
     36      * @title type - int
     37      */
     38     public void testN1() {
     39         T_iget_1 t = new T_iget_1();
     40         assertEquals(5, t.run());
     41     }
     42 
     43     /**
     44      * @title type - float
     45      */
     46     public void testN2() {
     47         T_iget_2 t = new T_iget_2();
     48         assertEquals(123f, t.run());
     49     }
     50 
     51     /**
     52      * @title access protected field from subclass
     53      */
     54     public void testN3() {
     55         //@uses dot.junit.opcodes.iget.d.T_iget_1
     56         //@uses dot.junit.opcodes.iget.d.T_iget_11
     57         T_iget_11 t = new T_iget_11();
     58         assertEquals(10, t.run());
     59     }
     60 
     61     /**
     62      * @title expected NullPointerException
     63      */
     64     public void testE2() {
     65         loadAndRun("dot.junit.opcodes.iget.d.T_iget_9", NullPointerException.class);
     66     }
     67 
     68     /**
     69      * @constraint A11
     70      * @title constant pool index
     71      */
     72     public void testVFE1() {
     73         load("dot.junit.opcodes.iget.d.T_iget_4", VerifyError.class);
     74     }
     75 
     76     /**
     77      * @constraint A23
     78      * @title number of registers
     79      */
     80     public void testVFE2() {
     81         load("dot.junit.opcodes.iget.d.T_iget_3", VerifyError.class);
     82     }
     83 
     84     /**
     85      * @constraint B13
     86      * @title read integer from long field - only field with same name but
     87      * different type exist
     88      */
     89     public void testVFE3() {
     90         loadAndRun("dot.junit.opcodes.iget.d.T_iget_13", NoSuchFieldError.class);
     91     }
     92 
     93     /**
     94      * @constraint n/a
     95      * @title Attempt to read inaccessible private field.
     96      */
     97     public void testVFE4() {
     98         //@uses dot.junit.opcodes.iget.TestStubs
     99         loadAndRun("dot.junit.opcodes.iget.d.T_iget_6",  IllegalAccessError.class);
    100     }
    101 
    102     /**
    103      * @constraint n/a
    104      * @title Attempt to read field of undefined class.
    105      */
    106     public void testVFE5() {
    107         loadAndRun("dot.junit.opcodes.iget.d.T_iget_7", NoClassDefFoundError.class);
    108     }
    109 
    110     /**
    111      * @constraint n/a
    112      * @title Attempt to read undefined field.
    113      */
    114     public void testVFE6() {
    115         loadAndRun("dot.junit.opcodes.iget.d.T_iget_8", NoSuchFieldError.class);
    116     }
    117 
    118     /**
    119      * @constraint n/a
    120      * @title Attempt to read superclass' private field from subclass.
    121      */
    122     public void testVFE7() {
    123         //@uses dot.junit.opcodes.iget.d.T_iget_1
    124         loadAndRun("dot.junit.opcodes.iget.d.T_iget_12", IllegalAccessError.class);
    125     }
    126 
    127     /**
    128      * @constraint B1
    129      * @title iget shall not work for reference fields
    130      */
    131     public void testVFE8() {
    132         load("dot.junit.opcodes.iget.d.T_iget_14", VerifyError.class);
    133     }
    134 
    135     /**
    136      * @constraint B1
    137      * @title iget shall not work for short fields
    138      */
    139     public void testVFE9() {
    140         load("dot.junit.opcodes.iget.d.T_iget_15", VerifyError.class);
    141     }
    142 
    143     /**
    144      * @constraint B1
    145      * @title iget shall not work for boolean fields
    146      */
    147     public void testVFE10() {
    148         load("dot.junit.opcodes.iget.d.T_iget_16", VerifyError.class);
    149     }
    150 
    151     /**
    152      * @constraint B1
    153      * @title iget shall not work for char fields
    154      */
    155     public void testVFE11() {
    156         load("dot.junit.opcodes.iget.d.T_iget_17", VerifyError.class);
    157     }
    158 
    159     /**
    160      * @constraint B1
    161      * @title iget shall not work for byte fields
    162      */
    163     public void testVFE12() {
    164         load("dot.junit.opcodes.iget.d.T_iget_18", VerifyError.class);
    165     }
    166 
    167     /**
    168      * @constraint B1
    169      * @title iget shall not work for double fields
    170      */
    171     public void testVFE13() {
    172         load("dot.junit.opcodes.iget.d.T_iget_19", VerifyError.class);
    173     }
    174 
    175     /**
    176      * @constraint B1
    177      * @title iget shall not work for long fields
    178      */
    179     public void testVFE14() {
    180         load("dot.junit.opcodes.iget.d.T_iget_20", VerifyError.class);
    181     }
    182 
    183     /**
    184      * @constraint B12
    185      * @title Attempt to read protected field of unrelated class.
    186      */
    187     public void testVFE15() {
    188         //@uses dot.junit.opcodes.iget.TestStubs
    189         loadAndRun("dot.junit.opcodes.iget.d.T_iget_21", IllegalAccessError.class);
    190     }
    191 
    192     /**
    193      * @constraint A11
    194      * @title Attempt to read static field.
    195      */
    196     public void testVFE16() {
    197         loadAndRun("dot.junit.opcodes.iget.d.T_iget_5", IncompatibleClassChangeError.class);
    198     }
    199 
    200     /**
    201      * @constraint B6
    202      * @title instance fields may only be accessed on already initialized instances.
    203      */
    204     public void testVFE30() {
    205         load("dot.junit.opcodes.iget.d.T_iget_30", VerifyError.class);
    206     }
    207 
    208     /**
    209      * @constraint N/A
    210      * @title instance fields may only be accessed on reference values.
    211      */
    212     public void testVFE31() {
    213         load("dot.junit.opcodes.iget.d.T_iget_31", VerifyError.class);
    214     }
    215 
    216     /**
    217      * @constraint N/A
    218      * @title Attempt to read inaccessible protected field on uninitialized reference.
    219      */
    220     public void testVFE35() {
    221         //@uses dot.junit.opcodes.iget.TestStubs
    222         load("dot.junit.opcodes.iget.d.T_iget_35", VerifyError.class);
    223     }
    224 }
    225 
    226