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.packed_switch; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.packed_switch.d.T_packed_switch_1; 22 import dot.junit.opcodes.packed_switch.d.T_packed_switch_2; 23 24 public class Test_packed_switch extends DxTestCase { 25 26 /** 27 * @title try different values 28 */ testN1()29 public void testN1() { 30 T_packed_switch_1 t = new T_packed_switch_1(); 31 assertEquals(2, t.run(-1)); 32 33 assertEquals(-1, t.run(4)); 34 assertEquals(20, t.run(2)); 35 assertEquals(-1, t.run(5)); 36 37 assertEquals(-1, t.run(6)); 38 assertEquals(20, t.run(3)); 39 assertEquals(-1, t.run(7)); 40 } 41 42 /** 43 * @title Types of arguments - float, int. Dalvik doens't distinguish 32-bits types internally, 44 * so this operation of float and int makes no sense but shall not crash the VM. 45 */ testN2()46 public void testN2() { 47 try { 48 T_packed_switch_2 t = new T_packed_switch_2(); 49 t.run(-1.23f); 50 } catch(Throwable t) { 51 52 } 53 } 54 55 /** 56 * @title Argument = Integer.MAX_VALUE 57 */ testB1()58 public void testB1() { 59 T_packed_switch_1 t = new T_packed_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_packed_switch_1 t = new T_packed_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_packed_switch_1 t = new T_packed_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.packed_switch.d.T_packed_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.packed_switch.d.T_packed_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.packed_switch.d.T_packed_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.packed_switch.d.T_packed_switch_6"); 127 fail("expected a verification exception"); 128 } catch (Throwable t) { 129 DxUtil.checkVerifyException(t); 130 } 131 } 132 133 /** 134 * @constraint A7 135 * @title branch target shall be inside the method 136 */ testVFE5()137 public void testVFE5() { 138 try { 139 Class.forName("dot.junit.opcodes.packed_switch.d.T_packed_switch_7"); 140 fail("expected a verification exception"); 141 } catch (Throwable t) { 142 DxUtil.checkVerifyException(t); 143 } 144 } 145 146 /** 147 * @constraint A7 148 * @title branch target shall not be "inside" instruction 149 */ testVFE6()150 public void testVFE6() { 151 try { 152 Class.forName("dot.junit.opcodes.packed_switch.d.T_packed_switch_8"); 153 fail("expected a verification exception"); 154 } catch (Throwable t) { 155 DxUtil.checkVerifyException(t); 156 } 157 } 158 159 160 /** 161 * @constraint A7 162 * @title offset to table shall be inside method 163 */ testVFE7()164 public void testVFE7() { 165 try { 166 Class.forName("dot.junit.opcodes.packed_switch.d.T_packed_switch_9"); 167 fail("expected a verification exception"); 168 } catch (Throwable t) { 169 DxUtil.checkVerifyException(t); 170 } 171 } 172 173 /** 174 * @constraint A7 175 * @title the size and the list of targets must be consistent. 176 */ testVFE9()177 public void testVFE9() { 178 try { 179 Class.forName("dot.junit.opcodes.packed_switch.d.T_packed_switch_11"); 180 fail("expected a verification exception"); 181 } catch (Throwable t) { 182 DxUtil.checkVerifyException(t); 183 } 184 } 185 186 187 /** 188 * @constraint B22 189 * @title packed-switch-data pseudo-instructions must not be reachable by control flow 190 */ testVFE10()191 public void testVFE10() { 192 try { 193 Class.forName("dot.junit.opcodes.packed_switch.d.T_packed_switch_12"); 194 fail("expected a verification exception"); 195 } catch (Throwable t) { 196 DxUtil.checkVerifyException(t); 197 } 198 } 199 200 /** 201 * @constraint A7 202 * @title table has wrong ident code 203 */ testVFE11()204 public void testVFE11() { 205 try { 206 Class.forName("dot.junit.opcodes.packed_switch.d.T_packed_switch_13"); 207 fail("expected a verification exception"); 208 } catch (Throwable t) { 209 DxUtil.checkVerifyException(t); 210 } 211 } 212 } 213