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.return_object;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.return_object.d.T_return_object_1;
22 import dot.junit.opcodes.return_object.d.T_return_object_12;
23 import dot.junit.opcodes.return_object.d.T_return_object_13;
24 import dot.junit.opcodes.return_object.d.T_return_object_2;
25 import dot.junit.opcodes.return_object.d.T_return_object_6;
26 import dot.junit.opcodes.return_object.d.T_return_object_8;
27 
28 
29 public class Test_return_object extends DxTestCase {
30     /**
31      * @title simple
32      */
testN1()33     public void testN1() {
34         T_return_object_1 t = new T_return_object_1();
35         assertEquals("hello", t.run());
36     }
37 
38     /**
39      * @title simple
40      */
testN2()41     public void testN2() {
42         T_return_object_1 t = new T_return_object_1();
43         assertEquals(t, t.run2());
44     }
45 
46     /**
47      * @title return null
48      */
testN4()49     public void testN4() {
50         T_return_object_2 t = new T_return_object_2();
51         assertNull(t.run());
52     }
53 
54     /**
55      * @title check that frames are discarded and reinstananted correctly
56      */
testN5()57     public void testN5() {
58         T_return_object_6 t = new T_return_object_6();
59         assertEquals("hello", t.run());
60     }
61 
62 
63     /**
64      * @title assignment compatibility (TChild returned as TSuper)
65      */
testN7()66     public void testN7() {
67         //@uses dot.junit.opcodes.return_object.d.T_return_object_12
68         //@uses dot.junit.opcodes.return_object.d.TChild
69         //@uses dot.junit.opcodes.return_object.d.TSuper
70         //@uses dot.junit.opcodes.return_object.d.TInterface
71         T_return_object_12 t = new T_return_object_12();
72         assertTrue(t.run());
73     }
74 
75     /**
76      * @title assignment compatibility (TChild returned as TInterface)
77      */
testN8()78     public void testN8() {
79         //@uses dot.junit.opcodes.return_object.d.T_return_object_13
80         //@uses dot.junit.opcodes.return_object.d.TChild
81         //@uses dot.junit.opcodes.return_object.d.TSuper
82         //@uses dot.junit.opcodes.return_object.d.TInterface
83         T_return_object_13 t = new T_return_object_13();
84         assertTrue(t.run());
85     }
86 
87     /**
88      * @title Method is synchronized but thread is not monitor owner
89      */
testE1()90     public void testE1() {
91         loadAndRun("dot.junit.opcodes.return_object.d.T_return_object_8",
92                    IllegalMonitorStateException.class);
93     }
94 
95 
96     /**
97      * @constraint B11
98      * @title method's return type - void
99      */
testVFE1()100     public void testVFE1() {
101         load("dot.junit.opcodes.return_object.d.T_return_object_3", VerifyError.class);
102     }
103 
104     /**
105      * @constraint B11
106      * @title method's return type - float
107      */
testVFE2()108     public void testVFE2() {
109         load("dot.junit.opcodes.return_object.d.T_return_object_4", VerifyError.class);
110     }
111 
112     /**
113      * @constraint B11
114      * @title method's return type - long
115      */
testVFE3()116     public void testVFE3() {
117         load("dot.junit.opcodes.return_object.d.T_return_object_16", VerifyError.class);
118     }
119 
120     /**
121      * @constraint A23
122      * @title number of registers
123      */
testVFE4()124     public void testVFE4() {
125         load("dot.junit.opcodes.return_object.d.T_return_object_5", VerifyError.class);
126     }
127 
128 
129     /**
130      * @constraint B1
131      * @title types of argument - int
132      */
testVFE6()133     public void testVFE6() {
134         load("dot.junit.opcodes.return_object.d.T_return_object_10", VerifyError.class);
135     }
136 
137     /**
138      * @constraint B1
139      * @title types of argument - long
140      */
testVFE7()141     public void testVFE7() {
142         load("dot.junit.opcodes.return_object.d.T_return_object_11", VerifyError.class);
143     }
144 
145     /**
146      * @constraint B11
147      * @title assignment incompatible references
148      */
testVFE8()149     public void testVFE8() {
150         //@uses dot.junit.opcodes.return_object.d.T_return_object_14
151         //@uses dot.junit.opcodes.return_object.d.TChild
152         //@uses dot.junit.opcodes.return_object.d.TSuper
153         //@uses dot.junit.opcodes.return_object.d.TInterface
154         load("dot.junit.opcodes.return_object.d.T_return_object_14", VerifyError.class);
155     }
156 
157     /**
158      * @constraint B11
159      * @title assignment incompatible references
160      */
testVFE9()161     public void testVFE9() {
162         //@uses dot.junit.opcodes.return_object.d.T_return_object_15
163         //@uses dot.junit.opcodes.return_object.Runner
164         //@uses dot.junit.opcodes.return_object.RunnerGenerator
165         //@uses dot.junit.opcodes.return_object.d.TSuper2
166         try {
167             RunnerGenerator rg = (RunnerGenerator) Class.forName(
168                     "dot.junit.opcodes.return_object.d.T_return_object_15").newInstance();
169             Runner r = rg.run();
170             assertFalse(r instanceof Runner);
171             assertFalse(Runner.class.isAssignableFrom(r.getClass()));
172             // only upon invocation of a concrete method,
173             // a java.lang.IncompatibleClassChangeError is thrown
174             r.doit();
175             fail("expected a verification exception");
176         } catch (Throwable t) {
177             DxUtil.checkVerifyException(t);
178         }
179     }
180 
181 
182 }
183