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.aput_object; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.aput_object.d.T_aput_object_1; 22 import dot.junit.opcodes.aput_object.d.T_aput_object_12; 23 import dot.junit.opcodes.aput_object.d.T_aput_object_2; 24 import dot.junit.opcodes.aput_object.d.T_aput_object_3; 25 import dot.junit.opcodes.aput_object.d.T_aput_object_4; 26 27 public class Test_aput_object extends DxTestCase { 28 /** 29 * @title put reference into array 30 */ 31 public void testN1() { 32 T_aput_object_1 t = new T_aput_object_1(); 33 String[] arr = new String[2]; 34 t.run(arr, 0, "hello"); 35 assertEquals("hello", arr[0]); 36 } 37 38 /** 39 * @title put reference into array 40 */ 41 public void testN2() { 42 T_aput_object_1 t = new T_aput_object_1(); 43 String[] value = {"world", null, ""}; 44 String[] arr = new String[2]; 45 for (int i = 0; i < value.length; i++) { 46 t.run(arr, 1, value[i]); 47 assertEquals(value[i], arr[1]); 48 } 49 } 50 51 /** 52 * @title put reference into array 53 */ 54 public void testN3() { 55 T_aput_object_2 t = new T_aput_object_2(); 56 Integer[] arr = new Integer[2]; 57 Integer value = new Integer(12345); 58 t.run(arr, 0, value); 59 assertEquals(value, arr[0]); 60 } 61 62 /** 63 * @title Check assignement compatibility rules 64 */ 65 public void testN4() { 66 T_aput_object_3 t = new T_aput_object_3(); 67 assertEquals(3, t.run()); 68 69 } 70 71 /** 72 * @title expected ArrayIndexOutOfBoundsException 73 */ 74 public void testE1() { 75 T_aput_object_1 t = new T_aput_object_1(); 76 String[] arr = new String[2]; 77 try { 78 t.run(arr, arr.length, "abc"); 79 fail("expected ArrayIndexOutOfBoundsException"); 80 } catch (ArrayIndexOutOfBoundsException aie) { 81 // expected 82 } 83 } 84 85 /** 86 * @title expected ArrayIndexOutOfBoundsException (negative index) 87 */ 88 public void testE2() { 89 T_aput_object_1 t = new T_aput_object_1(); 90 String[] arr = new String[2]; 91 try { 92 t.run(arr, -1, "abc"); 93 fail("expected ArrayIndexOutOfBoundsException"); 94 } catch (ArrayIndexOutOfBoundsException aie) { 95 // expected 96 } 97 } 98 99 /** 100 * @title expected NullPointerException 101 */ 102 public void testE3() { 103 T_aput_object_1 t = new T_aput_object_1(); 104 String[] arr = null; 105 try { 106 t.run(arr, 0, "abc"); 107 fail("expected NullPointerException"); 108 } catch (NullPointerException aie) { 109 // expected 110 } 111 } 112 113 /** 114 * @title expected ArrayStoreException 115 */ 116 public void testE4() { 117 T_aput_object_4 t = new T_aput_object_4(); 118 String[] arr = new String[2]; 119 try { 120 t.run(arr, 0, t); 121 fail("expected ArrayStoreException"); 122 } catch (ArrayStoreException aie) { 123 // expected 124 } 125 } 126 127 128 /** 129 * @constraint B1 130 * @title types of arguments - array, double, String 131 */ 132 public void testVFE1() { 133 try { 134 Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_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 - array, int, long 144 */ 145 public void testVFE2() { 146 try { 147 Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_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 - object, int, String 157 */ 158 public void testVFE3() { 159 try { 160 Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_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 - float[], int, String 170 */ 171 public void testVFE4() { 172 try { 173 Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_8"); 174 fail("expected a verification exception"); 175 } catch (Throwable t) { 176 DxUtil.checkVerifyException(t); 177 } 178 } 179 180 /** 181 * @constraint B1 182 * @title types of arguments - long[], int, String 183 */ 184 public void testVFE5() { 185 try { 186 Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_9"); 187 fail("expected a verification exception"); 188 } catch (Throwable t) { 189 DxUtil.checkVerifyException(t); 190 } 191 } 192 193 /** 194 * @constraint B1 195 * @title types of arguments - array, reference, String 196 */ 197 public void testVFE6() { 198 try { 199 Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_10"); 200 fail("expected a verification exception"); 201 } catch (Throwable t) { 202 DxUtil.checkVerifyException(t); 203 } 204 } 205 206 /** 207 * @constraint A23 208 * @title number of registers 209 */ 210 public void testVFE7() { 211 try { 212 Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_11"); 213 fail("expected a verification exception"); 214 } catch (Throwable t) { 215 DxUtil.checkVerifyException(t); 216 } 217 } 218 219 /** 220 * @constraint B15 221 * @title put integer into array of references 222 */ 223 public void testVFE8() { 224 try { 225 Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_13"); 226 fail("expected a verification exception"); 227 } catch (Throwable t) { 228 DxUtil.checkVerifyException(t); 229 } 230 } 231 232 /** 233 * @constraint B1 234 * @title Type of index argument - float. The verifier checks that ints 235 * and floats are not used interchangeably. 236 */ 237 public void testVFE9() { 238 try { 239 Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_12"); 240 fail("expected a verification exception"); 241 } catch (Throwable t) { 242 DxUtil.checkVerifyException(t); 243 } 244 } 245 } 246