• 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.iput_wide;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.iput_wide.d.T_iput_wide_1;
22 import dot.junit.opcodes.iput_wide.d.T_iput_wide_10;
23 import dot.junit.opcodes.iput_wide.d.T_iput_wide_11;
24 import dot.junit.opcodes.iput_wide.d.T_iput_wide_12;
25 import dot.junit.opcodes.iput_wide.d.T_iput_wide_13;
26 import dot.junit.opcodes.iput_wide.d.T_iput_wide_14;
27 import dot.junit.opcodes.iput_wide.d.T_iput_wide_15;
28 import dot.junit.opcodes.iput_wide.d.T_iput_wide_17;
29 import dot.junit.opcodes.iput_wide.d.T_iput_wide_5;
30 import dot.junit.opcodes.iput_wide.d.T_iput_wide_7;
31 import dot.junit.opcodes.iput_wide.d.T_iput_wide_8;
32 import dot.junit.opcodes.iput_wide.d.T_iput_wide_9;
33 
34 public class Test_iput_wide extends DxTestCase {
35     /**
36      * @title put long into field
37      */
testN1()38     public void testN1() {
39         T_iput_wide_1 t = new T_iput_wide_1();
40         assertEquals(0, t.st_i1);
41         t.run();
42         assertEquals(778899112233l, t.st_i1);
43     }
44 
45     /**
46      * @title put double into field
47      */
testN2()48     public void testN2() {
49         T_iput_wide_5 t = new T_iput_wide_5();
50         assertEquals(0.0d, t.st_i1);
51         t.run();
52         assertEquals(0.5d, t.st_i1);
53     }
54 
55 
56     /**
57      * @title modification of final field
58      */
testN3()59     public void testN3() {
60         T_iput_wide_12 t = new T_iput_wide_12();
61         assertEquals(0, t.st_i1);
62         t.run();
63         assertEquals(77, t.st_i1);
64     }
65 
66     /**
67      * @title modification of protected field from subclass
68      */
testN4()69     public void testN4() {
70         //@uses dot.junit.opcodes.iput_wide.d.T_iput_wide_1
71         //@uses dot.junit.opcodes.iput_wide.d.T_iput_wide_14
72         T_iput_wide_14 t = new T_iput_wide_14();
73         assertEquals(0, t.getProtectedField());
74         t.run();
75         assertEquals(77, t.getProtectedField());
76     }
77 
78     /**
79      * @title expected NullPointerException
80      */
testE2()81     public void testE2() {
82         T_iput_wide_13 t = new T_iput_wide_13();
83         try {
84             t.run();
85             fail("expected NullPointerException");
86         } catch (NullPointerException e) {
87             // expected
88         }
89     }
90 
91 
92 
93     /**
94      * @constraint A11
95      * @title constant pool index
96      */
testVFE1()97     public void testVFE1() {
98         try {
99             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_3");
100             fail("expected a verification exception");
101         } catch (Throwable t) {
102             DxUtil.checkVerifyException(t);
103         }
104     }
105 
106     /**
107      *
108      * @constraint A23
109      * @title number of registers
110      */
testVFE2()111     public void testVFE2() {
112         try {
113             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_4");
114             fail("expected a verification exception");
115         } catch (Throwable t) {
116             DxUtil.checkVerifyException(t);
117         }
118     }
119 
120 
121     /**
122      *
123      * @constraint B14
124      * @title put int into long field - only field with same name but
125      * different type exists
126      */
testVFE5()127     public void testVFE5() {
128         try {
129             new T_iput_wide_17().run();
130             fail("expected NoSuchFieldError");
131         } catch (NoSuchFieldError t) {
132         }
133     }
134 
135 
136 
137     /**
138      *
139      * @constraint B14
140      * @title type of field doesn't match opcode - attempt to modify float
141      * field with double-width register
142      */
testVFE7()143     public void testVFE7() {
144         try {
145             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_18");
146             fail("expected a verification exception");
147         } catch (Throwable t) {
148             DxUtil.checkVerifyException(t);
149         }
150     }
151 
152     /**
153      *
154      * @constraint A11
155      * @title Attempt to set non-static field.
156      */
testVFE8()157     public void testVFE8() {
158          try {
159              new T_iput_wide_7().run();
160              fail("expected IncompatibleClassChangeError");
161          } catch (IncompatibleClassChangeError t) {
162          }
163     }
164 
165     /**
166      * @constraint B12
167      * @title Attempt to modify inaccessible protected field.
168      */
testVFE9()169     public void testVFE9() {
170         //@uses dot.junit.opcodes.iput_wide.TestStubs
171         //@uses dot.junit.opcodes.iput_wide.d.T_iput_wide_8
172         try {
173             new T_iput_wide_8().run();
174             fail("expected IllegalAccessError");
175         } catch (IllegalAccessError t) {
176         }
177     }
178 
179 
180     /**
181      * @constraint n/a
182      * @title Attempt to modify field of undefined class.
183      */
testVFE10()184     public void testVFE10() {
185         try {
186             new T_iput_wide_9().run();
187             fail("expected NoClassDefFoundError");
188         } catch (NoClassDefFoundError t) {
189         }
190     }
191 
192     /**
193      * @constraint n/a
194      * @title Attempt to modify undefined field.
195      */
testVFE11()196     public void testVFE11() {
197         try {
198             new T_iput_wide_10().run();
199             fail("expected NoSuchFieldError");
200         } catch (NoSuchFieldError t) {
201         }
202     }
203 
204 
205 
206     /**
207      * @constraint n/a
208      * @title Attempt to modify superclass' private field from subclass.
209      */
testVFE12()210     public void testVFE12() {
211         //@uses dot.junit.opcodes.iput_wide.d.T_iput_wide_1
212         //@uses dot.junit.opcodes.iput_wide.d.T_iput_wide_15
213         try {
214             new T_iput_wide_15().run();
215             fail("expected IllegalAccessError");
216         } catch (IllegalAccessError t) {
217         }
218     }
219 
220 
221     /**
222      * @constraint B1
223      * @title iput-wide shall not work for single-width numbers
224      */
testVFE13()225     public void testVFE13() {
226         try {
227             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_2");
228             fail("expected a verification exception");
229         } catch (Throwable t) {
230             DxUtil.checkVerifyException(t);
231         }
232     }
233 
234     /**
235      *
236      * @constraint B1
237      * @title iput-wide shall not work for reference fields
238      */
testVFE14()239     public void testVFE14() {
240         try {
241             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_20");
242             fail("expected a verification exception");
243         } catch (Throwable t) {
244             DxUtil.checkVerifyException(t);
245         }
246     }
247 
248     /**
249      *
250      * @constraint B1
251      * @title iput-wide shall not work for char fields
252      */
testVFE15()253     public void testVFE15() {
254         try {
255             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_21");
256             fail("expected a verification exception");
257         } catch (Throwable t) {
258             DxUtil.checkVerifyException(t);
259         }
260     }
261 
262     /**
263      *
264      * @constraint B1
265      * @title iput-wide shall not work for int fields
266      */
testVFE16()267     public void testVFE16() {
268         try {
269             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_22");
270             fail("expected a verification exception");
271         } catch (Throwable t) {
272             DxUtil.checkVerifyException(t);
273         }
274     }
275 
276     /**
277      *
278      * @constraint B1
279      * @title iput-wide shall not work for byte fields
280      */
testVFE17()281     public void testVFE17() {
282         try {
283             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_23");
284             fail("expected a verification exception");
285         } catch (Throwable t) {
286             DxUtil.checkVerifyException(t);
287         }
288     }
289 
290     /**
291      *
292      * @constraint B1
293      * @title iput-wide shall not work for boolean fields
294      */
testVFE18()295     public void testVFE18() {
296         try {
297             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_24");
298             fail("expected a verification exception");
299         } catch (Throwable t) {
300             DxUtil.checkVerifyException(t);
301         }
302     }
303 
304     /**
305      *
306      * @constraint B1
307      * @title iput-wide shall not work for short fields
308      */
testVFE6()309     public void testVFE6() {
310         try {
311             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_6");
312             fail("expected a verification exception");
313         } catch (Throwable t) {
314             DxUtil.checkVerifyException(t);
315         }
316     }
317 
318 
319 
320     /**
321      * @constraint B6
322      * @title instance fields may only be accessed on already initialized instances.
323      */
testVFE30()324     public void testVFE30() {
325         try {
326             Class.forName("dot.junit.opcodes.iput_wide.d.T_iput_wide_30");
327             fail("expected a verification exception");
328         } catch (Throwable t) {
329             DxUtil.checkVerifyException(t);
330         }
331     }
332 
333     /**
334      * @constraint n/a
335      * @title Modification of final field in other class
336      */
testE5()337     public void testE5() {
338         //@uses dot.junit.opcodes.iput_wide.TestStubs
339         //@uses dot.junit.opcodes.iput_wide.d.T_iput_wide_11
340         try {
341             new T_iput_wide_11().run();
342             fail("expected IllegalAccessError");
343         } catch (IllegalAccessError t) {
344         }
345     }
346 }
347 
348