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_object;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.sput_object.d.T_sput_object_1;
22 import dot.junit.opcodes.sput_object.d.T_sput_object_10;
23 import dot.junit.opcodes.sput_object.d.T_sput_object_11;
24 import dot.junit.opcodes.sput_object.d.T_sput_object_12;
25 import dot.junit.opcodes.sput_object.d.T_sput_object_13;
26 import dot.junit.opcodes.sput_object.d.T_sput_object_14;
27 import dot.junit.opcodes.sput_object.d.T_sput_object_15;
28 import dot.junit.opcodes.sput_object.d.T_sput_object_17;
29 import dot.junit.opcodes.sput_object.d.T_sput_object_7;
30 import dot.junit.opcodes.sput_object.d.T_sput_object_8;
31 import dot.junit.opcodes.sput_object.d.T_sput_object_9;
32 
33 public class Test_sput_object extends DxTestCase {
34     /**
35      * @title put reference into static field
36      */
testN1()37     public void testN1() {
38         T_sput_object_1 t = new T_sput_object_1();
39         assertEquals(null, T_sput_object_1.st_i1);
40         t.run();
41         assertEquals(t, T_sput_object_1.st_i1);
42     }
43 
44 
45     /**
46      * @title modification of final field
47      */
testN2()48     public void testN2() {
49         T_sput_object_12 t = new T_sput_object_12();
50         assertEquals(null, T_sput_object_12.st_i1);
51         t.run();
52         assertEquals(t, T_sput_object_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_object.d.T_sput_object_1
60         //@uses dot.junit.opcodes.sput_object.d.T_sput_object_14
61         T_sput_object_14 t = new T_sput_object_14();
62         assertEquals(null, T_sput_object_14.getProtectedField());
63         t.run();
64         assertEquals(t, T_sput_object_14.getProtectedField());
65     }
66 
67 
68     /**
69      * @title initialization of referenced class throws exception
70      */
testE6()71     public void testE6() {
72         loadAndRun("dot.junit.opcodes.sput_object.d.T_sput_object_13",
73                    ExceptionInInitializerError.class);
74     }
75 
76     /**
77      * @constraint A12
78      * @title constant pool index
79      */
testVFE1()80     public void testVFE1() {
81         load("dot.junit.opcodes.sput_object.d.T_sput_object_3", VerifyError.class);
82     }
83 
84     /**
85      *
86      * @constraint A23
87      * @title number of registers
88      */
testVFE2()89     public void testVFE2() {
90         load("dot.junit.opcodes.sput_object.d.T_sput_object_4", VerifyError.class);
91     }
92 
93 
94     /**
95      *
96      * @constraint B13
97      * @title put object into long field - only field with same name but
98      * different type exists
99      */
testVFE5()100     public void testVFE5() {
101         loadAndRun("dot.junit.opcodes.sput_object.d.T_sput_object_17", NoSuchFieldError.class);
102     }
103 
104 
105     /**
106      *
107      * @constraint B13
108      * @title type of field doesn't match opcode - attempt to modify double
109      * field with single-width register
110      */
testVFE7()111     public void testVFE7() {
112         load("dot.junit.opcodes.sput_object.d.T_sput_object_18", VerifyError.class);
113     }
114 
115     /**
116      *
117      * @constraint A12
118      * @title Attempt to set non-static field.
119      */
testVFE8()120     public void testVFE8() {
121         loadAndRun("dot.junit.opcodes.sput_object.d.T_sput_object_7",
122                    IncompatibleClassChangeError.class);
123    }
124 
125     /**
126      * @constraint n/a
127      * @title Attempt to modify inaccessible field.
128      */
testVFE9()129     public void testVFE9() {
130         //@uses dot.junit.opcodes.sput_object.TestStubs
131         loadAndRun("dot.junit.opcodes.sput_object.d.T_sput_object_8", IllegalAccessError.class);
132     }
133 
134     /**
135      * @constraint n/a
136      * @title Attempt to modify field of undefined class.
137      */
testVFE10()138     public void testVFE10() {
139         loadAndRun("dot.junit.opcodes.sput_object.d.T_sput_object_9", NoClassDefFoundError.class);
140     }
141 
142     /**
143      * @constraint n/a
144      * @title Attempt to modify undefined field.
145      */
testVFE11()146     public void testVFE11() {
147         loadAndRun("dot.junit.opcodes.sput_object.d.T_sput_object_10", NoSuchFieldError.class);
148     }
149 
150 
151 
152     /**
153      * @constraint n/a
154      * @title Attempt to modify superclass' private field from subclass.
155      */
testVFE12()156     public void testVFE12() {
157         //@uses dot.junit.opcodes.sput_object.d.T_sput_object_1
158         loadAndRun("dot.junit.opcodes.sput_object.d.T_sput_object_15", IllegalAccessError.class);
159     }
160 
161 
162     /**
163      * @constraint B1
164      * @title sput-object shall not work for wide numbers
165      */
testVFE13()166     public void testVFE13() {
167         load("dot.junit.opcodes.sput_object.d.T_sput_object_2", VerifyError.class);
168     }
169 
170     /**
171      *
172      * @constraint B13
173      * @title assignment incompatible references
174      */
testVFE14()175     public void testVFE14() {
176         load("dot.junit.opcodes.sput_object.d.T_sput_object_20", VerifyError.class);
177     }
178 
179     /**
180      *
181      * @constraint B1
182      * @title sput-object shall not work for char fields
183      */
testVFE15()184     public void testVFE15() {
185         load("dot.junit.opcodes.sput_object.d.T_sput_object_21", VerifyError.class);
186     }
187 
188     /**
189      *
190      * @constraint B1
191      * @title sput-object shall not work for int fields
192      */
testVFE16()193     public void testVFE16() {
194         load("dot.junit.opcodes.sput_object.d.T_sput_object_22", VerifyError.class);
195     }
196 
197     /**
198      *
199      * @constraint B1
200      * @title sput-object shall not work for byte fields
201      */
testVFE17()202     public void testVFE17() {
203         load("dot.junit.opcodes.sput_object.d.T_sput_object_23", VerifyError.class);
204     }
205 
206     /**
207      *
208      * @constraint B1
209      * @title sput-object shall not work for boolean fields
210      */
testVFE18()211     public void testVFE18() {
212         load("dot.junit.opcodes.sput_object.d.T_sput_object_24", VerifyError.class);
213     }
214 
215     /**
216      *
217      * @constraint B1
218      * @title sput-object shall not work for short fields
219      */
testVFE6()220     public void testVFE6() {
221         load("dot.junit.opcodes.sput_object.d.T_sput_object_6", VerifyError.class);
222     }
223 
224 
225     /**
226      * @constraint B1
227      * @title Modification of final field in other class
228      */
testVFE19()229     public void testVFE19() {
230         //@uses dot.junit.opcodes.sput_object.TestStubs
231         loadAndRun("dot.junit.opcodes.sput_object.d.T_sput_object_11", IllegalAccessError.class);
232     }
233 }
234