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