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; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.iget.d.T_iget_1; 22 import dot.junit.opcodes.iget.d.T_iget_11; 23 import dot.junit.opcodes.iget.d.T_iget_12; 24 import dot.junit.opcodes.iget.d.T_iget_13; 25 import dot.junit.opcodes.iget.d.T_iget_2; 26 import dot.junit.opcodes.iget.d.T_iget_21; 27 import dot.junit.opcodes.iget.d.T_iget_5; 28 import dot.junit.opcodes.iget.d.T_iget_6; 29 import dot.junit.opcodes.iget.d.T_iget_7; 30 import dot.junit.opcodes.iget.d.T_iget_8; 31 import dot.junit.opcodes.iget.d.T_iget_9; 32 33 public class Test_iget extends DxTestCase { 34 35 /** 36 * @title type - int 37 */ testN1()38 public void testN1() { 39 T_iget_1 t = new T_iget_1(); 40 assertEquals(5, t.run()); 41 } 42 43 /** 44 * @title type - float 45 */ testN2()46 public void testN2() { 47 T_iget_2 t = new T_iget_2(); 48 assertEquals(123f, t.run()); 49 } 50 51 /** 52 * @title access protected field from subclass 53 */ testN3()54 public void testN3() { 55 //@uses dot.junit.opcodes.iget.d.T_iget_1 56 //@uses dot.junit.opcodes.iget.d.T_iget_11 57 T_iget_11 t = new T_iget_11(); 58 assertEquals(10, t.run()); 59 } 60 61 /** 62 * @title expected NullPointerException 63 */ testE2()64 public void testE2() { 65 loadAndRun("dot.junit.opcodes.iget.d.T_iget_9", NullPointerException.class); 66 } 67 68 /** 69 * @constraint A11 70 * @title constant pool index 71 */ testVFE1()72 public void testVFE1() { 73 load("dot.junit.opcodes.iget.d.T_iget_4", VerifyError.class); 74 } 75 76 /** 77 * 78 * @constraint A23 79 * @title number of registers 80 */ testVFE2()81 public void testVFE2() { 82 load("dot.junit.opcodes.iget.d.T_iget_3", VerifyError.class); 83 } 84 85 /** 86 * @constraint B13 87 * @title read integer from long field - only field with same name but 88 * different type exist 89 */ testVFE3()90 public void testVFE3() { 91 loadAndRun("dot.junit.opcodes.iget.d.T_iget_13", NoSuchFieldError.class); 92 } 93 94 /** 95 * @constraint n/a 96 * @title Attempt to read inaccessible private field. 97 */ testVFE4()98 public void testVFE4() { 99 //@uses dot.junit.opcodes.iget.TestStubs 100 loadAndRun("dot.junit.opcodes.iget.d.T_iget_6", IllegalAccessError.class); 101 } 102 103 /** 104 * @constraint n/a 105 * @title Attempt to read field of undefined class. 106 */ testVFE5()107 public void testVFE5() { 108 loadAndRun("dot.junit.opcodes.iget.d.T_iget_7", NoClassDefFoundError.class); 109 } 110 111 /** 112 * @constraint n/a 113 * @title Attempt to read undefined field. 114 */ testVFE6()115 public void testVFE6() { 116 loadAndRun("dot.junit.opcodes.iget.d.T_iget_8", NoSuchFieldError.class); 117 } 118 119 /** 120 * @constraint n/a 121 * @title Attempt to read superclass' private field from subclass. 122 */ testVFE7()123 public void testVFE7() { 124 //@uses dot.junit.opcodes.iget.d.T_iget_1 125 loadAndRun("dot.junit.opcodes.iget.d.T_iget_12", IllegalAccessError.class); 126 } 127 128 /** 129 * @constraint B1 130 * @title iget shall not work for reference fields 131 */ testVFE8()132 public void testVFE8() { 133 load("dot.junit.opcodes.iget.d.T_iget_14", VerifyError.class); 134 } 135 136 /** 137 * 138 * @constraint B1 139 * @title iget shall not work for short fields 140 */ testVFE9()141 public void testVFE9() { 142 load("dot.junit.opcodes.iget.d.T_iget_15", VerifyError.class); 143 } 144 145 /** 146 * 147 * @constraint B1 148 * @title iget shall not work for boolean fields 149 */ testVFE10()150 public void testVFE10() { 151 load("dot.junit.opcodes.iget.d.T_iget_16", VerifyError.class); 152 } 153 154 /** 155 * 156 * @constraint B1 157 * @title iget shall not work for char fields 158 */ testVFE11()159 public void testVFE11() { 160 load("dot.junit.opcodes.iget.d.T_iget_17", VerifyError.class); 161 } 162 163 /** 164 * 165 * @constraint B1 166 * @title iget shall not work for byte fields 167 */ testVFE12()168 public void testVFE12() { 169 load("dot.junit.opcodes.iget.d.T_iget_18", VerifyError.class); 170 } 171 172 /** 173 * 174 * @constraint B1 175 * @title iget shall not work for double fields 176 */ testVFE13()177 public void testVFE13() { 178 load("dot.junit.opcodes.iget.d.T_iget_19", VerifyError.class); 179 } 180 181 /** 182 * 183 * @constraint B1 184 * @title iget shall not work for long fields 185 */ testVFE14()186 public void testVFE14() { 187 load("dot.junit.opcodes.iget.d.T_iget_20", VerifyError.class); 188 } 189 190 /** 191 * @constraint B12 192 * @title Attempt to read protected field of unrelated class. 193 */ testVFE15()194 public void testVFE15() { 195 //@uses dot.junit.opcodes.iget.TestStubs 196 loadAndRun("dot.junit.opcodes.iget.d.T_iget_21", IllegalAccessError.class); 197 } 198 199 /** 200 * @constraint A11 201 * @title Attempt to read static field. 202 */ testVFE16()203 public void testVFE16() { 204 //@uses dot.junit.opcodes.iget.TestStubs 205 loadAndRun("dot.junit.opcodes.iget.d.T_iget_5", IncompatibleClassChangeError.class); 206 } 207 208 /** 209 * @constraint B6 210 * @title instance fields may only be accessed on already initialized instances. 211 */ testVFE30()212 public void testVFE30() { 213 load("dot.junit.opcodes.iget.d.T_iget_30", VerifyError.class); 214 } 215 216 /** 217 * @constraint N/A 218 * @title instance fields may only be accessed on reference values. 219 */ testVFE31()220 public void testVFE31() { 221 load("dot.junit.opcodes.iget.d.T_iget_31", VerifyError.class); 222 } 223 } 224 225