• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.sub_int;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.sub_int.d.T_sub_int_1;
22 import dot.junit.opcodes.sub_int.d.T_sub_int_5;
23 
24 public class Test_sub_int extends DxTestCase {
25 
26     /**
27      * @title Arguments = 8, 4
28      */
testN1()29     public void testN1() {
30         T_sub_int_1 t = new T_sub_int_1();
31         assertEquals(4, t.run(8, 4));
32     }
33 
34     /**
35      * @title Arguments = 0, 255
36      */
testN2()37     public void testN2() {
38         T_sub_int_1 t = new T_sub_int_1();
39         assertEquals(-255, t.run(0, 255));
40     }
41 
42     /**
43      * @title Arguments = 0, -65536
44      */
testN3()45     public void testN3() {
46         T_sub_int_1 t = new T_sub_int_1();
47         assertEquals(65536, t.run(0, -65536));
48     }
49 
50     /**
51      * @title Arguments = 0, -2147483647
52      */
testN4()53     public void testN4() {
54         T_sub_int_1 t = new T_sub_int_1();
55         assertEquals(Integer.MAX_VALUE, t.run(0, -2147483647));
56     }
57 
58     /**
59      * @title Types of arguments - int, float. Dalvik doens't distinguish 32-bits types internally,
60      * so this subtraction of float and int makes no sense but shall not crash the VM.
61      */
testN5()62     public void testN5() {
63         T_sub_int_5 t = new  T_sub_int_5();
64         try {
65             t.run(1, 3.14f);
66         } catch (Throwable e) {
67         }
68     }
69 
70     /**
71      * @title Arguments = 0, Integer.MAX_VALUE
72      */
testB1()73     public void testB1() {
74         T_sub_int_1 t = new T_sub_int_1();
75         assertEquals(-2147483647, t.run(0, Integer.MAX_VALUE));
76     }
77 
78     /**
79      * @title Arguments = Integer.MAX_VALUE, Integer.MAX_VALUE
80      */
testB2()81     public void testB2() {
82         T_sub_int_1 t = new T_sub_int_1();
83         assertEquals(0, t.run(Integer.MAX_VALUE, Integer.MAX_VALUE));
84     }
85 
86     /**
87      * @title Arguments = Integer.MAX_VALUE, -1
88      */
testB3()89     public void testB3() {
90         T_sub_int_1 t = new T_sub_int_1();
91         assertEquals(Integer.MIN_VALUE, t.run(Integer.MAX_VALUE, -1));
92     }
93 
94     /**
95      * @title Arguments = Integer.MIN_VALUE, 1
96      */
testB4()97     public void testB4() {
98         T_sub_int_1 t = new T_sub_int_1();
99         assertEquals(Integer.MAX_VALUE, t.run(Integer.MIN_VALUE, 1));
100     }
101 
102     /**
103      * @title Arguments = 0, 0
104      */
testB5()105     public void testB5() {
106         T_sub_int_1 t = new T_sub_int_1();
107         assertEquals(0, t.run(0, 0));
108     }
109 
110     /**
111      * @title Arguments = 0, -Integer.MIN_VALUE
112      */
testB6()113     public void testB6() {
114         T_sub_int_1 t = new T_sub_int_1();
115         assertEquals(-2147483648, t.run(0, -Integer.MIN_VALUE));
116     }
117 
118     /**
119      * @title Arguments = Integer.MAX_VALUE, 1
120      */
testB7()121     public void testB7() {
122         T_sub_int_1 t = new T_sub_int_1();
123         assertEquals(2147483646, t.run(Integer.MAX_VALUE, 1));
124     }
125 
126     /**
127      * @title Arguments = 1, Integer.MIN_VALUE
128      */
testB8()129     public void testB8() {
130         T_sub_int_1 t = new T_sub_int_1();
131         assertEquals(-2147483647, t.run(1, Integer.MIN_VALUE));
132     }
133 
134     /**
135      * @title Arguments = Integer.MAX_VALUE, Integer.MIN_VALUE
136      */
testB9()137     public void testB9() {
138         T_sub_int_1 t = new T_sub_int_1();
139         assertEquals(-1, t.run(Integer.MAX_VALUE, Integer.MIN_VALUE));
140     }
141 
142 
143 
144     /**
145      * @constraint B1
146      * @title types of arguments - int, double
147      */
testVFE2()148     public void testVFE2() {
149         try {
150             Class.forName("dot.junit.opcodes.sub_int.d.T_sub_int_2");
151             fail("expected a verification exception");
152         } catch (Throwable t) {
153             DxUtil.checkVerifyException(t);
154         }
155     }
156 
157     /**
158      * @constraint B1
159      * @title types of arguments - long, int
160      */
testVFE3()161     public void testVFE3() {
162         try {
163             Class.forName("dot.junit.opcodes.sub_int.d.T_sub_int_3");
164             fail("expected a verification exception");
165         } catch (Throwable t) {
166             DxUtil.checkVerifyException(t);
167         }
168     }
169 
170     /**
171      * @constraint B1
172      * @title types of arguments - reference, int
173      */
testVFE4()174     public void testVFE4() {
175         try {
176             Class.forName("dot.junit.opcodes.sub_int.d.T_sub_int_4");
177             fail("expected a verification exception");
178         } catch (Throwable t) {
179             DxUtil.checkVerifyException(t);
180         }
181     }
182 
183     /**
184      * @constraint A23
185      * @title number of registers
186      */
testVFE5()187     public void testVFE5() {
188         try {
189             Class.forName("dot.junit.opcodes.sub_int.d.T_sub_int_6");
190             fail("expected a verification exception");
191         } catch (Throwable t) {
192             DxUtil.checkVerifyException(t);
193         }
194     }
195 
196 }
197