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_static_range; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_1; 22 import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_14; 23 import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_15; 24 import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_18; 25 import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_2; 26 import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_4; 27 import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_6; 28 29 30 31 public class Test_invoke_static_range extends DxTestCase { 32 33 /** 34 * @title Static method from library class Math 35 */ testN1()36 public void testN1() { 37 T_invoke_static_range_1 t = new T_invoke_static_range_1(); 38 assertEquals(1234567, t.run()); 39 } 40 41 /** 42 * @title Static method from user class 43 */ testN2()44 public void testN2() { 45 //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_2 46 //@uses dot.junit.opcodes.invoke_static_range.TestClass 47 T_invoke_static_range_2 t = new T_invoke_static_range_2(); 48 assertEquals(777, t.run()); 49 } 50 51 /** 52 * @title Big number of registers 53 */ testN3()54 public void testN3() { 55 assertEquals(1, T_invoke_static_range_4.run()); 56 } 57 58 59 /** 60 * @title Check that new frame is created by invoke_static_range and 61 * arguments are passed to method 62 */ testN5()63 public void testN5() { 64 //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_15 65 //@uses dot.junit.opcodes.invoke_static_range.TestClass 66 T_invoke_static_range_15 t = new T_invoke_static_range_15(); 67 assertTrue(t.run()); 68 } 69 70 /** 71 * @title Static protected method from other class in the same package 72 */ testN6()73 public void testN6() { 74 T_invoke_static_range_18 t = new T_invoke_static_range_18(); 75 assertEquals(888, t.run()); 76 } 77 78 /** 79 * @title Native method can't be linked 80 * 81 */ testE2()82 public void testE2() { 83 T_invoke_static_range_6 t = new T_invoke_static_range_6(); 84 try { 85 t.run(); 86 fail("expected UnsatisfiedLinkError"); 87 } catch (UnsatisfiedLinkError ule) { 88 // expected 89 } 90 } 91 92 93 /** 94 * @title initialization of referenced class throws exception 95 */ testE7()96 public void testE7() { 97 T_invoke_static_range_14 t = new T_invoke_static_range_14(); 98 try { 99 t.run(); 100 fail("expected Error"); 101 } catch (Error e) { 102 // expected 103 } 104 } 105 106 /** 107 * @constraint A14 108 * @title invalid constant pool index 109 */ testVFE1()110 public void testVFE1() { 111 try { 112 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_3"); 113 fail("expected a verification exception"); 114 } catch (Throwable t) { 115 DxUtil.checkVerifyException(t); 116 } 117 } 118 119 /** 120 * @constraint A15 121 * @title <clinit> may not be called using invoke_static_range 122 */ testVFE3()123 public void testVFE3() { 124 try { 125 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_10"); 126 fail("expected a verification exception"); 127 } catch (Throwable t) { 128 DxUtil.checkVerifyException(t); 129 } 130 } 131 132 /** 133 * @constraint B1 134 * @title number of arguments passed to method 135 */ testVFE4()136 public void testVFE4() { 137 try { 138 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_11"); 139 fail("expected a verification exception"); 140 } catch (Throwable t) { 141 DxUtil.checkVerifyException(t); 142 } 143 } 144 145 /** 146 * @constraint A15 147 * @title <init> may not be called using invoke_static_range 148 */ testVFE5()149 public void testVFE5() { 150 try { 151 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_19"); 152 fail("expected a verification exception"); 153 } catch (Throwable t) { 154 DxUtil.checkVerifyException(t); 155 } 156 } 157 158 /** 159 * @constraint B9 160 * @title types of arguments passed to method 161 */ testVFE6()162 public void testVFE6() { 163 try { 164 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_20"); 165 fail("expected a verification exception"); 166 } catch (Throwable t) { 167 DxUtil.checkVerifyException(t); 168 } 169 } 170 171 172 /** 173 * @constraint n/a 174 * @title Attempt to call non-static method. Java throws IncompatibleClassChangeError 175 * on first access but Dalvik throws VerifyError on class loading. 176 */ testVFE7()177 public void testVFE7() { 178 try { 179 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_5"); 180 fail("expected a verification exception"); 181 } catch (Throwable t) { 182 DxUtil.checkVerifyException(t); 183 } 184 } 185 186 /** 187 * @constraint n/a 188 * @title Attempt to call undefined method. Java throws NoSuchMethodError 189 * on first access but Dalvik throws VerifyError on class loading. 190 */ testVFE8()191 public void testVFE8() { 192 try { 193 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_7"); 194 fail("expected a verification exception"); 195 } catch (Throwable t) { 196 DxUtil.checkVerifyException(t); 197 } 198 } 199 200 /** 201 * @constraint n/a 202 * @title Attempt to call private method of other class. Java throws IllegalAccessError 203 * on first access but Dalvik throws VerifyError on class loading. 204 */ testVFE9()205 public void testVFE9() { 206 //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_8 207 //@uses dot.junit.opcodes.invoke_static_range.TestClass 208 try { 209 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_8"); 210 fail("expected a verification exception"); 211 } catch (Throwable t) { 212 DxUtil.checkVerifyException(t); 213 } 214 } 215 216 /** 217 * @constraint n/a 218 * @title Method has different signature. Java throws NoSuchMethodError 219 * on first access but Dalvik throws VerifyError on class loading. 220 */ testVFE10()221 public void testVFE10() { 222 //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_13 223 //@uses dot.junit.opcodes.invoke_static_range.TestClass 224 try { 225 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_13"); 226 fail("expected a verification exception"); 227 } catch (Throwable t) { 228 DxUtil.checkVerifyException(t); 229 } 230 } 231 232 233 /** 234 * @constraint B12 235 * @title Attempt to call protected method of unrelated class. Java throws IllegalAccessError 236 * on first access but Dalvik throws VerifyError on class loading. 237 */ testVFE12()238 public void testVFE12() { 239 //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_17 240 //@uses dot.junit.opcodes.invoke_static_range.TestClass 241 try { 242 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_17"); 243 fail("expected a verification exception"); 244 } catch (Throwable t) { 245 DxUtil.checkVerifyException(t); 246 } 247 } 248 249 /** 250 * @constraint A23 251 * @title number of registers 252 */ testVFE13()253 public void testVFE13() { 254 try { 255 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_16"); 256 fail("expected a verification exception"); 257 } catch (Throwable t) { 258 DxUtil.checkVerifyException(t); 259 } 260 } 261 262 /** 263 * @constraint A14 264 * @title attempt to invoke interface method 265 */ testVFE18()266 public void testVFE18() { 267 try { 268 Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_24"); 269 fail("expected a verification exception"); 270 } catch (Throwable t) { 271 DxUtil.checkVerifyException(t); 272 } 273 } 274 } 275