blob: 6e41ec17e919cd79f343abfffa44442c8d70acc6 [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;
29import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_4;
30import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_5;
31import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_6;
32import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_7;
33
34public class Test_invoke_virtual extends DxTestCase {
35
36 /**
37 * @title invoke virtual method
38 */
39 public void testN1() {
40 T_invoke_virtual_1 t = new T_invoke_virtual_1();
41 int a = 1;
42 String sa = "a" + a;
43 String sb = "a1";
44 assertTrue(t.run(sa, sb));
45 assertFalse(t.run(t, sa));
46 assertFalse(t.run(sb, t));
47 }
48
49 /**
50 * @title Invoke protected method of superclass
51 */
52 public void testN3() {
53 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_7
54 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
55 T_invoke_virtual_7 t = new T_invoke_virtual_7();
56 assertEquals(5, t.run());
57 }
58
59 /**
60 * @title Check that new frame is created by invoke_virtual and
61 * arguments are passed to method
62 */
63 public void testN5() {
64 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_14
65 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
66 T_invoke_virtual_14 t = new T_invoke_virtual_14();
67 assertTrue(t.run());
68 }
69
70 /**
71 * @title Recursion of method lookup procedure
72 */
73 public void testN6() {
74 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_17
75 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
76 T_invoke_virtual_17 t = new T_invoke_virtual_17();
77 assertEquals(5, t.run());
78 }
79
80 /**
81 * @title expected NullPointerException
82 */
83 public void testE1() {
84 T_invoke_virtual_1 t = new T_invoke_virtual_1();
85 String s = "s";
86 try {
87 t.run(null, s);
88 fail("expected NullPointerException");
89 } catch (NullPointerException npe) {
90 // expected
91 }
92 }
93
94 /**
95 * @title Native method can't be linked
96 */
97 public void testE2() {
98 T_invoke_virtual_4 t = new T_invoke_virtual_4();
99 try {
100 t.run();
101 fail("expected UnsatisfiedLinkError");
102 } catch (UnsatisfiedLinkError ule) {
103 // expected
104 }
105 }
106
107 /**
108 * @title Attempt to invoke abstract method
109 */
110 public void testE4() {
111 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_6
112 //@uses dot.junit.opcodes.invoke_virtual.ATest
113 T_invoke_virtual_6 t = new T_invoke_virtual_6();
114 try {
115 t.run();
116 fail("expected AbstractMethodError");
117 } catch (AbstractMethodError iae) {
118 // expected
119 }
120 }
121
122 /**
123 * @constraint A13
124 * @title invalid constant pool index
125 */
126 public void testVFE1() {
127 try {
128 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_8");
129 fail("expected a verification exception");
130 } catch (Throwable t) {
131 DxUtil.checkVerifyException(t);
132 }
133 }
134
135 /**
136 * @constraint A15
137 * @title <clinit> may not be called using invoke-virtual
138 */
139 public void testVFE3() {
140 try {
141 new T_invoke_virtual_10().run();
142 fail("expected IncompatibleClassChangeError");
143 } catch (IncompatibleClassChangeError t) {
144 }
145 }
146
147 /**
148 * @constraint B1
149 * @title number of arguments passed to method
150 */
151 public void testVFE4() {
152 try {
153 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_11");
154 fail("expected a verification exception");
155 } catch (Throwable t) {
156 DxUtil.checkVerifyException(t);
157 }
158 }
159
160 /**
161 * @constraint B9
162 * @title types of arguments passed to method
163 */
164 public void testVFE5() {
165 try {
166 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_12");
167 fail("expected a verification exception");
168 } catch (Throwable t) {
169 DxUtil.checkVerifyException(t);
170 }
171 }
172
173 /**
174 * @constraint A15
175 * @title <init> may not be called using invoke_virtual
176 */
177 public void testVFE6() {
178 try {
179 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_16");
180 fail("expected a verification exception");
181 } catch (Throwable t) {
182 DxUtil.checkVerifyException(t);
183 }
184 }
185
186 /**
187 * @constraint B10
188 * @title assignment incompatible references when accessing
189 * protected method
190 */
191 public void testVFE8() {
192 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_22
193 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
194 //@uses dot.junit.opcodes.invoke_virtual.d.TPlain
195 try {
196 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_22");
197 fail("expected a verification exception");
198 } catch (Throwable t) {
199 DxUtil.checkVerifyException(t);
200 }
201 }
202
203 /**
204 * @constraint B10
205 * @title assignment incompatible references when accessing
206 * public method
207 */
208 public void testVFE9() {
209 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_23
210 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
211 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper2
212 try {
213 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_23");
214 fail("expected a verification exception");
215 } catch (Throwable t) {
216 DxUtil.checkVerifyException(t);
217 }
218 }
219
220
221 /**
222 * @constraint n/a
223 * @title Attempt to call static method.
224 */
225 public void testVFE10() {
226 try {
227 new T_invoke_virtual_5().run();
228 fail("expected IncompatibleClassChangeError");
229 } catch (IncompatibleClassChangeError t) {
230 }
231 }
232
233
234 /**
235 * @constraint n/a
236 * @title Attempt to invoke non-existing method.
237 */
238 public void testVFE12() {
239 try {
240 new T_invoke_virtual_15().run();
241 fail("expected NoSuchMethodError");
242 } catch (NoSuchMethodError t) {
243 }
244 }
245
246 /**
247 * @constraint n/a
248 * @title Attempt to invoke private method of other class.
249 */
250 public void testVFE13() {
251 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_18
252 //@uses dot.junit.opcodes.invoke_virtual.TestStubs
253 try {
254 new T_invoke_virtual_18().run(new TestStubs());
255 fail("expected IllegalAccessError");
256 } catch (IllegalAccessError t) {
257 }
258 }
259
260 /**
261 * @constraint B12
262 * @title Attempt to invoke protected method of unrelated class.
263 */
264 public void testVFE14() {
265 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_20
266 //@uses dot.junit.opcodes.invoke_virtual.TestStubs
267 try {
268 new T_invoke_virtual_20().run(new TestStubs());
269 fail("expected IllegalAccessError");
270 } catch (IllegalAccessError t) {
271 }
272 }
273
274 /**
275 * @constraint n/a
276 * @title Method has different signature.
277 */
278 public void testVFE15() {
279 //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_19
280 //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
281 try {
282 new T_invoke_virtual_19().run();
283 fail("expected NoSuchMethodError");
284 } catch (NoSuchMethodError t) {
285 }
286 }
287
288 /**
289 * @constraint n/a
290 * @title invoke-virtual shall be used to invoke private methods
291 */
292 public void testVFE16() {
293 try {
294 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_13");
295 fail("expected a verification exception");
296 } catch (Throwable t) {
297 DxUtil.checkVerifyException(t);
298 }
299 }
300
301 /**
302 * @constraint A23
303 * @title number of registers
304 */
305 public void testVFE17() {
306 try {
307 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_9");
308 fail("expected a verification exception");
309 } catch (Throwable t) {
310 DxUtil.checkVerifyException(t);
311 }
312 }
313
314 /**
315 * @constraint A13
316 * @title attempt to invoke interface method
317 */
318 public void testVFE18() {
319 try {
320 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_24");
321 fail("expected a verification exception");
322 } catch (Throwable t) {
323 DxUtil.checkVerifyException(t);
324 }
325 }
326
327 /**
328 * @constraint B6
329 * @title instance methods may only be invoked on already initialized instances.
330 */
331 public void testVFE19() {
332 try {
333 Class.forName("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_25");
334 fail("expected a verification exception");
335 } catch (Throwable t) {
336 DxUtil.checkVerifyException(t);
337 }
338 }
339
340}