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; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_12; 22 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_13; 23 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_16; 24 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_2; 25 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_21; 26 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_6; 27 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_7; 28 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_8; 29 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_9; 30 31 public class Test_invoke_direct extends DxTestCase { 32 33 /** 34 * @title private method call 35 */ 36 public void testN2() { 37 T_invoke_direct_2 t = new T_invoke_direct_2(); 38 assertEquals(345, t.run()); 39 } 40 41 42 /** 43 * @title Check that new frame is created by invoke_direct 44 */ 45 public void testN7() { 46 T_invoke_direct_21 t = new T_invoke_direct_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_8 t = new T_invoke_direct_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_9 t = new T_invoke_direct_9(); 70 try { 71 assertEquals(5, t.run()); 72 fail("expected UnsatisfiedLinkError"); 73 } catch (UnsatisfiedLinkError e) { 74 // expected 75 } 76 } 77 78 /** 79 * @constraint A13 80 * @title invalid constant pool index 81 */ 82 public void testVFE1() { 83 try { 84 Class.forName("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_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.d.T_invoke_direct_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.d.T_invoke_direct_6 110 //@uses dot.junit.opcodes.invoke_direct.TSuper 111 try { 112 new T_invoke_direct_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.d.T_invoke_direct_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.d.T_invoke_direct_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.d.T_invoke_direct_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.d.T_invoke_direct_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.d.T_invoke_direct_25 177 //@uses dot.junit.opcodes.invoke_direct.TPlain 178 //@uses dot.junit.opcodes.invoke_direct.TSuper 179 try { 180 Class.forName("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_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.d.T_invoke_direct_25 193 //@uses dot.junit.opcodes.invoke_direct.TSuper 194 try { 195 Class.forName("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_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.d.T_invoke_direct_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_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_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.d.T_invoke_direct_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. 258 */ 259 public void testVFE16() { 260 //@uses dot.junit.opcodes.invoke_direct.d.T_invoke_direct_12 261 //@uses dot.junit.opcodes.invoke_direct.TSuper 262 try { 263 new T_invoke_direct_12().run(); 264 fail("expected IllegalAccessError"); 265 } catch (IllegalAccessError t) { 266 } 267 } 268 269 270 /** 271 * @constraint n/a 272 * @title Attempt to invoke abstract method 273 */ 274 public void testVFE17() { 275 //@uses dot.junit.opcodes.invoke_direct.d.T_invoke_direct_13 276 //@uses dot.junit.opcodes.invoke_direct.TAbstract 277 try { 278 new T_invoke_direct_13().run(); 279 fail("expected NoSuchMethodError"); 280 } catch (NoSuchMethodError t) { 281 } 282 } 283 284 /** 285 * @constraint B5 286 * @title An instance initializer must only be invoked on an uninitialized instance. 287 */ 288 public void testVFE18() { 289 try { 290 Class.forName("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_17"); 291 fail("expected a verification exception"); 292 } catch (Throwable t) { 293 DxUtil.checkVerifyException(t); 294 } 295 } 296 297 /** 298 * @constraint B8 299 * @title attempt to access inherited instance field before <init> is called 300 */ 301 public void testVFE19() { 302 //@uses dot.junit.opcodes.invoke_direct.d.T_invoke_direct_18 303 //@uses dot.junit.opcodes.invoke_direct.TSuper 304 try { 305 Class.forName("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_18"); 306 fail("expected a verification exception"); 307 } catch (Throwable t) { 308 DxUtil.checkVerifyException(t); 309 } 310 } 311 312 /** 313 * @constraint A13 314 * @title attempt to invoke interface method 315 */ 316 public void testVFE20() { 317 try { 318 Class.forName("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_26"); 319 fail("expected a verification exception"); 320 } catch (Throwable t) { 321 DxUtil.checkVerifyException(t); 322 } 323 } 324 325 /** 326 * @constraint B6 327 * @title instance methods may only be invoked on already initialized instances. 328 */ 329 public void testVFE21() { 330 try { 331 Class.forName("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_27"); 332 fail("expected a verification exception"); 333 } catch (Throwable t) { 334 DxUtil.checkVerifyException(t); 335 } 336 } 337 } 338