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