• 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 dxc.junit.opcodes.athrow;
18 
19 import dxc.junit.DxTestCase;
20 import dxc.junit.DxUtil;
21 import dxc.junit.opcodes.athrow.jm.T_athrow_1;
22 import dxc.junit.opcodes.athrow.jm.T_athrow_11;
23 import dxc.junit.opcodes.athrow.jm.T_athrow_12;
24 import dxc.junit.opcodes.athrow.jm.T_athrow_2;
25 import dxc.junit.opcodes.athrow.jm.T_athrow_4;
26 import dxc.junit.opcodes.athrow.jm.T_athrow_5;
27 import dxc.junit.opcodes.athrow.jm.T_athrow_8;
28 
29 public class Test_athrow extends DxTestCase {
30 
31     /**
32      * @title normal test
33      */
testN1()34     public void testN1() {
35         T_athrow_1 t = new T_athrow_1();
36         try {
37             t.run();
38             fail("must throw a RuntimeException");
39         } catch (RuntimeException re) {
40             // expected
41         }
42     }
43 
44     /**
45      * @title  Throwing of the objectref on the class Throwable
46      */
testN2()47     public void testN2() {
48         T_athrow_2 t = new T_athrow_2();
49         try {
50             t.run();
51             fail("must throw a Throwable");
52         } catch (Throwable e) {
53             // expected
54         }
55     }
56 
57     /**
58      * @title  Throwing of the objectref on the subclass of Throwable
59      */
testN3()60     public void testN3() {
61         T_athrow_8 t = new T_athrow_8();
62         try {
63             t.run();
64             fail("must throw a Error");
65         } catch (Error e) {
66             // expected
67         }
68     }
69 
70     /**
71      * @title  Nearest matching catch must be executed in case of exception
72      */
testN4()73     public void testN4() {
74         T_athrow_12 t = new T_athrow_12();
75         assertTrue(t.run());
76     }
77 
78     /**
79      * @title  NullPointerException If objectref is null, athrow throws
80      * a NullPointerException instead of objectref
81      */
testE1()82     public void testE1() {
83         T_athrow_4 t = new T_athrow_4();
84         try {
85             t.run();
86             fail("expected NullPointerException");
87         } catch (NullPointerException npe) {
88             // expected
89         }
90     }
91 
92     /**
93      * @title  IllegalMonitorStateException expected
94      */
testE2()95     public void testE2() {
96         T_athrow_5 t = new T_athrow_5();
97         try {
98             t.run();
99             fail("expected IllegalMonitorStateException");
100         } catch (IllegalMonitorStateException imse) {
101             // expected
102         }
103     }
104 
105     /**
106      * @title IllegalMonitorStateException if structural lock rule violated -
107      */
testE3()108     public void testE3() {
109         T_athrow_11 t = new T_athrow_11();
110         try {
111             t.run();
112             fail("expected IllegalMonitorStateException");
113         } catch (IllegalMonitorStateException imse) {
114             // expected
115         } catch (NullPointerException npe) {
116             // the JVM spec says that it is optional to implement the structural
117             // lock rules, see JVM spec 8.13 and monitorenter/exit opcodes.
118             System.out.print("dvmvfe:");
119             //fail ("expected IllegalMonitorStateException, but got NPE");
120         }
121     }
122 
123     /**
124      * @constraint 4.8.1.19
125      * @title constant pool index
126      */
testVFE1()127     public void testVFE1() {
128         try {
129             Class.forName("dxc.junit.opcodes.athrow.jm.T_athrow_3");
130             fail("expected a verification exception");
131         } catch (Throwable t) {
132             DxUtil.checkVerifyException(t);
133         }
134     }
135 
136     /**
137      * @constraint 4.8.2.1
138      * @title number of arguments
139      */
testVFE2()140     public void testVFE2() {
141         try {
142             Class.forName("dxc.junit.opcodes.athrow.jm.T_athrow_6");
143             fail("expected a verification exception");
144         } catch (Throwable t) {
145             DxUtil.checkVerifyException(t);
146         }
147     }
148 
149     /**
150      * @constraint 4.8.2.1
151      * @title type of argument - float
152      */
testVFE3()153     public void testVFE3() {
154         try {
155             Class.forName("dxc.junit.opcodes.athrow.jm.T_athrow_7");
156             fail("expected a verification exception");
157         } catch (Throwable t) {
158             DxUtil.checkVerifyException(t);
159         }
160     }
161 
162     /**
163      * @constraint 4.8.2.1
164      * @title type of argument - String
165      */
testVFE4()166     public void testVFE4() {
167         try {
168             Class.forName("dxc.junit.opcodes.athrow.jm.T_athrow_10");
169             fail("expected a verification exception");
170         } catch (Throwable t) {
171             DxUtil.checkVerifyException(t);
172         }
173     }
174 
175     /**
176      * @constraint 4.8.2.19
177      * @title Throwing of the objectref on the class which is not
178      *          the class Throwable or a subclass of Throwable.
179      */
testVFE5()180     public void testVFE5() {
181         try {
182             Class.forName("dxc.junit.opcodes.athrow.jm.T_athrow_9");
183             fail("expected a verification exception");
184         } catch (Throwable t) {
185             DxUtil.checkVerifyException(t);
186         }
187     }
188 
189 }
190