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.ITest
67         loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_3",
68                    NullPointerException.class);
69     }
70 
71     /**
72      * @title object doesn't implement interface
73      */
testE4()74     public void testE4() {
75         //@uses dot.junit.opcodes.invoke_interface.ITest
76         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
77         loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11",
78                    IncompatibleClassChangeError.class);
79     }
80 
81     /**
82      * @title dvmInterpFindInterfaceMethod failures were putting NULL Method*s
83      * in the interface cache, leading to a null pointer deference the second
84      * time you made the same bad call, with no exception thrown.
85      * See http://code.google.com/p/android/issues/detail?id=29358 for details.
86      */
testE4_2()87     public void testE4_2() {
88         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11
89         //@uses dot.junit.opcodes.invoke_interface.ITest
90         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
91         loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11",
92                    IncompatibleClassChangeError.class);
93         loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11",
94                    IncompatibleClassChangeError.class);
95     }
96 
97     /**
98      * @title Native method can't be linked
99      */
testE5()100     public void testE5() {
101         //@uses dot.junit.opcodes.invoke_interface.ITest
102         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
103         loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_12",
104                    UnsatisfiedLinkError.class, new ITestImpl());
105     }
106 
107     /**
108      * @title Attempt to invoke abstract method
109      */
testE6()110     public void testE6() {
111         //@uses dot.junit.opcodes.invoke_interface.ITest
112         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
113         //@uses dot.junit.opcodes.invoke_interface.ITestImplAbstract
114         loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_13",
115                    AbstractMethodError.class);
116     }
117 
118     /**
119      * @constraint A16
120      * @title invalid constant pool index
121      */
testVFE1()122     public void testVFE1() {
123         load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_2", VerifyError.class);
124     }
125 
126     /**
127      * @constraint A16
128      * @title The referenced method_id must belong to an interface (not a class).
129      */
testVFE2()130     public void testVFE2() {
131         loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_4",
132                    IncompatibleClassChangeError.class);
133     }
134 
135     /**
136      * @constraint B1
137      * @title number of arguments
138      */
testVFE5()139     public void testVFE5() {
140         //@uses dot.junit.opcodes.invoke_interface.ITest
141         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
142         load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_5", VerifyError.class);
143     }
144 
145     /**
146      * @constraint B1
147      * @title int is passed instead of objref
148      */
testVFE6()149     public void testVFE6() {
150         load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_10", VerifyError.class);
151     }
152 
153     /**
154      * @constraint B9
155      * @title number of arguments passed to method
156      */
testVFE9()157     public void testVFE9() {
158         load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_9", VerifyError.class);
159     }
160 
161     /**
162      * @constraint A15
163      * @title invoke-interface may not be used to call <init>.
164      */
testVFE10()165     public void testVFE10() {
166         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_18
167         load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_18", VerifyError.class);
168     }
169 
170     /**
171      * @constraint A15
172      * @title invoke-interface may not be used to call <clinit>.
173      */
testVFE11()174     public void testVFE11() {
175         //@uses dot.junit.opcodes.invoke_interface.ITest
176         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
177         load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_20", VerifyError.class);
178     }
179 
180     /**
181      * @constraint B9
182      * @title types of arguments passed to method
183      */
testVFE12()184     public void testVFE12() {
185         //@uses dot.junit.opcodes.invoke_interface.ITest
186         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
187         load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_21", VerifyError.class);
188     }
189 
190     /**
191      * @constraint A23
192      * @title number of registers
193      */
testVFE13()194     public void testVFE13() {
195         load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_8", VerifyError.class);
196     }
197 
198     /**
199      * @constraint n/a
200      * @title Attempt to call undefined method.
201      */
testVFE14()202     public void testVFE14() {
203         //@uses dot.junit.opcodes.invoke_interface.ITest
204         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
205         loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_7",
206                    NoSuchMethodError.class, new ITestImpl());
207     }
208 
209     /**
210      * @constraint n/a
211      * @title Method has different signature.
212      */
testVFE15()213     public void testVFE15() {
214         //@uses dot.junit.opcodes.invoke_interface.ITest
215         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
216         loadAndRun("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_16",
217                    NoSuchMethodError.class, new ITestImpl());
218     }
219 
220 
221     /**
222      * @constraint B6
223      * @title instance methods may only be invoked on already initialized instances.
224      */
testVFE21()225     public void testVFE21() {
226         //@uses dot.junit.opcodes.invoke_interface.ITest
227         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
228         load("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_22", VerifyError.class);
229     }
230 }
231