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_virtual;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_1;
22 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_10;
23 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_14;
24 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_15;
25 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_17;
26 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_18;
27 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_19;
28 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_20;
29 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_24;
30 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_4;
31 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_5;
32 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_6;
33 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_7;
34 
35 public class Test_invoke_virtual extends DxTestCase {
36 
37     /**
38      * @title invoke virtual method
39      */
testN1()40     public void testN1() {
41         T_invoke_virtual_1 t = new T_invoke_virtual_1();
42         int a = 1;
43         String sa = "a" + a;
44         String sb = "a1";
45         assertTrue(t.run(sa, sb));
46         assertFalse(t.run(t, sa));
47         assertFalse(t.run(sb, t));
48     }
49 
50     /**
51      * @title Invoke protected method of superclass
52      */
testN3()53     public void testN3() {
54         //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_7
55         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
56         T_invoke_virtual_7 t = new T_invoke_virtual_7();
57         assertEquals(5, t.run());
58     }
59 
60     /**
61      * @title Check that new frame is created by invoke_virtual and
62      * arguments are passed to method
63      */
testN5()64     public void testN5() {
65         //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_14
66         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
67         T_invoke_virtual_14 t = new T_invoke_virtual_14();
68         assertTrue(t.run());
69     }
70 
71     /**
72      * @title Recursion of method lookup procedure
73      */
testN6()74     public void testN6() {
75         //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_17
76         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
77         T_invoke_virtual_17 t = new T_invoke_virtual_17();
78         assertEquals(5, t.run());
79     }
80 
81     /**
82      * @title expected NullPointerException
83      */
testE1()84     public void testE1() {
85         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_1",
86                    NullPointerException.class, null, "Test");
87     }
88 
89     /**
90      * @title Native method can't be linked
91      */
testE2()92     public void testE2() {
93         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_4",
94                    UnsatisfiedLinkError.class);
95     }
96 
97     /**
98      * @title Attempt to invoke abstract method
99      */
testE4()100     public void testE4() {
101         //@uses dot.junit.opcodes.invoke_virtual.ATest
102         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_6",
103                    AbstractMethodError.class);
104     }
105 
106     /**
107      * @constraint A13
108      * @title invalid constant pool index
109      */
testVFE1()110     public void testVFE1() {
111         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_8", VerifyError.class);
112     }
113 
114     /**
115      * @constraint A15
116      * @title <clinit> may not be called using invoke-virtual
117      */
testVFE3()118     public void testVFE3() {
119         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_10", VerifyError.class);
120     }
121 
122     /**
123      * @constraint B1
124      * @title number of arguments passed to method
125      */
testVFE4()126     public void testVFE4() {
127         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_11", VerifyError.class);
128     }
129 
130     /**
131      * @constraint B9
132      * @title types of arguments passed to method
133      */
testVFE5()134     public void testVFE5() {
135         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_12", VerifyError.class);
136     }
137 
138     /**
139      * @constraint A15
140      * @title <init> may not be called using invoke_virtual
141      */
testVFE6()142     public void testVFE6() {
143         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_16", VerifyError.class);
144     }
145 
146     /**
147      * @constraint B10
148      * @title assignment incompatible references when accessing
149      *                  protected method
150      */
testVFE8()151     public void testVFE8() {
152         //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_22
153         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
154         //@uses dot.junit.opcodes.invoke_virtual.d.TPlain
155         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_22", VerifyError.class);
156     }
157 
158     /**
159      * @constraint B10
160      * @title assignment incompatible references when accessing
161      *                  public method
162      */
testVFE9()163     public void testVFE9() {
164         //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_23
165         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
166         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper2
167         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_23", VerifyError.class);
168     }
169 
170 
171     /**
172      * @constraint n/a
173      * @title Attempt to call static method.
174      */
testVFE10()175     public void testVFE10() {
176         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_5",
177                    IncompatibleClassChangeError.class);
178     }
179 
180 
181     /**
182      * @constraint n/a
183      * @title Attempt to invoke non-existing method.
184      */
testVFE12()185     public void testVFE12() {
186         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_15",
187                    NoSuchMethodError.class);
188     }
189 
190     /**
191      * @constraint n/a
192      * @title Attempt to invoke private method of other class.
193      */
testVFE13()194     public void testVFE13() {
195         //@uses dot.junit.opcodes.invoke_virtual.TestStubs
196         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_18",
197                    IllegalAccessError.class, new TestStubs());
198     }
199 
200     /**
201      * @constraint B12
202      * @title Attempt to invoke protected method of unrelated class.
203      */
testVFE14()204     public void testVFE14() {
205         //@uses dot.junit.opcodes.invoke_virtual.TestStubs
206         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_20",
207                    IllegalAccessError.class, new TestStubs());
208     }
209 
210     /**
211      * @constraint n/a
212      * @title Method has different signature.
213      */
testVFE15()214     public void testVFE15() {
215         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
216         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_19",
217                    NoSuchMethodError.class);
218     }
219 
220     /**
221      * @constraint n/a
222      * @title invoke-virtual shall be used to invoke private methods
223      */
testVFE16()224     public void testVFE16() {
225         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_13", VerifyError.class);
226     }
227 
228     /**
229      * @constraint A23
230      * @title number of registers
231      */
testVFE17()232     public void testVFE17() {
233         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_9", VerifyError.class);
234     }
235 
236     /**
237      * @constraint A13
238      * @title attempt to invoke interface method
239      */
testVFE18()240     public void testVFE18() {
241         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_24",
242                    IncompatibleClassChangeError.class);
243     }
244 
245     /**
246      * @constraint B6
247      * @title instance methods may only be invoked on already initialized instances.
248      */
testVFE19()249     public void testVFE19() {
250         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_25", VerifyError.class);
251     }
252 
253 }
254