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;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.sput.d.T_sput_1;
22 import dot.junit.opcodes.sput.d.T_sput_10;
23 import dot.junit.opcodes.sput.d.T_sput_11;
24 import dot.junit.opcodes.sput.d.T_sput_12;
25 import dot.junit.opcodes.sput.d.T_sput_13;
26 import dot.junit.opcodes.sput.d.T_sput_14;
27 import dot.junit.opcodes.sput.d.T_sput_15;
28 import dot.junit.opcodes.sput.d.T_sput_17;
29 import dot.junit.opcodes.sput.d.T_sput_19;
30 import dot.junit.opcodes.sput.d.T_sput_5;
31 import dot.junit.opcodes.sput.d.T_sput_7;
32 import dot.junit.opcodes.sput.d.T_sput_8;
33 import dot.junit.opcodes.sput.d.T_sput_9;
34 
35 
36 public class Test_sput extends DxTestCase {
37 
38     /**
39      * @title type - int
40      */
testN1()41     public void testN1() {
42         T_sput_1 t = new T_sput_1();
43         assertEquals(0, T_sput_1.st_i1);
44         t.run();
45         assertEquals(1000000, T_sput_1.st_i1);
46     }
47 
48     /**
49      * @title type - float
50      */
testN2()51     public void testN2() {
52         T_sput_19 t = new T_sput_19();
53         assertEquals(0.0f, T_sput_19.st_f1);
54         t.run();
55         assertEquals(3.14f, T_sput_19.st_f1);
56     }
57 
58 
59     /**
60      * @title modification of final field
61      */
testN3()62     public void testN3() {
63         T_sput_12 t = new T_sput_12();
64         assertEquals(0, T_sput_12.st_i1);
65         t.run();
66         assertEquals(1000000, T_sput_12.st_i1);
67     }
68 
69     /**
70      * @title modification of protected field from subclass
71      */
testN4()72     public void testN4() {
73         //@uses dot.junit.opcodes.sput.d.T_sput_1
74         //@uses dot.junit.opcodes.sput.d.T_sput_14
75         T_sput_14 t = new T_sput_14();
76         assertEquals(0, T_sput_14.getProtectedField());
77         t.run();
78         assertEquals(1000000, T_sput_14.getProtectedField());
79     }
80 
81 
82 
83     /**
84      * @title initialization of referenced class throws exception
85      */
testE6()86     public void testE6() {
87         loadAndRun("dot.junit.opcodes.sput.d.T_sput_13", ExceptionInInitializerError.class);
88     }
89 
90     /**
91      * @constraint A12
92      * @title  constant pool index
93      */
testVFE1()94     public void testVFE1() {
95         load("dot.junit.opcodes.sput.d.T_sput_3", VerifyError.class);
96     }
97 
98     /**
99      *
100      * @constraint A23
101      * @title  number of registers
102      */
testVFE2()103     public void testVFE2() {
104         load("dot.junit.opcodes.sput.d.T_sput_4", VerifyError.class);
105     }
106 
107 
108     /**
109      *
110      * @constraint B13
111      * @title  put integer into long field - only field with same name but
112      * different type exists
113      */
testVFE5()114     public void testVFE5() {
115         loadAndRun("dot.junit.opcodes.sput.d.T_sput_17", NoSuchFieldError.class);
116     }
117 
118     /**
119      * @constraint B1
120      * @title Trying to put float into integer field. The verifier checks that ints
121      * and floats are not used interchangeably.
122      */
testVFE6()123     public void testVFE6() {
124         load("dot.junit.opcodes.sput.d.T_sput_5", VerifyError.class);
125     }
126 
127     /**
128      *
129      * @constraint B13
130      * @title type of field doesn't match opcode - attempt to modify double field
131      * with single-width register
132      */
testVFE7()133     public void testVFE7() {
134         load("dot.junit.opcodes.sput.d.T_sput_18", VerifyError.class);
135     }
136 
137     /**
138      *
139      * @constraint A12
140      * @title Attempt to set non-static field.
141      */
testVFE8()142     public void testVFE8() {
143         loadAndRun("dot.junit.opcodes.sput.d.T_sput_7", IncompatibleClassChangeError.class);
144     }
145 
146     /**
147      * @constraint n/a
148      * @title Attempt to modify inaccessible field.
149      */
testVFE9()150     public void testVFE9() {
151         //@uses dot.junit.opcodes.sput.TestStubs
152         loadAndRun("dot.junit.opcodes.sput.d.T_sput_8", IllegalAccessError.class);
153     }
154 
155     /**
156      * @constraint n/a
157      * @title Attempt to modify field of undefined class.
158      */
testVFE10()159     public void testVFE10() {
160         loadAndRun("dot.junit.opcodes.sput.d.T_sput_9", NoClassDefFoundError.class);
161     }
162 
163     /**
164      * @constraint n/a
165      * @title Attempt to modify undefined field.
166      */
testVFE11()167     public void testVFE11() {
168         loadAndRun("dot.junit.opcodes.sput.d.T_sput_10", NoSuchFieldError.class);
169     }
170 
171 
172 
173     /**
174      * @constraint n/a
175      * @title Attempt to modify superclass' private field from subclass.
176      */
testVFE12()177     public void testVFE12() {
178         //@uses dot.junit.opcodes.sput.d.T_sput_1
179         loadAndRun("dot.junit.opcodes.sput.d.T_sput_15", IllegalAccessError.class);
180     }
181 
182 
183     /**
184      * @constraint B1
185      * @title sput shall not work for wide numbers
186      */
testVFE13()187     public void testVFE13() {
188         load("dot.junit.opcodes.sput.d.T_sput_2", VerifyError.class);
189     }
190 
191     /**
192      *
193      * @constraint B1
194      * @title sput shall not work for reference fields
195      */
testVFE14()196     public void testVFE14() {
197         load("dot.junit.opcodes.sput.d.T_sput_20", VerifyError.class);
198     }
199 
200     /**
201      *
202      * @constraint B1
203      * @title sput shall not work for short fields
204      */
testVFE15()205     public void testVFE15() {
206         load("dot.junit.opcodes.sput.d.T_sput_21", VerifyError.class);
207     }
208 
209     /**
210      *
211      * @constraint B1
212      * @title sput shall not work for boolean fields
213      */
testVFE16()214     public void testVFE16() {
215         load("dot.junit.opcodes.sput.d.T_sput_22", VerifyError.class);
216     }
217 
218     /**
219      *
220      * @constraint B1
221      * @title sput shall not work for char fields
222      */
testVFE17()223     public void testVFE17() {
224         load("dot.junit.opcodes.sput.d.T_sput_23", VerifyError.class);
225     }
226 
227     /**
228      *
229      * @constraint B1
230      * @title sput shall not work for byte fields
231      */
testVFE18()232     public void testVFE18() {
233         load("dot.junit.opcodes.sput.d.T_sput_24", VerifyError.class);
234     }
235 
236     /**
237      * @constraint n/a
238      * @title Modification of final field in other class
239      */
testVFE19()240     public void testVFE19() {
241         //@uses dot.junit.opcodes.sput.TestStubs
242         loadAndRun("dot.junit.opcodes.sput.d.T_sput_11", IllegalAccessError.class);
243     }
244 
245 }
246