• 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 expected ArrayIndexOutOfBoundsException
73      */
testE1()74     public void testE1() {
75         loadAndRun("dot.junit.opcodes.aput_object.d.T_aput_object_1",
76                    ArrayIndexOutOfBoundsException.class, new String[2], 2, "abc");
77     }
78 
79     /**
80      * @title expected ArrayIndexOutOfBoundsException (negative index)
81      */
testE2()82     public void testE2() {
83         loadAndRun("dot.junit.opcodes.aput_object.d.T_aput_object_1",
84                    ArrayIndexOutOfBoundsException.class, new String[2], -1, "abc");
85 
86     }
87 
88     /**
89      * @title expected NullPointerException
90      */
testE3()91     public void testE3() {
92         loadAndRun("dot.junit.opcodes.aput_object.d.T_aput_object_1", NullPointerException.class,
93                    null, 0, "abc");
94     }
95 
96     /**
97      * @title expected ArrayStoreException
98      */
testE4()99     public void testE4() {
100         loadAndRun("dot.junit.opcodes.aput_object.d.T_aput_object_4", ArrayStoreException.class,
101                    new String[2], 0, new Integer(1));
102     }
103 
104 
105     /**
106      * @constraint B1
107      * @title types of arguments - array, double, String
108      */
testVFE1()109     public void testVFE1() {
110         load("dot.junit.opcodes.aput_object.d.T_aput_object_5", VerifyError.class);
111     }
112 
113     /**
114      * @constraint B1
115      * @title types of arguments - array, int, long
116      */
testVFE2()117     public void testVFE2() {
118         load("dot.junit.opcodes.aput_object.d.T_aput_object_6", VerifyError.class);
119     }
120 
121     /**
122      * @constraint B1
123      * @title types of arguments - object, int, String
124      */
testVFE3()125     public void testVFE3() {
126         load("dot.junit.opcodes.aput_object.d.T_aput_object_7", VerifyError.class);
127     }
128 
129     /**
130      * @constraint B1
131      * @title types of arguments - float[], int, String
132      */
testVFE4()133     public void testVFE4() {
134         load("dot.junit.opcodes.aput_object.d.T_aput_object_8", VerifyError.class);
135     }
136 
137     /**
138      * @constraint B1
139      * @title types of arguments - long[], int, String
140      */
testVFE5()141     public void testVFE5() {
142         load("dot.junit.opcodes.aput_object.d.T_aput_object_9", VerifyError.class);
143     }
144 
145     /**
146      * @constraint B1
147      * @title types of arguments - array, reference, String
148      */
testVFE6()149     public void testVFE6() {
150         load("dot.junit.opcodes.aput_object.d.T_aput_object_10", VerifyError.class);
151     }
152 
153     /**
154      * @constraint A23
155      * @title number of registers
156      */
testVFE7()157     public void testVFE7() {
158         load("dot.junit.opcodes.aput_object.d.T_aput_object_11", VerifyError.class);
159     }
160 
161     /**
162      * @constraint B15
163      * @title put integer into array of references
164      */
testVFE8()165     public void testVFE8() {
166         load("dot.junit.opcodes.aput_object.d.T_aput_object_13", VerifyError.class);
167     }
168 
169     /**
170      * @constraint B1
171      * @title Type of index argument - float. The verifier checks that ints
172      * and floats are not used interchangeably.
173      */
testVFE9()174     public void testVFE9() {
175         load("dot.junit.opcodes.aput_object.d.T_aput_object_12", VerifyError.class);
176     }
177 }
178