• 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_boolean;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_1;
22 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_11;
23 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_12;
24 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_13;
25 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_14;
26 
27 
28 public class Test_iput_boolean extends DxTestCase {
29 
30     /**
31      * @title put boolean into field
32      */
testN1()33     public void testN1() {
34         T_iput_boolean_1 t = new T_iput_boolean_1();
35         assertEquals(false, t.st_i1);
36         t.run();
37         assertEquals(true, t.st_i1);
38     }
39 
40 
41     /**
42      * @title modification of final field
43      */
testN2()44     public void testN2() {
45         T_iput_boolean_12 t = new T_iput_boolean_12();
46         assertEquals(false, t.st_i1);
47         t.run();
48         assertEquals(true, t.st_i1);
49     }
50 
51     /**
52      * @title modification of protected field from subclass
53      */
testN4()54     public void testN4() {
55         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_1
56         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_14
57         T_iput_boolean_14 t = new T_iput_boolean_14();
58         assertEquals(false, t.getProtectedField());
59         t.run();
60         assertEquals(true, t.getProtectedField());
61     }
62 
63 
64 
65     /**
66      * @title expected NullPointerException
67      */
testE2()68     public void testE2() {
69         T_iput_boolean_13 t = new T_iput_boolean_13();
70         try {
71             t.run();
72             fail("expected NullPointerException");
73         } catch (NullPointerException e) {
74             // expected
75         }
76     }
77 
78     /**
79      * @constraint A11
80      * @title constant pool index
81      */
testVFE1()82     public void testVFE1() {
83         try {
84             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_3");
85             fail("expected a verification exception");
86         } catch (Throwable t) {
87             DxUtil.checkVerifyException(t);
88         }
89     }
90 
91     /**
92      * @constraint A23
93      * @title number of registers
94      */
testVFE2()95     public void testVFE2() {
96         try {
97             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_4");
98             fail("expected a verification exception");
99         } catch (Throwable t) {
100             DxUtil.checkVerifyException(t);
101         }
102     }
103 
104 
105     /**
106      * @constraint B14
107      * @title put boolean into long field - only field with same name but
108      * different type exists
109      */
testVFE5()110     public void testVFE5() {
111         try {
112             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_17");
113             fail("expected a verification exception");
114         } catch (Throwable t) {
115             DxUtil.checkVerifyException(t);
116         }
117     }
118 
119     /**
120      *
121      * @constraint B14
122      * @title put value '2' into boolean field
123      */
testVFE6()124     public void testVFE6() {
125         try {
126             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_6");
127             fail("expected a verification exception");
128         } catch (Throwable t) {
129             DxUtil.checkVerifyException(t);
130         }
131     }
132 
133     /**
134      *
135      * @constraint B14
136      * @title type of field doesn't match opcode - attempt to modify double
137      * field with single-width register
138      */
testVFE7()139     public void testVFE7() {
140         try {
141             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_18");
142             fail("expected a verification exception");
143         } catch (Throwable t) {
144             DxUtil.checkVerifyException(t);
145         }
146     }
147 
148     /**
149      *
150      * @constraint A11
151      * @title Attempt to set static field. Java throws IncompatibleClassChangeError
152      * on first access but Dalvik throws VerifyError on class loading.
153      */
testVFE8()154     public void testVFE8() {
155          try {
156              Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_7");
157              fail("expected a verification exception");
158          } catch (Throwable t) {
159              DxUtil.checkVerifyException(t);
160          }
161     }
162 
163     /**
164      * @constraint B12
165      * @title Attempt to modify inaccessible protected field. Java throws IllegalAccessError
166      * on first access but Dalvik throws VerifyError on class loading.
167      */
testVFE9()168     public void testVFE9() {
169         //@uses dot.junit.opcodes.iput_boolean.TestStubs
170         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_8
171         try {
172             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_8");
173             fail("expected a verification exception");
174         } catch (Throwable t) {
175             DxUtil.checkVerifyException(t);
176         }
177     }
178 
179     /**
180      * @constraint n/a
181      * @title Attempt to modify field of undefined class. Java throws NoClassDefFoundError
182      * on first access but Dalvik throws VerifyError on class loading.
183      */
testVFE10()184     public void testVFE10() {
185         try {
186             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_9");
187             fail("expected a verification exception");
188         } catch (Throwable t) {
189             DxUtil.checkVerifyException(t);
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_boolean.d.T_iput_boolean_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_boolean.d.T_iput_boolean_1
216         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_15
217         try {
218             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_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_boolean shall not work for wide numbers
229      */
testVFE13()230     public void testVFE13() {
231         try {
232             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_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_boolean shall not work for reference fields
243      */
testVFE14()244     public void testVFE14() {
245         try {
246             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_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_boolean shall not work for short fields
257      */
testVFE15()258     public void testVFE15() {
259         try {
260             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_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_boolean shall not work for int fields
271      */
testVFE16()272     public void testVFE16() {
273         try {
274             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_22");
275             fail("expected a verification exception");
276         } catch (Throwable t) {
277             DxUtil.checkVerifyException(t);
278         }
279     }
280 
281     /**
282      * @constraint B1
283      * @title iput_boolean shall not work for char fields
284      */
testVFE17()285     public void testVFE17() {
286         try {
287             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_23");
288             fail("expected a verification exception");
289         } catch (Throwable t) {
290             DxUtil.checkVerifyException(t);
291         }
292     }
293 
294     /**
295      * @constraint B1
296      * @title iput_boolean shall not work for byte fields
297      */
testVFE18()298     public void testVFE18() {
299         try {
300             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_24");
301             fail("expected a verification exception");
302         } catch (Throwable t) {
303             DxUtil.checkVerifyException(t);
304         }
305     }
306 
307     /**
308      * @constraint B6
309      * @title instance fields may only be accessed on already initialized instances.
310      */
testVFE30()311     public void testVFE30() {
312         try {
313             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_30");
314             fail("expected a verification exception");
315         } catch (Throwable t) {
316             DxUtil.checkVerifyException(t);
317         }
318     }
319 
320     /**
321      * @constraint n/a
322      * @title Modification of final field in other class
323      */
testVFE19()324     public void testVFE19() {
325         //@uses dot.junit.opcodes.iput_boolean.TestStubs
326         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_11
327         try {
328             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_11");
329             fail("expected a verification exception");
330         } catch (Throwable t) {
331             DxUtil.checkVerifyException(t);
332         }
333     }
334 }
335 
336