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 dxc.junit.opcodes.invokespecial; 18 19 import dxc.junit.DxTestCase; 20 import dxc.junit.DxUtil; 21 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_1; 22 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_11; 23 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_12; 24 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_13; 25 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_15; 26 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_16; 27 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_17; 28 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_18; 29 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_19; 30 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_2; 31 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_21; 32 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_22; 33 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_7; 34 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_8; 35 import dxc.junit.opcodes.invokespecial.jm.T_invokespecial_9; 36 37 public class Test_invokespecial extends DxTestCase { 38 /** 39 * @title Superclass' method call 40 */ testN1()41 public void testN1() { 42 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 43 T_invokespecial_1 t = new T_invokespecial_1(); 44 assertEquals(5, t.run()); 45 } 46 47 /** 48 * @title private method call 49 */ testN2()50 public void testN2() { 51 T_invokespecial_2 t = new T_invokespecial_2(); 52 assertEquals(345, t.run()); 53 } 54 55 /** 56 * @title Invoke method of superclass of superclass 57 */ testN3()58 public void testN3() { 59 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 60 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper2 61 T_invokespecial_15 t = new T_invokespecial_15(); 62 assertEquals(5, t.run()); 63 } 64 65 /** 66 * @title Invoke protected method of superclass specifying "this" 67 * class 68 */ testN4()69 public void testN4() { 70 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 71 try { 72 T_invokespecial_17 t = new T_invokespecial_17(); 73 assertEquals(5, t.run()); 74 } catch (VerifyError vfe) { 75 // ok for dalvikvm; 76 System.out.print("dvmvfe:"); 77 } 78 } 79 80 /** 81 * @title Invoke protected method of superclass if method with the 82 * same name exists in "this" class 83 */ testN5()84 public void testN5() { 85 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 86 T_invokespecial_18 t = new T_invokespecial_18(); 87 assertEquals(5, t.run()); 88 } 89 90 /** 91 * @title Check that method's arguments are popped from stack 92 */ testN6()93 public void testN6() { 94 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 95 T_invokespecial_19 t = new T_invokespecial_19(); 96 assertEquals(2, t.run()); 97 } 98 99 /** 100 * @title Check that new frame is created by invokespecial 101 */ testN7()102 public void testN7() { 103 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 104 T_invokespecial_21 t = new T_invokespecial_21(); 105 assertEquals(1, t.run()); 106 } 107 108 /** 109 * @title Check that monitor is acquired if method is synchronized 110 */ testN8()111 public void testN8() { 112 assertTrue(T_invokespecial_22.execute()); 113 } 114 115 116 117 /** 118 * @title method doesn't exist in "this" and superclass 119 */ testE1()120 public void testE1() { 121 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 122 try { 123 T_invokespecial_7 t = new T_invokespecial_7(); 124 assertEquals(5, t.run()); 125 fail("expected NoSuchMethodError"); 126 } catch (NoSuchMethodError e) { 127 // expected 128 } catch (VerifyError vfe) { 129 // ok for dalvikvm; early resolution 130 System.out.print("dvmvfe:"); 131 } 132 } 133 134 /** 135 * @title method has different signature 136 */ testE2()137 public void testE2() { 138 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 139 try { 140 T_invokespecial_16 t = new T_invokespecial_16(); 141 assertEquals(5, t.run()); 142 fail("expected NoSuchMethodError"); 143 } catch (NoSuchMethodError e) { 144 // expected 145 } catch (VerifyError vfe) { 146 // ok for dalvikvm; early resolution 147 System.out.print("dvmvfe:"); 148 } 149 } 150 151 /** 152 * @title expected NullPointerException 153 */ testE3()154 public void testE3() { 155 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 156 T_invokespecial_8 t = new T_invokespecial_8(); 157 try { 158 assertEquals(5, t.run()); 159 fail("expected NullPointerException"); 160 } catch (NullPointerException e) { 161 // expected 162 } 163 } 164 165 /** 166 * @title Attempt to invoke static method 167 */ testE4()168 public void testE4() { 169 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 170 try { 171 T_invokespecial_11 t = new T_invokespecial_11(); 172 assertEquals(5, t.run()); 173 fail("expected IncompatibleClassChangeError"); 174 } catch (IncompatibleClassChangeError e) { 175 // expected 176 } catch (VerifyError vfe) { 177 // ok for dalvikvm; 178 System.out.print("dvmvfe:"); 179 } 180 } 181 182 /** 183 * @title Native method can't be linked 184 */ testE5()185 public void testE5() { 186 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 187 T_invokespecial_9 t = new T_invokespecial_9(); 188 try { 189 assertEquals(5, t.run()); 190 fail("expected UnsatisfiedLinkError"); 191 } catch (UnsatisfiedLinkError e) { 192 // expected 193 } 194 } 195 196 /** 197 * @title Attempt to invoke private method of superclass 198 */ testE6()199 public void testE6() { 200 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 201 try { 202 T_invokespecial_12 t = new T_invokespecial_12(); 203 assertEquals(5, t.run()); 204 fail("expected IllegalAccessError"); 205 } catch (IllegalAccessError e) { 206 // expected 207 } catch (VerifyError vfe) { 208 // ok for dalvikvm; 209 System.out.print("dvmvfe:"); 210 } 211 } 212 213 /** 214 * @title Attempt to invoke abstract method 215 */ testE7()216 public void testE7() { 217 //@uses dxc.junit.opcodes.invokespecial.jm.TAbstract 218 T_invokespecial_13 t = new T_invokespecial_13(); 219 try { 220 assertEquals(5, t.run()); 221 fail("expected AbstractMethodError"); 222 } catch (AbstractMethodError e) { 223 // expected 224 } 225 } 226 227 /** 228 * @constraint 4.8.1.13 229 * @title valid index into constant pool table 230 */ testVFE1()231 public void testVFE1() { 232 try { 233 Class 234 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_3"); 235 fail("expected a verification exception"); 236 } catch (Throwable t) { 237 DxUtil.checkVerifyException(t); 238 } 239 } 240 241 /** 242 * @constraint 4.8.1.13 243 * @title invalid index into constant pool table 244 */ testVFE2()245 public void testVFE2() { 246 try { 247 Class 248 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_23"); 249 fail("expected a verification exception"); 250 } catch (Throwable t) { 251 DxUtil.checkVerifyException(t); 252 } 253 } 254 255 /** 256 * @constraint 4.8.1.14 257 * @title only <init> may be called 258 */ testVFE3()259 public void testVFE3() { 260 try { 261 Class 262 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_4"); 263 fail("expected a verification exception"); 264 } catch (Throwable t) { 265 DxUtil.checkVerifyException(t); 266 } 267 } 268 269 /** 270 * @constraint 4.8.2.7 271 * @title invokespecial target must be in self or superclass 272 */ testVFE4()273 public void testVFE4() { 274 //@uses dxc.junit.opcodes.invokespecial.jm.TPlain 275 try { 276 Class 277 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_6"); 278 fail("expected a verification exception"); 279 } catch (Throwable t) { 280 DxUtil.checkVerifyException(t); 281 } 282 } 283 284 /** 285 * @constraint 4.8.2.1 286 * @title number of arguments 287 */ testVFE5()288 public void testVFE5() { 289 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 290 try { 291 Class 292 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_5"); 293 fail("expected a verification exception"); 294 } catch (Throwable t) { 295 DxUtil.checkVerifyException(t); 296 } 297 } 298 299 /** 300 * @constraint 4.8.2.1 301 * @title type of argument - int 302 */ testVFE6()303 public void testVFE6() { 304 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 305 try { 306 Class 307 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_10"); 308 fail("expected a verification exception"); 309 } catch (Throwable t) { 310 DxUtil.checkVerifyException(t); 311 } 312 } 313 314 /** 315 * @constraint 4.8.2.7 316 * @title invokespecial must name method of "this" class or 317 * superclass 318 */ testVFE7()319 public void testVFE7() { 320 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 321 try { 322 Class 323 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_20"); 324 fail("expected a verification exception"); 325 } catch (Throwable t) { 326 DxUtil.checkVerifyException(t); 327 } 328 } 329 330 /** 331 * @constraint 4.8.2.7 332 * @title number of arguments passed to method 333 */ testVFE8()334 public void testVFE8() { 335 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 336 try { 337 Class 338 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_14"); 339 fail("expected a verification exception"); 340 } catch (Throwable t) { 341 DxUtil.checkVerifyException(t); 342 } 343 } 344 345 /** 346 * @constraint 4.8.2.12 347 * @title types of arguments passed to method 348 */ testVFE9()349 public void testVFE9() { 350 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 351 try { 352 Class 353 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_24"); 354 fail("expected a verification exception"); 355 } catch (Throwable t) { 356 DxUtil.checkVerifyException(t); 357 } 358 } 359 360 /** 361 * @constraint 4.8.2.13 362 * @title assignment incompatible references when accessing 363 * protected method 364 */ testVFE10()365 public void testVFE10() { 366 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 367 //@uses dxc.junit.opcodes.invokespecial.jm.TPlain 368 try { 369 Class 370 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_25"); 371 fail("expected a verification exception"); 372 } catch (Throwable t) { 373 DxUtil.checkVerifyException(t); 374 } 375 } 376 377 /** 378 * @constraint 4.8.2.13 379 * @title assignment incompatible references when accessing 380 * public method 381 */ testVFE11()382 public void testVFE11() { 383 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper 384 //@uses dxc.junit.opcodes.invokespecial.jm.TSuper2 385 try { 386 Class 387 .forName("dxc.junit.opcodes.invokespecial.jm.T_invokespecial_26"); 388 fail("expected a verification exception"); 389 } catch (Throwable t) { 390 DxUtil.checkVerifyException(t); 391 } 392 } 393 } 394