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_boolean; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.sget_boolean.d.T_sget_boolean_1; 22 import dot.junit.opcodes.sget_boolean.d.T_sget_boolean_11; 23 import dot.junit.opcodes.sget_boolean.d.T_sget_boolean_12; 24 import dot.junit.opcodes.sget_boolean.d.T_sget_boolean_13; 25 import dot.junit.opcodes.sget_boolean.d.T_sget_boolean_5; 26 import dot.junit.opcodes.sget_boolean.d.T_sget_boolean_6; 27 import dot.junit.opcodes.sget_boolean.d.T_sget_boolean_7; 28 import dot.junit.opcodes.sget_boolean.d.T_sget_boolean_8; 29 import dot.junit.opcodes.sget_boolean.d.T_sget_boolean_9; 30 31 public class Test_sget_boolean extends DxTestCase { 32 33 /** 34 * @title get boolean from static field 35 */ 36 public void testN1() { 37 T_sget_boolean_1 t = new T_sget_boolean_1(); 38 assertEquals(true, t.run()); 39 } 40 41 42 /** 43 * @title access protected field from subclass 44 */ 45 public void testN3() { 46 //@uses dot.junit.opcodes.sget_boolean.d.T_sget_boolean_1 47 //@uses dot.junit.opcodes.sget_boolean.d.T_sget_boolean_11 48 T_sget_boolean_11 t = new T_sget_boolean_11(); 49 assertEquals(true, t.run()); 50 } 51 52 /** 53 * @constraint A12 54 * @title attempt to access non-static field 55 */ 56 public void testE1() { 57 58 T_sget_boolean_5 t = new T_sget_boolean_5(); 59 try { 60 t.run(); 61 fail("expected IncompatibleClassChangeError"); 62 } catch (IncompatibleClassChangeError e) { 63 // expected 64 } 65 } 66 67 /** 68 * @title initialization of referenced class throws exception 69 */ 70 public void testE6() { 71 T_sget_boolean_9 t = new T_sget_boolean_9(); 72 try { 73 t.run(); 74 fail("expected Error"); 75 } catch (Error e) { 76 // expected 77 } 78 } 79 80 81 82 /** 83 * @constraint A12 84 * @title constant pool index 85 */ 86 public void testVFE1() { 87 try { 88 Class.forName("dot.junit.opcodes.sget_boolean.d.T_sget_boolean_4"); 89 fail("expected a verification exception"); 90 } catch (Throwable t) { 91 DxUtil.checkVerifyException(t); 92 } 93 } 94 95 /** 96 * 97 * @constraint A23 98 * @title number of registers 99 */ 100 public void testVFE2() { 101 try { 102 Class.forName("dot.junit.opcodes.sget_boolean.d.T_sget_boolean_3"); 103 fail("expected a verification exception"); 104 } catch (Throwable t) { 105 DxUtil.checkVerifyException(t); 106 } 107 } 108 109 /** 110 * 111 * @constraint B13 112 * @title read boolean from long field - only field with same name but 113 * different type exists 114 */ 115 public void testVFE3() { 116 try { 117 new T_sget_boolean_13().run(); 118 fail("expected NoSuchFieldError"); 119 } catch (NoSuchFieldError t) { 120 } 121 } 122 123 /** 124 * @constraint n/a 125 * @title Attempt to read inaccessible field. 126 */ 127 public void testVFE4() { 128 //@uses dot.junit.opcodes.sget_boolean.d.T_sget_boolean_6 129 //@uses dot.junit.opcodes.sget_boolean.TestStubs 130 try { 131 new T_sget_boolean_6().run(); 132 } catch (IllegalAccessError t) { 133 } 134 } 135 136 /** 137 * @constraint n/a 138 * @title Attempt to read field of undefined class. 139 */ 140 public void testVFE5() { 141 try { 142 new T_sget_boolean_7().run(); 143 fail("expected NoClassDefFoundError"); 144 } catch (NoClassDefFoundError t) { 145 } 146 } 147 148 /** 149 * @constraint n/a 150 * @title Attempt to read undefined field. 151 */ 152 public void testVFE6() { 153 try { 154 new T_sget_boolean_8().run(); 155 fail("expected NoSuchFieldError"); 156 } catch (NoSuchFieldError t) { 157 } 158 } 159 160 /** 161 * @constraint n/a 162 * @title Attempt to read superclass' private field from subclass. 163 */ 164 public void testVFE7() { 165 //@uses dot.junit.opcodes.sget_boolean.d.T_sget_boolean_12 166 //@uses dot.junit.opcodes.sget_boolean.d.T_sget_boolean_1 167 try { 168 new T_sget_boolean_12().run(); 169 fail("expected IllegalAccessError"); 170 } catch (IllegalAccessError t) { 171 } 172 } 173 174 /** 175 * @constraint B1 176 * @title sget_boolean shall not work for reference fields 177 */ 178 public void testVFE8() { 179 try { 180 Class.forName("dot.junit.opcodes.sget_boolean.d.T_sget_boolean_14"); 181 fail("expected a verification exception"); 182 } catch (Throwable t) { 183 DxUtil.checkVerifyException(t); 184 } 185 } 186 187 /** 188 * 189 * @constraint B1 190 * @title sget_boolean shall not work for short fields 191 */ 192 public void testVFE9() { 193 try { 194 Class.forName("dot.junit.opcodes.sget_boolean.d.T_sget_boolean_15"); 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_boolean shall not work for int fields 205 */ 206 public void testVFE10() { 207 try { 208 Class.forName("dot.junit.opcodes.sget_boolean.d.T_sget_boolean_16"); 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_boolean shall not work for char fields 219 */ 220 public void testVFE11() { 221 try { 222 Class.forName("dot.junit.opcodes.sget_boolean.d.T_sget_boolean_17"); 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_boolean shall not work for byte fields 233 */ 234 public void testVFE12() { 235 try { 236 Class.forName("dot.junit.opcodes.sget_boolean.d.T_sget_boolean_18"); 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_boolean shall not work for double fields 247 */ 248 public void testVFE13() { 249 try { 250 Class.forName("dot.junit.opcodes.sget_boolean.d.T_sget_boolean_19"); 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_boolean shall not work for long fields 261 */ 262 public void testVFE14() { 263 try { 264 Class.forName("dot.junit.opcodes.sget_boolean.d.T_sget_boolean_20"); 265 fail("expected a verification exception"); 266 } catch (Throwable t) { 267 DxUtil.checkVerifyException(t); 268 } 269 } 270 } 271