• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package dot.junit.opcodes.invoke_virtual;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_1;
22 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_10;
23 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_14;
24 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_15;
25 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_17;
26 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_18;
27 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_19;
28 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_20;
29 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_24;
30 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_4;
31 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_5;
32 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_6;
33 import dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_7;
34 
35 public class Test_invoke_virtual extends DxTestCase {
36 
37     /**
38      * @title invoke virtual method
39      */
testN1()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      */
testN3()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      */
testN5()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      */
testN6()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 invoke default interface method
83      */
testN7()84     public void testN7() {
85         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_28", null);
86     }
87 
88     /**
89      * @title expected NullPointerException
90      */
testE1()91     public void testE1() {
92         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_1",
93                    NullPointerException.class, null, "Test");
94     }
95 
96     /**
97      * @title Native method can't be linked
98      */
testE2()99     public void testE2() {
100         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_4",
101                    UnsatisfiedLinkError.class);
102     }
103 
104     /**
105      * @title Attempt to invoke abstract method
106      */
testE4()107     public void testE4() {
108         //@uses dot.junit.opcodes.invoke_virtual.ATest
109         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_6",
110                    AbstractMethodError.class);
111     }
112 
113     /**
114      * @title Attempt to invoke conflict method
115      */
testE5()116     public void testE5() {
117         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_26",
118                    IncompatibleClassChangeError.class);
119     }
120 
121     /**
122      * @title Attempt to invoke abstract method
123      */
testE6()124     public void testE6() {
125         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_27",
126                    AbstractMethodError.class);
127     }
128 
129 
130     /**
131      * @constraint A13
132      * @title invalid constant pool index
133      */
testVFE1()134     public void testVFE1() {
135         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_8", VerifyError.class);
136     }
137 
138     /**
139      * @constraint A15
140      * @title <clinit> may not be called using invoke-virtual
141      */
testVFE3()142     public void testVFE3() {
143         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_10", VerifyError.class);
144     }
145 
146     /**
147      * @constraint B1
148      * @title number of arguments passed to method
149      */
testVFE4()150     public void testVFE4() {
151         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_11", VerifyError.class);
152     }
153 
154     /**
155      * @constraint B9
156      * @title types of arguments passed to method
157      */
testVFE5()158     public void testVFE5() {
159         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_12", VerifyError.class);
160     }
161 
162     /**
163      * @constraint A15
164      * @title <init> may not be called using invoke_virtual
165      */
testVFE6()166     public void testVFE6() {
167         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_16", VerifyError.class);
168     }
169 
170     /**
171      * @constraint B10
172      * @title assignment incompatible references when accessing
173      *                  protected method
174      */
testVFE8()175     public void testVFE8() {
176         //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_22
177         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
178         //@uses dot.junit.opcodes.invoke_virtual.d.TPlain
179         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_22", VerifyError.class);
180     }
181 
182     /**
183      * @constraint B10
184      * @title assignment incompatible references when accessing
185      *                  public method
186      */
testVFE9()187     public void testVFE9() {
188         //@uses dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_23
189         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
190         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper2
191         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_23", VerifyError.class);
192     }
193 
194 
195     /**
196      * @constraint n/a
197      * @title Attempt to call static method.
198      */
testVFE10()199     public void testVFE10() {
200         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_5",
201                    IncompatibleClassChangeError.class);
202     }
203 
204 
205     /**
206      * @constraint n/a
207      * @title Attempt to invoke non-existing method.
208      */
testVFE12()209     public void testVFE12() {
210         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_15",
211                    NoSuchMethodError.class);
212     }
213 
214     /**
215      * @constraint n/a
216      * @title Attempt to invoke private method of other class.
217      */
testVFE13()218     public void testVFE13() {
219         //@uses dot.junit.opcodes.invoke_virtual.TestStubs
220         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_18",
221                    IllegalAccessError.class, new TestStubs());
222     }
223 
224     /**
225      * @constraint B12
226      * @title Attempt to invoke protected method of unrelated class.
227      */
testVFE14()228     public void testVFE14() {
229         //@uses dot.junit.opcodes.invoke_virtual.TestStubs
230         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_20",
231                    IllegalAccessError.class, new TestStubs());
232     }
233 
234     /**
235      * @constraint n/a
236      * @title Method has different signature.
237      */
testVFE15()238     public void testVFE15() {
239         //@uses dot.junit.opcodes.invoke_virtual.d.TSuper
240         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_19",
241                    NoSuchMethodError.class);
242     }
243 
244     /**
245      * @constraint n/a
246      * @title invoke-virtual shall be used to invoke private methods
247      */
testVFE16()248     public void testVFE16() {
249         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_13", VerifyError.class);
250     }
251 
252     /**
253      * @constraint A23
254      * @title number of registers
255      */
testVFE17()256     public void testVFE17() {
257         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_9", VerifyError.class);
258     }
259 
260     /**
261      * @constraint A13
262      * @title attempt to invoke interface method
263      */
testVFE18()264     public void testVFE18() {
265         loadAndRun("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_24",
266                    IncompatibleClassChangeError.class);
267     }
268 
269     /**
270      * @constraint B6
271      * @title instance methods may only be invoked on already initialized instances.
272      */
testVFE19()273     public void testVFE19() {
274         load("dot.junit.opcodes.invoke_virtual.d.T_invoke_virtual_25", VerifyError.class);
275     }
276 
277 }
278