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.invoke_direct_range; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_12; 22 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_13; 23 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_16; 24 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_2; 25 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_21; 26 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_6; 27 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_7; 28 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_8; 29 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_9; 30 31 public class Test_invoke_direct_range extends DxTestCase { 32 33 /** 34 * @title private method call 35 */ 36 public void testN2() { 37 T_invoke_direct_range_2 t = new T_invoke_direct_range_2(); 38 assertEquals(345, t.run()); 39 } 40 41 42 /** 43 * @title Check that new frame is created by invoke_direct_range 44 */ 45 public void testN7() { 46 T_invoke_direct_range_21 t = new T_invoke_direct_range_21(); 47 assertEquals(1, t.run()); 48 } 49 50 51 52 /** 53 * @title objref is null 54 */ 55 public void testE3() { 56 T_invoke_direct_range_8 t = new T_invoke_direct_range_8(); 57 try { 58 assertEquals(5, t.run()); 59 fail("expected NullPointerException"); 60 } catch (NullPointerException e) { 61 // expected 62 } 63 } 64 65 /** 66 * @title Native method can't be linked 67 */ 68 public void testE5() { 69 T_invoke_direct_range_9 t = new T_invoke_direct_range_9(); 70 try { 71 assertEquals(5, t.run()); 72 fail("expected UnsatisfiedLinkError"); 73 } catch (UnsatisfiedLinkError e) { 74 // expected 75 } 76 } 77 78 /** 79 * @constraint A14 80 * @title invalid constant pool index 81 */ 82 public void testVFE1() { 83 try { 84 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_3"); 85 fail("expected a verification exception"); 86 } catch (Throwable t) { 87 DxUtil.checkVerifyException(t); 88 } 89 } 90 91 /** 92 * @constraint A15 93 * @title invoke-direct may not be used to invoke <clinit> 94 */ 95 public void testVFE3() { 96 try { 97 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_4"); 98 fail("expected a verification exception"); 99 } catch (Throwable t) { 100 DxUtil.checkVerifyException(t); 101 } 102 } 103 104 /** 105 * @constraint B4 106 * @title invoke-direct target must be in self or superclass 107 */ 108 public void testVFE4() { 109 //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_6 110 //@uses dot.junit.opcodes.invoke_direct_range.TSuper 111 try { 112 new T_invoke_direct_range_6(); 113 fail("expected NoSuchMethodError"); 114 } catch (NoSuchMethodError t) { 115 } 116 } 117 118 /** 119 * @constraint B1 120 * @title number of arguments 121 */ 122 public void testVFE5() { 123 try { 124 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_5"); 125 fail("expected a verification exception"); 126 } catch (Throwable t) { 127 DxUtil.checkVerifyException(t); 128 } 129 } 130 131 /** 132 * @constraint B1 133 * @title int is passed instead of obj ref 134 */ 135 public void testVFE6() { 136 try { 137 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_10"); 138 fail("expected a verification exception"); 139 } catch (Throwable t) { 140 DxUtil.checkVerifyException(t); 141 } 142 } 143 144 145 /** 146 * @constraint B9 147 * @title number of arguments passed to method 148 */ 149 public void testVFE8() { 150 try { 151 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_14"); 152 fail("expected a verification exception"); 153 } catch (Throwable t) { 154 DxUtil.checkVerifyException(t); 155 } 156 } 157 158 /** 159 * @constraint B9 160 * @title types of arguments passed to method 161 */ 162 public void testVFE9() { 163 try { 164 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_24"); 165 fail("expected a verification exception"); 166 } catch (Throwable t) { 167 DxUtil.checkVerifyException(t); 168 } 169 } 170 171 /** 172 * @constraint B10 173 * @title assignment incompatible references when accessing protected method 174 */ 175 public void testVFE10() { 176 //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_25 177 //@uses dot.junit.opcodes.invoke_direct_range.TPlain 178 //@uses dot.junit.opcodes.invoke_direct_range.TSuper 179 try { 180 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_25"); 181 fail("expected a verification exception"); 182 } catch (Throwable t) { 183 DxUtil.checkVerifyException(t); 184 } 185 } 186 187 /** 188 * @constraint B5 189 * @title Superclass' method call 190 */ 191 public void testVFE11() { 192 //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_25 193 //@uses dot.junit.opcodes.invoke_direct_range.TSuper 194 try { 195 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_1"); 196 fail("expected a verification exception"); 197 } catch (Throwable t) { 198 DxUtil.checkVerifyException(t); 199 } 200 } 201 202 /** 203 * @constraint A23 204 * @title number of registers 205 */ 206 public void testVFE12() { 207 try { 208 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_15"); 209 fail("expected a verification exception"); 210 } catch (Throwable t) { 211 DxUtil.checkVerifyException(t); 212 } 213 } 214 215 216 /** 217 * @constraint n/a 218 * @title Attempt to call undefined method. 219 */ 220 public void testVFE13() { 221 try { 222 new T_invoke_direct_range_7().run(); 223 fail("expected NoSuchMethodError"); 224 } catch (NoSuchMethodError t) { 225 } 226 } 227 228 /** 229 * @constraint n/a 230 * @title Method has different signature. 231 */ 232 public void testVFE14() { 233 try { 234 new T_invoke_direct_range_16().run(); 235 fail("expected NoSuchMethodError"); 236 } catch (NoSuchMethodError t) { 237 } 238 } 239 240 /** 241 * @constraint n/a 242 * @title Attempt to invoke static method. Java throws IncompatibleClassChangeError 243 * on first access but Dalvik throws VerifyError on class loading. 244 */ 245 public void testVFE15() { 246 try { 247 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_11"); 248 fail("expected a verification exception"); 249 } catch (Throwable t) { 250 DxUtil.checkVerifyException(t); 251 } 252 } 253 254 255 /** 256 * @constraint n/a 257 * @title Attempt to invoke private method of superclass. Java throws IllegalAccessError 258 * on first access but Dalvik throws VerifyError on class loading. 259 */ 260 public void testVFE16() { 261 //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_12 262 //@uses dot.junit.opcodes.invoke_direct_range.TSuper 263 try { 264 new T_invoke_direct_range_12().run(); 265 fail("expected IllegalAccessError"); 266 } catch (IllegalAccessError t) { 267 } 268 } 269 270 271 /** 272 * @constraint n/a 273 * @title Attempt to invoke abstract method 274 */ 275 public void testVFE17() { 276 //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_13 277 //@uses dot.junit.opcodes.invoke_direct_range.TAbstract 278 try { 279 new T_invoke_direct_range_13().run(); 280 fail("expected NoSuchMethodError"); 281 } catch (NoSuchMethodError t) { 282 } 283 } 284 285 /** 286 * @constraint B5 287 * @title An instance initializer must only be invoked on an uninitialized instance. 288 */ 289 public void testVFE18() { 290 try { 291 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_17"); 292 fail("expected a verification exception"); 293 } catch (Throwable t) { 294 DxUtil.checkVerifyException(t); 295 } 296 } 297 298 /** 299 * @constraint B8 300 * @title attempt to access inherited instance field before <init> is called 301 */ 302 public void testVFE19() { 303 //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_18 304 //@uses dot.junit.opcodes.invoke_direct_range.TSuper 305 try { 306 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_18"); 307 fail("expected a verification exception"); 308 } catch (Throwable t) { 309 DxUtil.checkVerifyException(t); 310 } 311 } 312 313 /** 314 * @constraint A14 315 * @title attempt to invoke interface method 316 */ 317 public void testVFE20() { 318 try { 319 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_26"); 320 fail("expected a verification exception"); 321 } catch (Throwable t) { 322 DxUtil.checkVerifyException(t); 323 } 324 } 325 326 /** 327 * @constraint B6 328 * @title instance methods may only be invoked on already initialized instances. 329 */ 330 public void testVFE21() { 331 try { 332 Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_27"); 333 fail("expected a verification exception"); 334 } catch (Throwable t) { 335 DxUtil.checkVerifyException(t); 336 } 337 } 338 } 339