author | vromero |
Wed, 16 Dec 2015 14:23:08 -0800 | |
changeset 34756 | d31f11c4cc75 |
parent 30730 | d3ce7619db2c |
child 39363 | ebaee646b121 |
permissions | -rw-r--r-- |
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
9721
diff
changeset
|
2 |
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
4 |
* |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
8 |
* |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
13 |
* accompanied this code). |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
14 |
* |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
18 |
* |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
21 |
* questions. |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
22 |
*/ |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
23 |
|
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
24 |
/* |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
25 |
* @test |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
26 |
* @bug 7006109 |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
27 |
* @summary Add test library to simplify the task of writing automated type-system tests |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
28 |
* @author mcimadamore |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
29 |
* @library . |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
9721
diff
changeset
|
30 |
* @modules jdk.compiler/com.sun.tools.javac.code |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
9721
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.comp |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
9721
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.javac.file |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
9721
diff
changeset
|
33 |
* jdk.compiler/com.sun.tools.javac.util |
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
34 |
* @run main CastTest |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
35 |
*/ |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
36 |
|
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.code.Type; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
38 |
import java.lang.reflect.Array; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
39 |
|
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
40 |
import static com.sun.tools.javac.code.Flags.*; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
41 |
|
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
42 |
/** |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
43 |
* Check invariants in cast conversion involving primitive types and arrays |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
44 |
*/ |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
45 |
public class CastTest extends TypeHarness { |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
46 |
|
9721
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
47 |
Type[] types_no_boxing; |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
48 |
Type[] types_boxing; |
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
49 |
|
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
50 |
static final boolean T = true; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
51 |
static final boolean F = false; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
52 |
|
9721
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
53 |
boolean[][] cast_result_no_boxing = { |
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
54 |
//byte, short, int, long, float, double, char, bool, C, +C, I, T, byte[], short[], int[], long[], float[], double[], char[], bool[], C[], +C[], I[], T[] |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
55 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
56 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
57 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
58 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
59 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
60 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
61 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
62 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
63 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
64 |
/*+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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
65 |
/*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 }, |
34756
d31f11c4cc75
8144832: cast conversion fails when converting a type-variable to primitive type
vromero
parents:
30730
diff
changeset
|
66 |
/*T*/ { T , T , T , T , T , T , T , T , T, T , T, T, T , T , T , T , T , T , T , T , T , T , T , T }, |
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
67 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
68 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
69 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
70 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
71 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
72 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
73 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
74 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
75 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
76 |
/*+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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
77 |
/*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 }, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
78 |
/*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 }}; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
79 |
|
9721
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
80 |
boolean[][] cast_result_boxing = { |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
81 |
//byte, short, int, long, float, double, char, bool, Byte, Short, Integer, Long, Float, Double, Character, Boolean, Object |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
82 |
/*byte*/ { T , T , T , T , T , T , T , F , T , F , F , F , F , F , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
83 |
/*short*/ { T , T , T , T , T , T , T , F , F , T , F , F , F , F , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
84 |
/*int*/ { T , T , T , T , T , T , T , F , F , F , T , F , F , F , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
85 |
/*long*/ { T , T , T , T , T , T , T , F , F , F , F , T , F , F , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
86 |
/*float*/ { T , T , T , T , T , T , T , F , F , F , F , F , T , F , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
87 |
/*double*/ { T , T , T , T , T , T , T , F , F , F , F , F , F , T , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
88 |
/*char*/ { T , T , T , T , T , T , T , F , F , F , F , F , F , F , T , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
89 |
/*bool*/ { F , F , F , F , F , F , F , T , F , F , F , F , F , F , F , T , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
90 |
/*Byte*/ { T , T , T , T , T , T , F , F , T , F , F , F , F , F , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
91 |
/*Short*/ { F , T , T , T , T , T , F , F , F , T , F , F , F , F , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
92 |
/*Integer*/ { F , F , T , T , T , T , F , F , F , F , T , F , F , F , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
93 |
/*Long*/ { F , F , F , T , T , T , F , F , F , F , F , T , F , F , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
94 |
/*Float*/ { F , F , F , F , T , T , F , F , F , F , F , F , T , F , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
95 |
/*Double*/ { F , F , F , F , F , T , F , F , F , F , F , F , F , T , F , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
96 |
/*Character*/ { F , F , T , T , T , T , T , F , F , F , F , F , F , F , T , F , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
97 |
/*Boolean*/ { F , F , F , F , F , F , F , T , F , F , F , F , F , F , F , T , T }, |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
98 |
/*Object*/ { T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T , T }}; |
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
99 |
CastTest() { |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
100 |
Type[] primitiveTypes = { |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
101 |
predef.byteType, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
102 |
predef.shortType, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
103 |
predef.intType, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
104 |
predef.longType, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
105 |
predef.floatType, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
106 |
predef.doubleType, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
107 |
predef.charType, |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
108 |
predef.booleanType }; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
109 |
|
9721
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
110 |
Type[] boxedTypes = new Type[primitiveTypes.length + 1]; |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
111 |
for (int i = 0 ; i < primitiveTypes.length ; i++) { |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
112 |
boxedTypes[i] = box(primitiveTypes[i]); |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
113 |
} |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
114 |
|
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
115 |
boxedTypes[primitiveTypes.length] = predef.objectType; |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
116 |
|
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
117 |
types_boxing = join(Type.class, primitiveTypes, boxedTypes); |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
118 |
|
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
119 |
Type[] referenceTypes = { |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
120 |
fac.Class(), |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
121 |
fac.Class(FINAL), |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
122 |
fac.Interface(), |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
123 |
fac.TypeVariable() }; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
124 |
|
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
125 |
Type[] arrayTypes = new Type[primitiveTypes.length + referenceTypes.length]; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
126 |
int idx = 0; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
127 |
for (Type t : join(Type.class, primitiveTypes, referenceTypes)) { |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
128 |
arrayTypes[idx++] = fac.Array(t); |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
129 |
} |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
130 |
|
9721
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
131 |
types_no_boxing = join(Type.class, primitiveTypes, referenceTypes, arrayTypes); |
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
132 |
} |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
133 |
|
9721
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
134 |
void test(Type[] all_types, boolean[][] cast_result) { |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
135 |
for (int i = 0; i < all_types.length ; i++) { |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
136 |
for (int j = 0; j < all_types.length ; j++) { |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
137 |
assertCastable(all_types[i], all_types[j], cast_result[i][j]); |
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
138 |
} |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
139 |
} |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
140 |
} |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
141 |
|
9721
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
142 |
void runTests() { |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
143 |
test(types_no_boxing, cast_result_no_boxing); |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
144 |
test(types_boxing, cast_result_boxing); |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
145 |
} |
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
146 |
|
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
147 |
@SuppressWarnings("unchecked") |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
148 |
<T> T[] join(Class<T> type, T[]... args) { |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
149 |
int totalLength = 0; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
150 |
for (T[] arr : args) { |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
151 |
totalLength += arr.length; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
152 |
} |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
153 |
T[] new_arr = (T[])Array.newInstance(type, totalLength); |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
154 |
int idx = 0; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
155 |
for (T[] arr : args) { |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
156 |
System.arraycopy(arr, 0, new_arr, idx, arr.length); |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
157 |
idx += arr.length; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
158 |
} |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
159 |
return new_arr; |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
160 |
} |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
161 |
|
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
162 |
public static void main(String[] args) { |
9721
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
7640
diff
changeset
|
163 |
new CastTest().runTests(); |
7640
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
164 |
} |
5d199da591db
7006109: Add test library to simplify the task of writing automated type-system tests
mcimadamore
parents:
diff
changeset
|
165 |
} |