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