• 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.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         T_return_object_8 t = new T_return_object_8();
92         try {
93             assertTrue(t.run());
94             fail("expected IllegalMonitorStateException");
95         } catch (IllegalMonitorStateException imse) {
96             // expected
97         }
98     }
99 
100 
101     /**
102      * @constraint B11
103      * @title method's return type - void
104      */
testVFE1()105     public void testVFE1() {
106         try {
107             Class.forName("dxc.junit.opcodes.return_object.jm.T_return_object_3");
108             fail("expected a verification exception");
109         } catch (Throwable t) {
110             DxUtil.checkVerifyException(t);
111         }
112     }
113 
114     /**
115      * @constraint B11
116      * @title method's return type - float
117      */
testVFE2()118     public void testVFE2() {
119         try {
120             Class.forName("dxc.junit.opcodes.return_object.jm.T_return_object_4");
121             fail("expected a verification exception");
122         } catch (Throwable t) {
123             DxUtil.checkVerifyException(t);
124         }
125     }
126 
127     /**
128      * @constraint B11
129      * @title method's return type - long
130      */
testVFE3()131     public void testVFE3() {
132         try {
133             Class.forName("dxc.junit.opcodes.return_object.jm.T_return_object_16");
134             fail("expected a verification exception");
135         } catch (Throwable t) {
136             DxUtil.checkVerifyException(t);
137         }
138     }
139 
140     /**
141      * @constraint A23
142      * @title number of registers
143      */
testVFE4()144     public void testVFE4() {
145         try {
146             Class.forName("dxc.junit.opcodes.return_object.jm.T_return_object_5");
147             fail("expected a verification exception");
148         } catch (Throwable t) {
149             DxUtil.checkVerifyException(t);
150         }
151     }
152 
153 
154     /**
155      * @constraint B1
156      * @title types of argument - int
157      */
testVFE6()158     public void testVFE6() {
159         try {
160             Class.forName("dxc.junit.opcodes.return_object.jm.T_return_object_10");
161             fail("expected a verification exception");
162         } catch (Throwable t) {
163             DxUtil.checkVerifyException(t);
164         }
165     }
166 
167     /**
168      * @constraint B1
169      * @title types of argument - long
170      */
testVFE7()171     public void testVFE7() {
172         try {
173             Class.forName("dxc.junit.opcodes.return_object.jm.T_return_object_11");
174             fail("expected a verification exception");
175         } catch (Throwable t) {
176             DxUtil.checkVerifyException(t);
177         }
178     }
179 
180     /**
181      * @constraint B11
182      * @title assignment incompatible references
183      */
testVFE8()184     public void testVFE8() {
185         //@uses dot.junit.opcodes.return_object.d.T_return_object_14
186         //@uses dot.junit.opcodes.return_object.d.TChild
187         //@uses dot.junit.opcodes.return_object.d.TSuper
188         //@uses dot.junit.opcodes.return_object.d.TInterface
189         try {
190             Class.forName("dxc.junit.opcodes.return_object.jm.T_return_object_14");
191             fail("expected a verification exception");
192         } catch (Throwable t) {
193             DxUtil.checkVerifyException(t);
194         }
195     }
196 
197     /**
198      * @constraint B11
199      * @title assignment incompatible references
200      */
testVFE9()201     public void testVFE9() {
202         //@uses dot.junit.opcodes.return_object.d.T_return_object_15
203         //@uses dot.junit.opcodes.return_object.Runner
204         //@uses dot.junit.opcodes.return_object.RunnerGenerator
205         //@uses dot.junit.opcodes.return_object.d.TSuper2
206         try {
207             RunnerGenerator rg = (RunnerGenerator) Class.forName(
208                     "dot.junit.opcodes.return_object.d.T_return_object_15").newInstance();
209             Runner r = rg.run();
210             assertFalse(r instanceof Runner);
211             assertFalse(Runner.class.isAssignableFrom(r.getClass()));
212             // only upon invocation of a concrete method,
213             // a java.lang.IncompatibleClassChangeError is thrown
214             r.doit();
215             fail("expected a verification exception");
216         } catch (Throwable t) {
217             DxUtil.checkVerifyException(t);
218         }
219     }
220 
221 
222 }
223