• 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.sget;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.sget.d.T_sget_1;
22 import dot.junit.opcodes.sget.d.T_sget_11;
23 import dot.junit.opcodes.sget.d.T_sget_12;
24 import dot.junit.opcodes.sget.d.T_sget_13;
25 import dot.junit.opcodes.sget.d.T_sget_2;
26 import dot.junit.opcodes.sget.d.T_sget_5;
27 import dot.junit.opcodes.sget.d.T_sget_6;
28 import dot.junit.opcodes.sget.d.T_sget_7;
29 import dot.junit.opcodes.sget.d.T_sget_8;
30 import dot.junit.opcodes.sget.d.T_sget_9;
31 
32 public class Test_sget extends DxTestCase {
33 
34     /**
35      * @title type - int
36      */
testN1()37     public void testN1() {
38         T_sget_1 t = new T_sget_1();
39         assertEquals(5, t.run());
40     }
41 
42     /**
43      * @title type - float
44      */
testN2()45     public void testN2() {
46         T_sget_2 t = new T_sget_2();
47         assertEquals(123f, t.run());
48     }
49 
50     /**
51      * @title access protected field from subclass
52      */
testN3()53     public void testN3() {
54         //@uses dot.junit.opcodes.sget.d.T_sget_1
55         //@uses dot.junit.opcodes.sget.d.T_sget_11
56         T_sget_11 t = new T_sget_11();
57         assertEquals(10, t.run());
58     }
59 
60     /**
61      * @constraint A12
62      * @title attempt to access non-static field
63      */
testE1()64     public void testE1() {
65         T_sget_5 t = new T_sget_5();
66         try {
67             t.run();
68             fail("expected IncompatibleClassChangeError");
69         } catch (IncompatibleClassChangeError e) {
70             // expected
71         }
72     }
73 
74     /**
75      * @title initialization of referenced class throws exception
76      */
testE6()77     public void testE6() {
78         T_sget_9 t = new T_sget_9();
79         try {
80             t.run();
81             fail("expected Error");
82         } catch (Error e) {
83             // expected
84         }
85     }
86 
87     /**
88      * @constraint A12
89      * @title constant pool index
90      */
testVFE1()91     public void testVFE1() {
92         try {
93             Class.forName("dot.junit.opcodes.sget.d.T_sget_4");
94             fail("expected a verification exception");
95         } catch (Throwable t) {
96             DxUtil.checkVerifyException(t);
97         }
98     }
99 
100     /**
101      *
102      * @constraint A23
103      * @title number of registers
104      */
testVFE2()105     public void testVFE2() {
106         try {
107             Class.forName("dot.junit.opcodes.sget.d.T_sget_3");
108             fail("expected a verification exception");
109         } catch (Throwable t) {
110             DxUtil.checkVerifyException(t);
111         }
112     }
113 
114     /**
115      *
116      * @constraint B13
117      * @title read integer from long field - only field with same name but
118      * different type exists
119      */
testVFE3()120     public void testVFE3() {
121         try {
122             new T_sget_13().run();
123             fail("expected NoSuchFieldError");
124         } catch (NoSuchFieldError t) {
125         }
126     }
127 
128     /**
129      * @constraint n/a
130      * @title Attempt to read inaccessible field.
131      */
testVFE4()132     public void testVFE4() {
133         //@uses dot.junit.opcodes.sget.d.T_sget_6
134         //@uses dot.junit.opcodes.sget.TestStubs
135         try {
136             new T_sget_6().run();
137             fail("expected IllegalAccessError");
138         } catch (IllegalAccessError t) {
139         }
140     }
141 
142     /**
143      * @constraint n/a
144      * @title Attempt to read field of undefined class.
145      */
testVFE5()146     public void testVFE5() {
147         try {
148             new T_sget_7().run();
149             fail("expected NoClassDefFoundError");
150         } catch (NoClassDefFoundError t) {
151         }
152     }
153 
154     /**
155      * @constraint n/a
156      * @title Attempt to read undefined field.
157      */
testVFE6()158     public void testVFE6() {
159         try {
160             new T_sget_8().run();
161             fail("expected NoSuchFieldError");
162         } catch (NoSuchFieldError t) {
163         }
164     }
165 
166     /**
167      * @constraint n/a
168      * @title Attempt to read superclass' private field from subclass.
169      */
testVFE7()170     public void testVFE7() {
171         //@uses dot.junit.opcodes.sget.d.T_sget_12
172         //@uses dot.junit.opcodes.sget.d.T_sget_1
173         try {
174             new T_sget_12().run();
175             fail("expected IllegalAccessError");
176         } catch (IllegalAccessError t) {
177         }
178     }
179 
180     /**
181      * @constraint B1
182      * @title sget shall not work for reference fields
183      */
testVFE8()184     public void testVFE8() {
185         try {
186             Class.forName("dot.junit.opcodes.sget.d.T_sget_14");
187             fail("expected a verification exception");
188         } catch (Throwable t) {
189             DxUtil.checkVerifyException(t);
190         }
191     }
192 
193     /**
194      *
195      * @constraint B1
196      * @title sget shall not work for short fields
197      */
testVFE9()198     public void testVFE9() {
199         try {
200             Class.forName("dot.junit.opcodes.sget.d.T_sget_15");
201             fail("expected a verification exception");
202         } catch (Throwable t) {
203             DxUtil.checkVerifyException(t);
204         }
205     }
206 
207     /**
208      *
209      * @constraint B1
210      * @title sget shall not work for boolean fields
211      */
testVFE10()212     public void testVFE10() {
213         try {
214             Class.forName("dot.junit.opcodes.sget.d.T_sget_16");
215             fail("expected a verification exception");
216         } catch (Throwable t) {
217             DxUtil.checkVerifyException(t);
218         }
219     }
220 
221     /**
222      *
223      * @constraint B1
224      * @title sget shall not work for char fields
225      */
testVFE11()226     public void testVFE11() {
227         try {
228             Class.forName("dot.junit.opcodes.sget.d.T_sget_17");
229             fail("expected a verification exception");
230         } catch (Throwable t) {
231             DxUtil.checkVerifyException(t);
232         }
233     }
234 
235     /**
236      *
237      * @constraint B1
238      * @title sget shall not work for byte fields
239      */
testVFE12()240     public void testVFE12() {
241         try {
242             Class.forName("dot.junit.opcodes.sget.d.T_sget_18");
243             fail("expected a verification exception");
244         } catch (Throwable t) {
245             DxUtil.checkVerifyException(t);
246         }
247     }
248 
249     /**
250      *
251      * @constraint B1
252      * @title sget shall not work for double fields
253      */
testVFE13()254     public void testVFE13() {
255         try {
256             Class.forName("dot.junit.opcodes.sget.d.T_sget_19");
257             fail("expected a verification exception");
258         } catch (Throwable t) {
259             DxUtil.checkVerifyException(t);
260         }
261     }
262 
263     /**
264      *
265      * @constraint B1
266      * @title sget shall not work for long fields
267      */
testVFE14()268     public void testVFE14() {
269         try {
270             Class.forName("dot.junit.opcodes.sget.d.T_sget_20");
271             fail("expected a verification exception");
272         } catch (Throwable t) {
273             DxUtil.checkVerifyException(t);
274         }
275     }
276 }
277