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