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