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