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.if_eq; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.if_eq.d.T_if_eq_1; 22 import dot.junit.opcodes.if_eq.d.T_if_eq_2; 23 import dot.junit.opcodes.if_eq.d.T_if_eq_4; 24 25 public class Test_if_eq extends DxTestCase { 26 27 /** 28 * @title Arguments = 5, 6 29 */ 30 public void testN1() { 31 T_if_eq_1 t = new T_if_eq_1(); 32 /* 33 * Compare with 1234 to check that in case of failed comparison 34 * execution proceeds at the address following if_eq instruction 35 */ 36 assertEquals(1234, t.run(5, 6)); 37 } 38 39 /** 40 * @title Arguments = 0x0f0e0d0c, 0x0f0e0d0c 41 */ 42 public void testN2() { 43 T_if_eq_1 t = new T_if_eq_1(); 44 assertEquals(1, t.run(0x0f0e0d0c, 0x0f0e0d0c)); 45 } 46 47 /** 48 * @title Arguments = 5, -5 49 */ 50 public void testN3() { 51 T_if_eq_1 t = new T_if_eq_1(); 52 assertEquals(1234, t.run(5, -5)); 53 } 54 55 /** 56 * @title Arguments = 0x01001234, 0x1234 57 */ 58 public void testN4() { 59 T_if_eq_1 t = new T_if_eq_1(); 60 assertEquals(1234, t.run(0x01001234, 0x1234)); 61 } 62 63 /** 64 * @title compare references 65 */ 66 public void testN5() { 67 T_if_eq_2 t = new T_if_eq_2(); 68 String a = "a"; 69 String b = "b"; 70 assertEquals(1234, t.run(a, b)); 71 } 72 73 /** 74 * @title compare references 75 */ 76 public void testN6() { 77 T_if_eq_2 t = new T_if_eq_2(); 78 String a = "a"; 79 assertEquals(1, t.run(a, a)); 80 } 81 82 /** 83 * @title Arguments = Integer.MAX_VALUE, Integer.MAX_VALUE 84 */ 85 public void testB1() { 86 T_if_eq_1 t = new T_if_eq_1(); 87 assertEquals(1, t.run(Integer.MAX_VALUE, Integer.MAX_VALUE)); 88 } 89 90 /** 91 * @title Arguments = Integer.MIN_VALUE, Integer.MIN_VALUE 92 */ 93 public void testB2() { 94 T_if_eq_1 t = new T_if_eq_1(); 95 assertEquals(1, t.run(Integer.MIN_VALUE, Integer.MIN_VALUE)); 96 } 97 98 /** 99 * @title Arguments = 0, 1234567 100 */ 101 public void testB3() { 102 T_if_eq_1 t = new T_if_eq_1(); 103 assertEquals(1234, t.run(0, 1234567)); 104 } 105 106 /** 107 * @title Arguments = 0, 0 108 */ 109 public void testB4() { 110 T_if_eq_1 t = new T_if_eq_1(); 111 assertEquals(1, t.run(0, 0)); 112 } 113 114 /** 115 * @title Compare reference with null 116 */ 117 public void testB5() { 118 T_if_eq_2 t = new T_if_eq_2(); 119 String a = "a"; 120 assertEquals(1234, t.run(null, a)); 121 } 122 123 /** 124 * @constraint A23 125 * @title number of registers 126 */ 127 public void testVFE1() { 128 try { 129 Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_5"); 130 fail("expected a verification exception"); 131 } catch (Throwable t) { 132 DxUtil.checkVerifyException(t); 133 } 134 } 135 136 137 /** 138 * @constraint B1 139 * @title types of arguments - int, double 140 */ 141 public void testVFE2() { 142 try { 143 Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_7"); 144 fail("expected a verification exception"); 145 } catch (Throwable t) { 146 DxUtil.checkVerifyException(t); 147 } 148 } 149 150 /** 151 * @constraint B1 152 * @title types of arguments - long, int 153 */ 154 public void testVFE3() { 155 try { 156 Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_8"); 157 fail("expected a verification exception"); 158 } catch (Throwable t) { 159 DxUtil.checkVerifyException(t); 160 } 161 } 162 163 /** 164 * @constraint B1 165 * @title types of arguments - int, reference 166 */ 167 public void testVFE4() { 168 try { 169 Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_9"); 170 fail("expected a verification exception"); 171 } catch (Throwable t) { 172 DxUtil.checkVerifyException(t); 173 } 174 } 175 176 /** 177 * @constraint A6 178 * @title branch target shall be inside the method 179 */ 180 public void testVFE5() { 181 try { 182 Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_10"); 183 fail("expected a verification exception"); 184 } catch (Throwable t) { 185 DxUtil.checkVerifyException(t); 186 } 187 } 188 189 /** 190 * @constraint A6 191 * @title branch target shall not be "inside" instruction 192 */ 193 public void testVFE6() { 194 try { 195 Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_11"); 196 fail("expected a verification exception"); 197 } catch (Throwable t) { 198 DxUtil.checkVerifyException(t); 199 } 200 } 201 202 /** 203 * @constraint n/a 204 * @title zero offset 205 */ 206 public void testVFE7() { 207 try { 208 Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_12"); 209 fail("expected a verification exception"); 210 } catch (Throwable t) { 211 DxUtil.checkVerifyException(t); 212 } 213 } 214 215 /** 216 * @constraint B1 217 * @title Types of arguments - int, float. The verifier checks that ints 218 * and floats are not used interchangeably. 219 */ 220 public void testVFE8() { 221 try { 222 Class.forName("dot.junit.opcodes.if_eq.d.T_if_eq_4"); 223 fail("expected a verification exception"); 224 } catch (Throwable t) { 225 DxUtil.checkVerifyException(t); 226 } 227 } 228 } 229