• 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         loadAndRun("dot.junit.opcodes.new_array.d.T_new_array_2", NegativeArraySizeException.class,
90                    -1);
91     }
92 
93 
94     /**
95      * @constraint B1
96      * @title  number of registers
97      */
testVFE1()98     public void testVFE1() {
99         load("dot.junit.opcodes.new_array.d.T_new_array_4", VerifyError.class);
100     }
101 
102     /**
103      *
104      * @constraint B1
105      * @title  size argument - long
106      */
testVFE2()107     public void testVFE2() {
108         load("dot.junit.opcodes.new_array.d.T_new_array_5", VerifyError.class);
109     }
110 
111     /**
112      *
113      * @constraint B1
114      * @title  size argument - reference
115      */
testVFE3()116     public void testVFE3() {
117         load("dot.junit.opcodes.new_array.d.T_new_array_9", VerifyError.class);
118     }
119 
120     /**
121      *
122      * @constraint A19
123      * @title  constant pool index
124      */
testVFE4()125     public void testVFE4() {
126         load("dot.junit.opcodes.new_array.d.T_new_array_6", VerifyError.class);
127     }
128 
129     /**
130      *
131      * @constraint A22
132      * @title  attempt to create object
133      */
testVFE5()134     public void testVFE5() {
135         load("dot.junit.opcodes.new_array.d.T_new_array_7", VerifyError.class);
136     }
137 
138     /**
139      *
140      * @constraint A20
141      * @title  array of more than 255 dimensions
142      */
testVFE6()143     public void testVFE6() {
144         load("dot.junit.opcodes.new_array.d.T_new_array_8", ClassNotFoundException.class);
145     }
146 
147     /**
148      * @constraint n/a
149      * @title Attempt to instantiate array of non-existent class.
150      */
testVFE7()151     public void testVFE7() {
152         loadAndRun("dot.junit.opcodes.new_array.d.T_new_array_11", NoClassDefFoundError.class);
153     }
154 
155     /**
156      * @constraint n/a
157      * @title Attempt to instantiate array of inaccessible class.
158      */
testVFE8()159     public void testVFE8() {
160         //@uses dot.junit.opcodes.new_array.TestStubs
161         loadAndRun("dot.junit.opcodes.new_array.d.T_new_array_10", IllegalAccessError.class);
162     }
163 
164 }
165