• 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_super;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.invoke_super.d.T_invoke_super_1;
22 import dot.junit.opcodes.invoke_super.d.T_invoke_super_14;
23 import dot.junit.opcodes.invoke_super.d.T_invoke_super_17;
24 import dot.junit.opcodes.invoke_super.d.T_invoke_super_2;
25 import dot.junit.opcodes.invoke_super.d.T_invoke_super_4;
26 import dot.junit.opcodes.invoke_super.d.T_invoke_super_6;
27 import dot.junit.opcodes.invoke_super.d.T_invoke_super_7;
28 
29 public class Test_invoke_super extends DxTestCase {
30 
31     /**
32      * @title invoke method of superclass
33      */
testN1()34     public void testN1() {
35         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_1
36         //@uses dot.junit.opcodes.invoke_super.d.TSuper
37         T_invoke_super_1 t = new T_invoke_super_1();
38         assertEquals(5, t.run());
39     }
40 
41 
42     /**
43      * @title Invoke protected method of superclass
44      */
testN3()45     public void testN3() {
46         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_7
47         //@uses dot.junit.opcodes.invoke_super.d.TSuper
48         T_invoke_super_7 t = new T_invoke_super_7();
49         assertEquals(5, t.run());
50     }
51 
52     /**
53      * @title Check that new frame is created by invoke_super and
54      * arguments are passed to method
55      */
testN5()56     public void testN5() {
57         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_14
58         //@uses dot.junit.opcodes.invoke_super.d.TSuper
59         T_invoke_super_14 t = new T_invoke_super_14();
60         assertTrue(t.run());
61     }
62 
63     /**
64      * @title Recursion of method lookup procedure
65      */
testN6()66     public void testN6() {
67         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_17
68         //@uses dot.junit.opcodes.invoke_super.d.TSuper
69         //@uses dot.junit.opcodes.invoke_super.d.TSuper2
70         T_invoke_super_17 t = new T_invoke_super_17();
71         assertEquals(5, t.run());
72     }
73 
74     /**
75      * @title obj ref is null
76      */
testE1()77     public void testE1() {
78         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_1
79         //@uses dot.junit.opcodes.invoke_super.d.TSuper
80         T_invoke_super_2 t = new T_invoke_super_2();
81         try {
82             t.run();
83             fail("expected NullPointerException");
84         } catch (NullPointerException npe) {
85             // expected
86         }
87     }
88 
89     /**
90      * @title Native method can't be linked
91      */
testE2()92     public void testE2() {
93         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_4
94         //@uses dot.junit.opcodes.invoke_super.d.TSuper
95         T_invoke_super_4 t = new T_invoke_super_4();
96         try {
97             t.run();
98             fail("expected UnsatisfiedLinkError");
99         } catch (UnsatisfiedLinkError ule) {
100             // expected
101         }
102     }
103 
104     /**
105      * @title Attempt to invoke abstract method
106      */
testE4()107     public void testE4() {
108         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_6
109         //@uses dot.junit.opcodes.invoke_super.ATest
110         T_invoke_super_6 t = new T_invoke_super_6();
111         try {
112             t.run();
113             fail("expected AbstractMethodError");
114         } catch (AbstractMethodError iae) {
115             // expected
116         }
117     }
118 
119     /**
120      * @constraint A13
121      * @title invalid constant pool index
122      */
testVFE1()123     public void testVFE1() {
124         try {
125             Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_8");
126             fail("expected a verification exception");
127         } catch (Throwable t) {
128             DxUtil.checkVerifyException(t);
129         }
130     }
131 
132     /**
133      * @constraint A15
134      * @title <clinit> may not be called using invoke-super
135      */
testVFE3()136     public void testVFE3() {
137         try {
138             Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_10");
139             fail("expected a verification exception");
140         } catch (Throwable t) {
141             DxUtil.checkVerifyException(t);
142         }
143     }
144 
145     /**
146      * @constraint B1
147      * @title number of arguments passed to method
148      */
testVFE4()149     public void testVFE4() {
150         try {
151             Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_11");
152             fail("expected a verification exception");
153         } catch (Throwable t) {
154             DxUtil.checkVerifyException(t);
155         }
156     }
157 
158     /**
159      * @constraint B9
160      * @title types of arguments passed to method.
161      */
testVFE5()162     public void testVFE5() {
163         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_12
164         //@uses dot.junit.opcodes.invoke_super.d.TSuper
165         try {
166             Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_12");
167             fail("expected a verification exception");
168         } catch (Throwable t) {
169             DxUtil.checkVerifyException(t);
170         }
171     }
172 
173     /**
174      * @constraint A15
175      * @title <init> may not be called using invoke_super
176      */
testVFE6()177     public void testVFE6() {
178         try {
179             Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_16");
180             fail("expected a verification exception");
181         } catch (Throwable t) {
182             DxUtil.checkVerifyException(t);
183         }
184     }
185 
186     /**
187      * @constraint B10
188      * @title assignment incompatible references when accessing
189      *                  protected method
190      */
testVFE8()191     public void testVFE8() {
192         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_22
193         //@uses dot.junit.opcodes.invoke_super.d.TSuper
194         //@uses dot.junit.opcodes.invoke_super.d.TPlain
195         try {
196             Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_22");
197             fail("expected a verification exception");
198         } catch (Throwable t) {
199             DxUtil.checkVerifyException(t);
200         }
201     }
202 
203     /**
204      * @constraint B10
205      * @title assignment incompatible references when accessing
206      *                  public method
207      */
testVFE9()208     public void testVFE9() {
209         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_23
210         //@uses dot.junit.opcodes.invoke_super.d.TSuper
211         //@uses dot.junit.opcodes.invoke_super.d.TSuper2
212         try {
213             Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_23");
214             fail("expected a verification exception");
215         } catch (Throwable t) {
216             DxUtil.checkVerifyException(t);
217         }
218     }
219 
220     /**
221      * @constraint n/a
222      * @title Attempt to call static method. Java throws IncompatibleClassChangeError
223      * on first access but Dalvik throws VerifyError on class loading.
224      */
testVFE10()225     public void testVFE10() {
226         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_5
227         //@uses dot.junit.opcodes.invoke_super.d.TSuper
228          try {
229              Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_5");
230              fail("expected a verification exception");
231          } catch (Throwable t) {
232              DxUtil.checkVerifyException(t);
233          }
234     }
235 
236 
237     /**
238      * @constraint n/a
239      * @title Attempt to invoke non-existing method. Java throws NoSuchMethodError
240      * on first access but Dalvik throws VerifyError on class loading.
241      */
testVFE12()242     public void testVFE12() {
243          try {
244              Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_15");
245              fail("expected a verification exception");
246          } catch (Throwable t) {
247              DxUtil.checkVerifyException(t);
248          }
249     }
250 
251     /**
252      * @constraint n/a
253      * @title Attempt to invoke private method of other class. Java throws IllegalAccessError
254      * on first access but Dalvik throws VerifyError on class loading.
255      */
testVFE13()256     public void testVFE13() {
257         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_18
258         //@uses dot.junit.opcodes.invoke_super.TestStubs
259          try {
260              Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_18");
261              fail("expected a verification exception");
262          } catch (Throwable t) {
263              DxUtil.checkVerifyException(t);
264          }
265     }
266 
267     /**
268      * @constraint B12
269      * @title Attempt to invoke protected method of unrelated class. Java throws
270      * IllegalAccessError on first access but Dalvik throws VerifyError on class loading.
271      */
testVFE14()272     public void testVFE14() {
273         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_20
274         //@uses dot.junit.opcodes.invoke_super.TestStubs
275          try {
276              Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_20");
277              fail("expected a verification exception");
278          } catch (Throwable t) {
279              DxUtil.checkVerifyException(t);
280          }
281     }
282 
283     /**
284      * @constraint n/a
285      * @title Method has different signature. Java throws
286      * NoSuchMethodError on first access but Dalvik throws VerifyError on class loading.
287      */
testVFE15()288     public void testVFE15() {
289         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_19
290         //@uses dot.junit.opcodes.invoke_super.d.TSuper
291          try {
292              Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_19");
293              fail("expected a verification exception");
294          } catch (Throwable t) {
295              DxUtil.checkVerifyException(t);
296          }
297     }
298 
299     /**
300      * @constraint n/a
301      * @title invoke-super shall be used to invoke private methods
302      */
testVFE16()303     public void testVFE16() {
304         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_13
305         //@uses dot.junit.opcodes.invoke_super.d.TSuper
306          try {
307              Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_13");
308              fail("expected a verification exception");
309          } catch (Throwable t) {
310              DxUtil.checkVerifyException(t);
311          }
312     }
313 
314     /**
315      * @constraint A23
316      * @title number of registers
317      */
testVFE17()318     public void testVFE17() {
319         try {
320             Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_9");
321             fail("expected a verification exception");
322         } catch (Throwable t) {
323             DxUtil.checkVerifyException(t);
324         }
325     }
326 
327     /**
328      * @constraint A13
329      * @title attempt to invoke interface method
330      */
testVFE18()331     public void testVFE18() {
332         try {
333             Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_24");
334             fail("expected a verification exception");
335         } catch (Throwable t) {
336             DxUtil.checkVerifyException(t);
337         }
338     }
339 
340     /**
341      * @constraint B6
342      * @title instance methods may only be invoked on already initialized instances.
343      */
testVFE19()344     public void testVFE19() {
345         //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_25
346         //@uses dot.junit.opcodes.invoke_super.d.TSuper
347          try {
348              Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_25");
349              fail("expected a verification exception");
350          } catch (Throwable t) {
351              DxUtil.checkVerifyException(t);
352          }
353     }
354 }
355