• 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.invoke_direct_range;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 
22 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_2;
23 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_21;
24 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_8;
25 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_9;
26 
27 public class Test_invoke_direct_range extends DxTestCase {
28 
29     /**
30      * @title private method call
31      */
testN2()32     public void testN2() {
33         T_invoke_direct_range_2 t = new T_invoke_direct_range_2();
34         assertEquals(345, t.run());
35     }
36 
37 
38     /**
39      * @title Check that new frame is created by invoke_direct_range
40      */
testN7()41     public void testN7() {
42         T_invoke_direct_range_21 t = new T_invoke_direct_range_21();
43         assertEquals(1, t.run());
44     }
45 
46 
47 
48     /**
49      * @title objref is null
50      */
testE3()51     public void testE3() {
52         T_invoke_direct_range_8 t = new T_invoke_direct_range_8();
53         try {
54             assertEquals(5, t.run());
55             fail("expected NullPointerException");
56         } catch (NullPointerException e) {
57             // expected
58         }
59     }
60 
61     /**
62      * @title Native method can't be linked
63      */
testE5()64     public void testE5() {
65         T_invoke_direct_range_9 t = new T_invoke_direct_range_9();
66         try {
67             assertEquals(5, t.run());
68             fail("expected UnsatisfiedLinkError");
69         } catch (UnsatisfiedLinkError e) {
70             // expected
71         }
72     }
73 
74     /**
75      * @constraint A14
76      * @title invalid constant pool index
77      */
testVFE1()78     public void testVFE1() {
79         try {
80             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_3");
81             fail("expected a verification exception");
82         } catch (Throwable t) {
83             DxUtil.checkVerifyException(t);
84         }
85     }
86 
87     /**
88      * @constraint A15
89      * @title invoke-direct may not be used to invoke <clinit>
90      */
testVFE3()91     public void testVFE3() {
92         try {
93             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_4");
94             fail("expected a verification exception");
95         } catch (Throwable t) {
96             DxUtil.checkVerifyException(t);
97         }
98     }
99 
100     /**
101      * @constraint B4
102      * @title invoke-direct target must be in self or superclass
103      */
testVFE4()104     public void testVFE4() {
105         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_6
106         //@uses dot.junit.opcodes.invoke_direct_range.TSuper
107         try {
108             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_6");
109             fail("expected a verification exception");
110         } catch (Throwable t) {
111             DxUtil.checkVerifyException(t);
112         }
113     }
114 
115     /**
116      * @constraint B1
117      * @title number of arguments
118      */
testVFE5()119     public void testVFE5() {
120         try {
121             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_5");
122             fail("expected a verification exception");
123         } catch (Throwable t) {
124             DxUtil.checkVerifyException(t);
125         }
126     }
127 
128     /**
129      * @constraint B1
130      * @title int is passed instead of obj ref
131      */
testVFE6()132     public void testVFE6() {
133         try {
134             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_10");
135             fail("expected a verification exception");
136         } catch (Throwable t) {
137             DxUtil.checkVerifyException(t);
138         }
139     }
140 
141 
142     /**
143      * @constraint B9
144      * @title number of arguments passed to method
145      */
testVFE8()146     public void testVFE8() {
147         try {
148             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_14");
149             fail("expected a verification exception");
150         } catch (Throwable t) {
151             DxUtil.checkVerifyException(t);
152         }
153     }
154 
155     /**
156      * @constraint B9
157      * @title types of arguments passed to method
158      */
testVFE9()159     public void testVFE9() {
160         try {
161             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_24");
162             fail("expected a verification exception");
163         } catch (Throwable t) {
164             DxUtil.checkVerifyException(t);
165         }
166     }
167 
168     /**
169      * @constraint B10
170      * @title assignment incompatible references when accessing protected method
171      */
testVFE10()172     public void testVFE10() {
173         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_25
174         //@uses dot.junit.opcodes.invoke_direct_range.TPlain
175         //@uses dot.junit.opcodes.invoke_direct_range.TSuper
176         try {
177             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_25");
178             fail("expected a verification exception");
179         } catch (Throwable t) {
180             DxUtil.checkVerifyException(t);
181         }
182     }
183 
184     /**
185      * @constraint B5
186      * @title  Superclass' method call
187      */
testVFE11()188     public void testVFE11() {
189         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_25
190         //@uses dot.junit.opcodes.invoke_direct_range.TSuper
191         try {
192             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_1");
193             fail("expected a verification exception");
194         } catch (Throwable t) {
195             DxUtil.checkVerifyException(t);
196         }
197     }
198 
199     /**
200      * @constraint A23
201      * @title number of registers
202      */
testVFE12()203     public void testVFE12() {
204         try {
205             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_15");
206             fail("expected a verification exception");
207         } catch (Throwable t) {
208             DxUtil.checkVerifyException(t);
209         }
210     }
211 
212 
213     /**
214      * @constraint n/a
215      * @title Attempt to call undefined method. Java throws NoSuchMethodError
216      * on first access but Dalvik throws VerifyError on class loading.
217      */
testVFE13()218     public void testVFE13() {
219         try {
220             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_7");
221             fail("expected a verification exception");
222         } catch (Throwable t) {
223             DxUtil.checkVerifyException(t);
224         }
225     }
226 
227     /**
228      * @constraint n/a
229      * @title Method has different signature. Java throws NoSuchMethodError
230      * on first access but Dalvik throws VerifyError on class loading.
231      */
testVFE14()232     public void testVFE14() {
233         try {
234             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_16");
235             fail("expected a verification exception");
236         } catch (Throwable t) {
237             DxUtil.checkVerifyException(t);
238         }
239     }
240 
241     /**
242      * @constraint n/a
243      * @title Attempt to invoke static method. Java throws IncompatibleClassChangeError
244      * on first access but Dalvik throws VerifyError on class loading.
245      */
testVFE15()246     public void testVFE15() {
247         try {
248             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_11");
249             fail("expected a verification exception");
250         } catch (Throwable t) {
251             DxUtil.checkVerifyException(t);
252         }
253     }
254 
255 
256     /**
257      * @constraint n/a
258      * @title Attempt to invoke private method of superclass. Java throws IllegalAccessError
259      * on first access but Dalvik throws VerifyError on class loading.
260      */
testVFE16()261     public void testVFE16() {
262         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_12
263         //@uses dot.junit.opcodes.invoke_direct_range.TSuper
264         try {
265             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_12");
266             fail("expected a verification exception");
267         } catch (Throwable t) {
268             DxUtil.checkVerifyException(t);
269         }
270     }
271 
272 
273     /**
274      * @constraint n/a
275      * @title Attempt to invoke abstract method
276      */
testVFE17()277     public void testVFE17() {
278         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_13
279         //@uses dot.junit.opcodes.invoke_direct_range.TAbstract
280         try {
281             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_13");
282             fail("expected a verification exception");
283         } catch (Throwable t) {
284             DxUtil.checkVerifyException(t);
285         }
286     }
287 
288     /**
289      * @constraint B5
290      * @title An instance initializer must only be invoked on an uninitialized instance.
291      */
testVFE18()292     public void testVFE18() {
293         try {
294             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_17");
295             fail("expected a verification exception");
296         } catch (Throwable t) {
297             DxUtil.checkVerifyException(t);
298         }
299     }
300 
301     /**
302      * @constraint B8
303      * @title attempt to access inherited instance field before <init> is called
304      */
testVFE19()305     public void testVFE19() {
306         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_18
307         //@uses dot.junit.opcodes.invoke_direct_range.TSuper
308         try {
309             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_18");
310             fail("expected a verification exception");
311         } catch (Throwable t) {
312             DxUtil.checkVerifyException(t);
313         }
314     }
315 
316     /**
317      * @constraint A14
318      * @title attempt to invoke interface method
319      */
testVFE20()320     public void testVFE20() {
321         try {
322             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_26");
323             fail("expected a verification exception");
324         } catch (Throwable t) {
325             DxUtil.checkVerifyException(t);
326         }
327     }
328 
329     /**
330      * @constraint B6
331      * @title instance methods may only be invoked on already initialized instances.
332      */
testVFE21()333     public void testVFE21() {
334         try {
335             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_27");
336             fail("expected a verification exception");
337         } catch (Throwable t) {
338             DxUtil.checkVerifyException(t);
339         }
340     }
341 }
342