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 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 */ testN3()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 */ testN4()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 */ testE1()81 public void testE1() { 82 loadAndRun("dot.junit.opcodes.opc_throw.d.T_opc_throw_4", NullPointerException.class); 83 } 84 85 /** 86 * @title expected IllegalMonitorStateException 87 */ testE2()88 public void testE2() { 89 loadAndRun("dot.junit.opcodes.opc_throw.d.T_opc_throw_5", 90 IllegalMonitorStateException.class); 91 } 92 93 /** 94 * @constraint A23 95 * @title (number of registers) 96 */ testVFE2()97 public void testVFE2() { 98 load("dot.junit.opcodes.opc_throw.d.T_opc_throw_6", VerifyError.class); 99 } 100 101 102 103 /** 104 * 105 * @constraint B1 106 * @title type of argument - float 107 */ testVFE3()108 public void testVFE3() { 109 load("dot.junit.opcodes.opc_throw.d.T_opc_throw_7", VerifyError.class); 110 } 111 112 /** 113 * 114 * @constraint B1 115 * @title type of argument - long 116 */ testVFE4()117 public void testVFE4() { 118 load("dot.junit.opcodes.opc_throw.d.T_opc_throw_7", VerifyError.class); 119 } 120 121 /** 122 * @constraint B16 123 * @title operand must be must be assignment-compatible 124 * with java.lang.Throwable 125 126 */ testVFE5()127 public void testVFE5() { 128 load("dot.junit.opcodes.opc_throw.d.T_opc_throw_10", VerifyError.class); 129 } 130 } 131