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