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_virtual_range; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_1; 22 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_10; 23 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_14; 24 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_15; 25 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_17; 26 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_18; 27 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_19; 28 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_2; 29 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_20; 30 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_24; 31 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_4; 32 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_5; 33 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_6; 34 import dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_7; 35 36 public class Test_invoke_virtual_range extends DxTestCase { 37 38 /** 39 * @title invoke virtual method 40 */ testN1()41 public void testN1() { 42 T_invoke_virtual_range_1 t = new T_invoke_virtual_range_1(); 43 int a = 1; 44 String sa = "a" + a; 45 String sb = "a1"; 46 assertTrue(t.run(sa, sb)); 47 assertFalse(t.run(t, sa)); 48 assertFalse(t.run(sb, t)); 49 } 50 51 /** 52 * @title Invoke protected method of superclass 53 */ testN3()54 public void testN3() { 55 //@uses dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_7 56 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper 57 T_invoke_virtual_range_7 t = new T_invoke_virtual_range_7(); 58 assertEquals(5, t.run()); 59 } 60 61 /** 62 * @title Check that new frame is created by invoke_virtual_range and 63 * arguments are passed to method 64 */ testN5()65 public void testN5() { 66 //@uses dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_14 67 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper 68 T_invoke_virtual_range_14 t = new T_invoke_virtual_range_14(); 69 assertTrue(t.run()); 70 } 71 72 /** 73 * @title Recursion of method lookup procedure 74 */ testN6()75 public void testN6() { 76 //@uses dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_17 77 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper 78 T_invoke_virtual_range_17 t = new T_invoke_virtual_range_17(); 79 assertEquals(5, t.run()); 80 } 81 82 /** 83 * @title Big number of arguments 84 */ testN7()85 public void testN7() { 86 T_invoke_virtual_range_2 t = new T_invoke_virtual_range_2(); 87 assertEquals(1, t.run()); 88 } 89 90 /** 91 * @title invoke default interface method 92 */ testN8()93 public void testN8() { 94 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_28", null); 95 } 96 97 /** 98 * @title expected NullPointerException 99 */ testE1()100 public void testE1() { 101 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_1", 102 NullPointerException.class, null, "Test"); 103 } 104 105 /** 106 * @title Native method can't be linked 107 */ testE2()108 public void testE2() { 109 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_4", 110 UnsatisfiedLinkError.class); 111 } 112 113 /** 114 * @title Attempt to invoke abstract method 115 */ testE4()116 public void testE4() { 117 //@uses dot.junit.opcodes.invoke_virtual_range.ATest 118 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_6", 119 AbstractMethodError.class); 120 } 121 122 /** 123 * @title Attempt to invoke conflict method 124 */ testE5()125 public void testE5() { 126 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_26", 127 IncompatibleClassChangeError.class); 128 } 129 130 /** 131 * @title Attempt to invoke abstract method 132 */ testE6()133 public void testE6() { 134 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_27", 135 AbstractMethodError.class); 136 } 137 138 /** 139 * @constraint A14 140 * @title invalid constant pool index 141 */ testVFE1()142 public void testVFE1() { 143 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_8", 144 VerifyError.class); 145 } 146 147 /** 148 * @constraint A15 149 * @title <clinit> may not be called using invoke-virtual 150 */ testVFE3()151 public void testVFE3() { 152 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_10", 153 VerifyError.class); 154 } 155 156 /** 157 * @constraint B1 158 * @title number of arguments passed to method 159 */ testVFE4()160 public void testVFE4() { 161 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_11", 162 VerifyError.class); 163 } 164 165 /** 166 * @constraint B9 167 * @title types of arguments passed to method 168 */ testVFE5()169 public void testVFE5() { 170 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_12", 171 VerifyError.class); 172 } 173 174 /** 175 * @constraint A15 176 * @title <init> may not be called using invoke_virtual_range 177 */ testVFE6()178 public void testVFE6() { 179 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_16", 180 VerifyError.class); 181 } 182 183 /** 184 * @constraint B10 185 * @title assignment incompatible references when accessing 186 * protected method 187 */ testVFE8()188 public void testVFE8() { 189 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper 190 //@uses dot.junit.opcodes.invoke_virtual_range.d.TPlain 191 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_22", 192 VerifyError.class); 193 } 194 195 /** 196 * @constraint B10 197 * @title assignment incompatible references when accessing 198 * public method 199 */ testVFE9()200 public void testVFE9() { 201 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper 202 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper2 203 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_23", 204 VerifyError.class); 205 } 206 207 /** 208 * @constraint n/a 209 * @title Attempt to call static method. 210 */ testVFE10()211 public void testVFE10() { 212 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_5", 213 IncompatibleClassChangeError.class); 214 } 215 216 217 /** 218 * @constraint n/a 219 * @title Attempt to invoke non-existing method. 220 */ testVFE12()221 public void testVFE12() { 222 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_15", 223 NoSuchMethodError.class); 224 } 225 226 /** 227 * @constraint n/a 228 * @title Attempt to invoke private method of other class. 229 */ testVFE13()230 public void testVFE13() { 231 //@uses dot.junit.opcodes.invoke_virtual_range.TestStubs 232 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_18", 233 IllegalAccessError.class, new TestStubs()); 234 } 235 236 /** 237 * @constraint B12 238 * @title Attempt to invoke protected method of unrelated class. 239 */ testVFE14()240 public void testVFE14() { 241 //@uses dot.junit.opcodes.invoke_virtual_range.TestStubs 242 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_20", 243 IllegalAccessError.class, new TestStubs()); 244 } 245 246 /** 247 * @constraint n/a 248 * @title Method has different signature. 249 */ testVFE15()250 public void testVFE15() { 251 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper 252 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_19", 253 NoSuchMethodError.class); 254 } 255 256 /** 257 * @constraint n/a 258 * @title invoke-virtual/range shall be used to invoke private methods 259 */ testVFE16()260 public void testVFE16() { 261 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_13", 262 VerifyError.class); 263 } 264 265 /** 266 * @constraint A23 267 * @title number of registers 268 */ testVFE17()269 public void testVFE17() { 270 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_9", 271 VerifyError.class); 272 } 273 274 /** 275 * @constraint A14 276 * @title attempt to invoke interface method 277 */ testVFE18()278 public void testVFE18() { 279 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_24", 280 IncompatibleClassChangeError.class); 281 } 282 283 /** 284 * @constraint B6 285 * @title instance methods may only be invoked on already initialized instances. 286 */ testVFE19()287 public void testVFE19() { 288 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_25", 289 VerifyError.class); 290 } 291 } 292