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