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