Tue, 10 Apr 2012 08:15:25 -0700
7074397: Build infrastructure changes (makefile re-write)
Summary: New makefiles transition, old and new living side by side for now.
Reviewed-by: ohair, jjg, dholmes, ohrstrom, erikj, ihse, tgranat, ykantser
Contributed-by: ohrstrom <fredrik.ohrstrom@oracle.com>, erikj <erik.joelsson@oracle.com>, ihse <magnus.ihse.bursie@oracle.com>, tgranat <torbjorn.granat@oracle.com>, ykantser <yekaterina.kantserova@oracle.com>
1 /*
2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
24 /*
25 * @test
26 * @bug 7006109
27 * @summary Add test library to simplify the task of writing automated type-system tests
28 * @author mcimadamore
29 * @library .
30 * @run main CastTest
31 */
33 import com.sun.tools.javac.code.Type;
34 import com.sun.tools.javac.code.Type.*;
35 import com.sun.tools.javac.code.Symbol.*;
36 import java.lang.reflect.Array;
38 import static com.sun.tools.javac.code.Flags.*;
40 /**
41 * Check invariants in cast conversion involving primitive types and arrays
42 */
43 public class CastTest extends TypeHarness {
45 Type[] types_no_boxing;
46 Type[] types_boxing;
48 static final boolean T = true;
49 static final boolean F = false;
51 boolean[][] cast_result_no_boxing = {
52 //byte, short, int, long, float, double, char, bool, C, +C, I, T, byte[], short[], int[], long[], float[], double[], char[], bool[], C[], +C[], I[], T[]
53 /*byte*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
54 /*short*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
55 /*int*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
56 /*long*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
57 /*float*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
58 /*double*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
59 /*char*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
60 /*bool*/ { F , F , F , F , F , F , F , T , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
61 /*C*/ { F , F , F , F , F , F , F , F , T, F , T, T, F , F , F , F , F , F , F , F , F , F , F , F },
62 /*+C*/ { F , F , F , F , F , F , F , F , F, T , F, T, F , F , F , F , F , F , F , F , F , F , F , F },
63 /*I*/ { F , F , F , F , F , F , F , F , T, F , T, T, F , F , F , F , F , F , F , F , F , F , F , F },
64 /*T*/ { F , F , F , F , F , F , F , F , T, T , T, T, T , T , T , T , T , T , T , T , T , T , T , T },
65 /*byte[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, T , F , F , F , F , F , F , F , F , F , F , F },
66 /*short[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , T , F , F , F , F , F , F , F , F , F , F },
67 /*int[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , T , F , F , F , F , F , F , F , F , F },
68 /*long[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , T , F , F , F , F , F , F , F , F },
69 /*float[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , T , F , F , F , F , F , F , F },
70 /*double[]*/{ F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , T , F , F , F , F , F , F },
71 /*char[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , T , F , F , F , F , F },
72 /*bool[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , T , F , F , F , F },
73 /*C[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , T , F , T , T },
74 /*+C[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , F , T , F , T },
75 /*I[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , T , F , T , T },
76 /*T[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , T , T , T , T }};
78 boolean[][] cast_result_boxing = {
79 //byte, short, int, long, float, double, char, bool, Byte, Short, Integer, Long, Float, Double, Character, Boolean, Object
80 /*byte*/ { T , T , T , T , T , T , T , F , T , F , F , F , F , F , F , F , T },
81 /*short*/ { T , T , T , T , T , T , T , F , F , T , F , F , F , F , F , F , T },
82 /*int*/ { T , T , T , T , T , T , T , F , F , F , T , F , F , F , F , F , T },
83 /*long*/ { T , T , T , T , T , T , T , F , F , F , F , T , F , F , F , F , T },
84 /*float*/ { T , T , T , T , T , T , T , F , F , F , F , F , T , F , F , F , T },
85 /*double*/ { T , T , T , T , T , T , T , F , F , F , F , F , F , T , F , F , T },
86 /*char*/ { T , T , T , T , T , T , T , F , F , F , F , F , F , F , T , F , T },
87 /*bool*/ { F , F , F , F , F , F , F , T , F , F , F , F , F , F , F , T , T },
88 /*Byte*/ { T , T , T , T , T , T , F , F , T , F , F , F , F , F , F , F , T },
89 /*Short*/ { F , T , T , T , T , T , F , F , F , T , F , F , F , F , F , F , T },
90 /*Integer*/ { F , F , T , T , T , T , F , F , F , F , T , F , F , F , F , F , T },
91 /*Long*/ { F , F , F , T , T , T , F , F , F , F , F , T , F , F , F , F , T },
92 /*Float*/ { F , F , F , F , T , T , F , F , F , F , F , F , T , F , F , F , T },
93 /*Double*/ { F , F , F , F , F , T , F , F , F , F , F , F , F , T , F , F , T },
94 /*Character*/ { F , F , T , T , T , T , T , F , F , F , F , F , F , F , T , F , T },
95 /*Boolean*/ { F , F , F , F , F , F , F , T , F , F , F , F , F , F , F , T , T },
96 /*Object*/ { T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T }};
97 CastTest() {
98 Type[] primitiveTypes = {
99 predef.byteType,
100 predef.shortType,
101 predef.intType,
102 predef.longType,
103 predef.floatType,
104 predef.doubleType,
105 predef.charType,
106 predef.booleanType };
108 Type[] boxedTypes = new Type[primitiveTypes.length + 1];
109 for (int i = 0 ; i < primitiveTypes.length ; i++) {
110 boxedTypes[i] = box(primitiveTypes[i]);
111 }
113 boxedTypes[primitiveTypes.length] = predef.objectType;
115 types_boxing = join(Type.class, primitiveTypes, boxedTypes);
117 Type[] referenceTypes = {
118 fac.Class(),
119 fac.Class(FINAL),
120 fac.Interface(),
121 fac.TypeVariable() };
123 Type[] arrayTypes = new Type[primitiveTypes.length + referenceTypes.length];
124 int idx = 0;
125 for (Type t : join(Type.class, primitiveTypes, referenceTypes)) {
126 arrayTypes[idx++] = fac.Array(t);
127 }
129 types_no_boxing = join(Type.class, primitiveTypes, referenceTypes, arrayTypes);
130 }
132 void test(Type[] all_types, boolean[][] cast_result) {
133 for (int i = 0; i < all_types.length ; i++) {
134 for (int j = 0; j < all_types.length ; j++) {
135 assertCastable(all_types[i], all_types[j], cast_result[i][j]);
136 }
137 }
138 }
140 void runTests() {
141 test(types_no_boxing, cast_result_no_boxing);
142 test(types_boxing, cast_result_boxing);
143 }
145 @SuppressWarnings("unchecked")
146 <T> T[] join(Class<T> type, T[]... args) {
147 int totalLength = 0;
148 for (T[] arr : args) {
149 totalLength += arr.length;
150 }
151 T[] new_arr = (T[])Array.newInstance(type, totalLength);
152 int idx = 0;
153 for (T[] arr : args) {
154 System.arraycopy(arr, 0, new_arr, idx, arr.length);
155 idx += arr.length;
156 }
157 return new_arr;
158 }
160 public static void main(String[] args) {
161 new CastTest().runTests();
162 }
163 }