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_direct; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_12; 22 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_13; 23 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_16; 24 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_2; 25 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_21; 26 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_26; 27 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_6; 28 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_7; 29 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_8; 30 import dot.junit.opcodes.invoke_direct.d.T_invoke_direct_9; 31 32 public class Test_invoke_direct extends DxTestCase { 33 34 /** 35 * @title private method call 36 */ testN2()37 public void testN2() { 38 T_invoke_direct_2 t = new T_invoke_direct_2(); 39 assertEquals(345, t.run()); 40 } 41 42 43 /** 44 * @title Check that new frame is created by invoke_direct 45 */ testN7()46 public void testN7() { 47 T_invoke_direct_21 t = new T_invoke_direct_21(); 48 assertEquals(1, t.run()); 49 } 50 51 52 53 /** 54 * @title objref is null 55 */ testE3()56 public void testE3() { 57 loadAndRun("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_8", 58 NullPointerException.class); 59 } 60 61 /** 62 * @title Native method can't be linked 63 */ testE5()64 public void testE5() { 65 loadAndRun("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_9", 66 UnsatisfiedLinkError.class); 67 } 68 69 /** 70 * @constraint A13 71 * @title invalid constant pool index 72 */ testVFE1()73 public void testVFE1() { 74 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_3", VerifyError.class); 75 } 76 77 /** 78 * @constraint A15 79 * @title invoke-direct may not be used to invoke <clinit> 80 */ testVFE3()81 public void testVFE3() { 82 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_4", VerifyError.class); 83 } 84 85 /** 86 * @constraint B4 87 * @title invoke-direct target must be in self or superclass 88 */ testVFE4()89 public void testVFE4() { 90 //@uses dot.junit.opcodes.invoke_direct.TSuper 91 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_6", VerifyError.class); 92 } 93 94 /** 95 * @constraint B1 96 * @title number of arguments 97 */ testVFE5()98 public void testVFE5() { 99 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_5", VerifyError.class); 100 } 101 102 /** 103 * @constraint B1 104 * @title int is passed instead of obj ref 105 */ testVFE6()106 public void testVFE6() { 107 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_10", VerifyError.class); 108 } 109 110 111 /** 112 * @constraint B9 113 * @title number of arguments passed to method 114 */ testVFE8()115 public void testVFE8() { 116 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_14", VerifyError.class); 117 } 118 119 /** 120 * @constraint B9 121 * @title types of arguments passed to method 122 */ testVFE9()123 public void testVFE9() { 124 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_24", VerifyError.class); 125 } 126 127 /** 128 * @constraint B10 129 * @title assignment incompatible references when accessing protected method 130 */ testVFE10()131 public void testVFE10() { 132 //@uses dot.junit.opcodes.invoke_direct.TPlain 133 //@uses dot.junit.opcodes.invoke_direct.TSuper 134 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_25", VerifyError.class); 135 } 136 137 /** 138 * @constraint B5 139 * @title Superclass' method call 140 */ testVFE11()141 public void testVFE11() { 142 //@uses dot.junit.opcodes.invoke_direct.TSuper 143 loadAndRun("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_1", 144 IncompatibleClassChangeError.class); 145 } 146 147 /** 148 * @constraint A23 149 * @title number of registers 150 */ testVFE12()151 public void testVFE12() { 152 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_15", VerifyError.class); 153 } 154 155 156 /** 157 * @constraint n/a 158 * @title Attempt to call undefined method. 159 */ testVFE13()160 public void testVFE13() { 161 loadAndRun("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_7", NoSuchMethodError.class); 162 } 163 164 /** 165 * @constraint n/a 166 * @title Method has different signature. 167 */ testVFE14()168 public void testVFE14() { 169 loadAndRun("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_16", NoSuchMethodError.class); 170 } 171 172 /** 173 * @constraint n/a 174 * @title Attempt to invoke static method. Java throws IncompatibleClassChangeError 175 * on first access. Dalvik threw VerifyError on class loading. 176 */ testVFE15()177 public void testVFE15() { 178 loadAndRun("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_11", 179 IncompatibleClassChangeError.class); 180 } 181 182 183 /** 184 * @constraint n/a 185 * @title Attempt to invoke private method of superclass. 186 */ testVFE16()187 public void testVFE16() { 188 //@uses dot.junit.opcodes.invoke_direct.TSuper 189 loadAndRun("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_12", 190 IllegalAccessError.class); 191 } 192 193 194 /** 195 * @constraint n/a 196 * @title Attempt to invoke abstract method 197 */ testVFE17()198 public void testVFE17() { 199 //@uses dot.junit.opcodes.invoke_direct.TAbstract 200 loadAndRun("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_13", 201 IncompatibleClassChangeError.class); 202 } 203 204 /** 205 * @constraint B5 206 * @title An instance initializer must only be invoked on an uninitialized instance. 207 */ testVFE18()208 public void testVFE18() { 209 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_17", VerifyError.class); 210 } 211 212 /** 213 * @constraint B8 214 * @title attempt to access inherited instance field before <init> is called 215 */ testVFE19()216 public void testVFE19() { 217 //@uses dot.junit.opcodes.invoke_direct.TSuper 218 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_18", VerifyError.class); 219 } 220 221 /** 222 * @constraint A13 223 * @title attempt to invoke interface method 224 */ testVFE20()225 public void testVFE20() { 226 loadAndRun("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_26", 227 IncompatibleClassChangeError.class); 228 } 229 230 /** 231 * @constraint B6 232 * @title instance methods may only be invoked on already initialized instances. 233 */ testVFE21()234 public void testVFE21() { 235 load("dot.junit.opcodes.invoke_direct.d.T_invoke_direct_27", VerifyError.class); 236 } 237 } 238