• 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_interface;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_1;
22 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11;
23 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_12;
24 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_13;
25 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_14;
26 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_16;
27 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_18;
28 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_20;
29 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_21;
30 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_3;
31 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_4;
32 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_5;
33 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_7;
34 
35 public class Test_invoke_interface extends DxTestCase {
36 
37     /**
38      * @title invoke interface method
39      */
testN1()40     public void testN1() {
41         T_invoke_interface_1 t = new T_invoke_interface_1();
42         assertEquals(0, t.run("aa", "aa"));
43         assertEquals(-1, t.run("aa", "bb"));
44         assertEquals(1, t.run("bb", "aa"));
45     }
46 
47     /**
48      * @title Check that new frame is created by invoke_interface and
49      * arguments are passed to method
50      */
testN2()51     public void testN2() {
52         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_14
53         //@uses dot.junit.opcodes.invoke_interface.ITest
54         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
55         T_invoke_interface_14 t = new T_invoke_interface_14();
56         ITestImpl impl = new ITestImpl();
57         assertEquals(1, t.run(impl));
58     }
59 
60 
61 
62     /**
63      * @title objref is null
64      */
testE3()65     public void testE3() {
66         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_3
67         //@uses dot.junit.opcodes.invoke_interface.ITest
68         try {
69             new T_invoke_interface_3(null);
70             fail("expected NullPointerException");
71         } catch (NullPointerException npe) {
72             // expected
73         }
74     }
75 
76     /**
77      * @title object doesn't implement interface
78      */
testE4()79     public void testE4() {
80         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11
81         //@uses dot.junit.opcodes.invoke_interface.ITest
82         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
83         T_invoke_interface_11 t = new T_invoke_interface_11();
84         try {
85             t.run();
86             fail("expected IncompatibleClassChangeError");
87         } catch (IncompatibleClassChangeError e) {
88             // expected
89         }
90     }
91 
92     /**
93      * @title Native method can't be linked
94      */
testE5()95     public void testE5() {
96         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_12
97         //@uses dot.junit.opcodes.invoke_interface.ITest
98         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
99         T_invoke_interface_12 t = new T_invoke_interface_12();
100         ITestImpl impl = new ITestImpl();
101         try {
102             t.run(impl);
103             fail("expected UnsatisfiedLinkError");
104         } catch (UnsatisfiedLinkError e) {
105             // expected
106         }
107     }
108 
109     /**
110      * @title Attempt to invoke abstract method
111      */
testE6()112     public void testE6() {
113         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_13
114         //@uses dot.junit.opcodes.invoke_interface.ITest
115         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
116         //@uses dot.junit.opcodes.invoke_interface.ITestImplAbstract
117         T_invoke_interface_13 t = new T_invoke_interface_13();
118         try {
119             t.run();
120             fail("expected AbstractMethodError");
121         } catch (AbstractMethodError e) {
122             // expected
123         }
124     }
125 
126     /**
127      * @constraint A16
128      * @title invalid constant pool index
129      */
testVFE1()130     public void testVFE1() {
131         try {
132             Class.forName("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_2");
133             fail("expected a verification exception");
134         } catch (Throwable t) {
135             DxUtil.checkVerifyException(t);
136         }
137     }
138 
139     /**
140      * @constraint A16
141      * @title The referenced method_id must belong to an interface (not a class).
142      */
testVFE2()143     public void testVFE2() {
144         try {
145             new T_invoke_interface_4().run();
146             fail("expected NoSuchMethodError");
147         } catch (NoSuchMethodError t) {
148         }
149     }
150 
151     /**
152      * @constraint B1
153      * @title number of arguments
154      */
testVFE5()155     public void testVFE5() {
156         //@uses dot.junit.opcodes.invoke_interface.ITest
157         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
158         try {
159             new T_invoke_interface_5(new ITestImpl());
160             fail("expected VerifyError");
161         } catch (VerifyError t) {
162         }
163     }
164 
165     /**
166      * @constraint B1
167      * @title int is passed instead of objref
168      */
testVFE6()169     public void testVFE6() {
170         try {
171             Class.forName("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_10");
172             fail("expected a verification exception");
173         } catch (Throwable t) {
174             DxUtil.checkVerifyException(t);
175         }
176     }
177 
178     /**
179      * @constraint B9
180      * @title number of arguments passed to method
181      */
testVFE9()182     public void testVFE9() {
183         try {
184             Class.forName("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_9");
185             fail("expected a verification exception");
186         } catch (Throwable t) {
187             DxUtil.checkVerifyException(t);
188         }
189     }
190 
191     /**
192      * @constraint A15
193      * @title invoke-interface may not be used to call <init>.
194      */
testVFE10()195     public void testVFE10() {
196         //@uses dot.junit.opcodes.invoke_interface.ITest
197         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
198         //@uses dot.junit.opcodes.invoke_interface.ITestImplAbstract
199         try {
200             new T_invoke_interface_18().run(new ITestImpl());
201             fail("expected InstantiationError");
202         } catch (InstantiationError t) {
203         }
204     }
205 
206     /**
207      * @constraint A15
208      * @title invoke-interface may not be used to call <clinit>.
209      */
testVFE11()210     public void testVFE11() {
211         //@uses dot.junit.opcodes.invoke_interface.ITest
212         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
213         try {
214             new T_invoke_interface_20().run(new ITestImpl());
215             fail("expected NoSuchMethodError");
216         } catch (NoSuchMethodError t) {
217         }
218     }
219 
220     /**
221      * @constraint B9
222      * @title types of arguments passed to method
223      */
testVFE12()224     public void testVFE12() {
225         //@uses dot.junit.opcodes.invoke_interface.ITest
226         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
227         try {
228             new T_invoke_interface_21().run(new ITestImpl());
229             fail("expected VerifyError");
230         } catch (VerifyError t) {
231         }
232     }
233 
234     /**
235      * @constraint A23
236      * @title number of registers
237      */
testVFE13()238     public void testVFE13() {
239         try {
240             Class.forName("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_8");
241             fail("expected a verification exception");
242         } catch (Throwable t) {
243             DxUtil.checkVerifyException(t);
244         }
245     }
246 
247     /**
248      * @constraint n/a
249      * @title Attempt to call undefined method.
250      */
testVFE14()251     public void testVFE14() {
252         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_7
253         //@uses dot.junit.opcodes.invoke_interface.ITest
254         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
255         try {
256             new T_invoke_interface_7().run(new ITestImpl());
257             fail("expected NoSuchMethodError");
258         } catch (NoSuchMethodError t) {
259         }
260     }
261 
262     /**
263      * @constraint n/a
264      * @title Method has different signature.
265      */
testVFE15()266     public void testVFE15() {
267         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_16
268         //@uses dot.junit.opcodes.invoke_interface.ITest
269         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
270         try {
271             new T_invoke_interface_16().run(new ITestImpl());
272             fail("expected NoSuchMethodError");
273         } catch (NoSuchMethodError t) {
274         }
275     }
276 
277 
278     /**
279      * @constraint B6
280      * @title instance methods may only be invoked on already initialized instances.
281      */
testVFE21()282     public void testVFE21() {
283         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_22
284         //@uses dot.junit.opcodes.invoke_interface.ITest
285         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
286         try {
287             Class.forName("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_22");
288             fail("expected a verification exception");
289         } catch (Throwable t) {
290             DxUtil.checkVerifyException(t);
291         }
292     }
293 }
294