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 put value '2' into boolean field 129 */ 130 public void testVFE6() { 131 try { 132 Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_6"); 133 fail("expected a verification exception"); 134 } catch (Throwable t) { 135 DxUtil.checkVerifyException(t); 136 } 137 } 138 139 /** 140 * 141 * @constraint B13 142 * @title type of field doesn't match opcode - attempt to modify double 143 * field with single-width register 144 */ 145 public void testVFE7() { 146 try { 147 Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_18"); 148 fail("expected a verification exception"); 149 } catch (Throwable t) { 150 DxUtil.checkVerifyException(t); 151 } 152 } 153 154 /** 155 * 156 * @constraint A12 157 * @title Attempt to set non-static field. 158 */ 159 public void testVFE8() { 160 try { 161 new T_sput_boolean_7().run(); 162 fail("expected IncompatibleClassChangeError"); 163 } catch (IncompatibleClassChangeError t) { 164 } 165 } 166 167 /** 168 * @constraint n/a 169 * @title Attempt to modify inaccessible field. 170 */ 171 public void testVFE9() { 172 //@uses dot.junit.opcodes.sput_boolean.TestStubs 173 //@uses dot.junit.opcodes.sput_boolean.d.T_sput_boolean_8 174 try { 175 new T_sput_boolean_8().run(); 176 fail("expected IllegalAccessError"); 177 } catch (IllegalAccessError t) { 178 } 179 } 180 181 /** 182 * @constraint n/a 183 * @title Attempt to modify field of undefined class. 184 */ 185 public void testVFE10() { 186 try { 187 new T_sput_boolean_9().run(); 188 fail("expected NoClassDefFoundError"); 189 } catch (NoClassDefFoundError t) { 190 } 191 } 192 193 /** 194 * @constraint n/a 195 * @title Attempt to modify undefined field. 196 */ 197 public void testVFE11() { 198 try { 199 new T_sput_boolean_10().run(); 200 fail("expected NoSuchFieldError"); 201 } catch (NoSuchFieldError t) { 202 } 203 } 204 205 206 207 /** 208 * @constraint n/a 209 * @title Attempt to modify superclass' private field from subclass. 210 */ 211 public void testVFE12() { 212 //@uses dot.junit.opcodes.sput_boolean.d.T_sput_boolean_1 213 //@uses dot.junit.opcodes.sput_boolean.d.T_sput_boolean_15 214 try { 215 new T_sput_boolean_15().run(); 216 fail("expected a verification exception"); 217 } catch (IllegalAccessError t) { 218 } 219 } 220 221 222 /** 223 * @constraint B1 224 * @title sput_boolean shall not work for wide numbers 225 */ 226 public void testVFE13() { 227 try { 228 Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_2"); 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 reference fields 239 */ 240 public void testVFE14() { 241 try { 242 Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_20"); 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 short fields 253 */ 254 public void testVFE15() { 255 try { 256 Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_21"); 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 int fields 267 */ 268 public void testVFE16() { 269 try { 270 Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_22"); 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 char fields 281 */ 282 public void testVFE17() { 283 try { 284 Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_23"); 285 fail("expected a verification exception"); 286 } catch (Throwable t) { 287 DxUtil.checkVerifyException(t); 288 } 289 } 290 291 /** 292 * 293 * @constraint B1 294 * @title sput_boolean shall not work for byte fields 295 */ 296 public void testVFE18() { 297 try { 298 Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_24"); 299 fail("expected a verification exception"); 300 } catch (Throwable t) { 301 DxUtil.checkVerifyException(t); 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_boolean.TestStubs 311 //@uses dot.junit.opcodes.sput_boolean.d.T_sput_boolean_11 312 313 try { 314 new T_sput_boolean_11().run(); 315 fail("expected IllegalAccessError"); 316 } catch (IllegalAccessError t) { 317 } 318 } 319 } 320