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.fill_array_data;
18 
19 import dot.junit.DxTestCase;
20 import dot.junit.DxUtil;
21 import dot.junit.opcodes.fill_array_data.d.T_fill_array_data_1;
22 import dot.junit.opcodes.fill_array_data.d.T_fill_array_data_2;
23 
24 public class Test_fill_array_data extends DxTestCase {
25     /**
26      * @title array of ints
27      */
testN1()28     public void testN1() {
29         int arr[] = new int[5];
30         T_fill_array_data_1 t = new T_fill_array_data_1();
31         t.run(arr);
32         for(int i = 0; i < 5; i++)
33             assertEquals(i + 1, arr[i]);
34      }
35 
36     /**
37      * @title array of doubles
38      */
testN2()39     public void testN2() {
40         double arr[] = new double[5];
41         T_fill_array_data_2 t = new T_fill_array_data_2();
42         t.run(arr);
43         for(int i = 0; i < 5; i++)
44             assertEquals((double)(i + 1), arr[i]);
45      }
46 
47     /**
48      * @title If there are less elements in the table than the array provides space for,
49      * the remaining array elements stay untouched.
50      */
testN3()51     public void testN3() {
52         int arr[] = new int[10];
53         T_fill_array_data_1 t = new T_fill_array_data_1();
54         t.run(arr);
55         for(int i = 0; i < 5; i++)
56             assertEquals(i + 1, arr[i]);
57         for(int i = 5; i < 10; i++)
58             assertEquals(0, arr[i]);
59      }
60 
61     /**
62      * @title expected NullPointerException
63      */
testE1()64     public void testE1() {
65         T_fill_array_data_1 t = new T_fill_array_data_1();
66         try {
67             t.run(null);
68         } catch(NullPointerException npe) {
69             // expected
70         }
71      }
72 
73     /**
74      * @title expected ArrayIndexOutOfBoundsException
75      */
testE2()76     public void testE2() {
77         int arr[] = new int[2];
78         T_fill_array_data_1 t = new T_fill_array_data_1();
79        try {
80             t.run(arr);
81         } catch(ArrayIndexOutOfBoundsException e) {
82             // expected
83            }
84      }
85 
86     /**
87      * @constraint A23
88      * @title number of registers
89      */
testVFE1()90     public void testVFE1() {
91         load("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_3", VerifyError.class);
92     }
93 
94     /**
95      * @constraint B1
96      * @title type of argument - double
97      */
testVFE2()98     public void testVFE2() {
99         load("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_4", VerifyError.class);
100     }
101 
102     /**
103      * @constraint B1
104      * @title type of argument - long
105      */
testVFE3()106     public void testVFE3() {
107         load("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_5", VerifyError.class);
108     }
109 
110     /**
111      * @constraint B1
112      * @title type of argument - reference (not array)
113      */
testVFE4()114     public void testVFE4() {
115         load("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_6", VerifyError.class);
116     }
117 
118     /**
119      * @constraint B1
120      * @title array of Objects
121      */
testVFE5()122     public void testVFE5() {
123         load("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_7", VerifyError.class);
124     }
125 
126     /**
127      * @constraint B1
128      * @title array type and data size shall be consistent
129      */
testVFE6()130     public void testVFE6() {
131         load("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_8", VerifyError.class);
132     }
133 
134     /**
135      * @constraint n/a
136      * @title offset to table shall be inside method
137      */
testVFE7()138     public void testVFE7() {
139         load("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_9", VerifyError.class);
140     }
141 
142     /**
143      * @constraint n/a
144      * @title the size and the list must be consistent.
145      */
testVFE9()146     public void testVFE9() {
147         load("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_11", VerifyError.class);
148     }
149 
150 
151     /**
152      * @constraint B22
153      * @title packed-switch-data pseudo-instructions must not be reachable by control flow
154      */
testVFE10()155     public void testVFE10() {
156         load("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_12", VerifyError.class);
157     }
158 
159     /**
160      * @constraint n/a
161      * @title table has wrong ident code
162      */
testVFE11()163     public void testVFE11() {
164         load("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_13", VerifyError.class);
165     }
166 }
167