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.iput_boolean;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_1;
22 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_10;
23 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_11;
24 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_12;
25 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_13;
26 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_14;
27 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_15;
28 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_17;
29 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_7;
30 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_8;
31 import dot.junit.opcodes.iput_boolean.d.T_iput_boolean_9;
32 
33 
34 public class Test_iput_boolean extends DxTestCase {
35 
36     /**
37      * @title put boolean into field
38      */
testN1()39     public void testN1() {
40         T_iput_boolean_1 t = new T_iput_boolean_1();
41         assertEquals(false, t.st_i1);
42         t.run();
43         assertEquals(true, t.st_i1);
44     }
45 
46 
47     /**
48      * @title modification of final field
49      */
testN2()50     public void testN2() {
51         T_iput_boolean_12 t = new T_iput_boolean_12();
52         assertEquals(false, t.st_i1);
53         t.run();
54         assertEquals(true, t.st_i1);
55     }
56 
57     /**
58      * @title modification of protected field from subclass
59      */
testN4()60     public void testN4() {
61         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_1
62         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_14
63         T_iput_boolean_14 t = new T_iput_boolean_14();
64         assertEquals(false, t.getProtectedField());
65         t.run();
66         assertEquals(true, t.getProtectedField());
67     }
68 
69 
70 
71     /**
72      * @title expected NullPointerException
73      */
testE2()74     public void testE2() {
75         loadAndRun("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_13",
76                    NullPointerException.class);
77     }
78 
79     /**
80      * @constraint A11
81      * @title constant pool index
82      */
testVFE1()83     public void testVFE1() {
84         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_3", VerifyError.class);
85     }
86 
87     /**
88      * @constraint A23
89      * @title number of registers
90      */
testVFE2()91     public void testVFE2() {
92         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_4", VerifyError.class);
93     }
94 
95     /**
96      * @constraint B14
97      * @title put boolean into long field - only field with same name but
98      * different type exists
99      */
testVFE5()100     public void testVFE5() {
101         loadAndRun("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_17", NoSuchFieldError.class);
102     }
103 
104     /**
105      *
106      * @constraint B14
107      * @title type of field doesn't match opcode - attempt to modify double
108      * field with single-width register
109      */
testVFE7()110     public void testVFE7() {
111         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_18", VerifyError.class);
112     }
113 
114     /**
115      *
116      * @constraint A11
117      * @title Attempt to set static field.
118      */
testVFE8()119     public void testVFE8() {
120         loadAndRun("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_7",
121                    IncompatibleClassChangeError.class);
122     }
123 
124     /**
125      * @constraint B12
126      * @title Attempt to modify inaccessible protected field.
127      */
testVFE9()128     public void testVFE9() {
129         //@uses dot.junit.opcodes.iput_boolean.TestStubs
130         loadAndRun("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_8", IllegalAccessError.class);
131     }
132 
133     /**
134      * @constraint n/a
135      * @title Attempt to modify field of undefined class.
136      */
testVFE10()137     public void testVFE10() {
138         loadAndRun("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_9", NoClassDefFoundError.class);
139     }
140 
141     /**
142      * @constraint n/a
143      * @title Attempt to modify undefined field.
144      */
testVFE11()145     public void testVFE11() {
146         loadAndRun("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_10", NoSuchFieldError.class);
147     }
148 
149     /**
150      * @constraint n/a
151      * @title Attempt to modify superclass' private field from subclass.
152      */
testVFE12()153     public void testVFE12() {
154         //@uses dot.junit.opcodes.iput_boolean.d.T_iput_boolean_1
155         loadAndRun("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_15", IllegalAccessError.class);
156     }
157 
158 
159     /**
160      * @constraint B1
161      * @title iput_boolean shall not work for wide numbers
162      */
testVFE13()163     public void testVFE13() {
164         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_2", VerifyError.class);
165     }
166 
167     /**
168      *
169      * @constraint B1
170      * @title iput_boolean shall not work for reference fields
171      */
testVFE14()172     public void testVFE14() {
173         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_20", VerifyError.class);
174     }
175 
176     /**
177      *
178      * @constraint B1
179      * @title iput_boolean shall not work for short fields
180      */
testVFE15()181     public void testVFE15() {
182         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_21", VerifyError.class);
183     }
184 
185     /**
186      *
187      * @constraint B1
188      * @title iput_boolean shall not work for int fields
189      */
testVFE16()190     public void testVFE16() {
191         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_22", VerifyError.class);
192     }
193 
194     /**
195      * @constraint B1
196      * @title iput_boolean shall not work for char fields
197      */
testVFE17()198     public void testVFE17() {
199         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_23", VerifyError.class);
200     }
201 
202     /**
203      * @constraint B1
204      * @title iput_boolean shall not work for byte fields
205      */
testVFE18()206     public void testVFE18() {
207         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_24", VerifyError.class);
208     }
209 
210     /**
211      * @constraint B6
212      * @title instance fields may only be accessed on already initialized instances.
213      */
testVFE30()214     public void testVFE30() {
215         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_30", VerifyError.class);
216     }
217 
218     /**
219      * @constraint N/A
220      * @title instance fields may only be accessed on reference registers.
221      */
testVFE31()222     public void testVFE31() {
223         load("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_31", VerifyError.class);
224     }
225 
226     /**
227      * @constraint n/a
228      * @title Modification of final field in other class
229      */
testVFE19()230     public void testVFE19() {
231         //@uses dot.junit.opcodes.iput_boolean.TestStubs
232         loadAndRun("dot.junit.opcodes.iput_boolean.d.T_iput_boolean_11", IllegalAccessError.class);
233     }
234 }
235 
236