Home | History | Annotate | Download | only in sget_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.sget_short;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.sget_short.d.T_sget_short_1;
     22 import dot.junit.opcodes.sget_short.d.T_sget_short_11;
     23 import dot.junit.opcodes.sget_short.d.T_sget_short_12;
     24 import dot.junit.opcodes.sget_short.d.T_sget_short_13;
     25 import dot.junit.opcodes.sget_short.d.T_sget_short_5;
     26 import dot.junit.opcodes.sget_short.d.T_sget_short_6;
     27 import dot.junit.opcodes.sget_short.d.T_sget_short_7;
     28 import dot.junit.opcodes.sget_short.d.T_sget_short_8;
     29 import dot.junit.opcodes.sget_short.d.T_sget_short_9;
     30 
     31 public class Test_sget_short extends DxTestCase {
     32 
     33     /**
     34      * @title get short from static field
     35      */
     36     public void testN1() {
     37         T_sget_short_1 t = new T_sget_short_1();
     38         assertEquals(32000, t.run());
     39     }
     40 
     41 
     42     /**
     43      * @title access protected field from subclass
     44      */
     45     public void testN3() {
     46         //@uses dot.junit.opcodes.sget_short.d.T_sget_short_1
     47         //@uses dot.junit.opcodes.sget_short.d.T_sget_short_11
     48         T_sget_short_11 t = new T_sget_short_11();
     49         assertEquals(32000, t.run());
     50     }
     51 
     52     /**
     53      * @constraint A12
     54      * @title attempt to access non-static field
     55      */
     56     public void testE1() {
     57 
     58         T_sget_short_5 t = new T_sget_short_5();
     59         try {
     60             t.run();
     61             fail("expected IncompatibleClassChangeError");
     62         } catch (IncompatibleClassChangeError e) {
     63             // expected
     64         }
     65     }
     66 
     67     /**
     68      * @title initialization of referenced class throws exception
     69      */
     70     public void testE6() {
     71         T_sget_short_9 t = new T_sget_short_9();
     72         try {
     73             t.run();
     74             fail("expected Error");
     75         } catch (Error e) {
     76             // expected
     77         }
     78     }
     79 
     80 
     81 
     82     /**
     83      * @constraint A12
     84      * @title constant pool index
     85      */
     86     public void testVFE1() {
     87         try {
     88             Class.forName("dot.junit.opcodes.sget_short.d.T_sget_short_4");
     89             fail("expected a verification exception");
     90         } catch (Throwable t) {
     91             DxUtil.checkVerifyException(t);
     92         }
     93     }
     94 
     95     /**
     96      *
     97      * @constraint A23
     98      * @title number of registers
     99      */
    100     public void testVFE2() {
    101         try {
    102             Class.forName("dot.junit.opcodes.sget_short.d.T_sget_short_3");
    103             fail("expected a verification exception");
    104         } catch (Throwable t) {
    105             DxUtil.checkVerifyException(t);
    106         }
    107     }
    108 
    109     /**
    110      *
    111      * @constraint B13
    112      * @title read short from long field - only field with same name but
    113      * different type exists
    114      */
    115     public void testVFE3() {
    116         try {
    117             new T_sget_short_13().run();
    118             fail("expected NoSuchFieldError");
    119         } catch (NoSuchFieldError t) {
    120         }
    121     }
    122 
    123     /**
    124      * @constraint n/a
    125      * @title Attempt to read inaccessible field.
    126      */
    127     public void testVFE4() {
    128         //@uses dot.junit.opcodes.sget_short.d.T_sget_short_6
    129         //@uses dot.junit.opcodes.sget_short.TestStubs
    130         try {
    131             new T_sget_short_6().run();
    132             fail("expected IllegalAccessError");
    133         } catch (IllegalAccessError t) {
    134         }
    135     }
    136 
    137     /**
    138      * @constraint n/a
    139      * @title Attempt to read field of undefined class.
    140      */
    141     public void testVFE5() {
    142         try {
    143             new T_sget_short_7().run();
    144             fail("expected NoClassDefFoundError");
    145         } catch (NoClassDefFoundError t) {
    146         }
    147     }
    148 
    149     /**
    150      * @constraint n/a
    151      * @title Attempt to read undefined field.
    152      */
    153     public void testVFE6() {
    154         try {
    155             new T_sget_short_8().run();
    156             fail("expected NoSuchFieldError");
    157         } catch (NoSuchFieldError t) {
    158         }
    159     }
    160 
    161     /**
    162      * @constraint n/a
    163      * @title Attempt to read superclass' private field from subclass.
    164      */
    165     public void testVFE7() {
    166         //@uses dot.junit.opcodes.sget_short.d.T_sget_short_12
    167         //@uses dot.junit.opcodes.sget_short.d.T_sget_short_1
    168         try {
    169             new T_sget_short_12().run();
    170             fail("expected IllegalAccessError");
    171         } catch (IllegalAccessError t) {
    172         }
    173     }
    174 
    175     /**
    176      * @constraint B1
    177      * @title sget_short shall not work for reference fields
    178      */
    179     public void testVFE8() {
    180         try {
    181             Class.forName("dot.junit.opcodes.sget_short.d.T_sget_short_14");
    182             fail("expected a verification exception");
    183         } catch (Throwable t) {
    184             DxUtil.checkVerifyException(t);
    185         }
    186     }
    187 
    188     /**
    189      *
    190      * @constraint B1
    191      * @title sget_short shall not work for char fields
    192      */
    193     public void testVFE9() {
    194         try {
    195             Class.forName("dot.junit.opcodes.sget_short.d.T_sget_short_15");
    196             fail("expected a verification exception");
    197         } catch (Throwable t) {
    198             DxUtil.checkVerifyException(t);
    199         }
    200     }
    201 
    202     /**
    203      *
    204      * @constraint B1
    205      * @title sget_short shall not work for int fields
    206      */
    207     public void testVFE10() {
    208         try {
    209             Class.forName("dot.junit.opcodes.sget_short.d.T_sget_short_16");
    210             fail("expected a verification exception");
    211         } catch (Throwable t) {
    212             DxUtil.checkVerifyException(t);
    213         }
    214     }
    215 
    216     /**
    217      *
    218      * @constraint B1
    219      * @title sget_short shall not work for byte fields
    220      */
    221     public void testVFE11() {
    222         try {
    223             Class.forName("dot.junit.opcodes.sget_short.d.T_sget_short_17");
    224             fail("expected a verification exception");
    225         } catch (Throwable t) {
    226             DxUtil.checkVerifyException(t);
    227         }
    228     }
    229 
    230     /**
    231      *
    232      * @constraint B1
    233      * @title sget_short shall not work for boolean fields
    234      */
    235     public void testVFE12() {
    236         try {
    237             Class.forName("dot.junit.opcodes.sget_short.d.T_sget_short_18");
    238             fail("expected a verification exception");
    239         } catch (Throwable t) {
    240             DxUtil.checkVerifyException(t);
    241         }
    242     }
    243 
    244     /**
    245      *
    246      * @constraint B1
    247      * @title sget_short shall not work for double fields
    248      */
    249     public void testVFE13() {
    250         try {
    251             Class.forName("dot.junit.opcodes.sget_short.d.T_sget_short_19");
    252             fail("expected a verification exception");
    253         } catch (Throwable t) {
    254             DxUtil.checkVerifyException(t);
    255         }
    256     }
    257 
    258     /**
    259      *
    260      * @constraint B1
    261      * @title sget_short shall not work for long fields
    262      */
    263     public void testVFE14() {
    264         try {
    265             Class.forName("dot.junit.opcodes.sget_short.d.T_sget_short_20");
    266             fail("expected a verification exception");
    267         } catch (Throwable t) {
    268             DxUtil.checkVerifyException(t);
    269         }
    270     }
    271 }
    272