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_static;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.invoke_static.d.T_invoke_static_1;
22 import dot.junit.opcodes.invoke_static.d.T_invoke_static_13;
23 import dot.junit.opcodes.invoke_static.d.T_invoke_static_14;
24 import dot.junit.opcodes.invoke_static.d.T_invoke_static_15;
25 import dot.junit.opcodes.invoke_static.d.T_invoke_static_17;
26 import dot.junit.opcodes.invoke_static.d.T_invoke_static_18;
27 import dot.junit.opcodes.invoke_static.d.T_invoke_static_19;
28 import dot.junit.opcodes.invoke_static.d.T_invoke_static_2;
29 import dot.junit.opcodes.invoke_static.d.T_invoke_static_24;
30 import dot.junit.opcodes.invoke_static.d.T_invoke_static_4;
31 import dot.junit.opcodes.invoke_static.d.T_invoke_static_5;
32 import dot.junit.opcodes.invoke_static.d.T_invoke_static_6;
33 import dot.junit.opcodes.invoke_static.d.T_invoke_static_7;
34 import dot.junit.opcodes.invoke_static.d.T_invoke_static_8;
35 
36 
37 
38 public class Test_invoke_static extends DxTestCase {
39 
40     /**
41      * @title Static method from library class Math
42      */
testN1()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      */
testN2()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      */
testN3()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      */
testN5()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      */
testN6()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      */
testE2()89     public void testE2() {
90         loadAndRun("dot.junit.opcodes.invoke_static.d.T_invoke_static_6",
91                    UnsatisfiedLinkError.class);
92     }
93 
94     /**
95      * @title initialization of referenced class throws exception
96      */
testE7()97     public void testE7() {
98         loadAndRun("dot.junit.opcodes.invoke_static.d.T_invoke_static_14",
99                    ExceptionInInitializerError.class);
100     }
101 
102     /**
103      * @constraint A13
104      * @title  invalid constant pool index
105      */
testVFE1()106     public void testVFE1() {
107         load("dot.junit.opcodes.invoke_static.d.T_invoke_static_3", VerifyError.class);
108     }
109 
110     /**
111      * @constraint A15
112      * @title &lt;clinit&gt; may not be called using invoke-static
113      */
testVFE3()114     public void testVFE3() {
115         load("dot.junit.opcodes.invoke_static.d.T_invoke_static_10", VerifyError.class);
116     }
117 
118     /**
119      * @constraint B1
120      * @title number of arguments passed to method.
121      */
testVFE4()122     public void testVFE4() {
123         load("dot.junit.opcodes.invoke_static.d.T_invoke_static_11", VerifyError.class);
124     }
125 
126     /**
127      * @constraint A15
128      * @title &lt;init&gt; may not be called using invoke_static
129      */
testVFE5()130     public void testVFE5() {
131         load("dot.junit.opcodes.invoke_static.d.T_invoke_static_19", VerifyError.class);
132     }
133 
134     /**
135      * @constraint B9
136      * @title types of arguments passed to method
137      */
testVFE6()138     public void testVFE6() {
139         load("dot.junit.opcodes.invoke_static.d.T_invoke_static_20", VerifyError.class);
140     }
141 
142 
143     /**
144      * @constraint n/a
145      * @title Attempt to call non-static method.
146      */
testVFE7()147     public void testVFE7() {
148         loadAndRun("dot.junit.opcodes.invoke_static.d.T_invoke_static_5",
149                    IncompatibleClassChangeError.class);
150     }
151 
152     /**
153      * @constraint n/a
154      * @title Attempt to call undefined method.
155      */
testVFE8()156     public void testVFE8() {
157         loadAndRun("dot.junit.opcodes.invoke_static.d.T_invoke_static_7", NoSuchMethodError.class);
158     }
159 
160     /**
161      * @constraint n/a
162      * @title Attempt to call private method of other class.
163      */
testVFE9()164     public void testVFE9() {
165         //@uses dot.junit.opcodes.invoke_static.TestClass
166         loadAndRun("dot.junit.opcodes.invoke_static.d.T_invoke_static_8", IllegalAccessError.class);
167     }
168 
169     /**
170      * @constraint n/a
171      * @title Method has different signature.
172      */
testVFE10()173     public void testVFE10() {
174         //@uses dot.junit.opcodes.invoke_static.TestClass
175         loadAndRun("dot.junit.opcodes.invoke_static.d.T_invoke_static_13", NoSuchMethodError.class);
176     }
177 
178     /**
179      * @constraint B12
180      * @title Attempt to call protected method of unrelated class.
181      */
testVFE12()182     public void testVFE12() {
183         //@uses dot.junit.opcodes.invoke_static.TestClass
184         loadAndRun("dot.junit.opcodes.invoke_static.d.T_invoke_static_17",
185                    IllegalAccessError.class);
186     }
187 
188     /**
189      * @constraint A23
190      * @title number of registers
191      */
testVFE13()192     public void testVFE13() {
193         load("dot.junit.opcodes.invoke_static.d.T_invoke_static_16", VerifyError.class);
194     }
195 
196     /**
197      * @constraint A13
198      * @title attempt to invoke interface method
199      */
testVFE18()200     public void testVFE18() {
201         load("dot.junit.opcodes.invoke_static.d.T_invoke_static_24", VerifyError.class);
202     }
203 }
204