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.aget_wide; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.aget_wide.d.T_aget_wide_1; 22 import dot.junit.opcodes.aget_wide.d.T_aget_wide_10; 23 import dot.junit.opcodes.aget_wide.d.T_aget_wide_2; 24 25 26 public class Test_aget_wide extends DxTestCase { 27 28 /** 29 * @title get long from array 30 */ 31 public void testN1() { 32 T_aget_wide_1 t = new T_aget_wide_1(); 33 long[] arr = new long[2]; 34 arr[1] = 1000000000000000000l; 35 assertEquals(1000000000000000000l, t.run(arr, 1)); 36 } 37 38 /** 39 * @title get long from array 40 */ 41 public void testN2() { 42 T_aget_wide_1 t = new T_aget_wide_1(); 43 long[] arr = new long[2]; 44 arr[0] = 1000000000000000000l; 45 assertEquals(1000000000000000000l, t.run(arr, 0)); 46 } 47 48 /** 49 * @title get double from array 50 */ 51 public void testN3() { 52 T_aget_wide_2 t = new T_aget_wide_2(); 53 double[] arr = new double[2]; 54 arr[0] = 3.1415d; 55 assertEquals(3.1415d, t.run(arr, 0)); 56 } 57 58 /** 59 * @title Type of index argument - float. Dalvik doens't distinguish 32-bits types internally, 60 * so this array[float] makes no sense but shall not crash the VM. 61 */ 62 63 public void testN4() { 64 long[] arr = new long[2]; 65 T_aget_wide_10 t = new T_aget_wide_10(); 66 try { 67 t.run(arr, 3.14f); 68 } catch (Throwable e) { 69 } 70 } 71 72 /** 73 * @title expected ArrayIndexOutOfBoundsException 74 */ 75 public void testE1() { 76 T_aget_wide_1 t = new T_aget_wide_1(); 77 long[] arr = new long[2]; 78 try { 79 t.run(arr, 2); 80 fail("expected ArrayIndexOutOfBoundsException"); 81 } catch (ArrayIndexOutOfBoundsException aie) { 82 // expected 83 } 84 } 85 86 /** 87 * @title expected NullPointerException 88 */ 89 public void testE2() { 90 T_aget_wide_1 t = new T_aget_wide_1(); 91 try { 92 t.run(null, 2); 93 fail("expected NullPointerException"); 94 } catch (NullPointerException np) { 95 // expected 96 } 97 } 98 99 /** 100 * @title expected ArrayIndexOutOfBoundsException (negative index) 101 */ 102 public void testE3() { 103 T_aget_wide_1 t = new T_aget_wide_1(); 104 long[] arr = new long[2]; 105 try { 106 t.run(arr, -1); 107 fail("expected ArrayIndexOutOfBoundsException"); 108 } catch (ArrayIndexOutOfBoundsException aie) { 109 // expected 110 } 111 } 112 113 114 115 /** 116 * @constraint B1 117 * @title types of arguments - array, double 118 */ 119 public void testVFE1() { 120 try { 121 Class.forName("dot.junit.opcodes.aget_wide.d.T_aget_wide_3"); 122 fail("expected a verification exception"); 123 } catch (Throwable t) { 124 DxUtil.checkVerifyException(t); 125 } 126 } 127 128 /** 129 * @constraint B1 130 * @title types of arguments - array, long 131 */ 132 public void testVFE2() { 133 try { 134 Class.forName("dot.junit.opcodes.aget_wide.d.T_aget_wide_5"); 135 fail("expected a verification exception"); 136 } catch (Throwable t) { 137 DxUtil.checkVerifyException(t); 138 } 139 } 140 141 /** 142 * @constraint B1 143 * @title types of arguments - Object, int 144 */ 145 public void testVFE3() { 146 try { 147 Class.forName("dot.junit.opcodes.aget_wide.d.T_aget_wide_6"); 148 fail("expected a verification exception"); 149 } catch (Throwable t) { 150 DxUtil.checkVerifyException(t); 151 } 152 } 153 154 /** 155 * @constraint B1 156 * @title types of arguments - int[], int 157 */ 158 public void testVFE4() { 159 try { 160 Class.forName("dot.junit.opcodes.aget_wide.d.T_aget_wide_7"); 161 fail("expected a verification exception"); 162 } catch (Throwable t) { 163 DxUtil.checkVerifyException(t); 164 } 165 } 166 167 /** 168 * @constraint B1 169 * @title types of arguments - array, reference 170 */ 171 public void testVFE5() { 172 try { 173 Class.forName("dot.junit.opcodes.aget_wide.d.T_aget_wide_8"); 174 fail("expected a verification exception"); 175 } catch (Throwable t) { 176 DxUtil.checkVerifyException(t); 177 } 178 } 179 180 /** 181 * @constraint A23 182 * @title number of registers 183 */ 184 public void testVFE6() { 185 try { 186 Class.forName("dot.junit.opcodes.aget_wide.d.T_aget_wide_9"); 187 fail("expected a verification exception"); 188 } catch (Throwable t) { 189 DxUtil.checkVerifyException(t); 190 } 191 } 192 193 /** 194 * @constraint A24 195 * @title number of registers 196 */ 197 public void testVFE7() { 198 try { 199 Class.forName("dot.junit.opcodes.aget_wide.d.T_aget_wide_11"); 200 fail("expected a verification exception"); 201 } catch (Throwable t) { 202 DxUtil.checkVerifyException(t); 203 } 204 } 205 } 206