• 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.float_to_int;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.float_to_int.d.T_float_to_int_1;
22 import dot.junit.opcodes.float_to_int.d.T_float_to_int_5;
23 
24 public class Test_float_to_int extends DxTestCase {
25 
26     /**
27      * @title Argument = 2.999999f
28      */
testN1()29     public void testN1() {
30         T_float_to_int_1 t = new T_float_to_int_1();
31         assertEquals(2, t.run(2.999999f));
32     }
33 
34     /**
35      * @title Argument = 1
36      */
testN2()37     public void testN2() {
38         T_float_to_int_1 t = new T_float_to_int_1();
39         assertEquals(1, t.run(1f));
40     }
41 
42     /**
43      * @title Argument = -1
44      */
testN3()45     public void testN3() {
46         T_float_to_int_1 t = new T_float_to_int_1();
47         assertEquals(-1, t.run(-1f));
48     }
49 
50     /**
51      * @title Type of argument - int. Dalvik doens't distinguish 32-bits types internally,
52      * so this conversion of int to int makes no sense but shall not crash the VM.
53      */
54 
testN4()55     public void testN4() {
56         T_float_to_int_5 t = new T_float_to_int_5();
57         try {
58             t.run(1);
59         } catch (Throwable e) {
60         }
61     }
62 
63     /**
64      * @title Argument = -0f
65      */
testB1()66     public void testB1() {
67         T_float_to_int_1 t = new T_float_to_int_1();
68         assertEquals(0, t.run(-0f));
69     }
70 
71     /**
72      * @title Argument = Float.MAX_VALUE
73      */
testB2()74     public void testB2() {
75         T_float_to_int_1 t = new T_float_to_int_1();
76         assertEquals(Integer.MAX_VALUE, t.run(Float.MAX_VALUE));
77     }
78 
79     /**
80      * @title Argument = Float.MIN_VALUE
81      */
testB3()82     public void testB3() {
83         T_float_to_int_1 t = new T_float_to_int_1();
84         assertEquals(0, t.run(Float.MIN_VALUE));
85     }
86 
87     /**
88      * @title Argument = NaN
89      */
testB4()90     public void testB4() {
91         T_float_to_int_1 t = new T_float_to_int_1();
92         assertEquals(0, t.run(Float.NaN));
93     }
94 
95     /**
96      * @title Argument = POSITIVE_INFINITY
97      */
testB5()98     public void testB5() {
99         T_float_to_int_1 t = new T_float_to_int_1();
100         assertEquals(Integer.MAX_VALUE, t.run(Float.POSITIVE_INFINITY));
101     }
102 
103     /**
104      * @title Argument = NEGATIVE_INFINITY
105      */
testB6()106     public void testB6() {
107         T_float_to_int_1 t = new T_float_to_int_1();
108         assertEquals(Integer.MIN_VALUE, t.run(Float.NEGATIVE_INFINITY));
109     }
110 
111 
112     /**
113      * @constraint B1
114      * @title type of argument - double
115      */
testVFE2()116     public void testVFE2() {
117         try {
118             Class.forName("dot.junit.opcodes.float_to_int.d.T_float_to_int_2");
119             fail("expected a verification exception");
120         } catch (Throwable t) {
121             DxUtil.checkVerifyException(t);
122         }
123     }
124 
125     /**
126      *
127      * @constraint B1
128      * @title  type of argument - long
129      */
testVFE3()130     public void testVFE3() {
131         try {
132             Class.forName("dot.junit.opcodes.float_to_int.d.T_float_to_int_3");
133             fail("expected a verification exception");
134         } catch (Throwable t) {
135             DxUtil.checkVerifyException(t);
136         }
137     }
138 
139     /**
140      *
141      * @constraint B1
142      * @title type of argument - reference
143      */
testVFE4()144     public void testVFE4() {
145         try {
146             Class.forName("dot.junit.opcodes.float_to_int.d.T_float_to_int_4");
147             fail("expected a verification exception");
148         } catch (Throwable t) {
149             DxUtil.checkVerifyException(t);
150         }
151     }
152 
153     /**
154      * @constraint A23
155      * @title number of registers
156      */
testVFE5()157     public void testVFE5() {
158         try {
159             Class.forName("dot.junit.opcodes.float_to_int.d.T_float_to_int_6");
160             fail("expected a verification exception");
161         } catch (Throwable t) {
162             DxUtil.checkVerifyException(t);
163         }
164     }
165 }
166