• 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_object;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.iput_object.d.T_iput_object_1;
22 import dot.junit.opcodes.iput_object.d.T_iput_object_11;
23 import dot.junit.opcodes.iput_object.d.T_iput_object_12;
24 import dot.junit.opcodes.iput_object.d.T_iput_object_13;
25 import dot.junit.opcodes.iput_object.d.T_iput_object_14;
26 
27 public class Test_iput_object extends DxTestCase {
28     /**
29      * @title put reference into field
30      */
testN1()31     public void testN1() {
32         T_iput_object_1 t = new T_iput_object_1();
33         assertEquals(null, t.st_i1);
34         t.run();
35         assertEquals(t, t.st_i1);
36     }
37 
38 
39     /**
40      * @title modification of final field
41      */
testN2()42     public void testN2() {
43         T_iput_object_12 t = new T_iput_object_12();
44         assertEquals(null, t.st_i1);
45         t.run();
46         assertEquals(t, 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_object.d.T_iput_object_1
54         //@uses dot.junit.opcodes.iput_object.d.T_iput_object_14
55         T_iput_object_14 t = new T_iput_object_14();
56         assertEquals(null, t.getProtectedField());
57         t.run();
58         assertEquals(t, t.getProtectedField());
59     }
60 
61     /**
62      * @title expected NullPointerException
63      */
testE2()64     public void testE2() {
65         T_iput_object_13 t = new T_iput_object_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_object.d.T_iput_object_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_object.d.T_iput_object_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 object 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_object.d.T_iput_object_17");
112             fail("expected a verification exception");
113         } catch (Throwable t) {
114             DxUtil.checkVerifyException(t);
115         }
116     }
117 
118 
119     /**
120      *
121      * @constraint B14
122      * @title type of field doesn't match opcode - attempt to modify double
123      * field with single-width register
124      */
testVFE7()125     public void testVFE7() {
126         try {
127             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_18");
128             fail("expected a verification exception");
129         } catch (Throwable t) {
130             DxUtil.checkVerifyException(t);
131         }
132     }
133 
134     /**
135      *
136      * @constraint A11
137      * @title Attempt to set non-static field. Java throws IncompatibleClassChangeError
138      * on first access but Dalvik throws VerifyError on class loading.
139      */
testVFE8()140     public void testVFE8() {
141          try {
142              Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_7");
143              fail("expected a verification exception");
144          } catch (Throwable t) {
145              DxUtil.checkVerifyException(t);
146          }
147     }
148 
149     /**
150      * @constraint B12
151      * @title Attempt to modify inaccessible protected field. Java throws IllegalAccessError
152      * on first access but Dalvik throws VerifyError on class loading.
153      */
testVFE9()154     public void testVFE9() {
155         //@uses dot.junit.opcodes.iput_object.TestStubs
156         //@uses dot.junit.opcodes.iput_object.d.T_iput_object_8
157         try {
158             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_8");
159             fail("expected a verification exception");
160         } catch (Throwable t) {
161             DxUtil.checkVerifyException(t);
162         }
163     }
164 
165     /**
166      * @constraint n/a
167      * @title Attempt to modify field of undefined class. Java throws NoClassDefFoundError
168      * on first access but Dalvik throws VerifyError on class loading.
169      */
testVFE10()170     public void testVFE10() {
171         try {
172             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_9");
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 undefined field. Java throws NoSuchFieldError
182      * on first access but Dalvik throws VerifyError on class loading.
183      */
testVFE11()184     public void testVFE11() {
185         try {
186             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_10");
187             fail("expected a verification exception");
188         } catch (Throwable t) {
189             DxUtil.checkVerifyException(t);
190         }
191     }
192 
193 
194 
195     /**
196      * @constraint n/a
197      * @title Attempt to modify superclass' private field from subclass. Java
198      * throws IllegalAccessError on first access but Dalvik throws VerifyError on class loading.
199      */
testVFE12()200     public void testVFE12() {
201         //@uses dot.junit.opcodes.iput_object.d.T_iput_object_1
202         //@uses dot.junit.opcodes.iput_object.d.T_iput_object_15
203         try {
204             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_15");
205             fail("expected a verification exception");
206         } catch (Throwable t) {
207             DxUtil.checkVerifyException(t);
208         }
209     }
210 
211 
212     /**
213      * @constraint B1
214      * @title iput-object shall not work for wide numbers
215      */
testVFE13()216     public void testVFE13() {
217         try {
218             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_2");
219             fail("expected a verification exception");
220         } catch (Throwable t) {
221             DxUtil.checkVerifyException(t);
222         }
223     }
224 
225     /**
226      *
227      * @constraint B13
228      * @title assignment incompatible references
229      */
testVFE14()230     public void testVFE14() {
231         try {
232             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_20");
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-object shall not work for char fields
243      */
testVFE15()244     public void testVFE15() {
245         try {
246             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_21");
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-object shall not work for int fields
257      */
testVFE16()258     public void testVFE16() {
259         try {
260             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_22");
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-object shall not work for byte fields
271      */
testVFE17()272     public void testVFE17() {
273         try {
274             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_23");
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-object shall not work for boolean fields
285      */
testVFE18()286     public void testVFE18() {
287         try {
288             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_24");
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-object shall not work for short fields
299      */
testVFE6()300     public void testVFE6() {
301         try {
302             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_6");
303             fail("expected a verification exception");
304         } catch (Throwable t) {
305             DxUtil.checkVerifyException(t);
306         }
307     }
308 
309 
310 
311     /**
312      * @constraint B6
313      * @title instance fields may only be accessed on already initialized instances.
314      */
testVFE30()315     public void testVFE30() {
316         try {
317             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_30");
318             fail("expected a verification exception");
319         } catch (Throwable t) {
320             DxUtil.checkVerifyException(t);
321         }
322     }
323 
324     /**
325      * @constraint n/a
326      * @title Modification of final field in other class
327      */
testVFE19()328     public void testVFE19() {
329         //@uses dot.junit.opcodes.iput_object.TestStubs
330         //@uses dot.junit.opcodes.iput_object.d.T_iput_object_11
331     	try {
332             Class.forName("dot.junit.opcodes.iput_object.d.T_iput_object_11");
333             fail("expected a verification exception");
334         } catch (Throwable t) {
335             DxUtil.checkVerifyException(t);
336         }
337     }
338 }
339 
340