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