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.iget_object;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.iget_object.d.T_iget_object_1;
22 import dot.junit.opcodes.iget_object.d.T_iget_object_11;
23 import dot.junit.opcodes.iget_object.d.T_iget_object_12;
24 import dot.junit.opcodes.iget_object.d.T_iget_object_13;
25 import dot.junit.opcodes.iget_object.d.T_iget_object_21;
26 import dot.junit.opcodes.iget_object.d.T_iget_object_22;
27 import dot.junit.opcodes.iget_object.d.T_iget_object_5;
28 import dot.junit.opcodes.iget_object.d.T_iget_object_6;
29 import dot.junit.opcodes.iget_object.d.T_iget_object_7;
30 import dot.junit.opcodes.iget_object.d.T_iget_object_8;
31 import dot.junit.opcodes.iget_object.d.T_iget_object_9;
32 
33 public class Test_iget_object extends DxTestCase {
34 
35     /**
36      * @title get reference from field
37      */
testN1()38     public void testN1() {
39         T_iget_object_1 t = new T_iget_object_1();
40         assertEquals(null, t.run());
41     }
42 
43 
44     /**
45      * @title access protected field from subclass
46      */
testN3()47     public void testN3() {
48         //@uses dot.junit.opcodes.iget_object.d.T_iget_object_1
49         //@uses dot.junit.opcodes.iget_object.d.T_iget_object_11
50         T_iget_object_11 t = new T_iget_object_11();
51         assertEquals(null, t.run());
52     }
53 
54     /**
55      * @title expected NullPointerException
56      */
testE2()57     public void testE2() {
58         loadAndRun("dot.junit.opcodes.iget_object.d.T_iget_object_9", NullPointerException.class);
59     }
60 
61     /**
62      * @constraint A11
63      * @title constant pool index
64      */
testVFE1()65     public void testVFE1() {
66         load("dot.junit.opcodes.iget_object.d.T_iget_object_4", VerifyError.class);
67     }
68 
69     /**
70      *
71      * @constraint A23
72      * @title number of registers
73      */
testVFE2()74     public void testVFE2() {
75         load("dot.junit.opcodes.iget_object.d.T_iget_object_3", VerifyError.class);
76     }
77 
78     /**
79      *
80      * @constraint B13
81      * @title  (read object from long field - only field with same name but
82      * different type exists)
83      */
testVFE3()84     public void testVFE3() {
85         loadAndRun("dot.junit.opcodes.iget_object.d.T_iget_object_13", NoSuchFieldError.class);
86     }
87 
88     /**
89      * @constraint n/a
90      * @title Attempt to read inaccessible field.
91      */
testVFE4()92     public void testVFE4() {
93         //@uses dot.junit.opcodes.iget_object.TestStubs
94         loadAndRun("dot.junit.opcodes.iget_object.d.T_iget_object_6", IllegalAccessError.class);
95     }
96 
97     /**
98      * @constraint n/a
99      * @title Attempt to read field of undefined class.
100      */
testVFE5()101     public void testVFE5() {
102         loadAndRun("dot.junit.opcodes.iget_object.d.T_iget_object_7", NoClassDefFoundError.class);
103     }
104 
105     /**
106      * @constraint n/a
107      * @title Attempt to read undefined field.
108      */
testVFE6()109     public void testVFE6() {
110         loadAndRun("dot.junit.opcodes.iget_object.d.T_iget_object_8", NoSuchFieldError.class);
111     }
112 
113     /**
114      * @constraint n/a
115      * @title Attempt to read superclass' private field from subclass.
116      */
testVFE7()117     public void testVFE7() {
118         //@uses dot.junit.opcodes.iget_object.d.T_iget_object_1
119         loadAndRun("dot.junit.opcodes.iget_object.d.T_iget_object_12", IllegalAccessError.class);
120     }
121 
122     /**
123      * @constraint B1
124      * @title iget_object shall not work for short fields
125      */
testVFE8()126     public void testVFE8() {
127         load("dot.junit.opcodes.iget_object.d.T_iget_object_14", VerifyError.class);
128     }
129 
130     /**
131      *
132      * @constraint B1
133      * @title iget_object shall not work for char fields
134      */
testVFE9()135     public void testVFE9() {
136         load("dot.junit.opcodes.iget_object.d.T_iget_object_15", VerifyError.class);
137     }
138 
139     /**
140      *
141      * @constraint B1
142      * @title iget_object shall not work for int fields
143      */
testVFE10()144     public void testVFE10() {
145         load("dot.junit.opcodes.iget_object.d.T_iget_object_16", VerifyError.class);
146     }
147 
148     /**
149      *
150      * @constraint B1
151      * @title iget_object shall not work for byte fields
152      */
testVFE11()153     public void testVFE11() {
154         load("dot.junit.opcodes.iget_object.d.T_iget_object_17", VerifyError.class);
155     }
156 
157     /**
158      *
159      * @constraint B1
160      * @title iget_object shall not work for boolean fields
161      */
testVFE12()162     public void testVFE12() {
163         load("dot.junit.opcodes.iget_object.d.T_iget_object_18", VerifyError.class);
164     }
165 
166     /**
167      *
168      * @constraint B1
169      * @title iget_object shall not work for double fields
170      */
testVFE13()171     public void testVFE13() {
172         load("dot.junit.opcodes.iget_object.d.T_iget_object_19", VerifyError.class);
173     }
174 
175     /**
176      *
177      * @constraint B1
178      * @title iget_object shall not work for long fields
179      */
testVFE14()180     public void testVFE14() {
181         load("dot.junit.opcodes.iget_object.d.T_iget_object_20", VerifyError.class);
182     }
183 
184     /**
185      *
186      * @constraint B13
187      * @title  only field of different type exists
188      */
testVFE15()189     public void testVFE15() {
190         loadAndRun("dot.junit.opcodes.iget_object.d.T_iget_object_21", NoSuchFieldError.class);
191     }
192 
193     /**
194      * @constraint B12
195      * @title Attempt to read inaccessible protected field.
196      */
testVFE16()197     public void testVFE16() {
198         //@uses dot.junit.opcodes.iget_object.TestStubs
199         loadAndRun("dot.junit.opcodes.iget_object.d.T_iget_object_22", IllegalAccessError.class);
200     }
201 
202     /**
203      * @constraint A11
204      * @title Attempt to read static field.
205      */
testVFE17()206     public void testVFE17() {
207         //@uses dot.junit.opcodes.iget_object.TestStubs
208         loadAndRun("dot.junit.opcodes.iget_object.d.T_iget_object_5",
209                    IncompatibleClassChangeError.class);
210     }
211 
212     /**
213      * @constraint B6
214      * @title instance fields may only be accessed on already initialized instances.
215      */
testVFE30()216     public void testVFE30() {
217         load("dot.junit.opcodes.iget_object.d.T_iget_object_30", VerifyError.class);
218     }
219 
220     /**
221      * @constraint N/A
222      * @title instance fields may only be accessed on already initialized instances.
223      */
testVFE31()224     public void testVFE31() {
225         load("dot.junit.opcodes.iget_object.d.T_iget_object_31", VerifyError.class);
226     }
227 }
228