• 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_instance;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.new_instance.d.T_new_instance_1;
22 import dot.junit.opcodes.new_instance.d.T_new_instance_3;
23 import dot.junit.opcodes.new_instance.d.T_new_instance_8;
24 import dot.junit.opcodes.new_instance.d.T_new_instance_9;
25 
26 
27 public class Test_new_instance extends DxTestCase {
28 
29     /**
30      * @title new String
31      */
testN1()32     public void testN1() {
33         T_new_instance_1 t = new T_new_instance_1();
34         String s = t.run();
35         assertNotNull(s);
36         assertEquals(0, s.compareTo("abc"));
37     }
38 
39     /**
40      * @title class initialization throws exception
41      */
testE1()42     public void testE1() {
43         try {
44             T_new_instance_3.run();
45             fail("expected Error");
46         } catch (Error e) {
47             // expected
48         }
49     }
50 
51     /**
52      * @constraint A21
53      * @title  attempt to instantiate interface
54      */
testE4()55     public void testE4() {
56         //@uses dot.junit.opcodes.new_instance.d.TestAbstractClass
57         //@uses dot.junit.opcodes.new_instance.d.T_new_instance_8
58         T_new_instance_8 t = new T_new_instance_8();
59         try {
60             t.run();
61             fail("expected InstantiationError");
62         } catch (InstantiationError ie) {
63             // expected
64         }
65     }
66 
67     /**
68      * @constraint A21
69      * @title  attempt to instantiate abstract
70      * class
71      */
testE5()72     public void testE5() {
73         //@uses dot.junit.opcodes.new_instance.d.TestAbstractClass
74         //@uses dot.junit.opcodes.new_instance.d.T_new_instance_9
75         T_new_instance_9 t = new T_new_instance_9();
76         try {
77             t.run();
78             fail("expected Error");
79         } catch (Error iae) {
80             // expected
81         }
82     }
83 
84     /**
85      * @constraint A18
86      * @title  constant pool index
87      */
testVFE1()88     public void testVFE1() {
89         try {
90             Class.forName("dot.junit.opcodes.new_instance.d.T_new_instance_6");
91             fail("expected a verification exception");
92         } catch (Throwable t) {
93             DxUtil.checkVerifyException(t);
94         }
95     }
96 
97     /**
98      *
99      * @constraint A21
100      * @title  attempt to create array using new
101      */
testVFE2()102     public void testVFE2() {
103         try {
104             Class.forName("dot.junit.opcodes.new_instance.d.T_new_instance_7");
105             fail("expected a verification exception");
106         } catch (Throwable t) {
107             DxUtil.checkVerifyException(t);
108         }
109     }
110 
111     /**
112      * @constraint B6
113      * @title Attempt to access uninitialized class (before <init> is
114      * called
115      */
testVFE3()116     public void testVFE3() {
117         try {
118             Class.forName("dot.junit.opcodes.new_instance.d.T_new_instance_2");
119             fail("expected a verification exception");
120         } catch (Throwable t) {
121             DxUtil.checkVerifyException(t);
122         }
123     }
124 
125     /**
126      * @constraint A23
127      * @title number of registers
128      */
testVFE4()129     public void testVFE4() {
130         try {
131             Class.forName("dot.junit.opcodes.new_instance.d.T_new_instance_10");
132             fail("expected a verification exception");
133         } catch (Throwable t) {
134             DxUtil.checkVerifyException(t);
135         }
136     }
137 
138     /**
139      * @constraint n/a
140      * @title Attempt to instantiate array of inaccessible class. Java
141      * throws IllegalAccessError on first access but Dalvik throws VerifyError on class loading.
142      */
testVFE5()143     public void testVFE5() {
144         //@uses dot.junit.opcodes.new_instance.TestStubs
145         //@uses dot.junit.opcodes.new_instance.d.T_new_instance_4
146         try {
147             Class.forName("dot.junit.opcodes.new_instance.d.T_new_instance_4");
148             fail("expected a verification exception");
149         } catch (Throwable t) {
150             DxUtil.checkVerifyException(t);
151         }
152     }
153 
154     /**
155      * @constraint n/a
156      * @title Attempt to instantiate array of non-existent class. Java
157      * throws NoClassDefFoundError on first access but Dalvik throws VerifyError on class loading.
158      */
testVFE6()159     public void testVFE6() {
160         try {
161             Class.forName("dot.junit.opcodes.new_instance.d.T_new_instance_5");
162             fail("expected a verification exception");
163         } catch (Throwable t) {
164             DxUtil.checkVerifyException(t);
165         }
166     }
167 
168     /**
169      * @constraint B7
170      * @title A register which holds the result of a new-instance instruction must not be used
171      * if the same new-instance  instruction is again executed before the instance is initialized
172      */
testVFE7()173     public void testVFE7() {
174         try {
175             Class.forName("dot.junit.opcodes.new_instance.d.T_new_instance_11");
176             fail("expected a verification exception");
177         } catch (Throwable t) {
178             DxUtil.checkVerifyException(t);
179         }
180     }
181 
182     /**
183      * @constraint B7
184      * @title A register which holds the result of a new-instance instruction must not be used
185      * if the same new-instance  instruction is again executed before the instance is initialized
186      */
testVFE8()187     public void testVFE8() {
188         try {
189             Class.forName("dot.junit.opcodes.new_instance.d.T_new_instance_12");
190             fail("expected a verification exception");
191         } catch (Throwable t) {
192             DxUtil.checkVerifyException(t);
193         }
194     }
195 }
196