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