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 dxc.junit.opcodes.ldiv; 18 19 import dxc.junit.DxTestCase; 20 import dxc.junit.DxUtil; 21 import dxc.junit.opcodes.ldiv.jm.T_ldiv_1; 22 23 public class Test_ldiv extends DxTestCase { 24 25 /** 26 * @title Arguments = 100000000000l, 40000000000l 27 */ 28 public void testN1() { 29 T_ldiv_1 t = new T_ldiv_1(); 30 assertEquals(2l, t.run(100000000000l, 40000000000l)); 31 } 32 33 /** 34 * @title Rounding 35 */ 36 public void testN2() { 37 T_ldiv_1 t = new T_ldiv_1(); 38 assertEquals(8l, t.run(98765432123456l, 12345678912345l)); 39 } 40 41 /** 42 * @title Dividend = 0 43 */ 44 public void testN3() { 45 T_ldiv_1 t = new T_ldiv_1(); 46 assertEquals(0l, t.run(0l, 98765432123456l)); 47 } 48 49 /** 50 * @title Dividend is negative 51 */ 52 public void testN4() { 53 T_ldiv_1 t = new T_ldiv_1(); 54 assertEquals(-8, t.run(-98765432123456l, 12345678912345l)); 55 } 56 57 /** 58 * @title Divisor is negative 59 */ 60 public void testN5() { 61 T_ldiv_1 t = new T_ldiv_1(); 62 assertEquals(-8, t.run(98765432123456l, -12345678912345l)); 63 } 64 65 /** 66 * @title Both Dividend and divisor are negative 67 */ 68 public void testN6() { 69 T_ldiv_1 t = new T_ldiv_1(); 70 assertEquals(80l, t.run(-98765432123456l, -1234567891234l)); 71 } 72 73 /** 74 * @title Arguments = Long.MIN_VALUE, -1 75 */ 76 public void testB1() { 77 T_ldiv_1 t = new T_ldiv_1(); 78 assertEquals(-9223372036854775808L, t.run(Long.MIN_VALUE, -1)); 79 } 80 /** 81 * @title Arguments = Long.MIN_VALUE, 1 82 */ 83 public void testB2() { 84 T_ldiv_1 t = new T_ldiv_1(); 85 assertEquals(-9223372036854775808L, t.run(Long.MIN_VALUE, 1)); 86 } 87 /** 88 * @title Arguments = Long.MAX_VALUE, 1 89 */ 90 public void testB3() { 91 T_ldiv_1 t = new T_ldiv_1(); 92 assertEquals(9223372036854775807L, t.run(Long.MAX_VALUE, 1)); 93 } 94 /** 95 * @title Arguments = Long.MIN_VALUE, Long.MAX_VALUE 96 */ 97 public void testB4() { 98 T_ldiv_1 t = new T_ldiv_1(); 99 assertEquals(-1, t.run(Long.MIN_VALUE, Long.MAX_VALUE)); 100 } 101 /** 102 * @title Arguments = 1, Long.MAX_VALUE 103 */ 104 public void testB5() { 105 T_ldiv_1 t = new T_ldiv_1(); 106 assertEquals(0, t.run(1, Long.MAX_VALUE)); 107 } 108 /** 109 * @title Arguments = 1, Long.MIN_VALUE 110 */ 111 public void testB6() { 112 T_ldiv_1 t = new T_ldiv_1(); 113 assertEquals(0, t.run(1, Long.MIN_VALUE)); 114 } 115 116 /** 117 * @title Divisor is 0 118 */ 119 public void testE1() { 120 T_ldiv_1 t = new T_ldiv_1(); 121 try { 122 t.run(12345678912345l, 0); 123 fail("expected ArithmeticException"); 124 } catch (ArithmeticException ae) { 125 // expected 126 } 127 } 128 129 /** 130 * @constraint 4.8.2.1 131 * @title number of arguments 132 */ 133 public void testVFE1() { 134 try { 135 Class.forName("dxc.junit.opcodes.ldiv.jm.T_ldiv_2"); 136 fail("expected a verification exception"); 137 } catch (Throwable t) { 138 DxUtil.checkVerifyException(t); 139 } 140 } 141 142 /** 143 * @constraint 4.8.2.1 144 * @title number of arguments 145 */ 146 public void testVFE2() { 147 try { 148 Class.forName("dxc.junit.opcodes.ldiv.jm.T_ldiv_3"); 149 fail("expected a verification exception"); 150 } catch (Throwable t) { 151 DxUtil.checkVerifyException(t); 152 } 153 } 154 155 /** 156 * @constraint 4.8.2.1 157 * @title types of arguments - long / double 158 */ 159 public void testVFE3() { 160 try { 161 Class.forName("dxc.junit.opcodes.ldiv.jm.T_ldiv_4"); 162 fail("expected a verification exception"); 163 } catch (Throwable t) { 164 DxUtil.checkVerifyException(t); 165 } 166 } 167 168 /** 169 * @constraint 4.8.2.1 170 * @title types of arguments - int / long 171 */ 172 public void testVFE4() { 173 try { 174 Class.forName("dxc.junit.opcodes.ldiv.jm.T_ldiv_5"); 175 fail("expected a verification exception"); 176 } catch (Throwable t) { 177 DxUtil.checkVerifyException(t); 178 } 179 } 180 181 /** 182 * @constraint 4.8.2.1 183 * @title types of arguments - float / long 184 */ 185 public void testVFE5() { 186 try { 187 Class.forName("dxc.junit.opcodes.ldiv.jm.T_ldiv_6"); 188 fail("expected a verification exception"); 189 } catch (Throwable t) { 190 DxUtil.checkVerifyException(t); 191 } 192 } 193 194 /** 195 * @constraint 4.8.2.1 196 * @title types of arguments - reference / long 197 */ 198 public void testVFE6() { 199 try { 200 Class.forName("dxc.junit.opcodes.ldiv.jm.T_ldiv_7"); 201 fail("expected a verification exception"); 202 } catch (Throwable t) { 203 DxUtil.checkVerifyException(t); 204 } 205 } 206 207 } 208