Home | History | Annotate | Download | only in sput_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.sput_object;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.sput_object.d.T_sput_object_1;
     22 import dot.junit.opcodes.sput_object.d.T_sput_object_10;
     23 import dot.junit.opcodes.sput_object.d.T_sput_object_11;
     24 import dot.junit.opcodes.sput_object.d.T_sput_object_12;
     25 import dot.junit.opcodes.sput_object.d.T_sput_object_13;
     26 import dot.junit.opcodes.sput_object.d.T_sput_object_14;
     27 import dot.junit.opcodes.sput_object.d.T_sput_object_15;
     28 import dot.junit.opcodes.sput_object.d.T_sput_object_17;
     29 import dot.junit.opcodes.sput_object.d.T_sput_object_7;
     30 import dot.junit.opcodes.sput_object.d.T_sput_object_8;
     31 import dot.junit.opcodes.sput_object.d.T_sput_object_9;
     32 
     33 public class Test_sput_object extends DxTestCase {
     34     /**
     35      * @title put reference into static field
     36      */
     37     public void testN1() {
     38         T_sput_object_1 t = new T_sput_object_1();
     39         assertEquals(null, T_sput_object_1.st_i1);
     40         t.run();
     41         assertEquals(t, T_sput_object_1.st_i1);
     42     }
     43 
     44 
     45     /**
     46      * @title modification of final field
     47      */
     48     public void testN2() {
     49         T_sput_object_12 t = new T_sput_object_12();
     50         assertEquals(null, T_sput_object_12.st_i1);
     51         t.run();
     52         assertEquals(t, T_sput_object_12.st_i1);
     53     }
     54 
     55     /**
     56      * @title modification of protected field from subclass
     57      */
     58     public void testN4() {
     59         //@uses dot.junit.opcodes.sput_object.d.T_sput_object_1
     60         //@uses dot.junit.opcodes.sput_object.d.T_sput_object_14
     61         T_sput_object_14 t = new T_sput_object_14();
     62         assertEquals(null, T_sput_object_14.getProtectedField());
     63         t.run();
     64         assertEquals(t, T_sput_object_14.getProtectedField());
     65     }
     66 
     67 
     68     /**
     69      * @title initialization of referenced class throws exception
     70      */
     71     public void testE6() {
     72         T_sput_object_13 t = new T_sput_object_13();
     73         try {
     74             t.run();
     75             fail("expected Error");
     76         } catch (Error e) {
     77             // expected
     78         }
     79     }
     80 
     81     /**
     82      * @constraint A12
     83      * @title constant pool index
     84      */
     85     public void testVFE1() {
     86         try {
     87             Class.forName("dot.junit.opcodes.sput_object.d.T_sput_object_3");
     88             fail("expected a verification exception");
     89         } catch (Throwable t) {
     90             DxUtil.checkVerifyException(t);
     91         }
     92     }
     93 
     94     /**
     95      *
     96      * @constraint A23
     97      * @title number of registers
     98      */
     99     public void testVFE2() {
    100         try {
    101             Class.forName("dot.junit.opcodes.sput_object.d.T_sput_object_4");
    102             fail("expected a verification exception");
    103         } catch (Throwable t) {
    104             DxUtil.checkVerifyException(t);
    105         }
    106     }
    107 
    108 
    109     /**
    110      *
    111      * @constraint B13
    112      * @title put object into long field - only field with same name but
    113      * different type exists
    114      */
    115     public void testVFE5() {
    116         try {
    117             new T_sput_object_17().run();
    118             fail("expected NoSuchFieldError");
    119         } catch (NoSuchFieldError t) {
    120         }
    121     }
    122 
    123 
    124     /**
    125      *
    126      * @constraint B13
    127      * @title type of field doesn't match opcode - attempt to modify double
    128      * field with single-width register
    129      */
    130     public void testVFE7() {
    131         try {
    132             Class.forName("dot.junit.opcodes.sput_object.d.T_sput_object_18");
    133             fail("expected a verification exception");
    134         } catch (Throwable t) {
    135             DxUtil.checkVerifyException(t);
    136         }
    137     }
    138 
    139     /**
    140      *
    141      * @constraint A12
    142      * @title Attempt to set non-static field.
    143      */
    144     public void testVFE8() {
    145          try {
    146              new T_sput_object_7().run();
    147              fail("expected IncompatibleClassChangeError");
    148          } catch (IncompatibleClassChangeError t) {
    149          }
    150     }
    151 
    152     /**
    153      * @constraint n/a
    154      * @title Attempt to modify inaccessible field.
    155      */
    156     public void testVFE9() {
    157         //@uses dot.junit.opcodes.sput_object.TestStubs
    158         //@uses dot.junit.opcodes.sput_object.d.T_sput_object_8
    159         try {
    160             new T_sput_object_8().run();
    161             fail("expected IllegalAccessError");
    162         } catch (IllegalAccessError t) {
    163         }
    164     }
    165 
    166     /**
    167      * @constraint n/a
    168      * @title Attempt to modify field of undefined class.
    169      */
    170     public void testVFE10() {
    171         try {
    172             new T_sput_object_9().run();
    173             fail("expected NoClassDefFoundError");
    174         } catch (NoClassDefFoundError t) {
    175         }
    176     }
    177 
    178     /**
    179      * @constraint n/a
    180      * @title Attempt to modify undefined field.
    181      */
    182     public void testVFE11() {
    183         try {
    184             new T_sput_object_10().run();
    185             fail("expected NoSuchFieldError");
    186         } catch (NoSuchFieldError t) {
    187         }
    188     }
    189 
    190 
    191 
    192     /**
    193      * @constraint n/a
    194      * @title Attempt to modify superclass' private field from subclass.
    195      */
    196     public void testVFE12() {
    197         //@uses dot.junit.opcodes.sput_object.d.T_sput_object_1
    198         //@uses dot.junit.opcodes.sput_object.d.T_sput_object_15
    199         try {
    200             new T_sput_object_15().run();
    201             fail("expected a verification exception");
    202         } catch (IllegalAccessError t) {
    203         }
    204     }
    205 
    206 
    207     /**
    208      * @constraint B1
    209      * @title sput-object shall not work for wide numbers
    210      */
    211     public void testVFE13() {
    212         try {
    213             Class.forName("dot.junit.opcodes.sput_object.d.T_sput_object_2");
    214             fail("expected a verification exception");
    215         } catch (Throwable t) {
    216             DxUtil.checkVerifyException(t);
    217         }
    218     }
    219 
    220     /**
    221      *
    222      * @constraint B13
    223      * @title assignment incompatible references
    224      */
    225     public void testVFE14() {
    226         try {
    227             Class.forName("dot.junit.opcodes.sput_object.d.T_sput_object_20");
    228             fail("expected a verification exception");
    229         } catch (Throwable t) {
    230             DxUtil.checkVerifyException(t);
    231         }
    232     }
    233 
    234     /**
    235      *
    236      * @constraint B1
    237      * @title sput-object shall not work for char fields
    238      */
    239     public void testVFE15() {
    240         try {
    241             Class.forName("dot.junit.opcodes.sput_object.d.T_sput_object_21");
    242             fail("expected a verification exception");
    243         } catch (Throwable t) {
    244             DxUtil.checkVerifyException(t);
    245         }
    246     }
    247 
    248     /**
    249      *
    250      * @constraint B1
    251      * @title sput-object shall not work for int fields
    252      */
    253     public void testVFE16() {
    254         try {
    255             Class.forName("dot.junit.opcodes.sput_object.d.T_sput_object_22");
    256             fail("expected a verification exception");
    257         } catch (Throwable t) {
    258             DxUtil.checkVerifyException(t);
    259         }
    260     }
    261 
    262     /**
    263      *
    264      * @constraint B1
    265      * @title sput-object shall not work for byte fields
    266      */
    267     public void testVFE17() {
    268         try {
    269             Class.forName("dot.junit.opcodes.sput_object.d.T_sput_object_23");
    270             fail("expected a verification exception");
    271         } catch (Throwable t) {
    272             DxUtil.checkVerifyException(t);
    273         }
    274     }
    275 
    276     /**
    277      *
    278      * @constraint B1
    279      * @title sput-object shall not work for boolean fields
    280      */
    281     public void testVFE18() {
    282         try {
    283             Class.forName("dot.junit.opcodes.sput_object.d.T_sput_object_24");
    284             fail("expected a verification exception");
    285         } catch (Throwable t) {
    286             DxUtil.checkVerifyException(t);
    287         }
    288     }
    289 
    290     /**
    291      *
    292      * @constraint B1
    293      * @title sput-object shall not work for short fields
    294      */
    295     public void testVFE6() {
    296         try {
    297             Class.forName("dot.junit.opcodes.sput_object.d.T_sput_object_6");
    298             fail("expected a verification exception");
    299         } catch (Throwable t) {
    300             DxUtil.checkVerifyException(t);
    301         }
    302     }
    303 
    304 
    305     /**
    306      * @constraint B1
    307      * @title Modification of final field in other class
    308      */
    309     public void testVFE19() {
    310         //@uses dot.junit.opcodes.sput_object.TestStubs
    311         //@uses dot.junit.opcodes.sput_object.d.T_sput_object_11
    312     	try {
    313             new T_sput_object_11().run();
    314             fail("expected IllegalAccessError");
    315         } catch (IllegalAccessError t) {
    316         }
    317     }
    318 }
    319