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