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