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_super; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.invoke_super.d.T_invoke_super_1; 22 import dot.junit.opcodes.invoke_super.d.T_invoke_super_10; 23 import dot.junit.opcodes.invoke_super.d.T_invoke_super_14; 24 import dot.junit.opcodes.invoke_super.d.T_invoke_super_15; 25 import dot.junit.opcodes.invoke_super.d.T_invoke_super_17; 26 import dot.junit.opcodes.invoke_super.d.T_invoke_super_18; 27 import dot.junit.opcodes.invoke_super.d.T_invoke_super_19; 28 import dot.junit.opcodes.invoke_super.d.T_invoke_super_2; 29 import dot.junit.opcodes.invoke_super.d.T_invoke_super_20; 30 import dot.junit.opcodes.invoke_super.d.T_invoke_super_4; 31 import dot.junit.opcodes.invoke_super.d.T_invoke_super_5; 32 import dot.junit.opcodes.invoke_super.d.T_invoke_super_6; 33 import dot.junit.opcodes.invoke_super.d.T_invoke_super_7; 34 35 public class Test_invoke_super extends DxTestCase { 36 37 /** 38 * @title invoke method of superclass 39 */ 40 public void testN1() { 41 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_1 42 //@uses dot.junit.opcodes.invoke_super.d.TSuper 43 T_invoke_super_1 t = new T_invoke_super_1(); 44 assertEquals(5, t.run()); 45 } 46 47 48 /** 49 * @title Invoke protected method of superclass 50 */ 51 public void testN3() { 52 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_7 53 //@uses dot.junit.opcodes.invoke_super.d.TSuper 54 T_invoke_super_7 t = new T_invoke_super_7(); 55 assertEquals(5, t.run()); 56 } 57 58 /** 59 * @title Check that new frame is created by invoke_super and 60 * arguments are passed to method 61 */ 62 public void testN5() { 63 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_14 64 //@uses dot.junit.opcodes.invoke_super.d.TSuper 65 T_invoke_super_14 t = new T_invoke_super_14(); 66 assertTrue(t.run()); 67 } 68 69 /** 70 * @title Recursion of method lookup procedure 71 */ 72 public void testN6() { 73 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_17 74 //@uses dot.junit.opcodes.invoke_super.d.TSuper 75 //@uses dot.junit.opcodes.invoke_super.d.TSuper2 76 T_invoke_super_17 t = new T_invoke_super_17(); 77 assertEquals(5, t.run()); 78 } 79 80 /** 81 * @title obj ref is null 82 */ 83 public void testE1() { 84 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_1 85 //@uses dot.junit.opcodes.invoke_super.d.TSuper 86 T_invoke_super_2 t = new T_invoke_super_2(); 87 try { 88 t.run(); 89 fail("expected NullPointerException"); 90 } catch (NullPointerException npe) { 91 // expected 92 } 93 } 94 95 /** 96 * @title Native method can't be linked 97 */ 98 public void testE2() { 99 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_4 100 //@uses dot.junit.opcodes.invoke_super.d.TSuper 101 T_invoke_super_4 t = new T_invoke_super_4(); 102 try { 103 t.run(); 104 fail("expected UnsatisfiedLinkError"); 105 } catch (UnsatisfiedLinkError ule) { 106 // expected 107 } 108 } 109 110 /** 111 * @title Attempt to invoke abstract method 112 */ 113 public void testE4() { 114 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_6 115 //@uses dot.junit.opcodes.invoke_super.ATest 116 T_invoke_super_6 t = new T_invoke_super_6(); 117 try { 118 t.run(); 119 fail("expected AbstractMethodError"); 120 } catch (AbstractMethodError iae) { 121 // expected 122 } 123 } 124 125 /** 126 * @constraint A13 127 * @title invalid constant pool index 128 */ 129 public void testVFE1() { 130 try { 131 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_8"); 132 fail("expected a verification exception"); 133 } catch (Throwable t) { 134 DxUtil.checkVerifyException(t); 135 } 136 } 137 138 /** 139 * @constraint A15 140 * @title <clinit> may not be called using invoke-super 141 */ 142 public void testVFE3() { 143 try { 144 new T_invoke_super_10().run(); 145 fail("expected IncompatibleClassChangeError"); 146 } catch (IncompatibleClassChangeError t) { 147 } 148 } 149 150 /** 151 * @constraint B1 152 * @title number of arguments passed to method 153 */ 154 public void testVFE4() { 155 try { 156 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_11"); 157 fail("expected a verification exception"); 158 } catch (Throwable t) { 159 DxUtil.checkVerifyException(t); 160 } 161 } 162 163 /** 164 * @constraint B9 165 * @title types of arguments passed to method. 166 */ 167 public void testVFE5() { 168 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_12 169 //@uses dot.junit.opcodes.invoke_super.d.TSuper 170 try { 171 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_12"); 172 fail("expected a verification exception"); 173 } catch (Throwable t) { 174 DxUtil.checkVerifyException(t); 175 } 176 } 177 178 /** 179 * @constraint A15 180 * @title <init> may not be called using invoke_super 181 */ 182 public void testVFE6() { 183 try { 184 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_16"); 185 fail("expected a verification exception"); 186 } catch (Throwable t) { 187 DxUtil.checkVerifyException(t); 188 } 189 } 190 191 /** 192 * @constraint B10 193 * @title assignment incompatible references when accessing 194 * protected method 195 */ 196 public void testVFE8() { 197 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_22 198 //@uses dot.junit.opcodes.invoke_super.d.TSuper 199 //@uses dot.junit.opcodes.invoke_super.d.TPlain 200 try { 201 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_22"); 202 fail("expected a verification exception"); 203 } catch (Throwable t) { 204 DxUtil.checkVerifyException(t); 205 } 206 } 207 208 /** 209 * @constraint B10 210 * @title assignment incompatible references when accessing 211 * public method 212 */ 213 public void testVFE9() { 214 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_23 215 //@uses dot.junit.opcodes.invoke_super.d.TSuper 216 //@uses dot.junit.opcodes.invoke_super.d.TSuper2 217 try { 218 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_23"); 219 fail("expected a verification exception"); 220 } catch (Throwable t) { 221 DxUtil.checkVerifyException(t); 222 } 223 } 224 225 /** 226 * @constraint n/a 227 * @title Attempt to call static method. 228 */ 229 public void testVFE10() { 230 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_5 231 //@uses dot.junit.opcodes.invoke_super.d.TSuper 232 try { 233 new T_invoke_super_5().run(); 234 fail("expected IncompatibleClassChangeError"); 235 } catch (IncompatibleClassChangeError t) { 236 } 237 } 238 239 240 /** 241 * @constraint n/a 242 * @title Attempt to invoke non-existing method. 243 */ 244 public void testVFE12() { 245 try { 246 new T_invoke_super_15().run(); 247 fail("expected NoSuchMethodError"); 248 } catch (NoSuchMethodError t) { 249 } 250 } 251 252 /** 253 * @constraint n/a 254 * @title Attempt to invoke private method of other class. 255 */ 256 public void testVFE13() { 257 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_18 258 //@uses dot.junit.opcodes.invoke_super.TestStubs 259 try { 260 new T_invoke_super_18().run(new TestStubs()); 261 fail("expected IllegalAccessError"); 262 } catch (IllegalAccessError t) { 263 } 264 } 265 266 /** 267 * @constraint B12 268 * @title Attempt to invoke protected method of unrelated class. 269 */ 270 public void testVFE14() { 271 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_20 272 //@uses dot.junit.opcodes.invoke_super.TestStubs 273 try { 274 new T_invoke_super_20().run(new TestStubs()); 275 fail("expected IllegalAccessError"); 276 } catch (IllegalAccessError t) { 277 } 278 } 279 280 /** 281 * @constraint n/a 282 * @title Method has different signature. 283 */ 284 public void testVFE15() { 285 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_19 286 //@uses dot.junit.opcodes.invoke_super.d.TSuper 287 try { 288 new T_invoke_super_19().run(); 289 fail("expected NoSuchMethodError"); 290 } catch (NoSuchMethodError t) { 291 } 292 } 293 294 /** 295 * @constraint n/a 296 * @title invoke-super shall be used to invoke private methods 297 */ 298 public void testVFE16() { 299 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_13 300 //@uses dot.junit.opcodes.invoke_super.d.TSuper 301 try { 302 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_13"); 303 fail("expected a verification exception"); 304 } catch (Throwable t) { 305 DxUtil.checkVerifyException(t); 306 } 307 } 308 309 /** 310 * @constraint A23 311 * @title number of registers 312 */ 313 public void testVFE17() { 314 try { 315 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_9"); 316 fail("expected a verification exception"); 317 } catch (Throwable t) { 318 DxUtil.checkVerifyException(t); 319 } 320 } 321 322 /** 323 * @constraint A13 324 * @title attempt to invoke interface method 325 */ 326 public void testVFE18() { 327 try { 328 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_24"); 329 fail("expected a verification exception"); 330 } catch (Throwable t) { 331 DxUtil.checkVerifyException(t); 332 } 333 } 334 335 /** 336 * @constraint B6 337 * @title instance methods may only be invoked on already initialized instances. 338 */ 339 public void testVFE19() { 340 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_25 341 //@uses dot.junit.opcodes.invoke_super.d.TSuper 342 try { 343 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_25"); 344 fail("expected a verification exception"); 345 } catch (Throwable t) { 346 DxUtil.checkVerifyException(t); 347 } 348 } 349 } 350