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 type of field doesn't match opcode - attempt to modify double
    126      * field with single-width register
    127      */
    128     public void testVFE7() {
    129         try {
    130             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_18");
    131             fail("expected a verification exception");
    132         } catch (Throwable t) {
    133             DxUtil.checkVerifyException(t);
    134         }
    135     }
    136 
    137     /**
    138      *
    139      * @constraint A11
    140      * @title Attempt to set static field.
    141      */
    142     public void testVFE8() {
    143          try {
    144              new T_iput_byte_7().run();
    145              fail("expected IncompatibleClassChangeError");
    146          } catch (IncompatibleClassChangeError t) {
    147          }
    148     }
    149 
    150     /**
    151      * @constraint B12
    152      * @title Attempt to modify inaccessible protected field.
    153      */
    154     public void testVFE9() {
    155         //@uses dot.junit.opcodes.iput_byte.TestStubs
    156         //@uses dot.junit.opcodes.iput_byte.d.T_iput_byte_8
    157         try {
    158             new T_iput_byte_8().run();
    159             fail("expected IllegalAccessError");
    160         } catch (IllegalAccessError t) {
    161         }
    162     }
    163 
    164     /**
    165      * @constraint n/a
    166      * @title Attempt to modify field of undefined class.
    167      */
    168     public void testVFE10() {
    169         try {
    170             new T_iput_byte_9().run();
    171             fail("expected NoClassDefFoundError");
    172         } catch (NoClassDefFoundError t) {
    173         }
    174     }
    175 
    176     /**
    177      * @constraint n/a
    178      * @title Attempt to modify undefined field.
    179      */
    180     public void testVFE11() {
    181         try {
    182             new T_iput_byte_10().run();
    183             fail("expected NoSuchFieldError");
    184         } catch (NoSuchFieldError t) {
    185         }
    186     }
    187 
    188 
    189 
    190     /**
    191      * @constraint n/a
    192      * @title Attempt to modify superclass' private field from subclass.
    193      */
    194     public void testVFE12() {
    195         //@uses dot.junit.opcodes.iput_byte.d.T_iput_byte_1
    196         //@uses dot.junit.opcodes.iput_byte.d.T_iput_byte_15
    197         try {
    198             new T_iput_byte_15().run();
    199             fail("expected IllegalAccessError");
    200         } catch (IllegalAccessError t) {
    201         }
    202     }
    203 
    204 
    205     /**
    206      * @constraint B1
    207      * @title iput-byte shall not work for wide numbers
    208      */
    209     public void testVFE13() {
    210         try {
    211             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_2");
    212             fail("expected a verification exception");
    213         } catch (Throwable t) {
    214             DxUtil.checkVerifyException(t);
    215         }
    216     }
    217 
    218     /**
    219      *
    220      * @constraint B1
    221      * @title iput-byte shall not work for reference fields
    222      */
    223     public void testVFE14() {
    224         try {
    225             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_20");
    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 short fields
    236      */
    237     public void testVFE15() {
    238         try {
    239             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_21");
    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 int fields
    250      */
    251     public void testVFE16() {
    252         try {
    253             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_22");
    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 char fields
    264      */
    265     public void testVFE17() {
    266         try {
    267             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_23");
    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 boolean fields
    278      */
    279     public void testVFE18() {
    280         try {
    281             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_24");
    282             fail("expected a verification exception");
    283         } catch (Throwable t) {
    284             DxUtil.checkVerifyException(t);
    285         }
    286     }
    287 
    288 
    289     /**
    290      * @constraint B6
    291      * @title instance fields may only be accessed on already initialized instances.
    292      */
    293     public void testVFE30() {
    294         try {
    295             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_30");
    296             fail("expected a verification exception");
    297         } catch (Throwable t) {
    298             DxUtil.checkVerifyException(t);
    299         }
    300     }
    301 
    302     /**
    303      * @constraint n/a
    304      * @title Modification of final field in other class
    305      */
    306     public void testVFE19() {
    307         //@uses dot.junit.opcodes.iput_byte.TestStubs
    308         //@uses dot.junit.opcodes.iput_byte.d.T_iput_byte_11
    309     	try {
    310             new T_iput_byte_11().run();
    311             fail("expected IllegalAccessError");
    312         } catch (IllegalAccessError t) {
    313         }
    314     }
    315 }
    316 
    317