• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_char;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.iput_char.d.T_iput_char_1;
22 import dot.junit.opcodes.iput_char.d.T_iput_char_11;
23 import dot.junit.opcodes.iput_char.d.T_iput_char_12;
24 import dot.junit.opcodes.iput_char.d.T_iput_char_13;
25 import dot.junit.opcodes.iput_char.d.T_iput_char_14;
26 
27 public class Test_iput_char extends DxTestCase {
28     /**
29      * @title put char into field
30      */
testN1()31     public void testN1() {
32         T_iput_char_1 t = new T_iput_char_1();
33         assertEquals(0, t.st_i1);
34         t.run();
35         assertEquals(77, t.st_i1);
36     }
37 
38 
39     /**
40      * @title modification of final field
41      */
testN2()42     public void testN2() {
43         T_iput_char_12 t = new T_iput_char_12();
44         assertEquals(0, t.st_i1);
45         t.run();
46         assertEquals(77, t.st_i1);
47     }
48 
49     /**
50      * @title modification of protected field from subclass
51      */
testN4()52     public void testN4() {
53         //@uses dot.junit.opcodes.iput_char.d.T_iput_char_1
54         //@uses dot.junit.opcodes.iput_char.d.T_iput_char_14
55         T_iput_char_14 t = new T_iput_char_14();
56         assertEquals(0, t.getProtectedField());
57         t.run();
58         assertEquals(77, t.getProtectedField());
59     }
60 
61     /**
62      * @title expected NullPointerException
63      */
testE2()64     public void testE2() {
65         T_iput_char_13 t = new T_iput_char_13();
66         try {
67             t.run();
68             fail("expected NullPointerException");
69         } catch (NullPointerException e) {
70             // expected
71         }
72     }
73 
74 
75     /**
76      * @constraint A11
77      * @title constant pool index
78      */
testVFE1()79     public void testVFE1() {
80         try {
81             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_3");
82             fail("expected a verification exception");
83         } catch (Throwable t) {
84             DxUtil.checkVerifyException(t);
85         }
86     }
87 
88     /**
89      *
90      * @constraint A23
91      * @title number of registers
92      */
testVFE2()93     public void testVFE2() {
94         try {
95             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_4");
96             fail("expected a verification exception");
97         } catch (Throwable t) {
98             DxUtil.checkVerifyException(t);
99         }
100     }
101 
102 
103     /**
104      *
105      * @constraint B14
106      * @title put char into long field - only field with same name but
107      * different type exists
108      */
testVFE5()109     public void testVFE5() {
110         try {
111             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_17");
112             fail("expected a verification exception");
113         } catch (Throwable t) {
114             DxUtil.checkVerifyException(t);
115         }
116     }
117 
118     /**
119      *
120      * @constraint B14
121      * @title put value '66000' into byte field
122      */
testVFE6()123     public void testVFE6() {
124         try {
125             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_6");
126             fail("expected a verification exception");
127         } catch (Throwable t) {
128             DxUtil.checkVerifyException(t);
129         }
130     }
131 
132     /**
133      *
134      * @constraint B14
135      * @title type of field doesn't match opcode - attempt to modify double
136      * field with single-width register
137      */
testVFE7()138     public void testVFE7() {
139         try {
140             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_18");
141             fail("expected a verification exception");
142         } catch (Throwable t) {
143             DxUtil.checkVerifyException(t);
144         }
145     }
146 
147     /**
148      *
149      * @constraint A11
150      * @title Attempt to set static field. Java throws IncompatibleClassChangeError
151      * on first access but Dalvik throws VerifyError on class loading.
152      */
testVFE8()153     public void testVFE8() {
154          try {
155              Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_7");
156              fail("expected a verification exception");
157          } catch (Throwable t) {
158              DxUtil.checkVerifyException(t);
159          }
160     }
161 
162     /**
163      * @constraint B12
164      * @title Attempt to modify inaccessible protected field. Java throws IllegalAccessError
165      * on first access but Dalvik throws VerifyError on class loading.
166      */
testVFE9()167     public void testVFE9() {
168         //@uses dot.junit.opcodes.iput_char.TestStubs
169         //@uses dot.junit.opcodes.iput_char.d.T_iput_char_8
170         try {
171             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_8");
172             fail("expected a verification exception");
173         } catch (Throwable t) {
174             DxUtil.checkVerifyException(t);
175         }
176     }
177 
178     /**
179      * @constraint n/a
180      * @title Attempt to modify field of undefined class. Java throws NoClassDefFoundError
181      * on first access but Dalvik throws VerifyError on class loading.
182      */
testVFE10()183     public void testVFE10() {
184         try {
185             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_9");
186             fail("expected a verification exception");
187         } catch (Throwable t) {
188             DxUtil.checkVerifyException(t);
189         }
190     }
191 
192 
193     /**
194      * @constraint n/a
195      * @title Attempt to modify undefined field. Java throws NoSuchFieldError
196      * on first access but Dalvik throws VerifyError on class loading.
197      */
testVFE11()198     public void testVFE11() {
199         try {
200             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_10");
201             fail("expected a verification exception");
202         } catch (Throwable t) {
203             DxUtil.checkVerifyException(t);
204         }
205     }
206 
207 
208 
209     /**
210      * @constraint n/a
211      * @title Attempt to modify superclass' private field from subclass. Java
212      * throws IllegalAccessError on first access but Dalvik throws VerifyError on class loading.
213      */
testVFE12()214     public void testVFE12() {
215         //@uses dot.junit.opcodes.iput_char.d.T_iput_char_1
216         //@uses dot.junit.opcodes.iput_char.d.T_iput_char_15
217         try {
218             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_15");
219             fail("expected a verification exception");
220         } catch (Throwable t) {
221             DxUtil.checkVerifyException(t);
222         }
223     }
224 
225 
226     /**
227      * @constraint B1
228      * @title iput-char shall not work for wide numbers
229      */
testVFE13()230     public void testVFE13() {
231         try {
232             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_2");
233             fail("expected a verification exception");
234         } catch (Throwable t) {
235             DxUtil.checkVerifyException(t);
236         }
237     }
238 
239     /**
240      *
241      * @constraint B1
242      * @title iput-char shall not work for reference fields
243      */
testVFE14()244     public void testVFE14() {
245         try {
246             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_20");
247             fail("expected a verification exception");
248         } catch (Throwable t) {
249             DxUtil.checkVerifyException(t);
250         }
251     }
252 
253     /**
254      *
255      * @constraint B1
256      * @title iput-char shall not work for short fields
257      */
testVFE15()258     public void testVFE15() {
259         try {
260             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_21");
261             fail("expected a verification exception");
262         } catch (Throwable t) {
263             DxUtil.checkVerifyException(t);
264         }
265     }
266 
267     /**
268      *
269      * @constraint B1
270      * @title iput-char shall not work for int fields
271      */
testVFE16()272     public void testVFE16() {
273         try {
274             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_22");
275             fail("expected a verification exception");
276         } catch (Throwable t) {
277             DxUtil.checkVerifyException(t);
278         }
279     }
280 
281     /**
282      *
283      * @constraint B1
284      * @title iput-char shall not work for byte fields
285      */
testVFE17()286     public void testVFE17() {
287         try {
288             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_23");
289             fail("expected a verification exception");
290         } catch (Throwable t) {
291             DxUtil.checkVerifyException(t);
292         }
293     }
294 
295     /**
296      *
297      * @constraint B1
298      * @title iput-char shall not work for boolean fields
299      */
testVFE18()300     public void testVFE18() {
301         try {
302             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_24");
303             fail("expected a verification exception");
304         } catch (Throwable t) {
305             DxUtil.checkVerifyException(t);
306         }
307     }
308 
309 
310     /**
311      * @constraint B6
312      * @title instance fields may only be accessed on already initialized instances.
313      */
testVFE30()314     public void testVFE30() {
315         try {
316             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_30");
317             fail("expected a verification exception");
318         } catch (Throwable t) {
319             DxUtil.checkVerifyException(t);
320         }
321     }
322 
323     /**
324      * @constraint n/a
325      * @title Modification of final field in other class
326      */
testVFE19()327     public void testVFE19() {
328         //@uses dot.junit.opcodes.iput_char.TestStubs
329         //@uses dot.junit.opcodes.iput_char.d.T_iput_char_11
330     	try {
331             Class.forName("dot.junit.opcodes.iput_char.d.T_iput_char_11");
332             fail("expected a verification exception");
333         } catch (Throwable t) {
334             DxUtil.checkVerifyException(t);
335         }
336     }
337 
338 }
339 
340