• 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.multianewarray;
18 
19 import dxc.junit.DxTestCase;
20 import dxc.junit.DxUtil;
21 import dxc.junit.opcodes.multianewarray.jm.T_multianewarray_1;
22 import dxc.junit.opcodes.multianewarray.jm.T_multianewarray_2;
23 import dxc.junit.opcodes.multianewarray.jm.T_multianewarray_7;
24 import dxc.junit.opcodes.multianewarray.jm.T_multianewarray_9;
25 
26 public class Test_multianewarray extends DxTestCase {
27 
28     /**
29      * @title normal test
30      */
testN1()31     public void testN1() {
32         T_multianewarray_1 t = new T_multianewarray_1();
33         String[][][] res = t.run(2, 5, 4);
34 
35         assertEquals(2, res.length);
36 
37         // check default initialization
38         for (int i = 0; i < 2; i++) {
39             assertEquals(5, res[i].length);
40 
41             for (int j = 0; j < 5; j++) {
42                 assertEquals(4, res[i][j].length);
43 
44                 for (int k = 0; j < 4; j++) {
45                     assertNull(res[i][j][k]);
46                 }
47             }
48         }
49     }
50 
51     /**
52      * @title  if count is zero, no subsequent dimensions allocated
53      */
testN2()54     public void testN2() {
55         T_multianewarray_1 t = new T_multianewarray_1();
56         String[][][] res = t.run(2, 0, 4);
57 
58         try {
59             String s = res[2][0][0];
60             fail("expected ArrayIndexOutOfBoundsException");
61             fail("dummy for s "+s);
62         } catch (ArrayIndexOutOfBoundsException ae) {
63             // expected
64         }
65     }
66 
67     /**
68      * @title  multinewarray must only be used to create array with
69      * dimensions specified by dimensions operand
70      */
testN3()71     public void testN3() {
72         T_multianewarray_9 t = new T_multianewarray_9();
73         String[][][] res = t.run(2, 1, 4);
74 
75         if (res.length != 2) fail("incorrect multiarray length");
76         if (res[0].length != 1) fail("incorrect array length");
77 
78         try {
79             int i = res[0][0].length;
80             fail("expected NullPointerException");
81             fail("dummy for i "+i);
82         } catch (NullPointerException npe) {
83             // expected
84         }
85     }
86 
87     /**
88      * @title expected NegativeArraySizeException
89      */
testE1()90     public void testE1() {
91         T_multianewarray_1 t = new T_multianewarray_1();
92         try {
93             t.run(2, -5, 3);
94             fail("expected NegativeArraySizeException");
95         } catch (NegativeArraySizeException nase) {
96             // expected
97         }
98     }
99 
100     /**
101      * @title expected IllegalAccessError
102      */
testE2()103     public void testE2() {
104         // @uses dxc.junit.opcodes.multianewarray.jm.sub.TestStubs$TestStub
105         try {
106             T_multianewarray_2 t = new T_multianewarray_2();
107             t.run(2, 5, 3);
108             fail("expected IllegalAccessError");
109         } catch (IllegalAccessError iae) {
110             // expected
111         } catch (VerifyError vfe) {
112             // ok for dalvikvm;
113             System.out.print("dvmvfe:");
114         }
115     }
116 
117     /**
118      * @title expected NoClassDefFoundError
119      */
testE3()120     public void testE3() {
121         try {
122         T_multianewarray_7 t = new T_multianewarray_7();
123             t.run(2, 5, 3);
124             fail("expected NoClassDefFoundError");
125         } catch (NoClassDefFoundError e) {
126             // expected
127         } catch (VerifyError vfe) {
128             // ok for dalvikvm;
129             System.out.print("dvmvfe:");
130         }
131     }
132 
133     /**
134      * @constraint 4.8.1.16
135      * @title constant pool index
136      */
testVFE1()137     public void testVFE1() {
138         try {
139             Class
140                     .forName("dxc.junit.opcodes.multianewarray.jm.T_multianewarray_3");
141             fail("expected a verification exception");
142         } catch (Throwable t) {
143             DxUtil.checkVerifyException(t);
144         }
145     }
146 
147     /**
148      * @constraint 4.8.2.1
149      * @title number of arguments
150      */
testVFE2()151     public void testVFE2() {
152         try {
153             Class
154                     .forName("dxc.junit.opcodes.multianewarray.jm.T_multianewarray_4");
155             fail("expected a verification exception");
156         } catch (Throwable t) {
157             DxUtil.checkVerifyException(t);
158         }
159     }
160 
161     /**
162      * @constraint 4.8.2.1
163      * @title type of argument - float
164      */
testVFE3()165     public void testVFE3() {
166         try {
167             Class
168                     .forName("dxc.junit.opcodes.multianewarray.jm.T_multianewarray_5");
169             fail("expected a verification exception");
170         } catch (Throwable t) {
171             DxUtil.checkVerifyException(t);
172         }
173     }
174 
175     /**
176      * @constraint 4.8.1.19
177      * @title dimension size must not be zero
178      */
testVFE4()179     public void testVFE4() {
180         try {
181             Class
182                     .forName("dxc.junit.opcodes.multianewarray.jm.T_multianewarray_6");
183             fail("expected a verification exception");
184         } catch (Throwable t) {
185             DxUtil.checkVerifyException(t);
186         }
187     }
188 
189     /**
190      * @constraint 4.8.1.16
191      * @title constant pool type
192      */
testVFE5()193     public void testVFE5() {
194         try {
195             Class
196                     .forName("dxc.junit.opcodes.multianewarray.jm.T_multianewarray_8");
197             fail("expected a verification exception");
198         } catch (Throwable t) {
199             DxUtil.checkVerifyException(t);
200         }
201     }
202 
203     /**
204      * @constraint 4.8.2.1
205      * @title type of argument - reference
206      */
testVFE6()207     public void testVFE6() {
208         try {
209             Class
210                     .forName("dxc.junit.opcodes.multianewarray.jm.T_multianewarray_10");
211             fail("expected a verification exception");
212         } catch (Throwable t) {
213             DxUtil.checkVerifyException(t);
214         }
215     }
216 }
217