• 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.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          try {
58              Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_3");
59              fail("expected a verification exception");
60          } catch (Throwable t) {
61              DxUtil.checkVerifyException(t);
62          }
63     }
64 
65     /**
66      * @constraint A23
67      * @title  number of registers
68      */
testVFE2()69     public void testVFE2() {
70         try {
71             Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_4");
72             fail("expected a verification exception");
73         } catch (Throwable t) {
74             DxUtil.checkVerifyException(t);
75         }
76 
77     }
78 
79     /**
80      * @constraint B1
81      * @title try to pass obj ref instead of int
82      */
testVFE3()83     public void testVFE3() {
84         try {
85             Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_5");
86             fail("expected a verification exception");
87         } catch (Throwable t) {
88             DxUtil.checkVerifyException(t);
89         }
90     }
91 
92     /**
93      * @constraint B1
94      * @title try to pass long instead of int
95      */
testVFE4()96     public void testVFE4() {
97         try {
98             Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_6");
99             fail("expected a verification exception");
100         } catch (Throwable t) {
101             DxUtil.checkVerifyException(t);
102         }
103     }
104 
105     /**
106      * @constraint B1
107      * @title try to create non-array type
108      */
testVFE5()109     public void testVFE5() {
110         try {
111             Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_7");
112             fail("expected a verification exception");
113         } catch (Throwable t) {
114             DxUtil.checkVerifyException(t);
115         }
116     }
117 
118     /**
119      * @constraint B1
120      * @title invalid arg count
121      */
testVFE6()122     public void testVFE6() {
123         try {
124             Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_8");
125             fail("expected a verification exception");
126         } catch (Throwable t) {
127             DxUtil.checkVerifyException(t);
128         }
129     }
130 
131     /**
132      * @constraint n/a
133      * @title attempt to instantiate String[] and fill it with reference to assignment-incompatible class
134      */
testVFE7()135     public void testVFE7() {
136         try {
137             Class.forName("dot.junit.opcodes.filled_new_array.d.T_filled_new_array_9");
138             fail("expected a verification exception");
139         } catch(Throwable t) {
140             DxUtil.checkVerifyException(t);
141         }
142     }
143 
144     /**
145      * @constraint n/a
146      * @title attempt to instantiate array of non-existent class
147      */
testVFE8()148     public void testVFE8() {
149         //@uses dot.junit.opcodes.filled_new_array.d.T_filled_new_array_10
150         try {
151             T_filled_new_array_10 T = new T_filled_new_array_10();
152             T.run();
153             fail("expected a NoClassDefFoundError exception");
154         } catch(NoClassDefFoundError t) {
155             // expected
156         }
157     }
158 
159     /**
160      * @constraint n/a
161      * @title attempt to instantiate array of inaccessible class
162      */
testVFE9()163     public void testVFE9() {
164         //@uses dot.junit.opcodes.filled_new_array.d.T_filled_new_array_11
165         //@uses dot.junit.opcodes.filled_new_array.TestStubs
166         try {
167             T_filled_new_array_11 T = new T_filled_new_array_11();
168             T.run();
169             fail("expected a IllegalAccessError exception");
170         } catch(IllegalAccessError t) {
171             // expected
172         }
173     }
174 
175 }
176