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; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.aget.d.T_aget_1; 22 import dot.junit.opcodes.aget.d.T_aget_8; 23 24 public class Test_aget extends DxTestCase { 25 /** 26 * @title get int from array 27 */ 28 public void testN1() { 29 T_aget_1 t = new T_aget_1(); 30 int[] arr = new int[2]; 31 arr[1] = 100000000; 32 assertEquals(100000000, t.run(arr, 1)); 33 } 34 35 /** 36 * @title get int from array 37 */ 38 public void testN2() { 39 T_aget_1 t = new T_aget_1(); 40 int[] arr = new int[2]; 41 arr[0] = 100000000; 42 assertEquals(100000000, t.run(arr, 0)); 43 } 44 45 /** 46 * @title Type of index argument - float. Dalvik doens't distinguish 32-bits types internally, 47 * so this array[float] makes no sense but shall not crash the VM. 48 */ 49 50 public void testN3() { 51 int[] arr = new int[2]; 52 T_aget_8 t = new T_aget_8(); 53 try { 54 t.run(arr, 3.14f); 55 } catch (Throwable e) { 56 } 57 } 58 59 /** 60 * @title expected ArrayIndexOutOfBoundsException 61 */ 62 public void testE1() { 63 T_aget_1 t = new T_aget_1(); 64 int[] arr = new int[2]; 65 try { 66 t.run(arr, 2); 67 fail("expected ArrayIndexOutOfBoundsException"); 68 } catch (ArrayIndexOutOfBoundsException aie) { 69 // expected 70 } 71 } 72 73 /** 74 * @title expected NullPointerException 75 */ 76 public void testE2() { 77 T_aget_1 t = new T_aget_1(); 78 try { 79 t.run(null, 2); 80 fail("expected NullPointerException"); 81 } catch (NullPointerException aie) { 82 // expected 83 } 84 } 85 86 /** 87 * @title expected ArrayIndexOutOfBoundsException (negative index) 88 */ 89 public void testE3() { 90 T_aget_1 t = new T_aget_1(); 91 int[] arr = new int[2]; 92 try { 93 t.run(arr, -1); 94 fail("expected ArrayIndexOutOfBoundsException"); 95 } catch (ArrayIndexOutOfBoundsException aie) { 96 // expected 97 } 98 } 99 100 101 102 /** 103 * @constraint B1 104 * @title types of arguments - array, double 105 */ 106 public void testVFE1() { 107 try { 108 Class.forName("dot.junit.opcodes.aget.d.T_aget_2"); 109 fail("expected a verification exception"); 110 } catch (Throwable t) { 111 DxUtil.checkVerifyException(t); 112 } 113 } 114 115 /** 116 * @constraint B1 117 * @title types of arguments - array, long 118 */ 119 public void testVFE2() { 120 try { 121 Class.forName("dot.junit.opcodes.aget.d.T_aget_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 - Object, int 131 */ 132 public void testVFE3() { 133 try { 134 Class.forName("dot.junit.opcodes.aget.d.T_aget_4"); 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 - double[], int 144 */ 145 public void testVFE4() { 146 try { 147 Class.forName("dot.junit.opcodes.aget.d.T_aget_5"); 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 - long[], int 157 */ 158 public void testVFE5() { 159 try { 160 Class.forName("dot.junit.opcodes.aget.d.T_aget_6"); 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 testVFE6() { 172 try { 173 Class.forName("dot.junit.opcodes.aget.d.T_aget_7"); 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 testVFE7() { 185 try { 186 Class.forName("dot.junit.opcodes.aget.d.T_aget_9"); 187 fail("expected a verification exception"); 188 } catch (Throwable t) { 189 DxUtil.checkVerifyException(t); 190 } 191 } 192 193 } 194