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 expected NullPointerException 92 */ testE1()93 public void testE1() { 94 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_1", 95 NullPointerException.class, null, "Test"); 96 } 97 98 /** 99 * @title Native method can't be linked 100 */ testE2()101 public void testE2() { 102 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_4", 103 UnsatisfiedLinkError.class); 104 } 105 106 /** 107 * @title Attempt to invoke abstract method 108 */ testE4()109 public void testE4() { 110 //@uses dot.junit.opcodes.invoke_virtual_range.ATest 111 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_6", 112 AbstractMethodError.class); 113 } 114 115 /** 116 * @constraint A14 117 * @title invalid constant pool index 118 */ testVFE1()119 public void testVFE1() { 120 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_8", 121 VerifyError.class); 122 } 123 124 /** 125 * @constraint A15 126 * @title <clinit> may not be called using invoke-virtual 127 */ testVFE3()128 public void testVFE3() { 129 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_10", 130 VerifyError.class); 131 } 132 133 /** 134 * @constraint B1 135 * @title number of arguments passed to method 136 */ testVFE4()137 public void testVFE4() { 138 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_11", 139 VerifyError.class); 140 } 141 142 /** 143 * @constraint B9 144 * @title types of arguments passed to method 145 */ testVFE5()146 public void testVFE5() { 147 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_12", 148 VerifyError.class); 149 } 150 151 /** 152 * @constraint A15 153 * @title <init> may not be called using invoke_virtual_range 154 */ testVFE6()155 public void testVFE6() { 156 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_16", 157 VerifyError.class); 158 } 159 160 /** 161 * @constraint B10 162 * @title assignment incompatible references when accessing 163 * protected method 164 */ testVFE8()165 public void testVFE8() { 166 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper 167 //@uses dot.junit.opcodes.invoke_virtual_range.d.TPlain 168 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_22", 169 VerifyError.class); 170 } 171 172 /** 173 * @constraint B10 174 * @title assignment incompatible references when accessing 175 * public method 176 */ testVFE9()177 public void testVFE9() { 178 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper 179 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper2 180 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_23", 181 VerifyError.class); 182 } 183 184 /** 185 * @constraint n/a 186 * @title Attempt to call static method. 187 */ testVFE10()188 public void testVFE10() { 189 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_5", 190 IncompatibleClassChangeError.class); 191 } 192 193 194 /** 195 * @constraint n/a 196 * @title Attempt to invoke non-existing method. 197 */ testVFE12()198 public void testVFE12() { 199 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_15", 200 NoSuchMethodError.class); 201 } 202 203 /** 204 * @constraint n/a 205 * @title Attempt to invoke private method of other class. 206 */ testVFE13()207 public void testVFE13() { 208 //@uses dot.junit.opcodes.invoke_virtual_range.TestStubs 209 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_18", 210 IllegalAccessError.class, new TestStubs()); 211 } 212 213 /** 214 * @constraint B12 215 * @title Attempt to invoke protected method of unrelated class. 216 */ testVFE14()217 public void testVFE14() { 218 //@uses dot.junit.opcodes.invoke_virtual_range.TestStubs 219 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_20", 220 IllegalAccessError.class, new TestStubs()); 221 } 222 223 /** 224 * @constraint n/a 225 * @title Method has different signature. 226 */ testVFE15()227 public void testVFE15() { 228 //@uses dot.junit.opcodes.invoke_virtual_range.d.TSuper 229 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_19", 230 NoSuchMethodError.class); 231 } 232 233 /** 234 * @constraint n/a 235 * @title invoke-virtual/range shall be used to invoke private methods 236 */ testVFE16()237 public void testVFE16() { 238 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_13", 239 VerifyError.class); 240 } 241 242 /** 243 * @constraint A23 244 * @title number of registers 245 */ testVFE17()246 public void testVFE17() { 247 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_9", 248 VerifyError.class); 249 } 250 251 /** 252 * @constraint A14 253 * @title attempt to invoke interface method 254 */ testVFE18()255 public void testVFE18() { 256 loadAndRun("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_24", 257 IncompatibleClassChangeError.class); 258 } 259 260 /** 261 * @constraint B6 262 * @title instance methods may only be invoked on already initialized instances. 263 */ testVFE19()264 public void testVFE19() { 265 load("dot.junit.opcodes.invoke_virtual_range.d.T_invoke_virtual_range_25", 266 VerifyError.class); 267 } 268 } 269