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