• 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 dxc.junit.opcodes.invokevirtual;
18 
19 import dxc.junit.DxTestCase;
20 import dxc.junit.DxUtil;
21 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_1;
22 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_13;
23 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_14;
24 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_15;
25 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_17;
26 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_18;
27 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_19;
28 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_2;
29 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_20;
30 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_3;
31 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_4;
32 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_5;
33 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_6;
34 import dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_7;
35 
36 public class Test_invokevirtual extends DxTestCase {
37 
38     /**
39      * @title normal test
40      */
testN1()41     public void testN1() {
42         T_invokevirtual_1 t = new T_invokevirtual_1();
43         int a = 1;
44         String sa = "a" + a;
45         String sb = "a1";
46         assertTrue(t.run(sa, sb));
47         assertFalse(t.run(this, sa));
48         assertFalse(t.run(sb, this));
49     }
50 
51     /**
52      * @title  Check that monitor is acquired if method is synchronized
53      */
testN2()54     public void testN2() {
55         assertTrue(T_invokevirtual_2.execute());
56     }
57 
58     /**
59      * @title  Invoke protected method of superclass
60      */
testN3()61     public void testN3() {
62         // @uses dxc.junit.opcodes.invokevirtual.jm.TSuper
63         T_invokevirtual_7 t = new T_invokevirtual_7();
64         assertEquals(5, t.run());
65     }
66 
67     /**
68      * @title  Private method call
69      */
testN4()70     public void testN4() {
71         T_invokevirtual_13 t = new T_invokevirtual_13();
72         assertEquals(345, t.run());
73     }
74 
75     /**
76      * @title  Check that new frame is created by invokevirtual and
77      * arguments are passed to method
78      */
testN5()79     public void testN5() {
80         // @uses dxc.junit.opcodes.invokevirtual.jm.TSuper
81         T_invokevirtual_14 t = new T_invokevirtual_14();
82         assertTrue(t.run());
83     }
84 
85     /**
86      * @title  Recursion of method lookup procedure
87      */
testN6()88     public void testN6() {
89         // @uses dxc.junit.opcodes.invokevirtual.jm.TSuper
90         T_invokevirtual_17 t = new T_invokevirtual_17();
91         assertEquals(5, t.run());
92     }
93 
94     /**
95      * @title
96      */
testE1()97     public void testE1() {
98         T_invokevirtual_3 t = new T_invokevirtual_3();
99         String s = "s";
100         try {
101             t.run(null, s);
102             fail("expected NullPointerException");
103         } catch (NullPointerException npe) {
104             // expected
105         }
106     }
107 
108     /**
109      * @title  Native method can't be linked
110      */
testE2()111     public void testE2() {
112         T_invokevirtual_4 t = new T_invokevirtual_4();
113         try {
114             t.run();
115             fail("expected UnsatisfiedLinkError");
116         } catch (UnsatisfiedLinkError ule) {
117             // expected
118         }
119     }
120 
121     /**
122      * @title  Attempt to invoke static method
123      */
testE3()124     public void testE3() {
125         try {
126             T_invokevirtual_5 t = new T_invokevirtual_5();
127             t.run();
128             fail("expected IncompatibleClassChangeError");
129         } catch (IncompatibleClassChangeError icce) {
130             // expected
131         } catch (VerifyError vfe) {
132             // ok for dalvikvm;
133             System.out.print("dvmvfe:");
134         }
135     }
136 
137     /**
138      * @title  Attempt to invoke abstract method
139      */
testE4()140     public void testE4() {
141         // @uses dxc.junit.opcodes.invokevirtual.jm.ATest
142         T_invokevirtual_6 t = new T_invokevirtual_6();
143         try {
144             t.run();
145             fail("expected AbstractMethodError");
146         } catch (AbstractMethodError iae) {
147             // expected
148         }
149     }
150 
151     /**
152      * @title  Attempt to invoke non-existing method
153      */
testE5()154     public void testE5() {
155         try {
156             T_invokevirtual_15 t = new T_invokevirtual_15();
157             t.run();
158             fail("expected NoSuchMethodError");
159         } catch (NoSuchMethodError iae) {
160             // expected
161         } catch (VerifyError vfe) {
162             // ok for dalvikvm;
163             System.out.print("dvmvfe:");
164         }
165     }
166 
167     /**
168      * @title  Attempt to invoke private method of other class
169      */
testE6()170     public void testE6() {
171         // @uses dxc.junit.opcodes.invokevirtual.jm.TSuper
172         // @uses dxc.junit.opcodes.invokevirtual.TProtected
173         try {
174             T_invokevirtual_18 t = new T_invokevirtual_18();
175             t.run(new TProtected());
176             fail("expected IllegalAccessError");
177         } catch (IllegalAccessError iae) {
178             // expected
179         } catch (VerifyError vfe) {
180             // ok for dalvikvm;
181             System.out.print("dvmvfe:");
182         }
183     }
184 
185     /**
186      * @title  Attempt to invoke protected method of other class
187      */
testE7()188     public void testE7() {
189         // @uses dxc.junit.opcodes.invokevirtual.jm.TSuper
190         // @uses dxc.junit.opcodes.invokevirtual.TProtected
191         try {
192             T_invokevirtual_20 t = new T_invokevirtual_20();
193             t.run(new TProtected());
194             fail("expected IllegalAccessError");
195         } catch (IllegalAccessError iae) {
196             // expected
197         } catch (VerifyError vfe) {
198             // ok for dalvikvm;
199             System.out.print("dvmvfe:");
200         }
201     }
202 
203     /**
204      * @title  method has different signature
205      */
testE8()206     public void testE8() {
207         // @uses dxc.junit.opcodes.invokevirtual.jm.TSuper
208         try {
209             T_invokevirtual_19 t = new T_invokevirtual_19();
210             t.run();
211             fail("expected NoSuchMethodError");
212         } catch (NoSuchMethodError iae) {
213             // expected
214         } catch (VerifyError vfe) {
215             // ok for dalvikvm;
216             System.out.print("dvmvfe:");
217         }
218     }
219 
220     /**
221      * @constraint 4.8.1.13
222      * @title valid index into constant pool table
223      */
testVFE1()224     public void testVFE1() {
225         try {
226             Class
227                     .forName("dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_8");
228             fail("expected a verification exception");
229         } catch (Throwable t) {
230             DxUtil.checkVerifyException(t);
231         }
232     }
233 
234     /**
235      * @constraint 4.8.1.13
236      * @title invalid index into constant pool table
237      */
testVFE2()238     public void testVFE2() {
239         try {
240             Class
241                     .forName("dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_9");
242             fail("expected a verification exception");
243         } catch (Throwable t) {
244             DxUtil.checkVerifyException(t);
245         }
246     }
247 
248     /**
249      * @constraint 4.8.1.14
250      * @title <clinit> may not be called using invokevirtual
251      */
testVFE3()252     public void testVFE3() {
253         try {
254             Class
255                     .forName("dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_10");
256             fail("expected a verification exception");
257         } catch (Throwable t) {
258             DxUtil.checkVerifyException(t);
259         }
260     }
261 
262     /**
263      * @constraint 4.8.2.1
264      * @title number of arguments passed to method
265      */
testVFE4()266     public void testVFE4() {
267         try {
268             Class
269                     .forName("dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_11");
270             fail("expected a verification exception");
271         } catch (Throwable t) {
272             DxUtil.checkVerifyException(t);
273         }
274     }
275 
276     /**
277      * @constraint 4.8.2.1
278      * @title type of argument - int
279      */
testVFE5()280     public void testVFE5() {
281         try {
282             Class
283                     .forName("dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_12");
284             fail("expected a verification exception");
285         } catch (Throwable t) {
286             DxUtil.checkVerifyException(t);
287         }
288     }
289 
290     /**
291      * @constraint 4.8.1.14
292      * @title <init> may not be called using invokevirtual
293      */
testVFE6()294     public void testVFE6() {
295         try {
296             Class
297                     .forName("dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_16");
298             fail("expected a verification exception");
299         } catch (Throwable t) {
300             DxUtil.checkVerifyException(t);
301         }
302     }
303 
304     /**
305      * @constraint 4.8.2.12
306      * @title types of arguments passed to method
307      */
testVFE7()308     public void testVFE7() {
309         // @uses dxc.junit.opcodes.invokevirtual.jm.TSuper
310         try {
311             Class
312                     .forName("dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_21");
313             fail("expected a verification exception");
314         } catch (Throwable t) {
315             DxUtil.checkVerifyException(t);
316         }
317     }
318 
319     /**
320      * @constraint 4.8.2.13
321      * @title assignment incompatible references when accessing
322      *                  protected method
323      */
testVFE8()324     public void testVFE8() {
325         // @uses dxc.junit.opcodes.invokevirtual.jm.TSuper
326         // @uses dxc.junit.opcodes.invokevirtual.jm.TPlain
327         try {
328             Class
329                     .forName("dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_22");
330             fail("expected a verification exception");
331         } catch (Throwable t) {
332             DxUtil.checkVerifyException(t);
333         }
334     }
335 
336     /**
337      * @constraint 4.8.2.13
338      * @title assignment incompatible references when accessing
339      *                  public method
340      */
testVFE9()341     public void testVFE9() {
342         // @uses dxc.junit.opcodes.invokevirtual.jm.TSuper
343         // @uses dxc.junit.opcodes.invokevirtual.jm.TSuper2
344         try {
345             Class
346                     .forName("dxc.junit.opcodes.invokevirtual.jm.T_invokevirtual_23");
347             fail("expected a verification exception");
348         } catch (Throwable t) {
349             DxUtil.checkVerifyException(t);
350         }
351     }
352 }
353