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_interface_range; |
| 18 | |
| 19 | import dot.junit.DxTestCase; |
| 20 | import dot.junit.DxUtil; |
| 21 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_1; |
| 22 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_11; |
| 23 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_12; |
| 24 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_13; |
| 25 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_14; |
| 26 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_16; |
| 27 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_18; |
| 28 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_20; |
| 29 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_21; |
| 30 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_3; |
| 31 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_4; |
| 32 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_5; |
| 33 | import dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_7; |
| 34 | |
| 35 | public class Test_invoke_interface_range extends DxTestCase { |
| 36 | |
| 37 | /** |
| 38 | * @title invoke interface method |
| 39 | */ |
| 40 | public void testN1() { |
| 41 | T_invoke_interface_range_1 t = new T_invoke_interface_range_1(); |
| 42 | assertEquals(0, t.run("aa", "aa")); |
| 43 | assertEquals(-1, t.run("aa", "bb")); |
| 44 | assertEquals(1, t.run("bb", "aa")); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @title Check that new frame is created by invoke_interface_range and |
| 49 | * arguments are passed to method |
| 50 | */ |
| 51 | public void testN2() { |
| 52 | //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_14 |
| 53 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 54 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 55 | T_invoke_interface_range_14 t = new T_invoke_interface_range_14(); |
| 56 | ITestImpl impl = new ITestImpl(); |
| 57 | assertEquals(1, t.run(impl)); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | |
| 62 | /** |
| 63 | * @title objref is null |
| 64 | */ |
| 65 | public void testE3() { |
| 66 | //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_3 |
| 67 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 68 | try { |
| 69 | new T_invoke_interface_range_3(null); |
| 70 | fail("expected NullPointerException"); |
| 71 | } catch (NullPointerException npe) { |
| 72 | // expected |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @title object doesn't implement interface |
| 78 | */ |
| 79 | public void testE4() { |
| 80 | //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_11 |
| 81 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 82 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 83 | T_invoke_interface_range_11 t = new T_invoke_interface_range_11(); |
| 84 | try { |
| 85 | t.run(); |
| 86 | fail("expected IncompatibleClassChangeError"); |
| 87 | } catch (IncompatibleClassChangeError e) { |
| 88 | // expected |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @title Native method can't be linked |
| 94 | */ |
| 95 | public void testE5() { |
| 96 | //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_12 |
| 97 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 98 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 99 | T_invoke_interface_range_12 t = new T_invoke_interface_range_12(); |
| 100 | ITestImpl impl = new ITestImpl(); |
| 101 | try { |
| 102 | t.run(impl); |
| 103 | fail("expected UnsatisfiedLinkError"); |
| 104 | } catch (UnsatisfiedLinkError e) { |
| 105 | // expected |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @title Attempt to invoke abstract method |
| 111 | */ |
| 112 | public void testE6() { |
| 113 | //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_13 |
| 114 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 115 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 116 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImplAbstract |
| 117 | T_invoke_interface_range_13 t = new T_invoke_interface_range_13(); |
| 118 | try { |
| 119 | t.run(); |
| 120 | fail("expected AbstractMethodError"); |
| 121 | } catch (AbstractMethodError e) { |
| 122 | // expected |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * @constraint A17 |
| 128 | * @title invalid constant pool index |
| 129 | */ |
| 130 | public void testVFE1() { |
| 131 | try { |
| 132 | Class.forName("dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_2"); |
| 133 | fail("expected a verification exception"); |
| 134 | } catch (Throwable t) { |
| 135 | DxUtil.checkVerifyException(t); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * @constraint A17 |
| 141 | * @title The referenced method_id must belong to an interface (not a class). |
| 142 | */ |
| 143 | public void testVFE2() { |
| 144 | try { |
| 145 | new T_invoke_interface_range_4().run(); |
| 146 | fail("expected NoSuchMethodError"); |
| 147 | } catch (NoSuchMethodError t) { |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * @constraint B1 |
| 153 | * @title number of arguments |
| 154 | */ |
| 155 | public void testVFE5() { |
| 156 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 157 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 158 | try { |
| 159 | new T_invoke_interface_range_5(new ITestImpl()); |
| 160 | fail("expected VerifyError"); |
| 161 | } catch (VerifyError t) { |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @constraint B1 |
| 167 | * @title int is passed instead of objref |
| 168 | */ |
| 169 | public void testVFE6() { |
| 170 | try { |
| 171 | Class.forName("dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_10"); |
| 172 | fail("expected a verification exception"); |
| 173 | } catch (Throwable t) { |
| 174 | DxUtil.checkVerifyException(t); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * @constraint B9 |
| 180 | * @title number of arguments passed to method |
| 181 | */ |
| 182 | public void testVFE9() { |
| 183 | try { |
| 184 | Class.forName("dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_9"); |
| 185 | fail("expected a verification exception"); |
| 186 | } catch (Throwable t) { |
| 187 | DxUtil.checkVerifyException(t); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @constraint A15 |
| 193 | * @title invoke-interface may not be used to call <init>. |
| 194 | */ |
| 195 | public void testVFE10() { |
| 196 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 197 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 198 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImplAbstract |
| 199 | try { |
| 200 | new T_invoke_interface_range_18().run(new ITestImpl()); |
| 201 | fail("expected InstantiationError"); |
| 202 | } catch (InstantiationError t) { |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * @constraint A15 |
| 208 | * @title invoke-interface may not be used to call <clinit>. |
| 209 | */ |
| 210 | public void testVFE11() { |
| 211 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 212 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 213 | try { |
| 214 | new T_invoke_interface_range_20().run(new ITestImpl()); |
| 215 | fail("expected NoSuchMethodError"); |
| 216 | } catch (NoSuchMethodError t) { |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * @constraint B9 |
| 222 | * @title types of arguments passed to method |
| 223 | */ |
| 224 | public void testVFE12() { |
| 225 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 226 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 227 | try { |
| 228 | new T_invoke_interface_range_21().run(new ITestImpl()); |
| 229 | fail("expected VerifyError"); |
| 230 | } catch (VerifyError t) { |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * @constraint A23 |
| 236 | * @title number of registers |
| 237 | */ |
| 238 | public void testVFE13() { |
| 239 | try { |
| 240 | Class.forName("dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_8"); |
| 241 | fail("expected a verification exception"); |
| 242 | } catch (Throwable t) { |
| 243 | DxUtil.checkVerifyException(t); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * @constraint n/a |
| 249 | * @title Attempt to call undefined method. |
| 250 | */ |
| 251 | public void testVFE14() { |
| 252 | //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_7 |
| 253 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 254 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 255 | try { |
| 256 | new T_invoke_interface_range_7().run(new ITestImpl()); |
| 257 | fail("expected NoSuchMethodError"); |
| 258 | } catch (NoSuchMethodError t) { |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * @constraint n/a |
| 264 | * @title Method has different signature. |
| 265 | */ |
| 266 | public void testVFE15() { |
| 267 | //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_16 |
| 268 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 269 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 270 | try { |
| 271 | new T_invoke_interface_range_16().run(new ITestImpl()); |
| 272 | fail("expected NoSuchMethodError"); |
| 273 | } catch (Throwable t) { |
| 274 | DxUtil.checkVerifyException(t); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * @constraint B6 |
| 280 | * @title instance methods may only be invoked on already initialized instances. |
| 281 | */ |
| 282 | public void testVFE21() { |
| 283 | //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_22 |
| 284 | //@uses dot.junit.opcodes.invoke_interface_range.ITest |
| 285 | //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl |
| 286 | try { |
| 287 | Class.forName("dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_22"); |
| 288 | fail("expected a verification exception"); |
| 289 | } catch (Throwable t) { |
| 290 | DxUtil.checkVerifyException(t); |
| 291 | } |
| 292 | } |
| 293 | } |