blob: 8585365d3b42556cd93db2df7fd213c2a179f8e3 [file] [log] [blame]
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -07001/*
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
17package dot.junit.opcodes.sput_char;
18
19import dot.junit.DxTestCase;
20import dot.junit.DxUtil;
21import dot.junit.opcodes.sput_char.d.T_sput_char_1;
22import dot.junit.opcodes.sput_char.d.T_sput_char_10;
23import dot.junit.opcodes.sput_char.d.T_sput_char_11;
24import dot.junit.opcodes.sput_char.d.T_sput_char_12;
25import dot.junit.opcodes.sput_char.d.T_sput_char_13;
26import dot.junit.opcodes.sput_char.d.T_sput_char_14;
27import dot.junit.opcodes.sput_char.d.T_sput_char_15;
28import dot.junit.opcodes.sput_char.d.T_sput_char_17;
29import dot.junit.opcodes.sput_char.d.T_sput_char_7;
30import dot.junit.opcodes.sput_char.d.T_sput_char_8;
31import dot.junit.opcodes.sput_char.d.T_sput_char_9;
32
33public class Test_sput_char extends DxTestCase {
34 /**
35 * @title put char into static field
36 */
37 public void testN1() {
38 T_sput_char_1 t = new T_sput_char_1();
39 assertEquals(0, T_sput_char_1.st_i1);
40 t.run();
41 assertEquals(77, T_sput_char_1.st_i1);
42 }
43
44
45 /**
46 * @title modification of final field
47 */
48 public void testN2() {
49 T_sput_char_12 t = new T_sput_char_12();
50 assertEquals(0, T_sput_char_12.st_i1);
51 t.run();
52 assertEquals(77, T_sput_char_12.st_i1);
53 }
54
55 /**
56 * @title modification of protected field from subclass
57 */
58 public void testN4() {
59 //@uses dot.junit.opcodes.sput_char.d.T_sput_char_1
60 //@uses dot.junit.opcodes.sput_char.d.T_sput_char_14
61 T_sput_char_14 t = new T_sput_char_14();
62 assertEquals(0, T_sput_char_14.getProtectedField());
63 t.run();
64 assertEquals(77, T_sput_char_14.getProtectedField());
65 }
66
67
68 /**
69 * @title initialization of referenced class throws exception
70 */
71 public void testE6() {
72 T_sput_char_13 t = new T_sput_char_13();
73 try {
74 t.run();
75 fail("expected Error");
76 } catch (Error e) {
77 // expected
78 }
79 }
80
81 /**
82 * @constraint A12
83 * @title constant pool index
84 */
85 public void testVFE1() {
86 try {
87 Class.forName("dot.junit.opcodes.sput_char.d.T_sput_char_3");
88 fail("expected a verification exception");
89 } catch (Throwable t) {
90 DxUtil.checkVerifyException(t);
91 }
92 }
93
94 /**
95 *
96 * @constraint A23
97 * @title number of registers
98 */
99 public void testVFE2() {
100 try {
101 Class.forName("dot.junit.opcodes.sput_char.d.T_sput_char_4");
102 fail("expected a verification exception");
103 } catch (Throwable t) {
104 DxUtil.checkVerifyException(t);
105 }
106 }
107
108
109 /**
110 *
111 * @constraint B13
112 * @title put char into long field - only field with same name but
113 * different type exists
114 */
115 public void testVFE5() {
116 try {
117 new T_sput_char_17().run();
118 fail("expected NoSuchFieldError");
119 } catch (NoSuchFieldError t) {
120 }
121 }
122
123 /**
124 *
125 * @constraint B13
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700126 * @title type of field doesn't match opcode - attempt to modify double
127 * field with single-width register
128 */
129 public void testVFE7() {
130 try {
131 Class.forName("dot.junit.opcodes.sput_char.d.T_sput_char_18");
132 fail("expected a verification exception");
133 } catch (Throwable t) {
134 DxUtil.checkVerifyException(t);
135 }
136 }
137
138 /**
139 *
140 * @constraint A12
141 * @title Attempt to set non-static field.
142 */
143 public void testVFE8() {
144 try {
145 new T_sput_char_7().run();
146 fail("expected IncompatibleClassChangeError");
147 } catch (IncompatibleClassChangeError t) {
148 }
149 }
150
151 /**
152 * @constraint n/a
153 * @title Attempt to modify inaccessible field.
154 */
155 public void testVFE9() {
156 //@uses dot.junit.opcodes.sput_char.TestStubs
157 //@uses dot.junit.opcodes.sput_char.d.T_sput_char_8
158 try {
159 new T_sput_char_8().run();
160 fail("expected IllegalAccessError");
161 } catch (IllegalAccessError t) {
162 }
163 }
164
165 /**
166 * @constraint n/a
167 * @title Attempt to modify field of undefined class.
168 */
169 public void testVFE10() {
170 try {
171 new T_sput_char_9().run();
172 fail("expected NoClassDefFoundError");
173 } catch (NoClassDefFoundError t) {
174 }
175 }
176
177 /**
178 * @constraint n/a
179 * @title Attempt to modify undefined field.
180 */
181 public void testVFE11() {
182 try {
183 new T_sput_char_10().run();
184 fail("expected NoSuchFieldError");
185 } catch (NoSuchFieldError t) {
186 }
187 }
188
189
190
191 /**
192 * @constraint n/a
193 * @title Attempt to modify superclass' private field from subclass.
194 */
195 public void testVFE12() {
196 //@uses dot.junit.opcodes.sput_char.d.T_sput_char_1
197 //@uses dot.junit.opcodes.sput_char.d.T_sput_char_15
198 try {
199 new T_sput_char_15().run();
200 fail("expected IllegalAccessError");
201 } catch (IllegalAccessError t) {
202 }
203 }
204
205
206 /**
207 * @constraint B1
208 * @title sput-char shall not work for wide numbers
209 */
210 public void testVFE13() {
211 try {
212 Class.forName("dot.junit.opcodes.sput_char.d.T_sput_char_2");
213 fail("expected a verification exception");
214 } catch (Throwable t) {
215 DxUtil.checkVerifyException(t);
216 }
217 }
218
219 /**
220 *
221 * @constraint B1
222 * @title sput-char shall not work for reference fields
223 */
224 public void testVFE14() {
225 try {
226 Class.forName("dot.junit.opcodes.sput_char.d.T_sput_char_20");
227 fail("expected a verification exception");
228 } catch (Throwable t) {
229 DxUtil.checkVerifyException(t);
230 }
231 }
232
233 /**
234 *
235 * @constraint B1
236 * @title sput-char shall not work for short fields
237 */
238 public void testVFE15() {
239 try {
240 Class.forName("dot.junit.opcodes.sput_char.d.T_sput_char_21");
241 fail("expected a verification exception");
242 } catch (Throwable t) {
243 DxUtil.checkVerifyException(t);
244 }
245 }
246
247 /**
248 *
249 * @constraint B1
250 * @title sput-char shall not work for int fields
251 */
252 public void testVFE16() {
253 try {
254 Class.forName("dot.junit.opcodes.sput_char.d.T_sput_char_22");
255 fail("expected a verification exception");
256 } catch (Throwable t) {
257 DxUtil.checkVerifyException(t);
258 }
259 }
260
261 /**
262 *
263 * @constraint B1
264 * @title sput-char shall not work for byte fields
265 */
266 public void testVFE17() {
267 try {
268 Class.forName("dot.junit.opcodes.sput_char.d.T_sput_char_23");
269 fail("expected a verification exception");
270 } catch (Throwable t) {
271 DxUtil.checkVerifyException(t);
272 }
273 }
274
275 /**
276 *
277 * @constraint B1
278 * @title sput-char shall not work for boolean fields
279 */
280 public void testVFE18() {
281 try {
282 Class.forName("dot.junit.opcodes.sput_char.d.T_sput_char_24");
283 fail("expected a verification exception");
284 } catch (Throwable t) {
285 DxUtil.checkVerifyException(t);
286 }
287 }
288
289 /**
290 * @constraint n/a
291 * @title Modification of final field in other class
292 */
293 public void testVFE19() {
294 //@uses dot.junit.opcodes.sput_char.TestStubs
295 //@uses dot.junit.opcodes.sput_char.d.T_sput_char_11
296 try {
297 new T_sput_char_11().run();
298 fail("expected IllegalAccessError");
299 } catch (IllegalAccessError t) {
300 }
301 }
302}