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.lookupswitch; 18 19 import dxc.junit.DxTestCase; 20 import dxc.junit.DxUtil; 21 import dxc.junit.opcodes.lookupswitch.jm.T_lookupswitch_1; 22 23 public class Test_lookupswitch extends DxTestCase { 24 25 /** 26 * @title normal test 27 */ testN1()28 public void testN1() { 29 T_lookupswitch_1 t = new T_lookupswitch_1(); 30 assertEquals(2, t.run(-1)); 31 32 assertEquals(-1, t.run(9)); 33 assertEquals(20, t.run(10)); 34 assertEquals(-1, t.run(11)); 35 36 assertEquals(-1, t.run(14)); 37 assertEquals(20, t.run(15)); 38 assertEquals(-1, t.run(16)); 39 } 40 41 /** 42 * @title check Integer.MAX_VALUE 43 */ testB1()44 public void testB1() { 45 T_lookupswitch_1 t = new T_lookupswitch_1(); 46 assertEquals(-1, t.run(Integer.MAX_VALUE)); 47 } 48 49 /** 50 * @title check Integer.MIN_VALUE 51 */ testB2()52 public void testB2() { 53 T_lookupswitch_1 t = new T_lookupswitch_1(); 54 assertEquals(-1, t.run(Integer.MIN_VALUE)); 55 } 56 57 58 /** 59 * @constraint 4.8.2.1 60 * @title number of arguments 61 */ testVFE1()62 public void testVFE1() { 63 try { 64 Class.forName("dxc.junit.opcodes.lookupswitch.jm.T_lookupswitch_2"); 65 fail("expected a verification exception"); 66 } catch (Throwable t) { 67 DxUtil.checkVerifyException(t); 68 } 69 } 70 71 /** 72 * @constraint 4.8.2.1 73 * @title type of argument - float 74 */ testVFE2()75 public void testVFE2() { 76 try { 77 Class.forName("dxc.junit.opcodes.lookupswitch.jm.T_lookupswitch_3"); 78 fail("expected a verification exception"); 79 } catch (Throwable t) { 80 DxUtil.checkVerifyException(t); 81 } 82 } 83 84 /** 85 * @constraint 4.8.1.9 86 * @title branch target shall be inside the 87 * method 88 */ testVFE3()89 public void testVFE3() { 90 try { 91 Class.forName("dxc.junit.opcodes.lookupswitch.jm.T_lookupswitch_4"); 92 fail("expected a verification exception"); 93 } catch (Throwable t) { 94 DxUtil.checkVerifyException(t); 95 } 96 } 97 98 /** 99 * @constraint 4.8.1.9 100 * @title branch target shall not be "inside" wide 101 * instruction 102 */ testVFE4()103 public void testVFE4() { 104 try { 105 Class.forName("dxc.junit.opcodes.lookupswitch.jm.T_lookupswitch_5"); 106 fail("expected a verification exception"); 107 } catch (Throwable t) { 108 DxUtil.checkVerifyException(t); 109 } 110 } 111 112 /** 113 * @constraint 4.8.1.9 114 * @title npairs shall be >= 0 115 */ testVFE5()116 public void testVFE5() { 117 try { 118 Class.forName("dxc.junit.opcodes.lookupswitch.jm.T_lookupswitch_6"); 119 fail("expected a verification exception"); 120 } catch (Throwable t) { 121 DxUtil.checkVerifyException(t); 122 } 123 } 124 125 /** 126 * @constraint 4.8.1.9 127 * @title non-zero padding 128 */ testVFE6()129 public void testVFE6() { 130 try { 131 Class.forName("dxc.junit.opcodes.lookupswitch.jm.T_lookupswitch_7"); 132 fail("expected a verification exception"); 133 } catch (Throwable t) { 134 DxUtil.checkVerifyException(t); 135 } 136 } 137 138 /** 139 * @constraint 4.8.1.9 140 * @title pairs shall be sorted in ascending 141 * order 142 */ testVFE7()143 public void testVFE7() { 144 try { 145 Class.forName("dxc.junit.opcodes.lookupswitch.jm.T_lookupswitch_8"); 146 fail("expected a verification exception"); 147 } catch (Throwable t) { 148 DxUtil.checkVerifyException(t); 149 } 150 } 151 152 /** 153 * @constraint 4.8.2.1 154 * @title type of argument - reference 155 */ testVFE8()156 public void testVFE8() { 157 try { 158 Class.forName("dxc.junit.opcodes.lookupswitch.jm.T_lookupswitch_9"); 159 fail("expected a verification exception"); 160 } catch (Throwable t) { 161 DxUtil.checkVerifyException(t); 162 } 163 } 164 165 /** 166 * @constraint 4.8.1.9 167 * @title number of entries in jump table 168 */ testVFE9()169 public void testVFE9() { 170 try { 171 Class 172 .forName("dxc.junit.opcodes.lookupswitch.jm.T_lookupswitch_10"); 173 fail("expected a verification exception"); 174 } catch (Throwable t) { 175 DxUtil.checkVerifyException(t); 176 } 177 } 178 179 } 180