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