• 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_boolean;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_1;
22 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_10;
23 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_11;
24 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_12;
25 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_13;
26 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_14;
27 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_15;
28 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_17;
29 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_7;
30 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_8;
31 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_9;
32 
33 
34 public class Test_iput_boolean extends DxTestCase {
35 
36     /**
37      * @title put boolean into field
38      */
testN1()39     public void testN1() {
40         T_iput_boolean_1 t = new T_iput_boolean_1();
41         assertEquals(false, t.st_i1);
42         t.run();
43         assertEquals(true, t.st_i1);
44     }
45 
46 
47     /**
48      * @title modification of final field
49      */
testN2()50     public void testN2() {
51         T_iput_boolean_12 t = new T_iput_boolean_12();
52         assertEquals(false, t.st_i1);
53         t.run();
54         assertEquals(true, t.st_i1);
55     }
56 
57     /**
58      * @title modification of protected field from subclass
59      */
testN4()60     public void testN4() {
61         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_1
62         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_14
63         T_iput_boolean_14 t = new T_iput_boolean_14();
64         assertEquals(false, t.getProtectedField());
65         t.run();
66         assertEquals(true, t.getProtectedField());
67     }
68 
69 
70 
71     /**
72      * @title expected NullPointerException
73      */
testE2()74     public void testE2() {
75         T_iput_boolean_13 t = new T_iput_boolean_13();
76         try {
77             t.run();
78             fail("expected NullPointerException");
79         } catch (NullPointerException e) {
80             // expected
81         }
82     }
83 
84     /**
85      * @constraint A11
86      * @title constant pool index
87      */
testVFE1()88     public void testVFE1() {
89         try {
90             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_3");
91             fail("expected a verification exception");
92         } catch (Throwable t) {
93             DxUtil.checkVerifyException(t);
94         }
95     }
96 
97     /**
98      * @constraint A23
99      * @title number of registers
100      */
testVFE2()101     public void testVFE2() {
102         try {
103             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_4");
104             fail("expected a verification exception");
105         } catch (Throwable t) {
106             DxUtil.checkVerifyException(t);
107         }
108     }
109 
110 
111     /**
112      * @constraint B14
113      * @title put boolean into long field - only field with same name but
114      * different type exists
115      */
testVFE5()116     public void testVFE5() {
117         try {
118             new T_iput_boolean_17().run();
119             fail("expected NoSuchFieldError");
120         } catch (NoSuchFieldError t) {
121         }
122     }
123 
124     /**
125      *
126      * @constraint B14
127      * @title put value '2' into boolean field
128      */
testVFE6()129     public void testVFE6() {
130         try {
131             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_6");
132             fail("expected a verification exception");
133         } catch (Throwable t) {
134             DxUtil.checkVerifyException(t);
135         }
136     }
137 
138     /**
139      *
140      * @constraint B14
141      * @title type of field doesn't match opcode - attempt to modify double
142      * field with single-width register
143      */
testVFE7()144     public void testVFE7() {
145         try {
146             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_18");
147             fail("expected a verification exception");
148         } catch (Throwable t) {
149             DxUtil.checkVerifyException(t);
150         }
151     }
152 
153     /**
154      *
155      * @constraint A11
156      * @title Attempt to set static field.
157      */
testVFE8()158     public void testVFE8() {
159          try {
160              new T_iput_boolean_7().run();
161              fail("expected IncompatibleClassChangeError");
162          } catch (IncompatibleClassChangeError t) {
163          }
164     }
165 
166     /**
167      * @constraint B12
168      * @title Attempt to modify inaccessible protected field.
169      */
testVFE9()170     public void testVFE9() {
171         //@uses dot.junit.opcodes.iput_boolean.TestStubs
172         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_8
173         try {
174             new T_iput_boolean_8().run();
175             fail("expected IllegalAccessError");
176         } catch (IllegalAccessError t) {
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_boolean_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_boolean_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_boolean.d.T_iput_boolean_1
212         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_15
213         try {
214             new T_iput_boolean_15().run();
215             fail("expected IllegalAccessError");
216         } catch (IllegalAccessError t) {
217         }
218     }
219 
220 
221     /**
222      * @constraint B1
223      * @title iput_boolean shall not work for wide numbers
224      */
testVFE13()225     public void testVFE13() {
226         try {
227             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_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_boolean shall not work for reference fields
238      */
testVFE14()239     public void testVFE14() {
240         try {
241             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_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_boolean shall not work for short fields
252      */
testVFE15()253     public void testVFE15() {
254         try {
255             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_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_boolean shall not work for int fields
266      */
testVFE16()267     public void testVFE16() {
268         try {
269             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_22");
270             fail("expected a verification exception");
271         } catch (Throwable t) {
272             DxUtil.checkVerifyException(t);
273         }
274     }
275 
276     /**
277      * @constraint B1
278      * @title iput_boolean shall not work for char fields
279      */
testVFE17()280     public void testVFE17() {
281         try {
282             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_23");
283             fail("expected a verification exception");
284         } catch (Throwable t) {
285             DxUtil.checkVerifyException(t);
286         }
287     }
288 
289     /**
290      * @constraint B1
291      * @title iput_boolean shall not work for byte fields
292      */
testVFE18()293     public void testVFE18() {
294         try {
295             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_24");
296             fail("expected a verification exception");
297         } catch (Throwable t) {
298             DxUtil.checkVerifyException(t);
299         }
300     }
301 
302     /**
303      * @constraint B6
304      * @title instance fields may only be accessed on already initialized instances.
305      */
testVFE30()306     public void testVFE30() {
307         try {
308             Class.forName("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_30");
309             fail("expected a verification exception");
310         } catch (Throwable t) {
311             DxUtil.checkVerifyException(t);
312         }
313     }
314 
315     /**
316      * @constraint n/a
317      * @title Modification of final field in other class
318      */
testVFE19()319     public void testVFE19() {
320         //@uses dot.junit.opcodes.iput_boolean.TestStubs
321         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_11
322         try {
323             new T_iput_boolean_11().run();
324             fail("expected IllegalAccessError");
325         } catch (IllegalAccessError t) {
326         }
327     }
328 }
329 
330