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; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_1; 22 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11; 23 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_12; 24 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_13; 25 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_14; 26 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_16; 27 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_18; 28 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_20; 29 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_21; 30 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_23; 31 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_24; 32 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_25; 33 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_3; 34 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_4; 35 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_5; 36 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_7; 37 38 public class Test_invoke_interface extends DxTestCase { 39 40 /** 41 * @title invoke interface method 42 */ testN1()43 public void testN1() { 44 T_invoke_interface_1 t = new T_invoke_interface_1(); 45 assertEquals(0, t.run("aa", "aa")); 46 assertEquals(-1, t.run("aa", "bb")); 47 assertEquals(1, t.run("bb", "aa")); 48 } 49 50 /** 51 * @title Check that new frame is created by invoke_interface and 52 * arguments are passed to method 53 */ testN2()54 public void testN2() { 55 //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_14 56 //@uses dot.junit.opcodes.invoke_interface.ITest 57 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 58 T_invoke_interface_14 t = new T_invoke_interface_14(); 59 ITestImpl impl = new ITestImpl(); 60 assertEquals(1, t.run(impl)); 61 } 62 63 /** 64 * @title invoke default interface method 65 */ testN3()66 public void testN3() { 67 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_25", null); 68 } 69 70 /** 71 * @title objref is null 72 */ testE3()73 public void testE3() { 74 //@uses dot.junit.opcodes.invoke_interface.ITest 75 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_3", 76 NullPointerException.class); 77 } 78 79 /** 80 * @title object doesn't implement interface 81 */ testE4()82 public void testE4() { 83 //@uses dot.junit.opcodes.invoke_interface.ITest 84 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 85 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11", 86 IncompatibleClassChangeError.class); 87 } 88 89 /** 90 * @title dvmInterpFindInterfaceMethod failures were putting NULL Method*s 91 * in the interface cache, leading to a null pointer deference the second 92 * time you made the same bad call, with no exception thrown. 93 * See http://code.google.com/p/android/issues/detail?id=29358 for details. 94 */ testE4_2()95 public void testE4_2() { 96 //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11 97 //@uses dot.junit.opcodes.invoke_interface.ITest 98 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 99 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11", 100 IncompatibleClassChangeError.class); 101 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11", 102 IncompatibleClassChangeError.class); 103 } 104 105 /** 106 * @title Native method can't be linked 107 */ testE5()108 public void testE5() { 109 //@uses dot.junit.opcodes.invoke_interface.ITest 110 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 111 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_12", 112 UnsatisfiedLinkError.class, new ITestImpl()); 113 } 114 115 /** 116 * @title Attempt to invoke abstract method 117 */ testE6()118 public void testE6() { 119 //@uses dot.junit.opcodes.invoke_interface.ITest 120 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 121 //@uses dot.junit.opcodes.invoke_interface.ITestImplAbstract 122 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_13", 123 AbstractMethodError.class); 124 } 125 126 /** 127 * @title Attempt to invoke conflict method 128 */ testE7()129 public void testE7() { 130 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_23", 131 IncompatibleClassChangeError.class); 132 } 133 134 /** 135 * @title Attempt to invoke abstract method 136 */ testE8()137 public void testE8() { 138 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_24", 139 AbstractMethodError.class); 140 } 141 142 /** 143 * @constraint A16 144 * @title invalid constant pool index 145 */ testVFE1()146 public void testVFE1() { 147 load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_2", VerifyError.class); 148 } 149 150 /** 151 * @constraint A16 152 * @title The referenced method_id must belong to an interface (not a class). 153 */ testVFE2()154 public void testVFE2() { 155 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_4", 156 IncompatibleClassChangeError.class); 157 } 158 159 /** 160 * @constraint B1 161 * @title number of arguments 162 */ testVFE5()163 public void testVFE5() { 164 //@uses dot.junit.opcodes.invoke_interface.ITest 165 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 166 load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_5", VerifyError.class); 167 } 168 169 /** 170 * @constraint B1 171 * @title int is passed instead of objref 172 */ testVFE6()173 public void testVFE6() { 174 load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_10", VerifyError.class); 175 } 176 177 /** 178 * @constraint B9 179 * @title number of arguments passed to method 180 */ testVFE9()181 public void testVFE9() { 182 load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_9", VerifyError.class); 183 } 184 185 /** 186 * @constraint A15 187 * @title invoke-interface may not be used to call <init>. 188 */ testVFE10()189 public void testVFE10() { 190 //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_18 191 load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_18", VerifyError.class); 192 } 193 194 /** 195 * @constraint A15 196 * @title invoke-interface may not be used to call <clinit>. 197 */ testVFE11()198 public void testVFE11() { 199 //@uses dot.junit.opcodes.invoke_interface.ITest 200 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 201 load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_20", VerifyError.class); 202 } 203 204 /** 205 * @constraint B9 206 * @title types of arguments passed to method 207 */ testVFE12()208 public void testVFE12() { 209 //@uses dot.junit.opcodes.invoke_interface.ITest 210 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 211 load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_21", VerifyError.class); 212 } 213 214 /** 215 * @constraint A23 216 * @title number of registers 217 */ testVFE13()218 public void testVFE13() { 219 load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_8", VerifyError.class); 220 } 221 222 /** 223 * @constraint n/a 224 * @title Attempt to call undefined method. 225 */ testVFE14()226 public void testVFE14() { 227 //@uses dot.junit.opcodes.invoke_interface.ITest 228 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 229 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_7", 230 NoSuchMethodError.class, new ITestImpl()); 231 } 232 233 /** 234 * @constraint n/a 235 * @title Method has different signature. 236 */ testVFE15()237 public void testVFE15() { 238 //@uses dot.junit.opcodes.invoke_interface.ITest 239 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 240 loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_16", 241 NoSuchMethodError.class, new ITestImpl()); 242 } 243 244 245 /** 246 * @constraint B6 247 * @title instance methods may only be invoked on already initialized instances. 248 */ testVFE21()249 public void testVFE21() { 250 //@uses dot.junit.opcodes.invoke_interface.ITest 251 //@uses dot.junit.opcodes.invoke_interface.ITestImpl 252 load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_22", VerifyError.class); 253 } 254 } 255