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; |
Jeff Hao | 5d7cb16 | 2013-08-02 16:59:44 -0700 | [diff] [blame] | 29 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_24; |
Tsu Chiang Chuang | 9a223d7 | 2011-04-27 17:19:46 -0700 | [diff] [blame] | 30 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_4; |
| 31 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_5; |
| 32 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_6; |
| 33 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_7; |
| 34 | import dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_8; |
| 35 | |
| 36 | |
| 37 | |
| 38 | public class Test_invoke_static_range extends DxTestCase { |
| 39 | |
| 40 | /** |
| 41 | * @title Static method from library class Math |
| 42 | */ |
| 43 | public void testN1() { |
| 44 | T_invoke_static_range_1 t = new T_invoke_static_range_1(); |
| 45 | assertEquals(1234567, t.run()); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @title Static method from user class |
| 50 | */ |
| 51 | public void testN2() { |
| 52 | //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_2 |
| 53 | //@uses dot.junit.opcodes.invoke_static_range.TestClass |
| 54 | T_invoke_static_range_2 t = new T_invoke_static_range_2(); |
| 55 | assertEquals(777, t.run()); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @title Big number of registers |
| 60 | */ |
| 61 | public void testN3() { |
| 62 | assertEquals(1, T_invoke_static_range_4.run()); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | /** |
| 67 | * @title Check that new frame is created by invoke_static_range and |
| 68 | * arguments are passed to method |
| 69 | */ |
| 70 | public void testN5() { |
| 71 | //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_15 |
| 72 | //@uses dot.junit.opcodes.invoke_static_range.TestClass |
| 73 | T_invoke_static_range_15 t = new T_invoke_static_range_15(); |
| 74 | assertTrue(t.run()); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @title Static protected method from other class in the same package |
| 79 | */ |
| 80 | public void testN6() { |
| 81 | T_invoke_static_range_18 t = new T_invoke_static_range_18(); |
| 82 | assertEquals(888, t.run()); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @title Native method can't be linked |
| 87 | * |
| 88 | */ |
| 89 | public void testE2() { |
| 90 | T_invoke_static_range_6 t = new T_invoke_static_range_6(); |
| 91 | try { |
| 92 | t.run(); |
| 93 | fail("expected UnsatisfiedLinkError"); |
| 94 | } catch (UnsatisfiedLinkError ule) { |
| 95 | // expected |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | |
| 100 | /** |
| 101 | * @title initialization of referenced class throws exception |
| 102 | */ |
| 103 | public void testE7() { |
| 104 | T_invoke_static_range_14 t = new T_invoke_static_range_14(); |
| 105 | try { |
| 106 | t.run(); |
| 107 | fail("expected Error"); |
| 108 | } catch (Error e) { |
| 109 | // expected |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @constraint A14 |
| 115 | * @title invalid constant pool index |
| 116 | */ |
| 117 | public void testVFE1() { |
| 118 | try { |
| 119 | Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_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_range |
| 129 | */ |
| 130 | public void testVFE3() { |
| 131 | try { |
| 132 | Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_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_range.d.T_invoke_static_range_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_range |
| 155 | */ |
| 156 | public void testVFE5() { |
| 157 | try { |
| 158 | new T_invoke_static_range_19().run(); |
Jeff Hao | 5d7cb16 | 2013-08-02 16:59:44 -0700 | [diff] [blame] | 159 | fail("expected a verification exception"); |
| 160 | } catch (Throwable t) { |
| 161 | DxUtil.checkVerifyException(t); |
Tsu Chiang Chuang | 9a223d7 | 2011-04-27 17:19:46 -0700 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @constraint B9 |
| 167 | * @title types of arguments passed to method |
| 168 | */ |
| 169 | public void testVFE6() { |
| 170 | try { |
| 171 | Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_20"); |
| 172 | fail("expected a verification exception"); |
| 173 | } catch (Throwable t) { |
| 174 | DxUtil.checkVerifyException(t); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | |
| 179 | /** |
| 180 | * @constraint n/a |
| 181 | * @title Attempt to call non-static method. |
| 182 | */ |
| 183 | public void testVFE7() { |
| 184 | try { |
| 185 | new T_invoke_static_range_5().run(); |
| 186 | fail("expected IncompatibleClassChangeError"); |
| 187 | } catch (IncompatibleClassChangeError t) { |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @constraint n/a |
| 193 | * @title Attempt to call undefined method. |
| 194 | */ |
| 195 | public void testVFE8() { |
| 196 | try { |
| 197 | new T_invoke_static_range_7().run(); |
| 198 | fail("expected NoSuchMethodError"); |
| 199 | } catch (NoSuchMethodError t) { |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * @constraint n/a |
| 205 | * @title Attempt to call private method of other class. |
| 206 | */ |
| 207 | public void testVFE9() { |
| 208 | //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_8 |
| 209 | //@uses dot.junit.opcodes.invoke_static_range.TestClass |
| 210 | try { |
| 211 | new T_invoke_static_range_8().run(); |
| 212 | fail("expected IllegalAccessError"); |
| 213 | } catch (IllegalAccessError t) { |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * @constraint n/a |
| 219 | * @title Method has different signature. |
| 220 | */ |
| 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 | new T_invoke_static_range_13().run(); |
| 226 | fail("expected NoSuchMethodError"); |
| 227 | } catch (NoSuchMethodError t) { |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | |
| 232 | /** |
| 233 | * @constraint B12 |
| 234 | * @title Attempt to call protected method of unrelated class. |
| 235 | */ |
| 236 | public void testVFE12() { |
| 237 | //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_17 |
| 238 | //@uses dot.junit.opcodes.invoke_static_range.TestClass |
| 239 | try { |
| 240 | new T_invoke_static_range_17().run(); |
| 241 | fail("expected IllegalAccessError"); |
| 242 | } catch (IllegalAccessError t) { |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * @constraint A23 |
| 248 | * @title number of registers |
| 249 | */ |
| 250 | public void testVFE13() { |
| 251 | try { |
| 252 | Class.forName("dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_16"); |
| 253 | fail("expected a verification exception"); |
| 254 | } catch (Throwable t) { |
| 255 | DxUtil.checkVerifyException(t); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * @constraint A14 |
| 261 | * @title attempt to invoke interface method |
| 262 | */ |
| 263 | public void testVFE18() { |
Jeff Hao | 5d7cb16 | 2013-08-02 16:59:44 -0700 | [diff] [blame] | 264 | //@uses dot.junit.opcodes.invoke_static_range.d.T_invoke_static_range_24 |
Tsu Chiang Chuang | 9a223d7 | 2011-04-27 17:19:46 -0700 | [diff] [blame] | 265 | try { |
Jeff Hao | 5d7cb16 | 2013-08-02 16:59:44 -0700 | [diff] [blame] | 266 | new T_invoke_static_range_24().run(); |
Tsu Chiang Chuang | 9a223d7 | 2011-04-27 17:19:46 -0700 | [diff] [blame] | 267 | fail("expected a verification exception"); |
| 268 | } catch (Throwable t) { |
| 269 | DxUtil.checkVerifyException(t); |
| 270 | } |
| 271 | } |
| 272 | } |