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