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.rsub_int; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.rsub_int.d.T_rsub_int_1; 22 import dot.junit.opcodes.rsub_int.d.T_rsub_int_2; 23 import dot.junit.opcodes.rsub_int.d.T_rsub_int_3; 24 import dot.junit.opcodes.rsub_int.d.T_rsub_int_4; 25 import dot.junit.opcodes.rsub_int.d.T_rsub_int_5; 26 import dot.junit.opcodes.rsub_int.d.T_rsub_int_6; 27 import dot.junit.opcodes.rsub_int.d.T_rsub_int_7; 28 import dot.junit.opcodes.rsub_int.d.T_rsub_int_12; 29 30 public class Test_rsub_int extends DxTestCase { 31 32 /** 33 * @title normal test - check different values 34 */ testN1()35 public void testN1() { 36 T_rsub_int_1 t = new T_rsub_int_1(); 37 assertEquals("Subtest_1 is failed", -4, t.run(8)); 38 assertEquals("Subtest_2 is failed",45, t.run1(15)); 39 assertEquals("Subtest_3 is failed",0, t.run2(20)); 40 assertEquals("Subtest_4 is failed",-35, t.run3(10)); 41 assertEquals("Subtest_5 is failed",-20, t.run4(-50)); 42 assertEquals("Subtest_6 is failed",20, t.run5(-70)); 43 } 44 45 /** 46 * @title normal test - check different values 47 */ testN2()48 public void testN2() { 49 T_rsub_int_2 t = new T_rsub_int_2(); 50 assertEquals("Subtest_1 is failed",255, t.run(0)); 51 assertEquals("Subtest_2 is failed",-32768, t.run1(0)); 52 assertEquals("Subtest_3 is failed",-15, t.run2(15)); 53 assertEquals("Subtest_4 is failed",123, t.run2(-123)); 54 } 55 56 /** 57 * @title Types of arguments - float, int. Dalvik doens't distinguish 32-bits types internally, 58 * so this operation of float and int makes no sense but shall not crash the VM. 59 */ testN3()60 public void testN3() { 61 T_rsub_int_12 t = new T_rsub_int_12(); 62 try { 63 t.run(3.14f); 64 } catch (Throwable e) { 65 } 66 } 67 68 /** 69 * @title 70 * 1: a = Integer.MAX_VALUE, b = 0, b-a = -Integer.MAX_VALUE 71 * 2: a = Short.MAX_VALUE, b = 0, b-a = -Short.MAX_VALUE 72 */ testB1()73 public void testB1() { 74 T_rsub_int_3 t = new T_rsub_int_3(); 75 assertEquals(-Integer.MAX_VALUE, t.run(Integer.MAX_VALUE)); 76 assertEquals(-Short.MAX_VALUE, t.run(Short.MAX_VALUE)); 77 } 78 79 /** 80 * @title 81 * 1: a = Integer.MIN_VALUE, b = 0, b-a = Integer.MIN_VALUE 82 * 2: a = Short.MIN_VALUE, b = 0, b-a = 32768 83 */ testB2()84 public void testB2() { 85 T_rsub_int_3 t = new T_rsub_int_3(); 86 assertEquals(Integer.MIN_VALUE, t.run(Integer.MIN_VALUE)); 87 assertEquals(32768, t.run(Short.MIN_VALUE)); 88 } 89 90 /** 91 * @title (a = 0, b = 0, b-a = 0) 92 */ testB3()93 public void testB3() { 94 T_rsub_int_3 t = new T_rsub_int_3(); 95 assertEquals(0, t.run(0)); 96 } 97 98 /** 99 * @title 100 * 1: a = 0, b = Short.MAX_VALUE, b-a = Short.MAX_VALUE 101 * 2: a = 1, b = Short.MAX_VALUE, b-a = 32766 102 * 3: a = -1, b = Short.MAX_VALUE, b-a = 32768 103 */ testB4()104 public void testB4() { 105 T_rsub_int_4 t = new T_rsub_int_4(); 106 assertEquals(Short.MAX_VALUE, t.run(0)); 107 assertEquals(32766, t.run(1)); 108 assertEquals(32768, t.run(-1)); 109 } 110 111 /** 112 * @title 113 * 1: a = Integer.MIN_VALUE, b = Short.MAX_VALUE, b-a = -2147450881 114 * 2: a = Integer.MAX_VALUE, b = Short.MAX_VALUE, b-a = -2147450880 115 * 3: a = Short.MIN_VALUE, b = Short.MAX_VALUE, b-a = 65535 116 */ testB5()117 public void testB5() { 118 T_rsub_int_4 t = new T_rsub_int_4(); 119 assertEquals(-2147450881, t.run(Integer.MIN_VALUE)); 120 assertEquals(-2147450880, t.run(Integer.MAX_VALUE)); 121 assertEquals(65535, t.run(Short.MIN_VALUE)); 122 } 123 124 /** 125 * @title 126 * 1: a = 0, b = Short.MIN_VALUE, b-a = Short.MIN_VALUE 127 * 2: a = 1, b = Short.MIN_VALUE, b-a = -32769 128 * 3: a = -1, b = Short.MIN_VALUE, b-a = -32767 129 */ testB6()130 public void testB6() { 131 T_rsub_int_5 t = new T_rsub_int_5(); 132 assertEquals(Short.MIN_VALUE, t.run(0)); 133 assertEquals(-32769, t.run(1)); 134 assertEquals(-32767, t.run(-1)); 135 } 136 137 /** 138 * @title 139 * 1: a = Integer.MAX_VALUE, b = Short.MIN_VALUE, b-a = 2147450881 140 * 2: a = Integer.MIN_VALUE, b = Short.MIN_VALUE, b-a = 2147450880 141 * 3: a = Short.MAX_VALUE, b = Short.MIN_VALUE, b-a = -65535 142 */ testB7()143 public void testB7() { 144 T_rsub_int_5 t = new T_rsub_int_5(); 145 assertEquals(2147450881, t.run(Integer.MAX_VALUE)); 146 assertEquals(2147450880, t.run(Integer.MIN_VALUE)); 147 assertEquals(-65535, t.run(Short.MAX_VALUE)); 148 } 149 150 /** 151 * @title 152 * 1: a = Integer.MIN_VALUE, b = -1, b-a = Integer.MAX_VALUE 153 * 2: a = Short.MIN_VALUE, b = -1, b-a = Short.MAX_VALUE 154 */ testB8()155 public void testB8() { 156 T_rsub_int_6 t = new T_rsub_int_6(); 157 assertEquals(Integer.MAX_VALUE, t.run(Integer.MIN_VALUE)); 158 assertEquals(Short.MAX_VALUE, t.run(Short.MIN_VALUE)); 159 } 160 161 /** 162 * @title 163 * 1: a = Integer.MAX_VALUE, b = -1, b-a = Integer.MIN_VALUE 164 * 2: a = Short.MAX_VALUE, b = -1, b-a = -32768 165 */ testB9()166 public void testB9() { 167 T_rsub_int_6 t = new T_rsub_int_6(); 168 assertEquals(Integer.MIN_VALUE, t.run(Integer.MAX_VALUE)); 169 assertEquals(-32768, t.run(Short.MAX_VALUE)); 170 } 171 172 /** 173 * @title 174 * 1: a = Integer.MIN_VALUE, b = 1, b-a = -Integer.MAX_VALUE 175 * 2: a = Integer.MAX_VALUE, b = 1, b-a = -2147483646 176 */ testB10()177 public void testB10() { 178 T_rsub_int_7 t = new T_rsub_int_7(); 179 assertEquals(-Integer.MAX_VALUE, t.run(Integer.MIN_VALUE)); 180 assertEquals(-2147483646, t.run(Integer.MAX_VALUE)); 181 } 182 183 /** 184 * @title 185 * 1: a = Short.MIN_VALUE, b = 1, b-a = 32769 186 * 2: a = Short.MAX_VALUE, b = 1, b-a = -32766 187 */ testB11()188 public void testB11() { 189 T_rsub_int_7 t = new T_rsub_int_7(); 190 assertEquals(32769, t.run(Short.MIN_VALUE)); 191 assertEquals(-32766, t.run(Short.MAX_VALUE)); 192 } 193 194 /** 195 * @title (a = 1, b = 1, b-a = 0) 196 */ testB12()197 public void testB12() { 198 T_rsub_int_7 t = new T_rsub_int_7(); 199 assertEquals(0, t.run(1)); 200 } 201 202 /** 203 * @constraint A23 204 * @title number of registers 205 */ testVFE1()206 public void testVFE1() { 207 try { 208 Class.forName("dot.junit.opcodes.rsub_int.d.T_rsub_int_8"); 209 fail("expected a verification exception"); 210 } catch (Throwable t) { 211 DxUtil.checkVerifyException(t); 212 } 213 } 214 215 216 217 /** 218 * @constraint B1 219 * @title types of arguments - double, int 220 */ testVFE2()221 public void testVFE2() { 222 try { 223 Class.forName("dot.junit.opcodes.rsub_int.d.T_rsub_int_9"); 224 fail("expected a verification exception"); 225 } catch (Throwable t) { 226 DxUtil.checkVerifyException(t); 227 } 228 } 229 230 /** 231 * @constraint B1 232 * @title types of arguments - long, int 233 */ testVFE3()234 public void testVFE3() { 235 try { 236 Class.forName("dot.junit.opcodes.rsub_int.d.T_rsub_int_10"); 237 fail("expected a verification exception"); 238 } catch (Throwable t) { 239 DxUtil.checkVerifyException(t); 240 } 241 } 242 243 /** 244 * @constraint B1 245 * @title types of arguments - reference, int 246 */ testVFE4()247 public void testVFE4() { 248 try { 249 Class.forName("dot.junit.opcodes.rsub_int.d.T_rsub_int_11"); 250 fail("expected a verification exception"); 251 } catch (Throwable t) { 252 DxUtil.checkVerifyException(t); 253 } 254 } 255 } 256