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