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 */ 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 */ 46 public void testN2() { 47 T_opc_throw_2 t = new T_opc_throw_2(); 48 try { 49 t.run(); 50 fail("must throw a Throwable"); 51 } catch (Throwable e) { 52 // expected 53 } 54 } 55 56 /** 57 * @title Throwing of the objectref on the subclass of Throwable 58 */ 59 public void testN3() { 60 T_opc_throw_8 t = new T_opc_throw_8(); 61 try { 62 t.run(); 63 fail("must throw a Error"); 64 } catch (Error e) { 65 // expected 66 } 67 } 68 69 /** 70 * @title Nearest matching catch must be executed in case of exception 71 */ 72 public void testN4() { 73 T_opc_throw_12 t = new T_opc_throw_12(); 74 assertTrue(t.run()); 75 } 76 77 /** 78 * @title NullPointerException If objectref is null, opc_throw throws 79 * a NullPointerException instead of objectref 80 */ 81 public void testE1() { 82 T_opc_throw_4 t = new T_opc_throw_4(); 83 try { 84 t.run(); 85 fail("expected NullPointerException"); 86 } catch (NullPointerException npe) { 87 // expected 88 } 89 } 90 91 /** 92 * @title expected IllegalMonitorStateException 93 */ 94 public void testE2() { 95 T_opc_throw_5 t = new T_opc_throw_5(); 96 try { 97 t.run(); 98 fail("expected IllegalMonitorStateException"); 99 } catch (IllegalMonitorStateException imse) { 100 // expected 101 } 102 } 103 104 /** 105 * @constraint A23 106 * @title (number of registers) 107 */ 108 public void testVFE2() { 109 try { 110 Class.forName("dxc.junit.opcodes.opc_throw.jm.T_opc_throw_6"); 111 fail("expected a verification exception"); 112 } catch (Throwable t) { 113 DxUtil.checkVerifyException(t); 114 } 115 } 116 117 118 119 /** 120 * 121 * @constraint B1 122 * @title type of argument - float 123 */ 124 public void testVFE3() { 125 try { 126 Class.forName("dxc.junit.opcodes.opc_throw.jm.T_opc_throw_7"); 127 fail("expected a verification exception"); 128 } catch (Throwable t) { 129 DxUtil.checkVerifyException(t); 130 } 131 } 132 133 /** 134 * 135 * @constraint B1 136 * @title type of argument - long 137 */ 138 public void testVFE4() { 139 try { 140 Class.forName("dxc.junit.opcodes.opc_throw.jm.T_opc_throw_7"); 141 fail("expected a verification exception"); 142 } catch (Throwable t) { 143 DxUtil.checkVerifyException(t); 144 } 145 } 146 147 /** 148 * @constraint B16 149 * @title operand must be must be assignment-compatible 150 * with java.lang.Throwable 151 152 */ 153 public void testVFE5() { 154 try { 155 Class.forName("dxc.junit.opcodes.opc_throw.jm.T_opc_throw_10"); 156 fail("expected a verification exception"); 157 } catch (Throwable t) { 158 DxUtil.checkVerifyException(t); 159 } 160 } 161 } 162