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