• 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_byte;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.iput_byte.d.T_iput_byte_1;
22 import dot.junit.opcodes.iput_byte.d.T_iput_byte_11;
23 import dot.junit.opcodes.iput_byte.d.T_iput_byte_12;
24 import dot.junit.opcodes.iput_byte.d.T_iput_byte_13;
25 import dot.junit.opcodes.iput_byte.d.T_iput_byte_14;
26 
27 public class Test_iput_byte extends DxTestCase {
28     /**
29      * @title put byte into field
30      */
testN1()31     public void testN1() {
32         T_iput_byte_1 t = new T_iput_byte_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_byte_12 t = new T_iput_byte_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_byte.d.T_iput_byte_1
54         //@uses dot.junit.opcodes.iput_byte.d.T_iput_byte_14
55         T_iput_byte_14 t = new T_iput_byte_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_byte_13 t = new T_iput_byte_13();
66         try {
67             t.run();
68             fail("expected NullPointerException");
69         } catch (NullPointerException e) {
70             // expected
71         }
72     }
73 
74     /**
75      * @constraint A11
76      * @title constant pool index
77      */
testVFE1()78     public void testVFE1() {
79         try {
80             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_3");
81             fail("expected a verification exception");
82         } catch (Throwable t) {
83             DxUtil.checkVerifyException(t);
84         }
85     }
86 
87     /**
88      *
89      * @constraint A23
90      * @title number of registers
91      */
testVFE2()92     public void testVFE2() {
93         try {
94             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_4");
95             fail("expected a verification exception");
96         } catch (Throwable t) {
97             DxUtil.checkVerifyException(t);
98         }
99     }
100 
101 
102     /**
103      *
104      * @constraint B14
105      * @title put byte into long field - only field with same name but
106      * different type exists
107      */
testVFE5()108     public void testVFE5() {
109         try {
110             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_17");
111             fail("expected a verification exception");
112         } catch (Throwable t) {
113             DxUtil.checkVerifyException(t);
114         }
115     }
116 
117     /**
118      *
119      * @constraint B14
120      * @title put value '256' into byte field
121      */
testVFE6()122     public void testVFE6() {
123         try {
124             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_6");
125             fail("expected a verification exception");
126         } catch (Throwable t) {
127             DxUtil.checkVerifyException(t);
128         }
129     }
130 
131     /**
132      *
133      * @constraint B14
134      * @title type of field doesn't match opcode - attempt to modify double
135      * field with single-width register
136      */
testVFE7()137     public void testVFE7() {
138         try {
139             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_18");
140             fail("expected a verification exception");
141         } catch (Throwable t) {
142             DxUtil.checkVerifyException(t);
143         }
144     }
145 
146     /**
147      *
148      * @constraint A11
149      * @title Attempt to set static field. Java throws IncompatibleClassChangeError
150      * on first access but Dalvik throws VerifyError on class loading.
151      */
testVFE8()152     public void testVFE8() {
153          try {
154              Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_7");
155              fail("expected a verification exception");
156          } catch (Throwable t) {
157              DxUtil.checkVerifyException(t);
158          }
159     }
160 
161     /**
162      * @constraint B12
163      * @title Attempt to modify inaccessible protected field. Java throws IllegalAccessError
164      * on first access but Dalvik throws VerifyError on class loading.
165      */
testVFE9()166     public void testVFE9() {
167         //@uses dot.junit.opcodes.iput_byte.TestStubs
168         //@uses dot.junit.opcodes.iput_byte.d.T_iput_byte_8
169         try {
170             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_8");
171             fail("expected a verification exception");
172         } catch (Throwable t) {
173             DxUtil.checkVerifyException(t);
174         }
175     }
176 
177     /**
178      * @constraint n/a
179      * @title Attempt to modify field of undefined class. Java throws NoClassDefFoundError
180      * on first access but Dalvik throws VerifyError on class loading.
181      */
testVFE10()182     public void testVFE10() {
183         try {
184             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_9");
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 undefined field. Java throws NoSuchFieldError
194      * on first access but Dalvik throws VerifyError on class loading.
195      */
testVFE11()196     public void testVFE11() {
197         try {
198             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_10");
199             fail("expected a verification exception");
200         } catch (Throwable t) {
201             DxUtil.checkVerifyException(t);
202         }
203     }
204 
205 
206 
207     /**
208      * @constraint n/a
209      * @title Attempt to modify superclass' private field from subclass. Java
210      * throws IllegalAccessError on first access but Dalvik throws VerifyError on class loading.
211      */
testVFE12()212     public void testVFE12() {
213         //@uses dot.junit.opcodes.iput_byte.d.T_iput_byte_1
214         //@uses dot.junit.opcodes.iput_byte.d.T_iput_byte_15
215         try {
216             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_15");
217             fail("expected a verification exception");
218         } catch (Throwable t) {
219             DxUtil.checkVerifyException(t);
220         }
221     }
222 
223 
224     /**
225      * @constraint B1
226      * @title iput-byte shall not work for wide numbers
227      */
testVFE13()228     public void testVFE13() {
229         try {
230             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_2");
231             fail("expected a verification exception");
232         } catch (Throwable t) {
233             DxUtil.checkVerifyException(t);
234         }
235     }
236 
237     /**
238      *
239      * @constraint B1
240      * @title iput-byte shall not work for reference fields
241      */
testVFE14()242     public void testVFE14() {
243         try {
244             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_20");
245             fail("expected a verification exception");
246         } catch (Throwable t) {
247             DxUtil.checkVerifyException(t);
248         }
249     }
250 
251     /**
252      *
253      * @constraint B1
254      * @title iput-byte shall not work for short fields
255      */
testVFE15()256     public void testVFE15() {
257         try {
258             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_21");
259             fail("expected a verification exception");
260         } catch (Throwable t) {
261             DxUtil.checkVerifyException(t);
262         }
263     }
264 
265     /**
266      *
267      * @constraint B1
268      * @title iput-byte shall not work for int fields
269      */
testVFE16()270     public void testVFE16() {
271         try {
272             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_22");
273             fail("expected a verification exception");
274         } catch (Throwable t) {
275             DxUtil.checkVerifyException(t);
276         }
277     }
278 
279     /**
280      *
281      * @constraint B1
282      * @title iput-byte shall not work for char fields
283      */
testVFE17()284     public void testVFE17() {
285         try {
286             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_23");
287             fail("expected a verification exception");
288         } catch (Throwable t) {
289             DxUtil.checkVerifyException(t);
290         }
291     }
292 
293     /**
294      *
295      * @constraint B1
296      * @title iput-byte shall not work for boolean fields
297      */
testVFE18()298     public void testVFE18() {
299         try {
300             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_24");
301             fail("expected a verification exception");
302         } catch (Throwable t) {
303             DxUtil.checkVerifyException(t);
304         }
305     }
306 
307 
308     /**
309      * @constraint B6
310      * @title instance fields may only be accessed on already initialized instances.
311      */
testVFE30()312     public void testVFE30() {
313         try {
314             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_30");
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.iput_byte.TestStubs
327         //@uses dot.junit.opcodes.iput_byte.d.T_iput_byte_11
328     	try {
329             Class.forName("dot.junit.opcodes.iput_byte.d.T_iput_byte_11");
330             fail("expected a verification exception");
331         } catch (Throwable t) {
332             DxUtil.checkVerifyException(t);
333         }
334     }
335 }
336 
337