• 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.sput_boolean;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.sput_boolean.d.T_sput_boolean_1;
22 import dot.junit.opcodes.sput_boolean.d.T_sput_boolean_11;
23 import dot.junit.opcodes.sput_boolean.d.T_sput_boolean_12;
24 import dot.junit.opcodes.sput_boolean.d.T_sput_boolean_13;
25 import dot.junit.opcodes.sput_boolean.d.T_sput_boolean_14;
26 
27 
28 public class Test_sput_boolean extends DxTestCase {
29 
30     /**
31      * @title put boolean into static field
32      */
testN1()33     public void testN1() {
34         T_sput_boolean_1 t = new T_sput_boolean_1();
35         assertEquals(false, T_sput_boolean_1.st_i1);
36         t.run();
37         assertEquals(true, T_sput_boolean_1.st_i1);
38     }
39 
40 
41     /**
42      * @title modification of final field
43      */
testN2()44     public void testN2() {
45         T_sput_boolean_12 t = new T_sput_boolean_12();
46         assertEquals(false, T_sput_boolean_12.st_i1);
47         t.run();
48         assertEquals(true, T_sput_boolean_12.st_i1);
49     }
50 
51     /**
52      * @title modification of protected field from subclass
53      */
testN4()54     public void testN4() {
55         //@uses dot.junit.opcodes.sput_boolean.d.T_sput_boolean_1
56         //@uses dot.junit.opcodes.sput_boolean.d.T_sput_boolean_14
57         T_sput_boolean_14 t = new T_sput_boolean_14();
58         assertEquals(false, T_sput_boolean_14.getProtectedField());
59         t.run();
60         assertEquals(true, T_sput_boolean_14.getProtectedField());
61     }
62 
63 
64     /**
65      * @title initialization of referenced class throws exception
66      */
testE6()67     public void testE6() {
68         T_sput_boolean_13 t = new T_sput_boolean_13();
69         try {
70             t.run();
71             fail("expected Error");
72         } catch (Error e) {
73             // expected
74         }
75     }
76 
77     /**
78      * @constraint A12
79      * @title constant pool index
80      */
testVFE1()81     public void testVFE1() {
82         try {
83             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_3");
84             fail("expected a verification exception");
85         } catch (Throwable t) {
86             DxUtil.checkVerifyException(t);
87         }
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.sput_boolean.d.T_sput_boolean_4");
98             fail("expected a verification exception");
99         } catch (Throwable t) {
100             DxUtil.checkVerifyException(t);
101         }
102     }
103 
104 
105     /**
106      *
107      * @constraint B13
108      * @title put boolean into long field - only field with same name but
109      * different type exists
110      */
testVFE5()111     public void testVFE5() {
112         try {
113             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_17");
114             fail("expected a verification exception");
115         } catch (Throwable t) {
116             DxUtil.checkVerifyException(t);
117         }
118     }
119 
120     /**
121      *
122      * @constraint B13
123      * @title put value '2' into boolean field
124      */
testVFE6()125     public void testVFE6() {
126         try {
127             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_6");
128             fail("expected a verification exception");
129         } catch (Throwable t) {
130             DxUtil.checkVerifyException(t);
131         }
132     }
133 
134     /**
135      *
136      * @constraint B13
137      * @title type of field doesn't match opcode - attempt to modify double
138      * field with single-width register
139      */
testVFE7()140     public void testVFE7() {
141         try {
142             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_18");
143             fail("expected a verification exception");
144         } catch (Throwable t) {
145             DxUtil.checkVerifyException(t);
146         }
147     }
148 
149     /**
150      *
151      * @constraint A12
152      * @title Attempt to set non-static field. Java throws IncompatibleClassChangeError
153      * on first access but Dalvik throws VerifyError on class loading.
154      */
testVFE8()155     public void testVFE8() {
156          try {
157              Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_7");
158              fail("expected a verification exception");
159          } catch (Throwable t) {
160              DxUtil.checkVerifyException(t);
161          }
162     }
163 
164     /**
165      * @constraint n/a
166      * @title Attempt to modify inaccessible field. Java throws IllegalAccessError
167      * on first access but Dalvik throws VerifyError on class loading.
168      */
testVFE9()169     public void testVFE9() {
170         //@uses dot.junit.opcodes.sput_boolean.TestStubs
171         //@uses dot.junit.opcodes.sput_boolean.d.T_sput_boolean_8
172         try {
173             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_8");
174             fail("expected a verification exception");
175         } catch (Throwable t) {
176             DxUtil.checkVerifyException(t);
177         }
178     }
179 
180     /**
181      * @constraint n/a
182      * @title Attempt to modify field of undefined class. Java throws NoClassDefFoundError
183      * on first access but Dalvik throws VerifyError on class loading.
184      */
testVFE10()185     public void testVFE10() {
186         try {
187             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_9");
188             fail("expected a verification exception");
189         } catch (Throwable t) {
190             DxUtil.checkVerifyException(t);
191         }
192     }
193 
194     /**
195      * @constraint n/a
196      * @title Attempt to modify undefined field. Java throws NoSuchFieldError
197      * on first access but Dalvik throws VerifyError on class loading.
198      */
testVFE11()199     public void testVFE11() {
200         try {
201             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_10");
202             fail("expected a verification exception");
203         } catch (Throwable t) {
204             DxUtil.checkVerifyException(t);
205         }
206     }
207 
208 
209 
210     /**
211      * @constraint n/a
212      * @title Attempt to modify superclass' private field from subclass. Java
213      * throws IllegalAccessError on first access but Dalvik throws VerifyError on class loading.
214      */
testVFE12()215     public void testVFE12() {
216         //@uses dot.junit.opcodes.sput_boolean.d.T_sput_boolean_1
217         //@uses dot.junit.opcodes.sput_boolean.d.T_sput_boolean_15
218         try {
219             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_15");
220             fail("expected a verification exception");
221         } catch (Throwable t) {
222             DxUtil.checkVerifyException(t);
223         }
224     }
225 
226 
227     /**
228      * @constraint B1
229      * @title sput_boolean shall not work for wide numbers
230      */
testVFE13()231     public void testVFE13() {
232         try {
233             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_2");
234             fail("expected a verification exception");
235         } catch (Throwable t) {
236             DxUtil.checkVerifyException(t);
237         }
238     }
239 
240     /**
241      *
242      * @constraint B1
243      * @title sput_boolean shall not work for reference fields
244      */
testVFE14()245     public void testVFE14() {
246         try {
247             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_20");
248             fail("expected a verification exception");
249         } catch (Throwable t) {
250             DxUtil.checkVerifyException(t);
251         }
252     }
253 
254     /**
255      *
256      * @constraint B1
257      * @title sput_boolean shall not work for short fields
258      */
testVFE15()259     public void testVFE15() {
260         try {
261             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_21");
262             fail("expected a verification exception");
263         } catch (Throwable t) {
264             DxUtil.checkVerifyException(t);
265         }
266     }
267 
268     /**
269      *
270      * @constraint B1
271      * @title sput_boolean shall not work for int fields
272      */
testVFE16()273     public void testVFE16() {
274         try {
275             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_22");
276             fail("expected a verification exception");
277         } catch (Throwable t) {
278             DxUtil.checkVerifyException(t);
279         }
280     }
281 
282     /**
283      *
284      * @constraint B1
285      * @title sput_boolean shall not work for char fields
286      */
testVFE17()287     public void testVFE17() {
288         try {
289             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_23");
290             fail("expected a verification exception");
291         } catch (Throwable t) {
292             DxUtil.checkVerifyException(t);
293         }
294     }
295 
296     /**
297      *
298      * @constraint B1
299      * @title sput_boolean shall not work for byte fields
300      */
testVFE18()301     public void testVFE18() {
302         try {
303             Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_24");
304             fail("expected a verification exception");
305         } catch (Throwable t) {
306             DxUtil.checkVerifyException(t);
307         }
308     }
309 
310     /**
311      * @constraint B1
312      * @title Modification of final field in other class.
313      */
testVFE19()314     public void testVFE19() {
315         //@uses dot.junit.opcodes.sput_boolean.TestStubs
316         //@uses dot.junit.opcodes.sput_boolean.d.T_sput_boolean_11
317 
318     	try {
319     		Class.forName("dot.junit.opcodes.sput_boolean.d.T_sput_boolean_11");
320     	}catch (Throwable t) {
321             DxUtil.checkVerifyException(t);
322         }
323     }
324 }
325