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