• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 dxc.junit.opcodes.anewarray;
18 
19 import dxc.junit.DxTestCase;
20 import dxc.junit.DxUtil;
21 import dxc.junit.opcodes.anewarray.jm.T_anewarray_1;
22 import dxc.junit.opcodes.anewarray.jm.T_anewarray_6;
23 import dxc.junit.opcodes.anewarray.jm.T_anewarray_7;
24 
25 public class Test_anewarray extends DxTestCase {
26 
27     /**
28      * @title Test for Object
29      */
testN1()30     public void testN1() {
31         T_anewarray_1 t = new T_anewarray_1();
32 
33         Object[] arr = t.run(10);
34         assertNotNull(arr);
35         assertEquals(10, arr.length);
36         for (int i = 0; i < 10; i++)
37             assertNull(arr[i]);
38     }
39 
40     /**
41      * @title Test for String
42      */
testN2()43     public void testN2() {
44         T_anewarray_1 t = new T_anewarray_1();
45 
46         String[] arr2 = t.run2(5);
47         assertNotNull(arr2);
48         assertEquals(5, arr2.length);
49         for (int i = 0; i < 5; i++)
50             assertNull(arr2[i]);
51     }
52 
53     /**
54      * @title Test for Integer
55      */
testN3()56     public void testN3() {
57         T_anewarray_1 t = new T_anewarray_1();
58 
59         Integer[] arr3 = t.run3(15);
60         assertNotNull(arr3);
61         assertEquals(15, arr3.length);
62         for (int i = 0; i < 15; i++)
63             assertNull(arr3[i]);
64     }
65 
66     /**
67      * @title if count is zero, no subsequent dimensions allocated
68      */
testE1()69     public void testE1() {
70         T_anewarray_1 t = new T_anewarray_1();
71         Object[] res = t.run(0);
72         try {
73             Object s = res[0];
74             fail("expected ArrayIndexOutOfBoundsException");
75         } catch (ArrayIndexOutOfBoundsException ae) {
76             // expected
77         }
78     }
79 
80     /**
81      * @title expected NegativeArraySizeException
82      */
testE2()83     public void testE2() {
84         T_anewarray_1 t = new T_anewarray_1();
85         try {
86             t.run(-2);
87             fail("expected NegativeArraySizeException");
88         } catch (NegativeArraySizeException nase) {
89             // expected
90         }
91     }
92 
93     /**
94      * @title expected NoClassDefFoundError
95      */
testE3()96     public void testE3() {
97         try {
98             T_anewarray_6 t = new T_anewarray_6();
99             t.run();
100             fail("expected NoClassDefFoundError");
101         } catch (NoClassDefFoundError e) {
102             // expected
103         } catch (VerifyError vfe) {
104             // ok for dalvikvm; eagerly tries to load the array type
105             System.out.print("dvmvfe:");
106         }
107     }
108 
109     /**
110      * @title expected IllegalAccessError
111      * <pre>
112      * V(15469) +++ dvmAddClassToHash '[Ldxc/junit/opcodes/anewarray/jm/TestStubs$TestStub;' 0x973d7708 (isnew=1) --> 0x973e1f10  (dalvikvm)
113      * V(15469) Created array class '[Ldxc/junit/opcodes/anewarray/jm/TestStubs$TestStub;' 0x973d7708 (access=0x6000.0010)  (dalvikvm)
114      * </pre>
115      * TestStub class is private. no IllegalAccessError is thrown, but VerifyError
116      */
testE4()117     public void testE4() {
118         try {
119             T_anewarray_7 t = new T_anewarray_7();
120             t.run();
121             fail("expected IllegalAccessError");
122         } catch (IllegalAccessError e) {
123             // expected
124         } catch (VerifyError vfe) {
125             // ok for dalvikvm;
126             System.out.print("dvmvfe:");
127         }
128     }
129 
130     /**
131      * @constraint 4.8.1.19
132      * @title constant pool index
133      */
testVFE1()134     public void testVFE1() {
135         try {
136             Class.forName("dxc.junit.opcodes.anewarray.jm.T_anewarray_2");
137             fail("expected a verification exception");
138         } catch (Throwable t) {
139             DxUtil.checkVerifyException(t);
140         }
141     }
142 
143     /**
144      * @constraint 4.8.2.1
145      * @title number of arguments
146      */
testVFE2()147     public void testVFE2() {
148         try {
149             Class.forName("dxc.junit.opcodes.anewarray.jm.T_anewarray_3");
150             fail("expected a verification exception");
151         } catch (Throwable t) {
152             DxUtil.checkVerifyException(t);
153         }
154     }
155 
156     /**
157      * @constraint 4.8.2.1
158      * @title type of argument - float
159      */
testVFE3()160     public void testVFE3() {
161         try {
162             Class.forName("dxc.junit.opcodes.anewarray.jm.T_anewarray_4");
163             fail("expected a verification exception");
164         } catch (Throwable t) {
165             DxUtil.checkVerifyException(t);
166         }
167     }
168 
169     /**
170      * @constraint 4.8.1.17
171      * @title array of more than 255 dimensions
172      */
testVFE4()173     public void testVFE4() {
174         try {
175             Class.forName("dxc.junit.opcodes.anewarray.jm.T_anewarray_5");
176             fail("expected a verification exception");
177         } catch (Throwable t) {
178             DxUtil.checkVerifyException(t);
179         }
180     }
181 
182     /**
183      * @constraint 4.8.2.1
184      * @title type of argument - reference
185      */
testVFE5()186     public void testVFE5() {
187         try {
188             Class.forName("dxc.junit.opcodes.anewarray.jm.T_anewarray_8");
189             fail("expected a verification exception");
190         } catch (Throwable t) {
191             DxUtil.checkVerifyException(t);
192         }
193     }
194 
195     /**
196      * @constraint 4.8.1.19
197      * @title constant pool type
198      */
testVFE6()199     public void testVFE6() {
200         try {
201             Class.forName("dxc.junit.opcodes.anewarray.jm.T_anewarray_9");
202             fail("expected a verification exception");
203         } catch (Throwable t) {
204             DxUtil.checkVerifyException(t);
205         }
206     }
207 
208 }
209