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