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