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