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.iget_wide; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.iget_wide.d.T_iget_wide_1; 22 import dot.junit.opcodes.iget_wide.d.T_iget_wide_11; 23 import dot.junit.opcodes.iget_wide.d.T_iget_wide_12; 24 import dot.junit.opcodes.iget_wide.d.T_iget_wide_13; 25 import dot.junit.opcodes.iget_wide.d.T_iget_wide_2; 26 import dot.junit.opcodes.iget_wide.d.T_iget_wide_21; 27 import dot.junit.opcodes.iget_wide.d.T_iget_wide_5; 28 import dot.junit.opcodes.iget_wide.d.T_iget_wide_6; 29 import dot.junit.opcodes.iget_wide.d.T_iget_wide_7; 30 import dot.junit.opcodes.iget_wide.d.T_iget_wide_8; 31 import dot.junit.opcodes.iget_wide.d.T_iget_wide_9; 32 33 public class Test_iget_wide extends DxTestCase { 34 35 /** 36 * @title type - long 37 */ 38 public void testN1() { 39 T_iget_wide_1 t = new T_iget_wide_1(); 40 assertEquals(12345679890123l, t.run()); 41 } 42 43 /** 44 * @title type - double 45 */ 46 public void testN2() { 47 T_iget_wide_2 t = new T_iget_wide_2(); 48 assertEquals(123.0, t.run()); 49 } 50 51 /** 52 * @title access protected field from subclass 53 */ 54 public void testN3() { 55 //@uses dot.junit.opcodes.iget_wide.d.T_iget_wide_1 56 //@uses dot.junit.opcodes.iget_wide.d.T_iget_wide_11 57 T_iget_wide_11 t = new T_iget_wide_11(); 58 assertEquals(10, t.run()); 59 } 60 61 /** 62 * @title expected NullPointerException 63 */ 64 public void testE2() { 65 T_iget_wide_9 t = new T_iget_wide_9(); 66 try { 67 t.run(); 68 fail("expected NullPointerException"); 69 } catch (NullPointerException e) { 70 // expected 71 } 72 } 73 74 /** 75 * @constraint A11 76 * @title constant pool index 77 */ 78 public void testVFE1() { 79 try { 80 Class.forName("dot.junit.opcodes.iget_wide.d.T_iget_wide_4"); 81 fail("expected a verification exception"); 82 } catch (Throwable t) { 83 DxUtil.checkVerifyException(t); 84 } 85 } 86 87 /** 88 * 89 * @constraint A23 90 * @title number of registers 91 */ 92 public void testVFE2() { 93 try { 94 Class.forName("dot.junit.opcodes.iget_wide.d.T_iget_wide_3"); 95 fail("expected a verification exception"); 96 } catch (Throwable t) { 97 DxUtil.checkVerifyException(t); 98 } 99 } 100 101 /** 102 * 103 * @constraint B13 104 * @title read long from integer field - only field with same name but 105 * different type exists 106 */ 107 public void testVFE3() { 108 try { 109 new T_iget_wide_13().run(); 110 fail("expected a NoSuchFieldError exception"); 111 } catch (NoSuchFieldError e) { 112 // expected 113 } 114 } 115 116 /** 117 * @constraint n/a 118 * @title Attempt to read inaccessible field. 119 */ 120 public void testVFE4() { 121 //@uses dot.junit.opcodes.iget_wide.d.T_iget_wide_6 122 //@uses dot.junit.opcodes.iget_wide.TestStubs 123 try { 124 new T_iget_wide_6().run(); 125 fail("expected an IllegalAccessError exception"); 126 } catch (IllegalAccessError e) { 127 // expected 128 } 129 } 130 131 /** 132 * @constraint n/a 133 * @title Attempt to read field of undefined class. 134 */ 135 public void testVFE5() { 136 try { 137 new T_iget_wide_7().run(); 138 fail("expected a NoClassDefFoundError exception"); 139 } catch (NoClassDefFoundError e) { 140 // expected 141 } 142 } 143 144 /** 145 * @constraint n/a 146 * @title Attempt to read undefined field. 147 */ 148 public void testVFE6() { 149 try { 150 new T_iget_wide_8().run(); 151 fail("expected a NoSuchFieldError exception"); 152 } catch (NoSuchFieldError e) { 153 // expected 154 } 155 } 156 157 /** 158 * @constraint n/a 159 * @title Attempt to read superclass' private field from subclass. 160 */ 161 public void testVFE7() { 162 //@uses dot.junit.opcodes.iget_wide.d.T_iget_wide_12 163 //@uses dot.junit.opcodes.iget_wide.d.T_iget_wide_1 164 try { 165 new T_iget_wide_12().run(); 166 fail("expected a IllegalAccessError exception"); 167 } catch (IllegalAccessError e) { 168 // expected 169 } 170 } 171 172 /** 173 * @constraint B1 174 * @title iget-wide shall not work for reference fields 175 */ 176 public void testVFE8() { 177 try { 178 Class.forName("dot.junit.opcodes.iget_wide.d.T_iget_wide_14"); 179 fail("expected a verification exception"); 180 } catch (Throwable t) { 181 DxUtil.checkVerifyException(t); 182 } 183 } 184 185 /** 186 * 187 * @constraint B1 188 * @title iget-wide shall not work for short fields 189 */ 190 public void testVFE9() { 191 try { 192 Class.forName("dot.junit.opcodes.iget_wide.d.T_iget_wide_15"); 193 fail("expected a verification exception"); 194 } catch (Throwable t) { 195 DxUtil.checkVerifyException(t); 196 } 197 } 198 199 /** 200 * 201 * @constraint B1 202 * @title iget-wide shall not work for boolean fields 203 */ 204 public void testVFE10() { 205 try { 206 Class.forName("dot.junit.opcodes.iget_wide.d.T_iget_wide_16"); 207 fail("expected a verification exception"); 208 } catch (Throwable t) { 209 DxUtil.checkVerifyException(t); 210 } 211 } 212 213 /** 214 * 215 * @constraint B1 216 * @title iget-wide shall not work for char fields 217 */ 218 public void testVFE11() { 219 try { 220 Class.forName("dot.junit.opcodes.iget_wide.d.T_iget_wide_17"); 221 fail("expected a verification exception"); 222 } catch (Throwable t) { 223 DxUtil.checkVerifyException(t); 224 } 225 } 226 227 /** 228 * 229 * @constraint B1 230 * @title iget-wide shall not work for byte fields 231 */ 232 public void testVFE12() { 233 try { 234 Class.forName("dot.junit.opcodes.iget_wide.d.T_iget_wide_18"); 235 fail("expected a verification exception"); 236 } catch (Throwable t) { 237 DxUtil.checkVerifyException(t); 238 } 239 } 240 241 /** 242 * 243 * @constraint B1 244 * @title iget-wide shall not work for float fields 245 */ 246 public void testVFE13() { 247 try { 248 Class.forName("dot.junit.opcodes.iget_wide.d.T_iget_wide_19"); 249 fail("expected a verification exception"); 250 } catch (Throwable t) { 251 DxUtil.checkVerifyException(t); 252 } 253 } 254 255 /** 256 * 257 * @constraint B1 258 * @title iget-wide shall not work for int fields 259 */ 260 public void testVFE14() { 261 try { 262 Class.forName("dot.junit.opcodes.iget_wide.d.T_iget_wide_20"); 263 fail("expected a verification exception"); 264 } catch (Throwable t) { 265 DxUtil.checkVerifyException(t); 266 } 267 } 268 269 /** 270 * @constraint B12 271 * @title Attempt to read inaccessible protected field. 272 */ 273 public void testVFE15() { 274 //@uses dot.junit.opcodes.iget_wide.d.T_iget_wide_21 275 //@uses dot.junit.opcodes.iget_wide.TestStubs 276 try { 277 new T_iget_wide_21().run(); 278 fail("expected an IllegalAccessError exception"); 279 } catch (IllegalAccessError e) { 280 // expected 281 } 282 } 283 284 /** 285 * @constraint A11 286 * @title Attempt to read static field. 287 */ 288 public void testVFE16() { 289 //@uses dot.junit.opcodes.iget_wide.d.T_iget_wide_5 290 //@uses dot.junit.opcodes.iget_wide.TestStubs 291 try { 292 new T_iget_wide_5().run(); 293 fail("expected a IncompatibleClassChangeError exception"); 294 } catch (IncompatibleClassChangeError e) { 295 // expected 296 } 297 } 298 299 /** 300 * @constraint B6 301 * @title instance fields may only be accessed on already initialized instances. 302 */ 303 public void testVFE30() { 304 try { 305 Class.forName("dot.junit.opcodes.iget_wide.d.T_iget_wide_30"); 306 fail("expected a verification exception"); 307 } catch (Throwable t) { 308 DxUtil.checkVerifyException(t); 309 } 310 } 311 } 312