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.div_int; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.div_int.d.T_div_int_1; 22 import dot.junit.opcodes.div_int.d.T_div_int_5; 23 24 public class Test_div_int extends DxTestCase { 25 26 /** 27 * @title Arguments = 8, 4 28 */ 29 public void testN1() { 30 T_div_int_1 t = new T_div_int_1(); 31 assertEquals(2, t.run(8, 4)); 32 } 33 34 /** 35 * @title Rounding 36 */ 37 public void testN2() { 38 T_div_int_1 t = new T_div_int_1(); 39 assertEquals(268435455, t.run(1073741823, 4)); 40 } 41 42 /** 43 * @title Dividend = 0 44 */ 45 public void testN3() { 46 T_div_int_1 t = new T_div_int_1(); 47 assertEquals(0, t.run(0, 4)); 48 } 49 50 /** 51 * @title Dividend is negative 52 */ 53 public void testN4() { 54 T_div_int_1 t = new T_div_int_1(); 55 assertEquals(-3, t.run(-10, 3)); 56 } 57 58 /** 59 * @title Divisor is negative 60 */ 61 public void testN5() { 62 T_div_int_1 t = new T_div_int_1(); 63 assertEquals(-357913941, t.run(1073741824, -3)); 64 } 65 66 /** 67 * @title Both Dividend and divisor are negative 68 */ 69 public void testN6() { 70 T_div_int_1 t = new T_div_int_1(); 71 assertEquals(5965, t.run(-17895697, -3000)); 72 } 73 74 /** 75 * @title Arguments = Integer.MIN_VALUE, -1 76 */ 77 public void testB1() { 78 T_div_int_1 t = new T_div_int_1(); 79 // result is MIN_VALUE because overflow occurs in this case 80 assertEquals(Integer.MIN_VALUE, t.run(Integer.MIN_VALUE, -1)); 81 } 82 83 /** 84 * @title Arguments = Integer.MIN_VALUE, 1 85 */ 86 public void testB2() { 87 T_div_int_1 t = new T_div_int_1(); 88 //fail("why this test causes floating point exception?"); 89 assertEquals(Integer.MIN_VALUE, t.run(Integer.MIN_VALUE, 1)); 90 } 91 92 /** 93 * @title Arguments = Integer.MAX_VALUE, 1 94 */ 95 public void testB3() { 96 T_div_int_1 t = new T_div_int_1(); 97 assertEquals(Integer.MAX_VALUE, t.run(Integer.MAX_VALUE, 1)); 98 } 99 100 /** 101 * @title Arguments = Integer.MIN_VALUE, Integer.MAX_VALUE 102 */ 103 public void testB4() { 104 T_div_int_1 t = new T_div_int_1(); 105 assertEquals(-1, t.run(Integer.MIN_VALUE, Integer.MAX_VALUE)); 106 } 107 108 /** 109 * @title Arguments = 1, Integer.MAX_VALUE 110 */ 111 public void testB5() { 112 T_div_int_1 t = new T_div_int_1(); 113 assertEquals(0, t.run(1, Integer.MAX_VALUE)); 114 } 115 116 /** 117 * @title Arguments = 1, Integer.MIN_VALUE 118 */ 119 public void testB6() { 120 T_div_int_1 t = new T_div_int_1(); 121 assertEquals(0, t.run(1, Integer.MIN_VALUE)); 122 } 123 124 /** 125 * @title Divisor is 0 126 */ 127 public void testE1() { 128 T_div_int_1 t = new T_div_int_1(); 129 try { 130 t.run(1, 0); 131 fail("expected ArithmeticException"); 132 } catch (ArithmeticException ae) { 133 // expected 134 } 135 } 136 137 138 139 /** 140 * @constraint B1 141 * @title types of arguments - int / double 142 */ 143 public void testVFE1() { 144 try { 145 Class.forName("dot.junit.opcodes.div_int.d.T_div_int_2"); 146 fail("expected a verification exception"); 147 } catch (Throwable t) { 148 DxUtil.checkVerifyException(t); 149 } 150 } 151 152 /** 153 * @constraint B1 154 * @title types of arguments - long / int 155 */ 156 public void testVFE2() { 157 try { 158 Class.forName("dot.junit.opcodes.div_int.d.T_div_int_3"); 159 fail("expected a verification exception"); 160 } catch (Throwable t) { 161 DxUtil.checkVerifyException(t); 162 } 163 } 164 165 /** 166 * @constraint B1 167 * @title types of arguments - reference / int 168 */ 169 public void testVFE3() { 170 try { 171 Class.forName("dot.junit.opcodes.div_int.d.T_div_int_4"); 172 fail("expected a verification exception"); 173 } catch (Throwable t) { 174 DxUtil.checkVerifyException(t); 175 } 176 } 177 178 /** 179 * @constraint A23 180 * @title number of registers 181 */ 182 public void testVFE4() { 183 try { 184 Class.forName("dot.junit.opcodes.div_int.d.T_div_int_6"); 185 fail("expected a verification exception"); 186 } catch (Throwable t) { 187 DxUtil.checkVerifyException(t); 188 } 189 } 190 191 /** 192 * @constraint B1 193 * @title Types of arguments - int, float. The verifier checks that ints 194 * and floats are not used interchangeably. 195 */ 196 public void testVFE5() { 197 try { 198 Class.forName("dot.junit.opcodes.div_int.d.T_div_int_5"); 199 fail("expected a verification exception"); 200 } catch (Throwable t) { 201 DxUtil.checkVerifyException(t); 202 } 203 } 204 205 } 206