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