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