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