Tsu Chiang Chuang | 9a223d7 | 2011-04-27 17:19:46 -0700 | [diff] [blame] | 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_13; |
| 23 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_14; |
| 24 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_15; |
| 25 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_17; |
| 26 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_18; |
| 27 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_19; |
| 28 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_2; |
| 29 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_4; |
| 30 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_5; |
| 31 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_6; |
| 32 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_7; |
| 33 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_8; |
| 34 | |
| 35 | |
| 36 | |
| 37 | public class Test_invoke_static_range extends DxTestCase { |
| 38 | |
| 39 | /** |
| 40 | * @title Static method from library class Math |
| 41 | */ |
| 42 | public void testN1() { |
| 43 | T_invoke_static_range_1 t = new T_invoke_static_range_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_range.d.T_invoke_static_range_2 |
| 52 | //@uses dot.junit.opcodes.invoke_static_range.TestClass |
| 53 | T_invoke_static_range_2 t = new T_invoke_static_range_2(); |
| 54 | assertEquals(777, t.run()); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @title Big number of registers |
| 59 | */ |
| 60 | public void testN3() { |
| 61 | assertEquals(1, T_invoke_static_range_4.run()); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | /** |
| 66 | * @title Check that new frame is created by invoke_static_range and |
| 67 | * arguments are passed to method |
| 68 | */ |
| 69 | public void testN5() { |
| 70 | //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_15 |
| 71 | //@uses dot.junit.opcodes.invoke_static_range.TestClass |
| 72 | T_invoke_static_range_15 t = new T_invoke_static_range_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_range_18 t = new T_invoke_static_range_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_range_6 t = new T_invoke_static_range_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_range_14 t = new T_invoke_static_range_14(); |
| 104 | try { |
| 105 | t.run(); |
| 106 | fail("expected Error"); |
| 107 | } catch (Error e) { |
| 108 | // expected |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @constraint A14 |
| 114 | * @title invalid constant pool index |
| 115 | */ |
| 116 | public void testVFE1() { |
| 117 | try { |
| 118 | Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_3"); |
| 119 | fail("expected a verification exception"); |
| 120 | } catch (Throwable t) { |
| 121 | DxUtil.checkVerifyException(t); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @constraint A15 |
| 127 | * @title <clinit> may not be called using invoke_static_range |
| 128 | */ |
| 129 | public void testVFE3() { |
| 130 | try { |
| 131 | Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_10"); |
| 132 | fail("expected a verification exception"); |
| 133 | } catch (Throwable t) { |
| 134 | DxUtil.checkVerifyException(t); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @constraint B1 |
| 140 | * @title number of arguments passed to method |
| 141 | */ |
| 142 | public void testVFE4() { |
| 143 | try { |
| 144 | Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_11"); |
| 145 | fail("expected a verification exception"); |
| 146 | } catch (Throwable t) { |
| 147 | DxUtil.checkVerifyException(t); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * @constraint A15 |
| 153 | * @title <init> may not be called using invoke_static_range |
| 154 | */ |
| 155 | public void testVFE5() { |
| 156 | try { |
| 157 | new T_invoke_static_range_19().run(); |
| 158 | fail("expected IncompatibleClassChangeError"); |
| 159 | } catch (IncompatibleClassChangeError t) { |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * @constraint B9 |
| 165 | * @title types of arguments passed to method |
| 166 | */ |
| 167 | public void testVFE6() { |
| 168 | try { |
| 169 | Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_20"); |
| 170 | fail("expected a verification exception"); |
| 171 | } catch (Throwable t) { |
| 172 | DxUtil.checkVerifyException(t); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | |
| 177 | /** |
| 178 | * @constraint n/a |
| 179 | * @title Attempt to call non-static method. |
| 180 | */ |
| 181 | public void testVFE7() { |
| 182 | try { |
| 183 | new T_invoke_static_range_5().run(); |
| 184 | fail("expected IncompatibleClassChangeError"); |
| 185 | } catch (IncompatibleClassChangeError t) { |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * @constraint n/a |
| 191 | * @title Attempt to call undefined method. |
| 192 | */ |
| 193 | public void testVFE8() { |
| 194 | try { |
| 195 | new T_invoke_static_range_7().run(); |
| 196 | fail("expected NoSuchMethodError"); |
| 197 | } catch (NoSuchMethodError t) { |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * @constraint n/a |
| 203 | * @title Attempt to call private method of other class. |
| 204 | */ |
| 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 | new T_invoke_static_range_8().run(); |
| 210 | fail("expected IllegalAccessError"); |
| 211 | } catch (IllegalAccessError t) { |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * @constraint n/a |
| 217 | * @title Method has different signature. |
| 218 | */ |
| 219 | public void testVFE10() { |
| 220 | //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_13 |
| 221 | //@uses dot.junit.opcodes.invoke_static_range.TestClass |
| 222 | try { |
| 223 | new T_invoke_static_range_13().run(); |
| 224 | fail("expected NoSuchMethodError"); |
| 225 | } catch (NoSuchMethodError t) { |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | |
| 230 | /** |
| 231 | * @constraint B12 |
| 232 | * @title Attempt to call protected method of unrelated class. |
| 233 | */ |
| 234 | public void testVFE12() { |
| 235 | //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_17 |
| 236 | //@uses dot.junit.opcodes.invoke_static_range.TestClass |
| 237 | try { |
| 238 | new T_invoke_static_range_17().run(); |
| 239 | fail("expected IllegalAccessError"); |
| 240 | } catch (IllegalAccessError t) { |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * @constraint A23 |
| 246 | * @title number of registers |
| 247 | */ |
| 248 | public void testVFE13() { |
| 249 | try { |
| 250 | Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_16"); |
| 251 | fail("expected a verification exception"); |
| 252 | } catch (Throwable t) { |
| 253 | DxUtil.checkVerifyException(t); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * @constraint A14 |
| 259 | * @title attempt to invoke interface method |
| 260 | */ |
| 261 | public void testVFE18() { |
| 262 | try { |
| 263 | Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_24"); |
| 264 | fail("expected a verification exception"); |
| 265 | } catch (Throwable t) { |
| 266 | DxUtil.checkVerifyException(t); |
| 267 | } |
| 268 | } |
| 269 | } |