blob: b1602b692ed959c8b2090f2c25394d481f0ca1e4 [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_super;
18
19import dot.junit.DxTestCase;
20import dot.junit.DxUtil;
21import dot.junit.opcodes.invoke_super.d.T_invoke_super_1;
22import dot.junit.opcodes.invoke_super.d.T_invoke_super_10;
23import dot.junit.opcodes.invoke_super.d.T_invoke_super_14;
24import dot.junit.opcodes.invoke_super.d.T_invoke_super_15;
25import dot.junit.opcodes.invoke_super.d.T_invoke_super_17;
26import dot.junit.opcodes.invoke_super.d.T_invoke_super_18;
27import dot.junit.opcodes.invoke_super.d.T_invoke_super_19;
28import dot.junit.opcodes.invoke_super.d.T_invoke_super_2;
29import dot.junit.opcodes.invoke_super.d.T_invoke_super_20;
Jeff Hao5d7cb162013-08-02 16:59:44 -070030import dot.junit.opcodes.invoke_super.d.T_invoke_super_24;
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -070031import dot.junit.opcodes.invoke_super.d.T_invoke_super_4;
32import dot.junit.opcodes.invoke_super.d.T_invoke_super_5;
33import dot.junit.opcodes.invoke_super.d.T_invoke_super_6;
34import dot.junit.opcodes.invoke_super.d.T_invoke_super_7;
35
36public class Test_invoke_super extends DxTestCase {
37
38 /**
39 * @title invoke method of superclass
40 */
41 public void testN1() {
42 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_1
43 //@uses dot.junit.opcodes.invoke_super.d.TSuper
44 T_invoke_super_1 t = new T_invoke_super_1();
45 assertEquals(5, t.run());
46 }
47
48
49 /**
50 * @title Invoke protected method of superclass
51 */
52 public void testN3() {
53 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_7
54 //@uses dot.junit.opcodes.invoke_super.d.TSuper
55 T_invoke_super_7 t = new T_invoke_super_7();
56 assertEquals(5, t.run());
57 }
58
59 /**
60 * @title Check that new frame is created by invoke_super and
61 * arguments are passed to method
62 */
63 public void testN5() {
64 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_14
65 //@uses dot.junit.opcodes.invoke_super.d.TSuper
66 T_invoke_super_14 t = new T_invoke_super_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_super.d.T_invoke_super_17
75 //@uses dot.junit.opcodes.invoke_super.d.TSuper
76 //@uses dot.junit.opcodes.invoke_super.d.TSuper2
77 T_invoke_super_17 t = new T_invoke_super_17();
78 assertEquals(5, t.run());
79 }
80
81 /**
82 * @title obj ref is null
83 */
84 public void testE1() {
85 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_1
86 //@uses dot.junit.opcodes.invoke_super.d.TSuper
87 T_invoke_super_2 t = new T_invoke_super_2();
88 try {
89 t.run();
90 fail("expected NullPointerException");
91 } catch (NullPointerException npe) {
92 // expected
93 }
94 }
95
96 /**
97 * @title Native method can't be linked
98 */
99 public void testE2() {
100 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_4
101 //@uses dot.junit.opcodes.invoke_super.d.TSuper
102 T_invoke_super_4 t = new T_invoke_super_4();
103 try {
104 t.run();
105 fail("expected UnsatisfiedLinkError");
106 } catch (UnsatisfiedLinkError ule) {
107 // expected
108 }
109 }
110
111 /**
112 * @title Attempt to invoke abstract method
113 */
114 public void testE4() {
115 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_6
116 //@uses dot.junit.opcodes.invoke_super.ATest
117 T_invoke_super_6 t = new T_invoke_super_6();
118 try {
119 t.run();
120 fail("expected AbstractMethodError");
121 } catch (AbstractMethodError iae) {
122 // expected
123 }
124 }
125
126 /**
127 * @constraint A13
128 * @title invalid constant pool index
129 */
130 public void testVFE1() {
131 try {
132 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_8");
133 fail("expected a verification exception");
134 } catch (Throwable t) {
135 DxUtil.checkVerifyException(t);
136 }
137 }
138
139 /**
140 * @constraint A15
141 * @title <clinit> may not be called using invoke-super
142 */
143 public void testVFE3() {
144 try {
145 new T_invoke_super_10().run();
Jeff Hao5d7cb162013-08-02 16:59:44 -0700146 fail("expected a verification exception");
147 } catch (Throwable t) {
148 DxUtil.checkVerifyException(t);
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700149 }
150 }
151
152 /**
153 * @constraint B1
154 * @title number of arguments passed to method
155 */
156 public void testVFE4() {
157 try {
158 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_11");
159 fail("expected a verification exception");
160 } catch (Throwable t) {
161 DxUtil.checkVerifyException(t);
162 }
163 }
164
165 /**
166 * @constraint B9
167 * @title types of arguments passed to method.
168 */
169 public void testVFE5() {
170 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_12
171 //@uses dot.junit.opcodes.invoke_super.d.TSuper
172 try {
173 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_12");
174 fail("expected a verification exception");
175 } catch (Throwable t) {
176 DxUtil.checkVerifyException(t);
177 }
178 }
179
180 /**
181 * @constraint A15
182 * @title <init> may not be called using invoke_super
183 */
184 public void testVFE6() {
185 try {
186 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_16");
187 fail("expected a verification exception");
188 } catch (Throwable t) {
189 DxUtil.checkVerifyException(t);
190 }
191 }
192
193 /**
194 * @constraint B10
195 * @title assignment incompatible references when accessing
196 * protected method
197 */
198 public void testVFE8() {
199 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_22
200 //@uses dot.junit.opcodes.invoke_super.d.TSuper
201 //@uses dot.junit.opcodes.invoke_super.d.TPlain
202 try {
203 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_22");
204 fail("expected a verification exception");
205 } catch (Throwable t) {
206 DxUtil.checkVerifyException(t);
207 }
208 }
209
210 /**
211 * @constraint B10
212 * @title assignment incompatible references when accessing
213 * public method
214 */
215 public void testVFE9() {
216 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_23
217 //@uses dot.junit.opcodes.invoke_super.d.TSuper
218 //@uses dot.junit.opcodes.invoke_super.d.TSuper2
219 try {
220 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_23");
221 fail("expected a verification exception");
222 } catch (Throwable t) {
223 DxUtil.checkVerifyException(t);
224 }
225 }
226
227 /**
228 * @constraint n/a
229 * @title Attempt to call static method.
230 */
231 public void testVFE10() {
232 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_5
233 //@uses dot.junit.opcodes.invoke_super.d.TSuper
234 try {
235 new T_invoke_super_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_super_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_super.d.T_invoke_super_18
260 //@uses dot.junit.opcodes.invoke_super.TestStubs
261 try {
262 new T_invoke_super_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_super.d.T_invoke_super_20
274 //@uses dot.junit.opcodes.invoke_super.TestStubs
275 try {
276 new T_invoke_super_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_super.d.T_invoke_super_19
288 //@uses dot.junit.opcodes.invoke_super.d.TSuper
289 try {
290 new T_invoke_super_19().run();
291 fail("expected NoSuchMethodError");
292 } catch (NoSuchMethodError t) {
293 }
294 }
295
296 /**
297 * @constraint n/a
298 * @title invoke-super shall be used to invoke private methods
299 */
300 public void testVFE16() {
301 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_13
302 //@uses dot.junit.opcodes.invoke_super.d.TSuper
303 try {
304 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_13");
305 fail("expected a verification exception");
306 } catch (Throwable t) {
307 DxUtil.checkVerifyException(t);
308 }
309 }
310
311 /**
312 * @constraint A23
313 * @title number of registers
314 */
315 public void testVFE17() {
316 try {
317 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_9");
318 fail("expected a verification exception");
319 } catch (Throwable t) {
320 DxUtil.checkVerifyException(t);
321 }
322 }
323
324 /**
325 * @constraint A13
326 * @title attempt to invoke interface method
327 */
328 public void testVFE18() {
Jeff Hao5d7cb162013-08-02 16:59:44 -0700329 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_24
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700330 try {
Jeff Hao5d7cb162013-08-02 16:59:44 -0700331 new T_invoke_super_24().run();
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700332 fail("expected a verification exception");
333 } catch (Throwable t) {
334 DxUtil.checkVerifyException(t);
335 }
336 }
337
338 /**
339 * @constraint B6
340 * @title instance methods may only be invoked on already initialized instances.
341 */
342 public void testVFE19() {
343 //@uses dot.junit.opcodes.invoke_super.d.T_invoke_super_25
344 //@uses dot.junit.opcodes.invoke_super.d.TSuper
345 try {
346 Class.forName("dot.junit.opcodes.invoke_super.d.T_invoke_super_25");
347 fail("expected a verification exception");
348 } catch (Throwable t) {
349 DxUtil.checkVerifyException(t);
350 }
351 }
352}