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_char;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.iget_char.d.T_iget_char_1;
22 import dot.junit.opcodes.iget_char.d.T_iget_char_11;
23 import dot.junit.opcodes.iget_char.d.T_iget_char_12;
24 import dot.junit.opcodes.iget_char.d.T_iget_char_13;
25 import dot.junit.opcodes.iget_char.d.T_iget_char_21;
26 import dot.junit.opcodes.iget_char.d.T_iget_char_5;
27 import dot.junit.opcodes.iget_char.d.T_iget_char_6;
28 import dot.junit.opcodes.iget_char.d.T_iget_char_7;
29 import dot.junit.opcodes.iget_char.d.T_iget_char_8;
30 import dot.junit.opcodes.iget_char.d.T_iget_char_9;
31 
32 public class Test_iget_char extends DxTestCase {
33 
34     /**
35      * @title get char from field
36      */
testN1()37     public void testN1() {
38         T_iget_char_1 t = new T_iget_char_1();
39         assertEquals(77, 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_char.d.T_iget_char_1
48         //@uses dot.junit.opcodes.iget_char.d.T_iget_char_11
49         T_iget_char_11 t = new T_iget_char_11();
50         assertEquals(77, t.run());
51     }
52 
53     /**
54      * @title expected NullPointerException
55      */
testE2()56     public void testE2() {
57         loadAndRun("dot.junit.opcodes.iget_char.d.T_iget_char_9", NullPointerException.class);
58     }
59 
60 
61     /**
62      * @constraint A11
63      * @title constant pool index
64      */
testVFE1()65     public void testVFE1() {
66         load("dot.junit.opcodes.iget_char.d.T_iget_char_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_char.d.T_iget_char_3", VerifyError.class);
76     }
77 
78     /**
79      *
80      * @constraint B13
81      * @title read char 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_char.d.T_iget_char_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_char.TestStubs
94         loadAndRun("dot.junit.opcodes.iget_char.d.T_iget_char_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_char.d.T_iget_char_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_char.d.T_iget_char_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_char.d.T_iget_char_1
119         loadAndRun("dot.junit.opcodes.iget_char.d.T_iget_char_12", IllegalAccessError.class);
120     }
121 
122     /**
123      * @constraint B1
124      * @title iget_char shall not work for reference fields
125      */
testVFE8()126     public void testVFE8() {
127         load("dot.junit.opcodes.iget_char.d.T_iget_char_14", VerifyError.class);
128     }
129 
130     /**
131      *
132      * @constraint B1
133      * @title iget_char shall not work for short fields
134      */
testVFE9()135     public void testVFE9() {
136         load("dot.junit.opcodes.iget_char.d.T_iget_char_15", VerifyError.class);
137     }
138 
139     /**
140      *
141      * @constraint B1
142      * @title iget_char shall not work for int fields
143      */
testVFE10()144     public void testVFE10() {
145         load("dot.junit.opcodes.iget_char.d.T_iget_char_16", VerifyError.class);
146     }
147 
148     /**
149      *
150      * @constraint B1
151      * @title iget_char shall not work for byte fields
152      */
testVFE11()153     public void testVFE11() {
154         load("dot.junit.opcodes.iget_char.d.T_iget_char_17", VerifyError.class);
155     }
156 
157     /**
158      *
159      * @constraint B1
160      * @title iget_char shall not work for boolean fields
161      */
testVFE12()162     public void testVFE12() {
163         load("dot.junit.opcodes.iget_char.d.T_iget_char_18", VerifyError.class);
164     }
165 
166     /**
167      * @constraint B1
168      * @title iget_char shall not work for double fields
169      */
testVFE13()170     public void testVFE13() {
171         load("dot.junit.opcodes.iget_char.d.T_iget_char_19", VerifyError.class);
172     }
173 
174     /**
175      * @constraint B1
176      * @title iget_char shall not work for long fields
177      */
testVFE14()178     public void testVFE14() {
179         load("dot.junit.opcodes.iget_char.d.T_iget_char_20", VerifyError.class);
180     }
181 
182     /**
183      * @constraint B12
184      * @title Attempt to read inaccessible protected field.
185      */
testVFE15()186     public void testVFE15() {
187         //@uses dot.junit.opcodes.iget_char.TestStubs
188         loadAndRun("dot.junit.opcodes.iget_char.d.T_iget_char_21", IllegalAccessError.class);
189     }
190 
191 
192     /**
193      * @constraint A11
194      * @title Attempt to read static  field.
195      */
testVFE16()196     public void testVFE16() {
197         //@uses dot.junit.opcodes.iget_char.TestStubs
198         loadAndRun("dot.junit.opcodes.iget_char.d.T_iget_char_5",
199                    IncompatibleClassChangeError.class);
200     }
201 
202 
203     /**
204      * @constraint B6
205      * @title instance fields may only be accessed on already initialized instances.
206      */
testVFE30()207     public void testVFE30() {
208         load("dot.junit.opcodes.iget_char.d.T_iget_char_30", VerifyError.class);
209     }
210 
211     /**
212      * @constraint N/A
213      * @title instance fields may only be accessed on reference values.
214      */
testVFE31()215     public void testVFE31() {
216         load("dot.junit.opcodes.iget_char.d.T_iget_char_31", VerifyError.class);
217     }
218 }
219