blob: 02793fd2fd9d453db1a908e6cfc9be1684e162d0 [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_static;
18
19import dot.junit.DxTestCase;
20import dot.junit.DxUtil;
21import dot.junit.opcodes.invoke_static.d.T_invoke_static_1;
22import dot.junit.opcodes.invoke_static.d.T_invoke_static_13;
23import dot.junit.opcodes.invoke_static.d.T_invoke_static_14;
24import dot.junit.opcodes.invoke_static.d.T_invoke_static_15;
25import dot.junit.opcodes.invoke_static.d.T_invoke_static_17;
26import dot.junit.opcodes.invoke_static.d.T_invoke_static_18;
27import dot.junit.opcodes.invoke_static.d.T_invoke_static_19;
28import dot.junit.opcodes.invoke_static.d.T_invoke_static_2;
Jeff Hao5d7cb162013-08-02 16:59:44 -070029import dot.junit.opcodes.invoke_static.d.T_invoke_static_24;
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -070030import dot.junit.opcodes.invoke_static.d.T_invoke_static_4;
31import dot.junit.opcodes.invoke_static.d.T_invoke_static_5;
32import dot.junit.opcodes.invoke_static.d.T_invoke_static_6;
33import dot.junit.opcodes.invoke_static.d.T_invoke_static_7;
34import dot.junit.opcodes.invoke_static.d.T_invoke_static_8;
35
36
37
38public class Test_invoke_static extends DxTestCase {
39
40 /**
41 * @title Static method from library class Math
42 */
43 public void testN1() {
44 T_invoke_static_1 t = new T_invoke_static_1();
45 assertEquals(1234567, t.run());
46 }
47
48 /**
49 * @title Static method from user class
50 */
51 public void testN2() {
52 //@uses dot.junit.opcodes.invoke_static.d.T_invoke_static_2
53 //@uses dot.junit.opcodes.invoke_static.TestClass
54 T_invoke_static_2 t = new T_invoke_static_2();
55 assertEquals(777, t.run());
56 }
57
58 /**
59 * @title Check that <clinit> is called
60 */
61 public void testN3() {
62 assertEquals(123456789l, T_invoke_static_4.run());
63 }
64
65
66 /**
67 * @title Check that new frame is created by invoke_static and
68 * arguments are passed to method
69 */
70 public void testN5() {
71 //@uses dot.junit.opcodes.invoke_static.d.T_invoke_static_15
72 //@uses dot.junit.opcodes.invoke_static.TestClass
73 T_invoke_static_15 t = new T_invoke_static_15();
74 assertTrue(t.run());
75 }
76
77 /**
78 * @title Static protected method from other class in the same package
79 */
80 public void testN6() {
81 T_invoke_static_18 t = new T_invoke_static_18();
82 assertEquals(888, t.run());
83 }
84
85 /**
86 * @title Native method can't be linked
87 *
88 */
89 public void testE2() {
90 T_invoke_static_6 t = new T_invoke_static_6();
91 try {
92 t.run();
93 fail("expected UnsatisfiedLinkError");
94 } catch (UnsatisfiedLinkError ule) {
95 // expected
96 }
97 }
98
99
100 /**
101 * @title initialization of referenced class throws exception
102 */
103 public void testE7() {
104 T_invoke_static_14 t = new T_invoke_static_14();
105 try {
106 t.run();
107 fail("expected Error");
108 } catch (Error e) {
109 // expected
110 }
111 }
112
113
114 /**
115 * @constraint A13
116 * @title invalid constant pool index
117 */
118 public void testVFE1() {
119 try {
120 Class.forName("dot.junit.opcodes.invoke_static.d.T_invoke_static_3");
121 fail("expected a verification exception");
122 } catch (Throwable t) {
123 DxUtil.checkVerifyException(t);
124 }
125 }
126
127 /**
128 * @constraint A15
129 * @title &lt;clinit&gt; may not be called using invoke-static
130 */
131 public void testVFE3() {
132 try {
133 Class.forName("dot.junit.opcodes.invoke_static.d.T_invoke_static_10");
134 fail("expected a verification exception");
135 } catch (Throwable t) {
136 DxUtil.checkVerifyException(t);
137 }
138 }
139
140 /**
141 * @constraint B1
142 * @title number of arguments passed to method.
143 */
144 public void testVFE4() {
145 try {
146 Class.forName("dot.junit.opcodes.invoke_static.d.T_invoke_static_11");
147 fail("expected a verification exception");
148 } catch (Throwable t) {
149 DxUtil.checkVerifyException(t);
150 }
151 }
152
153 /**
154 * @constraint A15
155 * @title &lt;init&gt; may not be called using invoke_static
156 */
157 public void testVFE5() {
158 try {
159 new T_invoke_static_19().run();
Jeff Hao5d7cb162013-08-02 16:59:44 -0700160 fail("expected a verification exception");
161 } catch (Throwable t) {
162 DxUtil.checkVerifyException(t);
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700163 }
164 }
165
166 /**
167 * @constraint B9
168 * @title types of arguments passed to method
169 */
170 public void testVFE6() {
171 try {
172 Class.forName("dot.junit.opcodes.invoke_static.d.T_invoke_static_20");
173 fail("expected a verification exception");
174 } catch (Throwable t) {
175 DxUtil.checkVerifyException(t);
176 }
177 }
178
179
180 /**
181 * @constraint n/a
182 * @title Attempt to call non-static method.
183 */
184 public void testVFE7() {
185 try {
186 new T_invoke_static_5().run();
187 fail("expected IncompatibleClassChangeError");
188 } catch (IncompatibleClassChangeError t) {
189 }
190 }
191
192 /**
193 * @constraint n/a
194 * @title Attempt to call undefined method.
195 */
196 public void testVFE8() {
197 try {
198 new T_invoke_static_7().run();
199 fail("expected NoSuchMethodError");
200 } catch (NoSuchMethodError t) {
201 }
202 }
203
204 /**
205 * @constraint n/a
206 * @title Attempt to call private method of other class.
207 */
208 public void testVFE9() {
209 //@uses dot.junit.opcodes.invoke_static.d.T_invoke_static_8
210 //@uses dot.junit.opcodes.invoke_static.TestClass
211 try {
212 new T_invoke_static_8().run();
213 fail("expected IllegalAccessError");
214 } catch (IllegalAccessError t) {
215 }
216 }
217
218 /**
219 * @constraint n/a
220 * @title Method has different signature.
221 */
222 public void testVFE10() {
223 //@uses dot.junit.opcodes.invoke_static.d.T_invoke_static_13
224 //@uses dot.junit.opcodes.invoke_static.TestClass
225 try {
226 new T_invoke_static_13().run();
227 fail("expected NoSuchMethodError");
228 } catch (NoSuchMethodError t) {
229 }
230 }
231
232
233 /**
234 * @constraint B12
235 * @title Attempt to call protected method of unrelated class.
236 */
237 public void testVFE12() {
238 //@uses dot.junit.opcodes.invoke_static.d.T_invoke_static_17
239 //@uses dot.junit.opcodes.invoke_static.TestClass
240 try {
241 new T_invoke_static_17().run();
242 fail("expected IllegalAccessError");
243 } catch (IllegalAccessError t) {
244 }
245 }
246
247 /**
248 * @constraint A23
249 * @title number of registers
250 */
251 public void testVFE13() {
252 try {
253 Class.forName("dot.junit.opcodes.invoke_static.d.T_invoke_static_16");
254 fail("expected a verification exception");
255 } catch (Throwable t) {
256 DxUtil.checkVerifyException(t);
257 }
258 }
259
260 /**
261 * @constraint A13
262 * @title attempt to invoke interface method
263 */
264 public void testVFE18() {
Jeff Hao5d7cb162013-08-02 16:59:44 -0700265 //@uses dot.junit.opcodes.invoke_static.d.T_invoke_static_24
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700266 try {
Jeff Hao5d7cb162013-08-02 16:59:44 -0700267 new T_invoke_static_24().run();
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700268 fail("expected a verification exception");
269 } catch (Throwable t) {
270 DxUtil.checkVerifyException(t);
271 }
272 }
273}