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.iput; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.iput.d.T_iput_1; 22 import dot.junit.opcodes.iput.d.T_iput_10; 23 import dot.junit.opcodes.iput.d.T_iput_11; 24 import dot.junit.opcodes.iput.d.T_iput_12; 25 import dot.junit.opcodes.iput.d.T_iput_13; 26 import dot.junit.opcodes.iput.d.T_iput_14; 27 import dot.junit.opcodes.iput.d.T_iput_15; 28 import dot.junit.opcodes.iput.d.T_iput_17; 29 import dot.junit.opcodes.iput.d.T_iput_19; 30 import dot.junit.opcodes.iput.d.T_iput_5; 31 import dot.junit.opcodes.iput.d.T_iput_7; 32 import dot.junit.opcodes.iput.d.T_iput_8; 33 import dot.junit.opcodes.iput.d.T_iput_9; 34 35 public class Test_iput extends DxTestCase { 36 37 /** 38 * @title type - int 39 */ 40 public void testN1() { 41 T_iput_1 t = new T_iput_1(); 42 assertEquals(0, t.st_i1); 43 t.run(); 44 assertEquals(1000000, t.st_i1); 45 } 46 47 /** 48 * @title type - float 49 */ 50 public void testN2() { 51 T_iput_19 t = new T_iput_19(); 52 assertEquals(0.0f, t.st_f1); 53 t.run(); 54 assertEquals(3.14f, t.st_f1); 55 } 56 57 58 /** 59 * @title modification of final field 60 */ 61 public void testN3() { 62 T_iput_12 t = new T_iput_12(); 63 assertEquals(0, t.st_i1); 64 t.run(); 65 assertEquals(1000000, t.st_i1); 66 } 67 68 /** 69 * @title modification of protected field from subclass 70 */ 71 public void testN4() { 72 //@uses dot.junit.opcodes.iput.d.T_iput_1 73 //@uses dot.junit.opcodes.iput.d.T_iput_14 74 T_iput_14 t = new T_iput_14(); 75 assertEquals(0, t.getProtectedField()); 76 t.run(); 77 assertEquals(1000000, t.getProtectedField()); 78 } 79 80 81 /** 82 * @title expected NullPointerException 83 */ 84 public void testE2() { 85 loadAndRun("dot.junit.opcodes.iput.d.T_iput_13", NullPointerException.class); 86 } 87 88 /** 89 * @constraint A11 90 * @title constant pool index 91 */ 92 public void testVFE1() { 93 load("dot.junit.opcodes.iput.d.T_iput_3", VerifyError.class); 94 } 95 96 /** 97 * 98 * @constraint A23 99 * @title number of registers 100 */ 101 public void testVFE2() { 102 load("dot.junit.opcodes.iput.d.T_iput_4", VerifyError.class); 103 } 104 105 106 /** 107 * 108 * @constraint B14 109 * @title put integer into long field - only field with same name but 110 * different type exists 111 */ 112 public void testVFE5() { 113 loadAndRun("dot.junit.opcodes.iput.d.T_iput_17", NoSuchFieldError.class); 114 } 115 116 /** 117 * @constraint B1 118 * @title Trying to put float into integer field. The verifier checks that ints 119 * and floats are not used interchangeably. 120 */ 121 public void testVFE6() { 122 load("dot.junit.opcodes.iput.d.T_iput_5", VerifyError.class); 123 } 124 125 /** 126 * 127 * @constraint B14 128 * @title type of field doesn't match opcode - attempt to modify double field 129 * with single-width register 130 */ 131 public void testVFE7() { 132 load("dot.junit.opcodes.iput.d.T_iput_18", VerifyError.class); 133 } 134 135 /** 136 * @constraint A11 137 * @title Attempt to set static field. 138 */ 139 public void testVFE8() { 140 loadAndRun("dot.junit.opcodes.iput.d.T_iput_7", IncompatibleClassChangeError.class); 141 } 142 143 /** 144 * @constraint B12 145 * @title Attempt to modify inaccessible protected field. 146 */ 147 public void testVFE9() { 148 //@uses dot.junit.opcodes.iput.TestStubs 149 loadAndRun("dot.junit.opcodes.iput.d.T_iput_8", IllegalAccessError.class); 150 } 151 152 /** 153 * @constraint n/a 154 * @title Attempt to modify field of undefined class. 155 */ 156 public void testVFE10() { 157 loadAndRun("dot.junit.opcodes.iput.d.T_iput_9", NoClassDefFoundError.class); 158 } 159 160 /** 161 * @constraint n/a 162 * @title Attempt to modify undefined field. 163 */ 164 public void testVFE11() { 165 loadAndRun("dot.junit.opcodes.iput.d.T_iput_10", NoSuchFieldError.class); 166 } 167 168 /** 169 * @constraint n/a 170 * @title Attempt to modify superclass' private field from subclass. 171 */ 172 public void testVFE12() { 173 //@uses dot.junit.opcodes.iput.d.T_iput_1 174 loadAndRun("dot.junit.opcodes.iput.d.T_iput_15", IllegalAccessError.class); 175 } 176 177 /** 178 * @constraint B1 179 * @title iput shall not work for wide numbers 180 */ 181 public void testVFE13() { 182 load("dot.junit.opcodes.iput.d.T_iput_2", VerifyError.class); 183 } 184 185 /** 186 * 187 * @constraint B1 188 * @title iput shall not work for reference fields 189 */ 190 public void testVFE14() { 191 load("dot.junit.opcodes.iput.d.T_iput_20", VerifyError.class); 192 } 193 194 /** 195 * 196 * @constraint B1 197 * @title iput shall not work for short fields 198 */ 199 public void testVFE15() { 200 load("dot.junit.opcodes.iput.d.T_iput_21", VerifyError.class); 201 } 202 203 /** 204 * 205 * @constraint B1 206 * @title iput shall not work for boolean fields 207 */ 208 public void testVFE16() { 209 load("dot.junit.opcodes.iput.d.T_iput_22", VerifyError.class); 210 } 211 212 /** 213 * 214 * @constraint B1 215 * @title iput shall not work for char fields 216 */ 217 public void testVFE17() { 218 load("dot.junit.opcodes.iput.d.T_iput_23", VerifyError.class); 219 } 220 221 /** 222 * 223 * @constraint B1 224 * @title iput shall not work for byte fields 225 */ 226 public void testVFE18() { 227 load("dot.junit.opcodes.iput.d.T_iput_24", VerifyError.class); 228 } 229 230 231 /** 232 * @constraint B6 233 * @title instance fields may only be accessed on already initialized instances. 234 */ 235 public void testVFE30() { 236 load("dot.junit.opcodes.iput.d.T_iput_30", VerifyError.class); 237 } 238 239 /** 240 * @constraint N/A 241 * @title instance fields may only be accessed on reference registers 242 */ 243 public void testVFE31() { 244 load("dot.junit.opcodes.iput.d.T_iput_31", VerifyError.class); 245 } 246 247 /** 248 * @constraint n/a 249 * @title Modification of final field in other class 250 */ 251 public void testE5() { 252 //@uses dot.junit.opcodes.iput.TestStubs 253 loadAndRun("dot.junit.opcodes.iput.d.T_iput_11", IllegalAccessError.class); 254 } 255 } 256