Home | History | Annotate | Download | only in iget_short
      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_short;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.iget_short.d.T_iget_short_1;
     22 import dot.junit.opcodes.iget_short.d.T_iget_short_11;
     23 import dot.junit.opcodes.iget_short.d.T_iget_short_12;
     24 import dot.junit.opcodes.iget_short.d.T_iget_short_13;
     25 import dot.junit.opcodes.iget_short.d.T_iget_short_21;
     26 import dot.junit.opcodes.iget_short.d.T_iget_short_5;
     27 import dot.junit.opcodes.iget_short.d.T_iget_short_6;
     28 import dot.junit.opcodes.iget_short.d.T_iget_short_7;
     29 import dot.junit.opcodes.iget_short.d.T_iget_short_8;
     30 import dot.junit.opcodes.iget_short.d.T_iget_short_9;
     31 
     32 public class Test_iget_short extends DxTestCase {
     33 
     34     /**
     35      * @title get short from field
     36      */
     37     public void testN1() {
     38         T_iget_short_1 t = new T_iget_short_1();
     39         assertEquals(32000, t.run());
     40     }
     41 
     42 
     43     /**
     44      * @title access protected field from subclass
     45      */
     46     public void testN3() {
     47         //@uses dot.junit.opcodes.iget_short.d.T_iget_short_1
     48         //@uses dot.junit.opcodes.iget_short.d.T_iget_short_11
     49         T_iget_short_11 t = new T_iget_short_11();
     50         assertEquals(32000, t.run());
     51     }
     52 
     53     /**
     54      * @title expected NullPointerException
     55      */
     56     public void testE2() {
     57         T_iget_short_9 t = new T_iget_short_9();
     58         try {
     59             t.run();
     60             fail("expected NullPointerException");
     61         } catch (NullPointerException e) {
     62             // expected
     63         }
     64     }
     65 
     66 
     67 
     68     /**
     69      * @constraint A11
     70      * @title constant pool index
     71      */
     72     public void testVFE1() {
     73         try {
     74             Class.forName("dot.junit.opcodes.iget_short.d.T_iget_short_4");
     75             fail("expected a verification exception");
     76         } catch (Throwable t) {
     77             DxUtil.checkVerifyException(t);
     78         }
     79     }
     80 
     81     /**
     82      *
     83      * @constraint A23
     84      * @title number of registers
     85      */
     86     public void testVFE2() {
     87         try {
     88             Class.forName("dot.junit.opcodes.iget_short.d.T_iget_short_3");
     89             fail("expected a verification exception");
     90         } catch (Throwable t) {
     91             DxUtil.checkVerifyException(t);
     92         }
     93     }
     94 
     95     /**
     96      *
     97      * @constraint B13
     98      * @title read short from long field - only field with same name but
     99      * different type exists
    100      */
    101     public void testVFE3() {
    102         try {
    103             new T_iget_short_13().run();
    104             fail("expected a NoSuchFieldError exception");
    105         } catch (NoSuchFieldError e) {
    106             // expected
    107         }
    108     }
    109 
    110     /**
    111      * @constraint n/a
    112      * @title Attempt to read inaccessible field.
    113      */
    114     public void testVFE4() {
    115         //@uses dot.junit.opcodes.iget_short.d.T_iget_short_6
    116         //@uses dot.junit.opcodes.iget_short.TestStubs
    117         try {
    118             new T_iget_short_6().run();
    119             fail("expected an IllegalAccessError exception");
    120         } catch (IllegalAccessError e) {
    121             // expected
    122         }
    123     }
    124 
    125     /**
    126      * @constraint n/a
    127      * @title Attempt to read field of undefined class.
    128      */
    129     public void testVFE5() {
    130         try {
    131             new T_iget_short_7().run();
    132             fail("expected a NoClassDefFoundError exception");
    133         } catch (NoClassDefFoundError e) {
    134             // expected
    135         }
    136     }
    137 
    138     /**
    139      * @constraint n/a
    140      * @title Attempt to read undefined field.
    141      */
    142     public void testVFE6() {
    143         try {
    144             new T_iget_short_8().run();
    145             fail("expected a NoSuchFieldError exception");
    146         } catch (NoSuchFieldError e) {
    147             // expected
    148         }
    149     }
    150 
    151     /**
    152      * @constraint n/a
    153      * @title Attempt to read superclass' private field from subclass.
    154      */
    155     public void testVFE7() {
    156         //@uses dot.junit.opcodes.iget_short.d.T_iget_short_12
    157         //@uses dot.junit.opcodes.iget_short.d.T_iget_short_1
    158         try {
    159             new T_iget_short_12().run();
    160             fail("expected an IllegalAccessError exception");
    161         } catch (IllegalAccessError e) {
    162             // expected
    163         }
    164     }
    165 
    166     /**
    167      * @constraint B1
    168      * @title iget_short shall not work for reference fields
    169      */
    170     public void testVFE8() {
    171         try {
    172             Class.forName("dot.junit.opcodes.iget_short.d.T_iget_short_14");
    173             fail("expected a verification exception");
    174         } catch (Throwable t) {
    175             DxUtil.checkVerifyException(t);
    176         }
    177     }
    178 
    179     /**
    180      *
    181      * @constraint B1
    182      * @title iget_short shall not work for char fields
    183      */
    184     public void testVFE9() {
    185         try {
    186             Class.forName("dot.junit.opcodes.iget_short.d.T_iget_short_15");
    187             fail("expected a verification exception");
    188         } catch (Throwable t) {
    189             DxUtil.checkVerifyException(t);
    190         }
    191     }
    192 
    193     /**
    194      *
    195      * @constraint B1
    196      * @title iget_short shall not work for int fields
    197      */
    198     public void testVFE10() {
    199         try {
    200             Class.forName("dot.junit.opcodes.iget_short.d.T_iget_short_16");
    201             fail("expected a verification exception");
    202         } catch (Throwable t) {
    203             DxUtil.checkVerifyException(t);
    204         }
    205     }
    206 
    207     /**
    208      *
    209      * @constraint B1
    210      * @title iget_short shall not work for byte fields
    211      */
    212     public void testVFE11() {
    213         try {
    214             Class.forName("dot.junit.opcodes.iget_short.d.T_iget_short_17");
    215             fail("expected a verification exception");
    216         } catch (Throwable t) {
    217             DxUtil.checkVerifyException(t);
    218         }
    219     }
    220 
    221     /**
    222      *
    223      * @constraint B1
    224      * @title iget_short shall not work for boolean fields
    225      */
    226     public void testVFE12() {
    227         try {
    228             Class.forName("dot.junit.opcodes.iget_short.d.T_iget_short_18");
    229             fail("expected a verification exception");
    230         } catch (Throwable t) {
    231             DxUtil.checkVerifyException(t);
    232         }
    233     }
    234 
    235     /**
    236      *
    237      * @constraint B1
    238      * @title iget_short shall not work for double fields
    239      */
    240     public void testVFE13() {
    241         try {
    242             Class.forName("dot.junit.opcodes.iget_short.d.T_iget_short_19");
    243             fail("expected a verification exception");
    244         } catch (Throwable t) {
    245             DxUtil.checkVerifyException(t);
    246         }
    247     }
    248 
    249     /**
    250      *
    251      * @constraint B1
    252      * @title iget_short shall not work for long fields
    253      */
    254     public void testVFE14() {
    255         try {
    256             Class.forName("dot.junit.opcodes.iget_short.d.T_iget_short_20");
    257             fail("expected a verification exception");
    258         } catch (Throwable t) {
    259             DxUtil.checkVerifyException(t);
    260         }
    261     }
    262 
    263     /**
    264      * @constraint B12
    265      * @title Attempt to read inaccessible protected field.
    266      */
    267     public void testVFE15() {
    268         //@uses dot.junit.opcodes.iget_short.d.T_iget_short_21
    269         //@uses dot.junit.opcodes.iget_short.TestStubs
    270         try {
    271             new T_iget_short_21().run();
    272             fail("expected an IllegalAccessError exception");
    273         } catch (IllegalAccessError e) {
    274             // expected
    275         }
    276     }
    277 
    278 
    279     /**
    280      * @constraint A11
    281      * @title Attempt to read static  field.
    282      */
    283     public void testVFE16() {
    284         //@uses dot.junit.opcodes.iget_short.d.T_iget_short_5
    285         //@uses dot.junit.opcodes.iget_short.TestStubs
    286         try {
    287             new T_iget_short_5().run();
    288             fail("expected an IncompatibleClassChangeError exception");
    289         } catch (IncompatibleClassChangeError e) {
    290             // expected
    291         }
    292     }
    293 
    294     /**
    295      * @constraint B6
    296      * @title instance fields may only be accessed on already initialized instances.
    297      */
    298     public void testVFE30() {
    299         try {
    300             Class.forName("dot.junit.opcodes.iget_short.d.T_iget_short_30");
    301             fail("expected a verification exception");
    302         } catch (Throwable t) {
    303             DxUtil.checkVerifyException(t);
    304         }
    305     }
    306 }
    307