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.filled_new_array_range; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_1; 22 import dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_10; 23 import dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_11; 24 import dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_2; 25 26 public class Test_filled_new_array_range extends DxTestCase { 27 /** 28 * @title array of ints 29 */ 30 public void testN1() { 31 T_filled_new_array_range_1 t = new T_filled_new_array_range_1(); 32 int[] arr = t.run(1, 2, 3, 4, 5); 33 assertNotNull(arr); 34 assertEquals(5, arr.length); 35 for(int i = 0; i < 5; i++) 36 assertEquals(i + 1, arr[i]); 37 } 38 39 /** 40 * @title array of objects 41 */ 42 public void testN2() { 43 T_filled_new_array_range_2 t = new T_filled_new_array_range_2(); 44 String s = "android"; 45 Object[] arr = t.run(t, s); 46 assertNotNull(arr); 47 assertEquals(2, arr.length); 48 assertEquals(t, arr[0]); 49 assertEquals(s, arr[1]); 50 } 51 52 /** 53 * @constraint A18 54 * @title invalid constant pool index 55 */ 56 public void testVFE1() { 57 try { 58 Class.forName("dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_3"); 59 fail("expected a verification exception"); 60 } catch (Throwable t) { 61 DxUtil.checkVerifyException(t); 62 } 63 } 64 65 /** 66 * @constraint A23 67 * @title number of registers 68 */ 69 public void testVFE2() { 70 try { 71 Class.forName("dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_4"); 72 fail("expected a verification exception"); 73 } catch (Throwable t) { 74 DxUtil.checkVerifyException(t); 75 } 76 } 77 78 /** 79 * @constraint B1 80 * @title try to pass obj ref instead of int 81 */ 82 public void testVFE3() { 83 try { 84 Class.forName("dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_5"); 85 fail("expected a verification exception"); 86 } catch (Throwable t) { 87 DxUtil.checkVerifyException(t); 88 } 89 } 90 91 /** 92 * @constraint B1 93 * @title try to pass long instead of int 94 */ 95 public void testVFE4() { 96 try { 97 Class.forName("dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_6"); 98 fail("expected a verification exception"); 99 } catch (Throwable t) { 100 DxUtil.checkVerifyException(t); 101 } 102 } 103 104 /** 105 * @constraint B1 106 * @title try to create non-array type 107 */ 108 public void testVFE5() { 109 try { 110 Class.forName("dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_7"); 111 fail("expected a verification exception"); 112 } catch (Throwable t) { 113 DxUtil.checkVerifyException(t); 114 } 115 } 116 117 /** 118 * @constraint B1 119 * @title invalid arg count 120 */ 121 public void testVFE6() { 122 try { 123 Class.forName("dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_8"); 124 fail("expected a verification exception"); 125 } catch (Throwable t) { 126 DxUtil.checkVerifyException(t); 127 } 128 } 129 130 /** 131 * @constraint n/a 132 * @title attempt to instantiate String[] and fill it with reference to assignment-incompatible class 133 */ 134 public void testVFE7() { 135 try { 136 Class.forName("dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_9"); 137 fail("expected a verification exception"); 138 } catch(Throwable t) { 139 DxUtil.checkVerifyException(t); 140 } 141 } 142 143 /** 144 * @constraint n/a 145 * @title attempt to instantiate array of non-existent class 146 */ 147 public void testVFE8() { 148 T_filled_new_array_range_10 t = new T_filled_new_array_range_10(); 149 try { 150 t.run(); 151 fail("expected NoClassDefFoundError exception"); 152 } catch (NoClassDefFoundError e) { 153 // expected 154 } 155 } 156 157 /** 158 * @constraint n/a 159 * @title attempt to instantiate array of inaccessible class 160 */ 161 public void testVFE9() { 162 //@uses dot.junit.opcodes.filled_new_array_range.d.T_filled_new_array_range_11 163 //@uses dot.junit.opcodes.filled_new_array_range.TestStubs 164 T_filled_new_array_range_11 t = new T_filled_new_array_range_11(); 165 try { 166 t.run(); 167 fail("expected IllegalAccessError exception"); 168 } catch (IllegalAccessError e) { 169 // expected 170 } 171 } 172 } 173