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.not_int; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.not_int.d.T_not_int_1; 22 import dot.junit.opcodes.not_int.d.T_not_int_2; 23 24 public class Test_not_int extends DxTestCase { 25 26 /** 27 * @title Argument = 5; 256 28 */ testN1()29 public void testN1() { 30 T_not_int_1 t = new T_not_int_1(); 31 assertEquals(-6, t.run(5)); 32 assertEquals(-257, t.run(256)); 33 } 34 35 /** 36 * @title Argument = -5, -256 37 */ testN2()38 public void testN2() { 39 T_not_int_1 t = new T_not_int_1(); 40 assertEquals(4, t.run(-5)); 41 assertEquals(255, t.run(-256)); 42 } 43 44 /** 45 * @title Argument = 0xcafe; 0x12c 46 */ testN3()47 public void testN3() { 48 T_not_int_1 t = new T_not_int_1(); 49 assertEquals(-0xcaff, t.run(0xcafe)); 50 assertEquals(-0x12d, t.run(0x12c)); 51 } 52 53 /** 54 * @title Types of arguments - int, float. Dalvik doens't distinguish 32-bits types internally, 55 * so this multiplication of float and int makes no sense but shall not crash the VM. 56 */ testN4()57 public void testN4() { 58 T_not_int_2 t = new T_not_int_2(); 59 try { 60 t.run(3.14f); 61 } catch (Throwable e) { 62 } 63 } 64 65 /** 66 * @title Argument = Integer.MAX_VALUE 67 */ testB1()68 public void testB1() { 69 T_not_int_1 t = new T_not_int_1(); 70 assertEquals(Integer.MIN_VALUE, t.run(Integer.MAX_VALUE)); 71 } 72 73 /** 74 * @title Argument = Integer.MIN_VALUE 75 */ testB2()76 public void testB2() { 77 T_not_int_1 t = new T_not_int_1(); 78 assertEquals(Integer.MAX_VALUE, t.run(Integer.MIN_VALUE)); 79 } 80 81 /** 82 * @title Argument = 1 83 */ testB3()84 public void testB3() { 85 T_not_int_1 t = new T_not_int_1(); 86 assertEquals(-2, t.run(1)); 87 } 88 89 /** 90 * @title Argument = 0 91 */ testB4()92 public void testB4() { 93 T_not_int_1 t = new T_not_int_1(); 94 assertEquals(-1, t.run(0)); 95 } 96 97 /** 98 * @title Argument = -1 99 */ testB5()100 public void testB5() { 101 T_not_int_1 t = new T_not_int_1(); 102 assertEquals(0, t.run(-1)); 103 } 104 105 /** 106 * @title Argument = Short.MAX_VALUE 107 */ testB6()108 public void testB6() { 109 T_not_int_1 t = new T_not_int_1(); 110 assertEquals(Short.MIN_VALUE, t.run(Short.MAX_VALUE)); 111 } 112 113 /** 114 * @title Argument = Short.MIN_VALUE 115 */ testB7()116 public void testB7() { 117 T_not_int_1 t = new T_not_int_1(); 118 assertEquals(Short.MAX_VALUE, t.run(Short.MIN_VALUE)); 119 } 120 121 /** 122 * @constraint A23 123 * @title number of registers 124 */ testVFE1()125 public void testVFE1() { 126 try { 127 Class.forName("dot.junit.opcodes.not_int.d.T_not_int_3"); 128 fail("expected a verification exception"); 129 } catch (Throwable t) { 130 DxUtil.checkVerifyException(t); 131 } 132 } 133 134 135 136 /** 137 * @constraint B1 138 * @title types of arguments - double 139 */ testVFE2()140 public void testVFE2() { 141 try { 142 Class.forName("dot.junit.opcodes.not_int.d.T_not_int_4"); 143 fail("expected a verification exception"); 144 } catch (Throwable t) { 145 DxUtil.checkVerifyException(t); 146 } 147 } 148 149 /** 150 * @constraint B1 151 * @title types of arguments - long 152 */ testVFE3()153 public void testVFE3() { 154 try { 155 Class.forName("dot.junit.opcodes.not_int.d.T_not_int_5"); 156 fail("expected a verification exception"); 157 } catch (Throwable t) { 158 DxUtil.checkVerifyException(t); 159 } 160 } 161 162 /** 163 * @constraint B1 164 * @title types of arguments - reference 165 */ testVFE4()166 public void testVFE4() { 167 try { 168 Class.forName("dot.junit.opcodes.not_int.d.T_not_int_6"); 169 fail("expected a verification exception"); 170 } catch (Throwable t) { 171 DxUtil.checkVerifyException(t); 172 } 173 } 174 175 } 176