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