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