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_10; 23 import dot.junit.opcodes.filled_new_array.d.T_filled_new_array_11; 24 import dot.junit.opcodes.filled_new_array.d.T_filled_new_array_2; 25 26 public class Test_filled_new_array extends DxTestCase { 27 /** 28 * @title array of ints 29 */ testN1()30 public void testN1() { 31 T_filled_new_array_1 t = new T_filled_new_array_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 */ testN2()42 public void testN2() { 43 T_filled_new_array_2 t = new T_filled_new_array_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 A17 54 * @title invalid constant pool index 55 */ testVFE1()56 public void testVFE1() { 57 load("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_3", VerifyError.class); 58 } 59 60 /** 61 * @constraint A23 62 * @title number of registers 63 */ testVFE2()64 public void testVFE2() { 65 load("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_4", VerifyError.class); 66 67 } 68 69 /** 70 * @constraint B1 71 * @title try to pass obj ref instead of int 72 */ testVFE3()73 public void testVFE3() { 74 load("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_5", VerifyError.class); 75 } 76 77 /** 78 * @constraint B1 79 * @title try to pass long instead of int 80 */ testVFE4()81 public void testVFE4() { 82 load("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_6", VerifyError.class); 83 } 84 85 /** 86 * @constraint B1 87 * @title try to create non-array type 88 */ testVFE5()89 public void testVFE5() { 90 load("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_7", VerifyError.class); 91 } 92 93 /** 94 * @constraint B1 95 * @title invalid arg count 96 */ testVFE6()97 public void testVFE6() { 98 load("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_8", VerifyError.class); 99 } 100 101 /** 102 * @constraint n/a 103 * @title attempt to instantiate String[] and fill it with reference to assignment-incompatible class 104 */ testVFE7()105 public void testVFE7() { 106 load("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_9", VerifyError.class); 107 } 108 109 /** 110 * @constraint n/a 111 * @title attempt to instantiate array of non-existent class 112 */ testVFE8()113 public void testVFE8() { 114 loadAndRun("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_10", 115 NoClassDefFoundError.class); 116 } 117 118 /** 119 * @constraint n/a 120 * @title attempt to instantiate array of inaccessible class 121 */ testVFE9()122 public void testVFE9() { 123 //@uses dot.junit.opcodes.filled_new_array.TestStubs 124 loadAndRun("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_11", 125 IllegalAccessError.class); 126 } 127 128 } 129