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      */
testN1()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      */
testN2()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      */
testN3()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      */
testN4()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      */
testN5()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      */
testN6()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      */
testB1()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      */
testB2()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      */
testB3()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      */
testB4()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      */
testB5()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      */
testB6()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      */
testE1()127     public void testE1() {
128         loadAndRun("dot.junit.opcodes.div_int.d.T_div_int_1", ArithmeticException.class, 1, 0);
129     }
130 
131     /**
132      * @constraint B1
133      * @title types of arguments - int / double
134      */
testVFE1()135     public void testVFE1() {
136         load("dot.junit.opcodes.div_int.d.T_div_int_2", VerifyError.class);
137     }
138 
139     /**
140      * @constraint B1
141      * @title types of arguments - long / int
142      */
testVFE2()143     public void testVFE2() {
144         load("dot.junit.opcodes.div_int.d.T_div_int_3", VerifyError.class);
145     }
146 
147     /**
148      * @constraint B1
149      * @title types of arguments - reference / int
150      */
testVFE3()151     public void testVFE3() {
152         load("dot.junit.opcodes.div_int.d.T_div_int_4", VerifyError.class);
153     }
154 
155     /**
156      * @constraint A23
157      * @title  number of registers
158      */
testVFE4()159     public void testVFE4() {
160         load("dot.junit.opcodes.div_int.d.T_div_int_6", VerifyError.class);
161     }
162 
163     /**
164      * @constraint B1
165      * @title Types of arguments - int, float. The verifier checks that ints
166      * and floats are not used interchangeably.
167      */
testVFE5()168     public void testVFE5() {
169         load("dot.junit.opcodes.div_int.d.T_div_int_5", VerifyError.class);
170     }
171 
172 }
173