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