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.opc_throw;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.opc_throw.d.T_opc_throw_1;
22 import dot.junit.opcodes.opc_throw.d.T_opc_throw_12;
23 import dot.junit.opcodes.opc_throw.d.T_opc_throw_2;
24 import dot.junit.opcodes.opc_throw.d.T_opc_throw_4;
25 import dot.junit.opcodes.opc_throw.d.T_opc_throw_5;
26 import dot.junit.opcodes.opc_throw.d.T_opc_throw_8;
27 
28 public class Test_opc_throw extends DxTestCase {
29     /**
30      * @title check throw functionality. This test also tests constraint C17 allowing to have
31      * throw as a last opcode in the method.
32      */
testN1()33     public void testN1() {
34         T_opc_throw_1 t = new T_opc_throw_1();
35         try {
36             t.run();
37             fail("must throw a RuntimeException");
38         } catch (RuntimeException re) {
39             // expected
40         }
41     }
42 
43     /**
44      * @title Throwing of the objectref on the class Throwable
45      */
testN2()46     public void testN2() {
47         T_opc_throw_2 t = new T_opc_throw_2();
48         try {
49             t.run();
50         } catch (Throwable e) {
51             // expected
52             return;
53         }
54         fail("must throw a Throwable");
55     }
56 
57     /**
58      * @title Throwing of the objectref on the subclass of Throwable
59      */
testN3()60     public void testN3() {
61         T_opc_throw_8 t = new T_opc_throw_8();
62         try {
63             t.run();
64         } catch (Error e) {
65             // expected
66             return;
67         }
68         fail("must throw a Error");
69     }
70 
71     /**
72      * @title Nearest matching catch must be executed in case of exception
73      */
testN4()74     public void testN4() {
75         T_opc_throw_12 t = new T_opc_throw_12();
76         assertTrue(t.run());
77     }
78 
79     /**
80      * @title NullPointerException If objectref is null, opc_throw throws
81      * a NullPointerException instead of objectref
82      */
testE1()83     public void testE1() {
84         loadAndRun("dot.junit.opcodes.opc_throw.d.T_opc_throw_4", NullPointerException.class);
85     }
86 
87     /**
88      * @title expected IllegalMonitorStateException
89      */
testE2()90     public void testE2() {
91         loadAndRun("dot.junit.opcodes.opc_throw.d.T_opc_throw_5",
92                    IllegalMonitorStateException.class);
93     }
94 
95     /**
96      * @constraint A23
97      * @title  (number of registers)
98      */
testVFE2()99     public void testVFE2() {
100         load("dot.junit.opcodes.opc_throw.d.T_opc_throw_6", VerifyError.class);
101     }
102 
103 
104 
105     /**
106      *
107      * @constraint B1
108      * @title type of argument - float
109      */
testVFE3()110     public void testVFE3() {
111         load("dot.junit.opcodes.opc_throw.d.T_opc_throw_7", VerifyError.class);
112     }
113 
114     /**
115      *
116      * @constraint B1
117      * @title type of argument - long
118      */
testVFE4()119     public void testVFE4() {
120         load("dot.junit.opcodes.opc_throw.d.T_opc_throw_7", VerifyError.class);
121     }
122 
123     /**
124      * @constraint B16
125      * @title operand must be must be assignment-compatible
126      * with java.lang.Throwable
127 
128      */
testVFE5()129     public void testVFE5() {
130         load("dot.junit.opcodes.opc_throw.d.T_opc_throw_10", VerifyError.class);
131     }
132 }
133