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