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 or IncompatibleClassChangeError"); 147 } catch (NoSuchMethodError t) { 148 } catch (IncompatibleClassChangeError e) { 149 } 150 } 151 152 /** 153 * @constraint B1 154 * @title number of arguments 155 */ 156 public void testVFE5() { 157 //@uses dot.junit.opcodes.invoke_interface_range.ITest 158 //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl 159 try { 160 new T_invoke_interface_range_5(new ITestImpl()); 161 fail("expected VerifyError"); 162 } catch (VerifyError t) { 163 } 164 } 165 166 /** 167 * @constraint B1 168 * @title int is passed instead of objref 169 */ 170 public void testVFE6() { 171 try { 172 Class.forName("dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_10"); 173 fail("expected a verification exception"); 174 } catch (Throwable t) { 175 DxUtil.checkVerifyException(t); 176 } 177 } 178 179 /** 180 * @constraint B9 181 * @title number of arguments passed to method 182 */ 183 public void testVFE9() { 184 try { 185 Class.forName("dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_9"); 186 fail("expected a verification exception"); 187 } catch (Throwable t) { 188 DxUtil.checkVerifyException(t); 189 } 190 } 191 192 /** 193 * @constraint A15 194 * @title invoke-interface may not be used to call <init>. 195 */ 196 public void testVFE10() { 197 //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_18 198 try { 199 new T_invoke_interface_range_18().run(new ITestImpl()); 200 fail("expected NoSuchMethodError or verification exception"); 201 } catch (NoSuchMethodError t) { 202 } catch (Throwable t) { 203 DxUtil.checkVerifyException(t); 204 } 205 } 206 207 /** 208 * @constraint A15 209 * @title invoke-interface may not be used to call <clinit>. 210 */ 211 public void testVFE11() { 212 //@uses dot.junit.opcodes.invoke_interface_range.ITest 213 //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl 214 try { 215 new T_invoke_interface_range_20().run(new ITestImpl()); 216 fail("expected NoSuchMethodError or verification exception"); 217 } catch (NoSuchMethodError t) { 218 } catch (Throwable t) { 219 DxUtil.checkVerifyException(t); 220 } 221 } 222 223 /** 224 * @constraint B9 225 * @title types of arguments passed to method 226 */ 227 public void testVFE12() { 228 //@uses dot.junit.opcodes.invoke_interface_range.ITest 229 //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl 230 try { 231 new T_invoke_interface_range_21().run(new ITestImpl()); 232 fail("expected VerifyError"); 233 } catch (VerifyError t) { 234 } 235 } 236 237 /** 238 * @constraint A23 239 * @title number of registers 240 */ 241 public void testVFE13() { 242 try { 243 Class.forName("dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_8"); 244 fail("expected a verification exception"); 245 } catch (Throwable t) { 246 DxUtil.checkVerifyException(t); 247 } 248 } 249 250 /** 251 * @constraint n/a 252 * @title Attempt to call undefined method. 253 */ 254 public void testVFE14() { 255 //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_7 256 //@uses dot.junit.opcodes.invoke_interface_range.ITest 257 //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl 258 try { 259 new T_invoke_interface_range_7().run(new ITestImpl()); 260 fail("expected NoSuchMethodError"); 261 } catch (NoSuchMethodError t) { 262 } 263 } 264 265 /** 266 * @constraint n/a 267 * @title Method has different signature. 268 */ 269 public void testVFE15() { 270 //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_16 271 //@uses dot.junit.opcodes.invoke_interface_range.ITest 272 //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl 273 try { 274 new T_invoke_interface_range_16().run(new ITestImpl()); 275 fail("expected NoSuchMethodError"); 276 } catch (Throwable t) { 277 DxUtil.checkVerifyException(t); 278 } 279 } 280 281 /** 282 * @constraint B6 283 * @title instance methods may only be invoked on already initialized instances. 284 */ 285 public void testVFE21() { 286 //@uses dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_22 287 //@uses dot.junit.opcodes.invoke_interface_range.ITest 288 //@uses dot.junit.opcodes.invoke_interface_range.ITestImpl 289 try { 290 Class.forName("dot.junit.opcodes.invoke_interface_range.d.T_invoke_interface_range_22"); 291 fail("expected a verification exception"); 292 } catch (Throwable t) { 293 DxUtil.checkVerifyException(t); 294 } 295 } 296 } 297