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_lit16; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_1; 22 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_10; 23 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_11; 24 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_12; 25 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_13; 26 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_17; 27 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_2; 28 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_3; 29 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_4; 30 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_5; 31 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_6; 32 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_7; 33 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_8; 34 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_9; 35 36 37 public class Test_div_int_lit16 extends DxTestCase { 38 /** 39 * @title Arguments = 8 / 4 40 */ testN1()41 public void testN1() { 42 T_div_int_lit16_1 t = new T_div_int_lit16_1(); 43 assertEquals(2, t.run()); 44 } 45 46 /** 47 * @title Rounding 48 */ testN2()49 public void testN2() { 50 T_div_int_lit16_2 t = new T_div_int_lit16_2(); 51 assertEquals(268435455, t.run()); 52 } 53 54 /** 55 * @title Dividend = 0 56 */ testN3()57 public void testN3() { 58 T_div_int_lit16_3 t = new T_div_int_lit16_3(); 59 assertEquals(0, t.run()); 60 } 61 62 /** 63 * @title Dividend is negative 64 */ testN4()65 public void testN4() { 66 T_div_int_lit16_4 t = new T_div_int_lit16_4(); 67 assertEquals(-3, t.run()); 68 } 69 70 /** 71 * @title Divisor is negative 72 */ testN5()73 public void testN5() { 74 T_div_int_lit16_5 t = new T_div_int_lit16_5(); 75 assertEquals(-357913941, t.run()); 76 } 77 78 /** 79 * @title Both Dividend and divisor are negative 80 */ testN6()81 public void testN6() { 82 T_div_int_lit16_6 t = new T_div_int_lit16_6(); 83 assertEquals(5965, t.run()); 84 } 85 86 /** 87 * @title Arguments = Integer.MIN_VALUE / -1 88 */ testB1()89 public void testB1() { 90 T_div_int_lit16_7 t = new T_div_int_lit16_7(); 91 // result is MIN_VALUE because overflow occurs in this case 92 assertEquals(Integer.MIN_VALUE, t.run()); 93 } 94 95 /** 96 * @title Arguments = Integer.MIN_VALUE / 1 97 */ testB2()98 public void testB2() { 99 T_div_int_lit16_8 t = new T_div_int_lit16_8(); 100 assertEquals(Integer.MIN_VALUE, t.run()); 101 } 102 103 /** 104 * @title Arguments = Integer.MAX_VALUE / 1 105 */ testB3()106 public void testB3() { 107 T_div_int_lit16_9 t = new T_div_int_lit16_9(); 108 assertEquals(Integer.MAX_VALUE, t.run()); 109 } 110 111 /** 112 * @title Arguments = Integer.MIN_VALUE / Short.MAX_VALUE 113 */ testB4()114 public void testB4() { 115 T_div_int_lit16_10 t = new T_div_int_lit16_10(); 116 assertEquals(-65538, t.run()); 117 } 118 119 /** 120 * @title Arguments = 1 / Short.MAX_VALUE 121 */ testB5()122 public void testB5() { 123 T_div_int_lit16_11 t = new T_div_int_lit16_11(); 124 assertEquals(0, t.run()); 125 } 126 127 /** 128 * @title Arguments = 1 / Short.MIN_VALUE 129 */ testB6()130 public void testB6() { 131 T_div_int_lit16_12 t = new T_div_int_lit16_12(); 132 assertEquals(0, t.run()); 133 } 134 135 /** 136 * @title Divisor is 0 137 */ testE1()138 public void testE1() { 139 loadAndRun("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_13", 140 ArithmeticException.class); 141 } 142 143 /** 144 * @constraint B1 145 * @title types of arguments - int / double 146 */ testVFE1()147 public void testVFE1() { 148 load("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_14", VerifyError.class); 149 } 150 151 /** 152 * @constraint B1 153 * @title types of arguments - long / int 154 */ testVFE2()155 public void testVFE2() { 156 load("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_15", VerifyError.class); 157 } 158 159 /** 160 * @constraint B1 161 * @title types of arguments - reference / int 162 */ testVFE3()163 public void testVFE3() { 164 load("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_16", VerifyError.class); 165 } 166 167 /** 168 * @constraint A23 169 * @title number of registers 170 */ testVFE4()171 public void testVFE4() { 172 load("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_18", VerifyError.class); 173 } 174 175 /** 176 * @constraint B1 177 * @title Types of arguments - int, float. The verifier checks that ints 178 * and floats are not used interchangeably. 179 */ testVFE5()180 public void testVFE5() { 181 load("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_17", VerifyError.class); 182 } 183 } 184