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 Types of arguments - int, float. Dalvik doens't distinguish 32-bits types internally, 76 * so this division of float and int makes no sense but shall not crash the VM. 77 */ 78 79 public void testN7() { 80 T_div_int_5 t = new T_div_int_5(); 81 try { 82 t.run(1, 3.14f); 83 } catch (Throwable e) { 84 } 85 } 86 87 /** 88 * @title Arguments = Integer.MIN_VALUE, -1 89 */ 90 public void testB1() { 91 T_div_int_1 t = new T_div_int_1(); 92 // result is MIN_VALUE because overflow occurs in this case 93 assertEquals(Integer.MIN_VALUE, t.run(Integer.MIN_VALUE, -1)); 94 } 95 96 /** 97 * @title Arguments = Integer.MIN_VALUE, 1 98 */ 99 public void testB2() { 100 T_div_int_1 t = new T_div_int_1(); 101 //fail("why this test causes floating point exception?"); 102 assertEquals(Integer.MIN_VALUE, t.run(Integer.MIN_VALUE, 1)); 103 } 104 105 /** 106 * @title Arguments = Integer.MAX_VALUE, 1 107 */ 108 public void testB3() { 109 T_div_int_1 t = new T_div_int_1(); 110 assertEquals(Integer.MAX_VALUE, t.run(Integer.MAX_VALUE, 1)); 111 } 112 113 /** 114 * @title Arguments = Integer.MIN_VALUE, Integer.MAX_VALUE 115 */ 116 public void testB4() { 117 T_div_int_1 t = new T_div_int_1(); 118 assertEquals(-1, t.run(Integer.MIN_VALUE, Integer.MAX_VALUE)); 119 } 120 121 /** 122 * @title Arguments = 1, Integer.MAX_VALUE 123 */ 124 public void testB5() { 125 T_div_int_1 t = new T_div_int_1(); 126 assertEquals(0, t.run(1, Integer.MAX_VALUE)); 127 } 128 129 /** 130 * @title Arguments = 1, Integer.MIN_VALUE 131 */ 132 public void testB6() { 133 T_div_int_1 t = new T_div_int_1(); 134 assertEquals(0, t.run(1, Integer.MIN_VALUE)); 135 } 136 137 /** 138 * @title Divisor is 0 139 */ 140 public void testE1() { 141 T_div_int_1 t = new T_div_int_1(); 142 try { 143 t.run(1, 0); 144 fail("expected ArithmeticException"); 145 } catch (ArithmeticException ae) { 146 // expected 147 } 148 } 149 150 151 152 /** 153 * @constraint B1 154 * @title types of arguments - int / double 155 */ 156 public void testVFE1() { 157 try { 158 Class.forName("dot.junit.opcodes.div_int.d.T_div_int_2"); 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 - long / int 168 */ 169 public void testVFE2() { 170 try { 171 Class.forName("dot.junit.opcodes.div_int.d.T_div_int_3"); 172 fail("expected a verification exception"); 173 } catch (Throwable t) { 174 DxUtil.checkVerifyException(t); 175 } 176 } 177 178 /** 179 * @constraint B1 180 * @title types of arguments - reference / int 181 */ 182 public void testVFE3() { 183 try { 184 Class.forName("dot.junit.opcodes.div_int.d.T_div_int_4"); 185 fail("expected a verification exception"); 186 } catch (Throwable t) { 187 DxUtil.checkVerifyException(t); 188 } 189 } 190 191 /** 192 * @constraint A23 193 * @title number of registers 194 */ 195 public void testVFE4() { 196 try { 197 Class.forName("dot.junit.opcodes.div_int.d.T_div_int_6"); 198 fail("expected a verification exception"); 199 } catch (Throwable t) { 200 DxUtil.checkVerifyException(t); 201 } 202 } 203 204 } 205