• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.aput_object;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.aput_object.d.T_aput_object_1;
22 import dot.junit.opcodes.aput_object.d.T_aput_object_12;
23 import dot.junit.opcodes.aput_object.d.T_aput_object_2;
24 import dot.junit.opcodes.aput_object.d.T_aput_object_3;
25 import dot.junit.opcodes.aput_object.d.T_aput_object_4;
26 
27 public class Test_aput_object extends DxTestCase {
28     /**
29      * @title put reference into array
30      */
testN1()31     public void testN1() {
32         T_aput_object_1 t = new T_aput_object_1();
33         String[] arr = new String[2];
34         t.run(arr, 0, "hello");
35         assertEquals("hello", arr[0]);
36     }
37 
38     /**
39      * @title put reference into array
40      */
testN2()41     public void testN2() {
42         T_aput_object_1 t = new T_aput_object_1();
43         String[] value = {"world", null, ""};
44         String[] arr = new String[2];
45         for (int i = 0; i < value.length; i++) {
46             t.run(arr, 1, value[i]);
47             assertEquals(value[i], arr[1]);
48         }
49     }
50 
51     /**
52      * @title put reference into array
53      */
testN3()54     public void testN3() {
55         T_aput_object_2 t = new T_aput_object_2();
56         Integer[] arr = new Integer[2];
57         Integer value = new Integer(12345);
58         t.run(arr, 0, value);
59         assertEquals(value, arr[0]);
60     }
61 
62     /**
63      * @title Check assignement compatibility rules
64      */
testN4()65     public void testN4() {
66         T_aput_object_3 t = new T_aput_object_3();
67         assertEquals(3, t.run());
68 
69     }
70 
71     /**
72      * @title Type of index argument - float. Dalvik doens't distinguish 32-bits types internally,
73      * so this array[float]=value makes no sense but shall not crash the VM.
74      */
testN5()75     public void testN5() {
76         String[] arr = new String[2];
77         T_aput_object_12 t = new T_aput_object_12();
78         try {
79             t.run(arr, 3.14f, new String());
80         } catch (Throwable e) {
81         }
82     }
83 
84     /**
85      * @title expected ArrayIndexOutOfBoundsException
86      */
testE1()87     public void testE1() {
88         T_aput_object_1 t = new T_aput_object_1();
89         String[] arr = new String[2];
90         try {
91             t.run(arr, arr.length, "abc");
92             fail("expected ArrayIndexOutOfBoundsException");
93         } catch (ArrayIndexOutOfBoundsException aie) {
94             // expected
95         }
96     }
97 
98     /**
99      * @title expected ArrayIndexOutOfBoundsException (negative index)
100      */
testE2()101     public void testE2() {
102         T_aput_object_1 t = new T_aput_object_1();
103         String[] arr = new String[2];
104         try {
105             t.run(arr, -1, "abc");
106             fail("expected ArrayIndexOutOfBoundsException");
107         } catch (ArrayIndexOutOfBoundsException aie) {
108             // expected
109         }
110     }
111 
112     /**
113      * @title expected NullPointerException
114      */
testE3()115     public void testE3() {
116         T_aput_object_1 t = new T_aput_object_1();
117         String[] arr = null;
118         try {
119             t.run(arr, 0, "abc");
120             fail("expected NullPointerException");
121         } catch (NullPointerException aie) {
122             // expected
123         }
124     }
125 
126     /**
127      * @title expected ArrayStoreException
128      */
testE4()129     public void testE4() {
130         T_aput_object_4 t = new T_aput_object_4();
131         String[] arr = new String[2];
132         try {
133             t.run(arr, 0, t);
134             fail("expected ArrayStoreException");
135         } catch (ArrayStoreException aie) {
136             // expected
137         }
138     }
139 
140 
141     /**
142      * @constraint B1
143      * @title types of arguments - array, double, String
144      */
testVFE1()145     public void testVFE1() {
146         try {
147             Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_5");
148             fail("expected a verification exception");
149         } catch (Throwable t) {
150             DxUtil.checkVerifyException(t);
151         }
152     }
153 
154     /**
155      * @constraint B1
156      * @title types of arguments - array, int, long
157      */
testVFE2()158     public void testVFE2() {
159         try {
160             Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_6");
161             fail("expected a verification exception");
162         } catch (Throwable t) {
163             DxUtil.checkVerifyException(t);
164         }
165     }
166 
167     /**
168      * @constraint B1
169      * @title types of arguments - object, int, String
170      */
testVFE3()171     public void testVFE3() {
172         try {
173             Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_7");
174             fail("expected a verification exception");
175         } catch (Throwable t) {
176             DxUtil.checkVerifyException(t);
177         }
178     }
179 
180     /**
181      * @constraint B1
182      * @title types of arguments - float[], int, String
183      */
testVFE4()184     public void testVFE4() {
185         try {
186             Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_8");
187             fail("expected a verification exception");
188         } catch (Throwable t) {
189             DxUtil.checkVerifyException(t);
190         }
191     }
192 
193     /**
194      * @constraint B1
195      * @title types of arguments - long[], int, String
196      */
testVFE5()197     public void testVFE5() {
198         try {
199             Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_9");
200             fail("expected a verification exception");
201         } catch (Throwable t) {
202             DxUtil.checkVerifyException(t);
203         }
204     }
205 
206     /**
207      * @constraint B1
208      * @title types of arguments - array, reference, String
209      */
testVFE6()210     public void testVFE6() {
211         try {
212             Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_10");
213             fail("expected a verification exception");
214         } catch (Throwable t) {
215             DxUtil.checkVerifyException(t);
216         }
217     }
218 
219     /**
220      * @constraint A23
221      * @title number of registers
222      */
testVFE7()223     public void testVFE7() {
224         try {
225             Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_11");
226             fail("expected a verification exception");
227         } catch (Throwable t) {
228             DxUtil.checkVerifyException(t);
229         }
230     }
231 
232     /**
233      * @constraint B15
234      * @title put integer into array of references
235      */
testVFE8()236     public void testVFE8() {
237         try {
238             Class.forName("dot.junit.opcodes.aput_object.d.T_aput_object_13");
239             fail("expected a verification exception");
240         } catch (Throwable t) {
241             DxUtil.checkVerifyException(t);
242         }
243     }
244 
245 }
246