• 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 dot.junit.opcodes.new_array;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.new_array.d.T_new_array_1;
22 import dot.junit.opcodes.new_array.d.T_new_array_10;
23 import dot.junit.opcodes.new_array.d.T_new_array_11;
24 import dot.junit.opcodes.new_array.d.T_new_array_2;
25 import dot.junit.opcodes.new_array.d.T_new_array_3;
26 
27 public class Test_new_array extends DxTestCase {
28 
29     /**
30      * @title Array of ints
31      */
testN1()32     public void testN1() {
33         T_new_array_1 t = new T_new_array_1();
34         int[] r = t.run(10);
35         int l = r.length;
36         assertEquals(10, l);
37 
38         // check default initialization
39         for (int i = 0; i < l; i++) {
40             assertEquals(0, r[i]);
41         }
42 
43     }
44 
45     /**
46      * @title Array of booleans
47      */
testN2()48     public void testN2() {
49         T_new_array_2 t = new T_new_array_2();
50         boolean[] r = t.run(10);
51         int l = r.length;
52         assertEquals(10, l);
53 
54         // check default initialization
55         for (int i = 0; i < l; i++) {
56             assertFalse(r[i]);
57         }
58     }
59 
60     /**
61      * @title Array of Objects
62      */
testN3()63     public void testN3() {
64         T_new_array_3 t = new T_new_array_3();
65         Object[] r = t.run(10);
66         int l = r.length;
67         assertEquals(10, l);
68 
69         // check default initialization
70         for (int i = 0; i < l; i++) {
71             assertNull(r[i]);
72         }
73     }
74 
75     /**
76      * @title Array size = 0
77      */
testB1()78     public void testB1() {
79         T_new_array_1 t = new T_new_array_1();
80         int[] r = t.run(0);
81         assertNotNull(r);
82         assertEquals(0, r.length);
83     }
84 
85     /**
86      * @title expected NegativeArraySizeException
87      */
testE1()88     public void testE1() {
89         T_new_array_2 t = new T_new_array_2();
90         try {
91             t.run(-1);
92             fail("expected NegativeArraySizeException");
93         } catch (NegativeArraySizeException nase) {
94             // expected
95         }
96     }
97 
98 
99     /**
100      * @constraint B1
101      * @title  number of registers
102      */
testVFE1()103     public void testVFE1() {
104         try {
105             Class.forName("dot.junit.opcodes.new_array.d.T_new_array_4");
106             fail("expected a verification exception");
107         } catch (Throwable t) {
108             DxUtil.checkVerifyException(t);
109         }
110     }
111 
112     /**
113      *
114      * @constraint B1
115      * @title  size argument - long
116      */
testVFE2()117     public void testVFE2() {
118         try {
119             Class.forName("dot.junit.opcodes.new_array.d.T_new_array_5");
120             fail("expected a verification exception");
121         } catch (Throwable t) {
122             DxUtil.checkVerifyException(t);
123         }
124     }
125 
126     /**
127      *
128      * @constraint B1
129      * @title  size argument - reference
130      */
testVFE3()131     public void testVFE3() {
132         try {
133             Class.forName("dot.junit.opcodes.new_array.d.T_new_array_9");
134             fail("expected a verification exception");
135         } catch (Throwable t) {
136             DxUtil.checkVerifyException(t);
137         }
138     }
139 
140     /**
141      *
142      * @constraint A19
143      * @title  constant pool index
144      */
testVFE4()145     public void testVFE4() {
146         try {
147             Class.forName("dot.junit.opcodes.new_array.d.T_new_array_6");
148             fail("expected a verification exception");
149         } catch (Throwable t) {
150             DxUtil.checkVerifyException(t);
151         }
152     }
153 
154     /**
155      *
156      * @constraint A22
157      * @title  attempt to create object
158      */
testVFE5()159     public void testVFE5() {
160         try {
161             Class.forName("dot.junit.opcodes.new_array.d.T_new_array_7");
162             fail("expected a verification exception");
163         } catch (Throwable t) {
164             DxUtil.checkVerifyException(t);
165         }
166     }
167 
168     /**
169      *
170      * @constraint A20
171      * @title  array of more than 255 dimensions
172      */
testVFE6()173     public void testVFE6() {
174         try {
175             Class.forName("dot.junit.opcodes.new_array.d.T_new_array_8");
176             fail("expected a verification exception");
177         } catch (Throwable t) {
178             DxUtil.checkVerifyException(t);
179         }
180     }
181 
182     /**
183      * @constraint n/a
184      * @title Attempt to instantiate array of non-existent class.
185      */
testVFE7()186     public void testVFE7() {
187         try {
188             new T_new_array_11().run();
189             fail("expected NoClassDefFoundError");
190         } catch (NoClassDefFoundError t) {
191         }
192     }
193 
194     /**
195      * @constraint n/a
196      * @title Attempt to instantiate array of inaccessible class.
197      */
testVFE8()198     public void testVFE8() {
199         //@uses dot.junit.opcodes.new_array.TestStubs
200         try {
201             new T_new_array_10().run();
202             fail("expected IllegalAccessError");
203         } catch (IllegalAccessError t) {
204         }
205     }
206 
207 }
208