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