• 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.iget_object;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.iget_object.d.T_iget_object_1;
22 import dot.junit.opcodes.iget_object.d.T_iget_object_11;
23 import dot.junit.opcodes.iget_object.d.T_iget_object_9;
24 
25 public class Test_iget_object extends DxTestCase {
26 
27     /**
28      * @title get reference from field
29      */
testN1()30     public void testN1() {
31         T_iget_object_1 t = new T_iget_object_1();
32         assertEquals(null, t.run());
33     }
34 
35 
36     /**
37      * @title access protected field from subclass
38      */
testN3()39     public void testN3() {
40         //@uses dot.junit.opcodes.iget_object.d.T_iget_object_1
41         //@uses dot.junit.opcodes.iget_object.d.T_iget_object_11
42         T_iget_object_11 t = new T_iget_object_11();
43         assertEquals(null, t.run());
44     }
45 
46     /**
47      * @title expected NullPointerException
48      */
testE2()49     public void testE2() {
50         T_iget_object_9 t = new T_iget_object_9();
51         try {
52             t.run();
53             fail("expected NullPointerException");
54         } catch (NullPointerException e) {
55             // expected
56         }
57     }
58 
59     /**
60      * @constraint A11
61      * @title constant pool index
62      */
testVFE1()63     public void testVFE1() {
64         try {
65             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_4");
66             fail("expected a verification exception");
67         } catch (Throwable t) {
68             DxUtil.checkVerifyException(t);
69         }
70     }
71 
72     /**
73      *
74      * @constraint A23
75      * @title number of registers
76      */
testVFE2()77     public void testVFE2() {
78         try {
79             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_3");
80             fail("expected a verification exception");
81         } catch (Throwable t) {
82             DxUtil.checkVerifyException(t);
83         }
84     }
85 
86     /**
87      *
88      * @constraint B13
89      * @title  (read object from long field - only field with same name but
90      * different type exists)
91      */
testVFE3()92     public void testVFE3() {
93         try {
94             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_13");
95             fail("expected a verification exception");
96         } catch (Throwable t) {
97             DxUtil.checkVerifyException(t);
98         }
99     }
100 
101     /**
102      * @constraint n/a
103      * @title Attempt to read inaccessible field. Java throws IllegalAccessError
104      * on first access but Dalvik throws VerifyError on class loading.
105      */
testVFE4()106     public void testVFE4() {
107         //@uses dot.junit.opcodes.iget_object.d.T_iget_object_6
108         //@uses dot.junit.opcodes.iget_object.TestStubs
109         try {
110             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_6");
111             fail("expected a verification exception");
112         } catch (Throwable t) {
113             DxUtil.checkVerifyException(t);
114         }
115     }
116 
117     /**
118      * @constraint n/a
119      * @title Attempt to read field of undefined class. Java throws NoClassDefFoundError
120      * on first access but Dalvik throws VerifyError on class loading.
121      */
testVFE5()122     public void testVFE5() {
123         try {
124             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_7");
125             fail("expected a verification exception");
126         } catch (Throwable t) {
127             DxUtil.checkVerifyException(t);
128         }
129     }
130 
131     /**
132      * @constraint n/a
133      * @title Attempt to read undefined field. Java throws NoSuchFieldError
134      * on first access but Dalvik throws VerifyError on class loading.
135      */
testVFE6()136     public void testVFE6() {
137         try {
138             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_8");
139             fail("expected a verification exception");
140         } catch (Throwable t) {
141             DxUtil.checkVerifyException(t);
142         }
143     }
144 
145     /**
146      * @constraint n/a
147      * @title Attempt to read superclass' private field from subclass. Java
148      * throws IllegalAccessError on first access but Dalvik throws VerifyError on class loading.
149      */
testVFE7()150     public void testVFE7() {
151         //@uses dot.junit.opcodes.iget_object.d.T_iget_object_12
152         //@uses dot.junit.opcodes.iget_object.d.T_iget_object_1
153         try {
154             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_12");
155             fail("expected a verification exception");
156         } catch (Throwable t) {
157             DxUtil.checkVerifyException(t);
158         }
159     }
160 
161     /**
162      * @constraint B1
163      * @title iget_object shall not work for short fields
164      */
testVFE8()165     public void testVFE8() {
166         try {
167             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_14");
168             fail("expected a verification exception");
169         } catch (Throwable t) {
170             DxUtil.checkVerifyException(t);
171         }
172     }
173 
174     /**
175      *
176      * @constraint B1
177      * @title iget_object shall not work for char fields
178      */
testVFE9()179     public void testVFE9() {
180         try {
181             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_15");
182             fail("expected a verification exception");
183         } catch (Throwable t) {
184             DxUtil.checkVerifyException(t);
185         }
186     }
187 
188     /**
189      *
190      * @constraint B1
191      * @title iget_object shall not work for int fields
192      */
testVFE10()193     public void testVFE10() {
194         try {
195             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_16");
196             fail("expected a verification exception");
197         } catch (Throwable t) {
198             DxUtil.checkVerifyException(t);
199         }
200     }
201 
202     /**
203      *
204      * @constraint B1
205      * @title iget_object shall not work for byte fields
206      */
testVFE11()207     public void testVFE11() {
208         try {
209             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_17");
210             fail("expected a verification exception");
211         } catch (Throwable t) {
212             DxUtil.checkVerifyException(t);
213         }
214     }
215 
216     /**
217      *
218      * @constraint B1
219      * @title iget_object shall not work for boolean fields
220      */
testVFE12()221     public void testVFE12() {
222         try {
223             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_18");
224             fail("expected a verification exception");
225         } catch (Throwable t) {
226             DxUtil.checkVerifyException(t);
227         }
228     }
229 
230     /**
231      *
232      * @constraint B1
233      * @title iget_object shall not work for double fields
234      */
testVFE13()235     public void testVFE13() {
236         try {
237             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_19");
238             fail("expected a verification exception");
239         } catch (Throwable t) {
240             DxUtil.checkVerifyException(t);
241         }
242     }
243 
244     /**
245      *
246      * @constraint B1
247      * @title iget_object shall not work for long fields
248      */
testVFE14()249     public void testVFE14() {
250         try {
251             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_20");
252             fail("expected a verification exception");
253         } catch (Throwable t) {
254             DxUtil.checkVerifyException(t);
255         }
256     }
257 
258     /**
259      *
260      * @constraint B13
261      * @title  only field of different type exists
262      */
testVFE15()263     public void testVFE15() {
264         try {
265             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_21");
266             fail("expected a verification exception");
267         } catch (Throwable t) {
268             DxUtil.checkVerifyException(t);
269         }
270     }
271 
272     /**
273      * @constraint B12
274      * @title Attempt to read inaccessible protected field. Java throws IllegalAccessError
275      * on first access but Dalvik throws VerifyError on class loading.
276      */
testVFE16()277     public void testVFE16() {
278         //@uses dot.junit.opcodes.iget_object.d.T_iget_object_22
279         //@uses dot.junit.opcodes.iget_object.TestStubs
280         try {
281             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_22");
282             fail("expected a verification exception");
283         } catch (Throwable t) {
284             DxUtil.checkVerifyException(t);
285         }
286     }
287 
288 
289     /**
290      * @constraint A11
291      * @title Attempt to read static field. Java throws IncompatibleClassChangeError
292      * on first access but Dalvik throws VerifyError on class loading.
293      */
testVFE17()294     public void testVFE17() {
295         //@uses dot.junit.opcodes.iget_object.d.T_iget_object_5
296         //@uses dot.junit.opcodes.iget_object.TestStubs
297         try {
298             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_5");
299             fail("expected a verification exception");
300         } catch (Throwable t) {
301             DxUtil.checkVerifyException(t);
302         }
303     }
304 
305     /**
306      * @constraint B6
307      * @title instance fields may only be accessed on already initialized instances.
308      */
testVFE30()309     public void testVFE30() {
310         try {
311             Class.forName("dot.junit.opcodes.iget_object.d.T_iget_object_30");
312             fail("expected a verification exception");
313         } catch (Throwable t) {
314             DxUtil.checkVerifyException(t);
315         }
316     }
317 }
318 
319