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.sparse_switch; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.sparse_switch.d.T_sparse_switch_1; 22 import dot.junit.opcodes.sparse_switch.d.T_sparse_switch_2 23 ; 24 25 public class Test_sparse_switch extends DxTestCase { 26 27 /** 28 * @title try different values 29 */ 30 public void testN1() { 31 T_sparse_switch_1 t = new T_sparse_switch_1(); 32 assertEquals(2, t.run(-1)); 33 34 assertEquals(-1, t.run(9)); 35 assertEquals(20, t.run(10)); 36 assertEquals(-1, t.run(11)); 37 38 assertEquals(-1, t.run(14)); 39 assertEquals(20, t.run(15)); 40 assertEquals(-1, t.run(16)); 41 } 42 43 /** 44 * @title Argument = Integer.MAX_VALUE 45 */ 46 public void testB1() { 47 T_sparse_switch_1 t = new T_sparse_switch_1(); 48 assertEquals(-1, t.run(Integer.MAX_VALUE)); 49 } 50 51 /** 52 * @title Argument = Integer.MIN_VALUE 53 */ 54 public void testB2() { 55 T_sparse_switch_1 t = new T_sparse_switch_1(); 56 assertEquals(-1, t.run(Integer.MIN_VALUE)); 57 } 58 59 /** 60 * @title Argument = 0 61 */ 62 public void testB3() { 63 T_sparse_switch_1 t = new T_sparse_switch_1(); 64 assertEquals(-1, t.run(0)); 65 } 66 67 /** 68 * @constraint A23 69 * @title number of registers 70 */ 71 public void testVFE1() { 72 try { 73 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_3"); 74 fail("expected a verification exception"); 75 } catch (Throwable t) { 76 DxUtil.checkVerifyException(t); 77 } 78 } 79 80 81 82 /** 83 * @constraint B1 84 * @title type of argument - double 85 */ 86 public void testVFE2() { 87 try { 88 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_4"); 89 fail("expected a verification exception"); 90 } catch (Throwable t) { 91 DxUtil.checkVerifyException(t); 92 } 93 } 94 95 /** 96 * @constraint B1 97 * @title type of argument - long 98 */ 99 public void testVFE3() { 100 try { 101 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_5"); 102 fail("expected a verification exception"); 103 } catch (Throwable t) { 104 DxUtil.checkVerifyException(t); 105 } 106 } 107 108 /** 109 * @constraint B1 110 * @title type of argument - reference 111 */ 112 public void testVFE4() { 113 try { 114 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_6"); 115 fail("expected a verification exception"); 116 } catch (Throwable t) { 117 DxUtil.checkVerifyException(t); 118 } 119 } 120 121 /** 122 * @constraint A8 123 * @title branch target shall be inside the method 124 */ 125 public void testVFE5() { 126 try { 127 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_7"); 128 fail("expected a verification exception"); 129 } catch (Throwable t) { 130 DxUtil.checkVerifyException(t); 131 } 132 } 133 134 /** 135 * @constraint A8 136 * @title branch target shall not be "inside" instruction 137 */ 138 public void testVFE6() { 139 try { 140 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_8"); 141 fail("expected a verification exception"); 142 } catch (Throwable t) { 143 DxUtil.checkVerifyException(t); 144 } 145 } 146 147 /** 148 * @constraint A8 149 * @title offset to table shall be inside method 150 */ 151 public void testVFE7() { 152 try { 153 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_9"); 154 fail("expected a verification exception"); 155 } catch (Throwable t) { 156 DxUtil.checkVerifyException(t); 157 } 158 } 159 160 /** 161 * @constraint B1 162 * @title Types of arguments - float, int. The verifier checks that ints 163 * and floats are not used interchangeably. 164 */ 165 public void testVFE8() { 166 try { 167 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_2"); 168 fail("expected a verification exception"); 169 } catch (Throwable t) { 170 DxUtil.checkVerifyException(t); 171 } 172 } 173 174 /** 175 * @constraint A8 176 * @title pairs shall be sorted in ascending order 177 */ 178 public void testVFE9() { 179 try { 180 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_11"); 181 fail("expected a verification exception"); 182 } catch (Throwable t) { 183 DxUtil.checkVerifyException(t); 184 } 185 } 186 187 /** 188 * @constraint A8 189 * @title number of entries in jump table 190 */ 191 public void testVFE10() { 192 try { 193 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_12"); 194 fail("expected a verification exception"); 195 } catch (Throwable t) { 196 DxUtil.checkVerifyException(t); 197 } 198 } 199 200 /** 201 * @constraint B22 202 * @title sparse-switch-data pseudo-instructions must not be reachable by control flow 203 */ 204 public void testVFE11() { 205 try { 206 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_13"); 207 fail("expected a verification exception"); 208 } catch (Throwable t) { 209 DxUtil.checkVerifyException(t); 210 } 211 } 212 213 /** 214 * @constraint A8 215 * @title table has wrong ident code 216 */ 217 public void testVFE12() { 218 try { 219 Class.forName("dot.junit.opcodes.sparse_switch.d.T_sparse_switch_14"); 220 fail("expected a verification exception"); 221 } catch (Throwable t) { 222 DxUtil.checkVerifyException(t); 223 } 224 } 225 } 226