blob: 03f2bb65ff36995a4675276ee1eb561f4eb9030d [file] [log] [blame]
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -07001/*
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
17package dot.junit.opcodes.invoke_virtual;
18
19import dot.junit.DxTestCase;
20import dot.junit.DxUtil;
21import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_1;
22import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_10;
23import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_14;
24import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_15;
25import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_17;
26import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_18;
27import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_19;
28import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_20;
Jeff Hao5d7cb162013-08-02 16:59:44 -070029import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_24;
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -070030import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_4;
31import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_5;
32import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_6;
33import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_7;
34
35public class Test_invoke_virtual extends DxTestCase {
36
37 /**
38 * @title invoke virtual method
39 */
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 */
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 */
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 */
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 */
84 public void testE1() {
85 T_invoke_virtual_1 t = new T_invoke_virtual_1();
86 String s = "s";
87 try {
88 t.run(null, s);
89 fail("expected NullPointerException");
90 } catch (NullPointerException npe) {
91 // expected
92 }
93 }
94
95 /**
96 * @title Native method can't be linked
97 */
98 public void testE2() {
99 T_invoke_virtual_4 t = new T_invoke_virtual_4();
100 try {
101 t.run();
102 fail("expected UnsatisfiedLinkError");
103 } catch (UnsatisfiedLinkError ule) {
104 // expected
105 }
106 }
107
108 /**
109 * @title Attempt to invoke abstract method
110 */
111 public void testE4() {
112 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_6
113 //@uses dot.junit.opcodes.invoke_virtual.ATest
114 T_invoke_virtual_6 t = new T_invoke_virtual_6();
115 try {
116 t.run();
117 fail("expected AbstractMethodError");
118 } catch (AbstractMethodError iae) {
119 // expected
120 }
121 }
122
123 /**
124 * @constraint A13
125 * @title invalid constant pool index
126 */
127 public void testVFE1() {
128 try {
129 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_8");
130 fail("expected a verification exception");
131 } catch (Throwable t) {
132 DxUtil.checkVerifyException(t);
133 }
134 }
135
136 /**
137 * @constraint A15
138 * @title <clinit> may not be called using invoke-virtual
139 */
140 public void testVFE3() {
141 try {
142 new T_invoke_virtual_10().run();
Jeff Hao5d7cb162013-08-02 16:59:44 -0700143 fail("expected a verification exception");
144 } catch (Throwable t) {
145 DxUtil.checkVerifyException(t);
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700146 }
147 }
148
149 /**
150 * @constraint B1
151 * @title number of arguments passed to method
152 */
153 public void testVFE4() {
154 try {
155 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_11");
156 fail("expected a verification exception");
157 } catch (Throwable t) {
158 DxUtil.checkVerifyException(t);
159 }
160 }
161
162 /**
163 * @constraint B9
164 * @title types of arguments passed to method
165 */
166 public void testVFE5() {
167 try {
168 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_12");
169 fail("expected a verification exception");
170 } catch (Throwable t) {
171 DxUtil.checkVerifyException(t);
172 }
173 }
174
175 /**
176 * @constraint A15
177 * @title <init> may not be called using invoke_virtual
178 */
179 public void testVFE6() {
180 try {
181 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_16");
182 fail("expected a verification exception");
183 } catch (Throwable t) {
184 DxUtil.checkVerifyException(t);
185 }
186 }
187
188 /**
189 * @constraint B10
190 * @title assignment incompatible references when accessing
191 * protected method
192 */
193 public void testVFE8() {
194 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_22
195 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
196 //@uses dot.junit.opcodes.invoke_virtual.d.TPlain
197 try {
198 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_22");
199 fail("expected a verification exception");
200 } catch (Throwable t) {
201 DxUtil.checkVerifyException(t);
202 }
203 }
204
205 /**
206 * @constraint B10
207 * @title assignment incompatible references when accessing
208 * public method
209 */
210 public void testVFE9() {
211 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_23
212 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
213 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper2
214 try {
215 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_23");
216 fail("expected a verification exception");
217 } catch (Throwable t) {
218 DxUtil.checkVerifyException(t);
219 }
220 }
221
222
223 /**
224 * @constraint n/a
225 * @title Attempt to call static method.
226 */
227 public void testVFE10() {
228 try {
229 new T_invoke_virtual_5().run();
230 fail("expected IncompatibleClassChangeError");
231 } catch (IncompatibleClassChangeError t) {
232 }
233 }
234
235
236 /**
237 * @constraint n/a
238 * @title Attempt to invoke non-existing method.
239 */
240 public void testVFE12() {
241 try {
242 new T_invoke_virtual_15().run();
243 fail("expected NoSuchMethodError");
244 } catch (NoSuchMethodError t) {
245 }
246 }
247
248 /**
249 * @constraint n/a
250 * @title Attempt to invoke private method of other class.
251 */
252 public void testVFE13() {
253 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_18
254 //@uses dot.junit.opcodes.invoke_virtual.TestStubs
255 try {
256 new T_invoke_virtual_18().run(new TestStubs());
257 fail("expected IllegalAccessError");
258 } catch (IllegalAccessError t) {
259 }
260 }
261
262 /**
263 * @constraint B12
264 * @title Attempt to invoke protected method of unrelated class.
265 */
266 public void testVFE14() {
267 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_20
268 //@uses dot.junit.opcodes.invoke_virtual.TestStubs
269 try {
270 new T_invoke_virtual_20().run(new TestStubs());
271 fail("expected IllegalAccessError");
272 } catch (IllegalAccessError t) {
273 }
274 }
275
276 /**
277 * @constraint n/a
278 * @title Method has different signature.
279 */
280 public void testVFE15() {
281 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_19
282 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
283 try {
284 new T_invoke_virtual_19().run();
285 fail("expected NoSuchMethodError");
286 } catch (NoSuchMethodError t) {
287 }
288 }
289
290 /**
291 * @constraint n/a
292 * @title invoke-virtual shall be used to invoke private methods
293 */
294 public void testVFE16() {
295 try {
296 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_13");
297 fail("expected a verification exception");
298 } catch (Throwable t) {
299 DxUtil.checkVerifyException(t);
300 }
301 }
302
303 /**
304 * @constraint A23
305 * @title number of registers
306 */
307 public void testVFE17() {
308 try {
309 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_9");
310 fail("expected a verification exception");
311 } catch (Throwable t) {
312 DxUtil.checkVerifyException(t);
313 }
314 }
315
316 /**
317 * @constraint A13
318 * @title attempt to invoke interface method
319 */
320 public void testVFE18() {
Jeff Hao5d7cb162013-08-02 16:59:44 -0700321 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_24
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700322 try {
Jeff Hao5d7cb162013-08-02 16:59:44 -0700323 new T_invoke_virtual_24().run();
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700324 fail("expected a verification exception");
325 } catch (Throwable t) {
326 DxUtil.checkVerifyException(t);
327 }
328 }
329
330 /**
331 * @constraint B6
332 * @title instance methods may only be invoked on already initialized instances.
333 */
334 public void testVFE19() {
335 try {
336 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_25");
337 fail("expected a verification exception");
338 } catch (Throwable t) {
339 DxUtil.checkVerifyException(t);
340 }
341 }
342
343}