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.sput_short; |
| 18 | |
| 19 | import dot.junit.DxTestCase; |
| 20 | import dot.junit.DxUtil; |
| 21 | import dot.junit.opcodes.sput_short.d.T_sput_short_1; |
| 22 | import dot.junit.opcodes.sput_short.d.T_sput_short_10; |
| 23 | import dot.junit.opcodes.sput_short.d.T_sput_short_11; |
| 24 | import dot.junit.opcodes.sput_short.d.T_sput_short_12; |
| 25 | import dot.junit.opcodes.sput_short.d.T_sput_short_13; |
| 26 | import dot.junit.opcodes.sput_short.d.T_sput_short_14; |
| 27 | import dot.junit.opcodes.sput_short.d.T_sput_short_15; |
| 28 | import dot.junit.opcodes.sput_short.d.T_sput_short_17; |
| 29 | import dot.junit.opcodes.sput_short.d.T_sput_short_7; |
| 30 | import dot.junit.opcodes.sput_short.d.T_sput_short_8; |
| 31 | import dot.junit.opcodes.sput_short.d.T_sput_short_9; |
| 32 | |
| 33 | public class Test_sput_short extends DxTestCase { |
| 34 | /** |
| 35 | * @title put short into static field |
| 36 | */ |
| 37 | public void testN1() { |
| 38 | T_sput_short_1 t = new T_sput_short_1(); |
| 39 | assertEquals(0, T_sput_short_1.st_i1); |
| 40 | t.run(); |
| 41 | assertEquals(77, T_sput_short_1.st_i1); |
| 42 | } |
| 43 | |
| 44 | |
| 45 | /** |
| 46 | * @title modification of final field |
| 47 | */ |
| 48 | public void testN2() { |
| 49 | T_sput_short_12 t = new T_sput_short_12(); |
| 50 | assertEquals(0, T_sput_short_12.st_i1); |
| 51 | t.run(); |
| 52 | assertEquals(77, T_sput_short_12.st_i1); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @title modification of protected field from subclass |
| 57 | */ |
| 58 | public void testN4() { |
| 59 | //@uses dot.junit.opcodes.sput_short.d.T_sput_short_1 |
| 60 | //@uses dot.junit.opcodes.sput_short.d.T_sput_short_14 |
| 61 | T_sput_short_14 t = new T_sput_short_14(); |
| 62 | assertEquals(0, T_sput_short_14.getProtectedField()); |
| 63 | t.run(); |
| 64 | assertEquals(77, T_sput_short_14.getProtectedField()); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * @title initialization of referenced class throws exception |
| 70 | */ |
| 71 | public void testE6() { |
| 72 | T_sput_short_13 t = new T_sput_short_13(); |
| 73 | try { |
| 74 | t.run(); |
| 75 | fail("expected Error"); |
| 76 | } catch (Error e) { |
| 77 | // expected |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @constraint A12 |
| 83 | * @title constant pool index |
| 84 | */ |
| 85 | public void testVFE1() { |
| 86 | try { |
| 87 | Class.forName("dot.junit.opcodes.sput_short.d.T_sput_short_3"); |
| 88 | fail("expected a verification exception"); |
| 89 | } catch (Throwable t) { |
| 90 | DxUtil.checkVerifyException(t); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * |
| 96 | * @constraint A23 |
| 97 | * @title number of registers |
| 98 | */ |
| 99 | public void testVFE2() { |
| 100 | try { |
| 101 | Class.forName("dot.junit.opcodes.sput_short.d.T_sput_short_4"); |
| 102 | fail("expected a verification exception"); |
| 103 | } catch (Throwable t) { |
| 104 | DxUtil.checkVerifyException(t); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | |
| 109 | /** |
| 110 | * |
| 111 | * @constraint B13 |
| 112 | * @title put short into long field - only field with same name but |
| 113 | * different type exists |
| 114 | */ |
| 115 | public void testVFE5() { |
| 116 | try { |
| 117 | new T_sput_short_17().run(); |
| 118 | fail("expected NoSuchFieldError"); |
| 119 | } catch (NoSuchFieldError t) { |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * |
| 125 | * @constraint B13 |
| 126 | * @title put value '66000' into byte field |
| 127 | */ |
| 128 | public void testVFE6() { |
| 129 | try { |
| 130 | Class.forName("dot.junit.opcodes.sput_short.d.T_sput_short_6"); |
| 131 | fail("expected a verification exception"); |
| 132 | } catch (Throwable t) { |
| 133 | DxUtil.checkVerifyException(t); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * |
| 139 | * @constraint B13 |
| 140 | * @title type of field doesn't match opcode - attempt to modify double |
| 141 | * field with single-width register |
| 142 | */ |
| 143 | public void testVFE7() { |
| 144 | try { |
| 145 | Class.forName("dot.junit.opcodes.sput_short.d.T_sput_short_18"); |
| 146 | fail("expected a verification exception"); |
| 147 | } catch (Throwable t) { |
| 148 | DxUtil.checkVerifyException(t); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * |
| 154 | * @constraint A12 |
| 155 | * @title Attempt to set non-static field. |
| 156 | */ |
| 157 | public void testVFE8() { |
| 158 | try { |
| 159 | new T_sput_short_7().run(); |
| 160 | fail("expected IncompatibleClassChangeError"); |
| 161 | } catch (IncompatibleClassChangeError t) { |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @constraint n/a |
| 167 | * @title Attempt to modify inaccessible field. |
| 168 | */ |
| 169 | public void testVFE9() { |
| 170 | //@uses dot.junit.opcodes.sput_short.TestStubs |
| 171 | //@uses dot.junit.opcodes.sput_short.d.T_sput_short_8 |
| 172 | try { |
| 173 | new T_sput_short_8().run(); |
| 174 | fail("expected IllegalAccessError"); |
| 175 | } catch (IllegalAccessError t) { |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @constraint n/a |
| 181 | * @title Attempt to modify field of undefined class. |
| 182 | */ |
| 183 | public void testVFE10() { |
| 184 | try { |
| 185 | new T_sput_short_9().run(); |
| 186 | fail("expected NoClassDefFoundError"); |
| 187 | } catch (NoClassDefFoundError t) { |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @constraint n/a |
| 193 | * @title Attempt to modify undefined field. |
| 194 | */ |
| 195 | public void testVFE11() { |
| 196 | try { |
| 197 | new T_sput_short_10().run(); |
| 198 | fail("expected NoSuchFieldError"); |
| 199 | } catch (NoSuchFieldError t) { |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | |
| 204 | |
| 205 | /** |
| 206 | * @constraint n/a |
| 207 | * @title Attempt to modify superclass' private field from subclass. |
| 208 | */ |
| 209 | public void testVFE12() { |
| 210 | //@uses dot.junit.opcodes.sput_short.d.T_sput_short_1 |
| 211 | //@uses dot.junit.opcodes.sput_short.d.T_sput_short_15 |
| 212 | try { |
| 213 | new T_sput_short_15().run(); |
| 214 | fail("expected IllegalAccessError"); |
| 215 | } catch (IllegalAccessError t) { |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | |
| 220 | /** |
| 221 | * @constraint B1 |
| 222 | * @title sput-short shall not work for wide numbers |
| 223 | */ |
| 224 | public void testVFE13() { |
| 225 | try { |
| 226 | Class.forName("dot.junit.opcodes.sput_short.d.T_sput_short_2"); |
| 227 | fail("expected a verification exception"); |
| 228 | } catch (Throwable t) { |
| 229 | DxUtil.checkVerifyException(t); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * |
| 235 | * @constraint B1 |
| 236 | * @title sput-short shall not work for reference fields |
| 237 | */ |
| 238 | public void testVFE14() { |
| 239 | try { |
| 240 | Class.forName("dot.junit.opcodes.sput_short.d.T_sput_short_20"); |
| 241 | fail("expected a verification exception"); |
| 242 | } catch (Throwable t) { |
| 243 | DxUtil.checkVerifyException(t); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * |
| 249 | * @constraint B1 |
| 250 | * @title sput-short shall not work for char fields |
| 251 | */ |
| 252 | public void testVFE15() { |
| 253 | try { |
| 254 | Class.forName("dot.junit.opcodes.sput_short.d.T_sput_short_21"); |
| 255 | fail("expected a verification exception"); |
| 256 | } catch (Throwable t) { |
| 257 | DxUtil.checkVerifyException(t); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * |
| 263 | * @constraint B1 |
| 264 | * @title sput-short shall not work for int fields |
| 265 | */ |
| 266 | public void testVFE16() { |
| 267 | try { |
| 268 | Class.forName("dot.junit.opcodes.sput_short.d.T_sput_short_22"); |
| 269 | fail("expected a verification exception"); |
| 270 | } catch (Throwable t) { |
| 271 | DxUtil.checkVerifyException(t); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * |
| 277 | * @constraint B1 |
| 278 | * @title sput-short shall not work for byte fields |
| 279 | */ |
| 280 | public void testVFE17() { |
| 281 | try { |
| 282 | Class.forName("dot.junit.opcodes.sput_short.d.T_sput_short_23"); |
| 283 | fail("expected a verification exception"); |
| 284 | } catch (Throwable t) { |
| 285 | DxUtil.checkVerifyException(t); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * |
| 291 | * @constraint B1 |
| 292 | * @title sput-short shall not work for boolean fields |
| 293 | */ |
| 294 | public void testVFE18() { |
| 295 | try { |
| 296 | Class.forName("dot.junit.opcodes.sput_short.d.T_sput_short_24"); |
| 297 | fail("expected a verification exception"); |
| 298 | } catch (Throwable t) { |
| 299 | DxUtil.checkVerifyException(t); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * @constraint n/a |
| 305 | * @title Modification of final field in other class |
| 306 | */ |
| 307 | public void testVFE19() { |
| 308 | //@uses dot.junit.opcodes.sput_short.TestStubs |
| 309 | //@uses dot.junit.opcodes.sput_short.d.T_sput_short_11 |
| 310 | try { |
| 311 | new T_sput_short_11().run(); |
| 312 | fail("expected IllegalAccessError"); |
| 313 | } catch (IllegalAccessError t) { |
| 314 | } |
| 315 | } |
| 316 | } |