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; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.filled_new_array.d.T_filled_new_array_1; 22 import dot.junit.opcodes.filled_new_array.d.T_filled_new_array_2; 23 import dot.junit.opcodes.filled_new_array.d.T_filled_new_array_9; 24 25 public class Test_filled_new_array extends DxTestCase { 26 /** 27 * @title array of ints 28 */ testN1()29 public void testN1() { 30 T_filled_new_array_1 t = new T_filled_new_array_1(); 31 int[] arr = t.run(1, 2, 3, 4, 5); 32 assertNotNull(arr); 33 assertEquals(5, arr.length); 34 for(int i = 0; i < 5; i++) 35 assertEquals(i + 1, arr[i]); 36 } 37 38 /** 39 * @title array of objects 40 */ testN2()41 public void testN2() { 42 T_filled_new_array_2 t = new T_filled_new_array_2(); 43 String s = "android"; 44 Object[] arr = t.run(t, s); 45 assertNotNull(arr); 46 assertEquals(2, arr.length); 47 assertEquals(t, arr[0]); 48 assertEquals(s, arr[1]); 49 } 50 51 /** 52 * @constraint A17 53 * @title invalid constant pool index 54 */ testVFE1()55 public void testVFE1() { 56 try { 57 Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_3"); 58 fail("expected a verification exception"); 59 } catch (Throwable t) { 60 DxUtil.checkVerifyException(t); 61 } 62 } 63 64 /** 65 * @constraint A23 66 * @title number of registers 67 */ testVFE2()68 public void testVFE2() { 69 try { 70 Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_4"); 71 fail("expected a verification exception"); 72 } catch (Throwable t) { 73 DxUtil.checkVerifyException(t); 74 } 75 76 } 77 78 /** 79 * @constraint B1 80 * @title try to pass obj ref instead of int 81 */ testVFE3()82 public void testVFE3() { 83 try { 84 Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_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 */ testVFE4()95 public void testVFE4() { 96 try { 97 Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_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 */ testVFE5()108 public void testVFE5() { 109 try { 110 Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_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 */ testVFE6()121 public void testVFE6() { 122 try { 123 Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_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 */ testVFE7()134 public void testVFE7() { 135 try { 136 Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_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 */ testVFE8()147 public void testVFE8() { 148 try { 149 Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_10"); 150 fail("expected a verification exception"); 151 } catch(Throwable t) { 152 DxUtil.checkVerifyException(t); 153 } 154 } 155 156 /** 157 * @constraint n/a 158 * @title attempt to instantiate array of inaccessible class 159 */ testVFE9()160 public void testVFE9() { 161 //@uses dot.junit.opcodes.filled_new_array.d.T_filled_new_array_11 162 //@uses dot.junit.opcodes.filled_new_array.TestStubs 163 try { 164 Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_11"); 165 fail("expected a verification exception"); 166 } catch(Throwable t) { 167 DxUtil.checkVerifyException(t); 168 } 169 } 170 171 } 172