author | jiangli |
Wed, 27 Sep 2017 17:55:20 -0400 | |
changeset 47548 | 664b9d44db74 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
47025
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
1 |
/* |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
4 |
* |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
8 |
* |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
13 |
* accompanied this code). |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
14 |
* |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
18 |
* |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
21 |
* questions. |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
22 |
*/ |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
23 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
24 |
/* @test |
47115 | 25 |
* @bug 8186801 8186751 |
47025
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
26 |
* @summary Test the charset mappings |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
27 |
*/ |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
28 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
29 |
import java.io.*; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
30 |
import java.nio.*; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
31 |
import java.nio.file.*; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
32 |
import java.nio.charset.*; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
33 |
import java.util.*; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
34 |
import java.util.function.*; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
35 |
import java.util.regex.*; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
36 |
import java.util.stream.*; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
37 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
38 |
public class TestCharsetMapping { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
39 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
40 |
private static final int BUFSIZ = 8192; // Initial buffer size |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
41 |
private static final int MAXERRS = 10; // Errors reported per test |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
42 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
43 |
private static final PrintStream log = System.out; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
44 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
45 |
// Set by -v on the command line |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
46 |
private static boolean verbose = false; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
47 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
48 |
// Test modes |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
49 |
private static final int ENCODE = 1; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
50 |
private static final int DECODE = 2; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
51 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
52 |
// Utilities |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
53 |
private static ByteBuffer expand(ByteBuffer bb) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
54 |
ByteBuffer nbb = ByteBuffer.allocate(bb.capacity() * 2); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
55 |
bb.flip(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
56 |
nbb.put(bb); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
57 |
return nbb; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
58 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
59 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
60 |
private static CharBuffer expand(CharBuffer cb) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
61 |
CharBuffer ncb = CharBuffer.allocate(cb.capacity() * 2); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
62 |
cb.flip(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
63 |
ncb.put(cb); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
64 |
return ncb; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
65 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
66 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
67 |
private static byte[] parseBytes(String s) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
68 |
int nb = s.length() / 2; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
69 |
byte[] bs = new byte[nb]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
70 |
for (int i = 0; i < nb; i++) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
71 |
int j = i * 2; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
72 |
if (j + 2 > s.length()) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
73 |
throw new RuntimeException("Malformed byte string: " + s); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
74 |
bs[i] = (byte)Integer.parseInt(s.substring(j, j + 2), 16); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
75 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
76 |
return bs; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
77 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
78 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
79 |
private static String printBytes(byte[] bs) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
80 |
StringBuffer sb = new StringBuffer(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
81 |
for (int i = 0; i < bs.length; i++) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
82 |
sb.append(Integer.toHexString((bs[i] >> 4) & 0xf)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
83 |
sb.append(Integer.toHexString((bs[i] >> 0) & 0xf)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
84 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
85 |
return sb.toString(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
86 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
87 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
88 |
private static String printCodePoint(int cp) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
89 |
StringBuffer sb = new StringBuffer(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
90 |
sb.append("U+"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
91 |
if (cp > 0xffff) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
92 |
sb.append(Integer.toHexString((cp >> 16) & 0xf)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
93 |
sb.append(Integer.toHexString((cp >> 12) & 0xf)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
94 |
sb.append(Integer.toHexString((cp >> 8) & 0xf)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
95 |
sb.append(Integer.toHexString((cp >> 4) & 0xf)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
96 |
sb.append(Integer.toHexString((cp >> 0) & 0xf)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
97 |
return sb.toString(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
98 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
99 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
100 |
private static int getCodePoint(CharBuffer cb) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
101 |
char c = cb.get(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
102 |
if (Character.isHighSurrogate(c)) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
103 |
return Character.toCodePoint(c, cb.get()); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
104 |
else |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
105 |
return c; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
106 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
107 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
108 |
private static String plural(int n) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
109 |
return (n == 1 ? "" : "s"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
110 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
111 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
112 |
// TestCharsetMapping |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
113 |
private CharsetInfo csinfo; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
114 |
private CharsetDecoder decoder = null; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
115 |
private CharsetEncoder encoder = null; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
116 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
117 |
// Stateful dbcs encoding has leading shift byte '0x0e' |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
118 |
// and trailing shift byte '0x0f'. |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
119 |
// The flag variable shiftHackDBCS is 'true' for stateful |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
120 |
// EBCDIC encodings, which indicates the need of adding/ |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
121 |
// removing the shift bytes. |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
122 |
private boolean shiftHackDBCS = false; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
123 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
124 |
private TestCharsetMapping(CharsetInfo csinfo) throws Exception { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
125 |
this.csinfo = csinfo; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
126 |
this.encoder = csinfo.cs.newEncoder() |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
127 |
.onUnmappableCharacter(CodingErrorAction.REPLACE) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
128 |
.onMalformedInput(CodingErrorAction.REPLACE); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
129 |
this.decoder = csinfo.cs.newDecoder() |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
130 |
.onUnmappableCharacter(CodingErrorAction.REPLACE) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
131 |
.onMalformedInput(CodingErrorAction.REPLACE); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
132 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
133 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
134 |
private class Test { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
135 |
// An instance of this class tests all mappings for |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
136 |
// a particular bytesPerChar value |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
137 |
private int bytesPerChar; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
138 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
139 |
// Reference data from .map/nr/c2b files |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
140 |
private ByteBuffer refBytes = ByteBuffer.allocate(BUFSIZ); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
141 |
private CharBuffer refChars = CharBuffer.allocate(BUFSIZ); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
142 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
143 |
private ByteBuffer dRefBytes = ByteBuffer.allocateDirect(BUFSIZ); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
144 |
private CharBuffer dRefChars = ByteBuffer.allocateDirect(BUFSIZ*2).asCharBuffer(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
145 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
146 |
private Test(int bpc) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
147 |
bytesPerChar = bpc; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
148 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
149 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
150 |
// shiftHackDBCS can add the leading/trailing shift bytesa |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
151 |
private void put(byte[] bs) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
152 |
if (refBytes.remaining() < bytesPerChar) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
153 |
refBytes = expand(refBytes); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
154 |
refBytes.put(bs); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
155 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
156 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
157 |
private void put(byte[] bs, char[] cc) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
158 |
if (bs.length != bytesPerChar) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
159 |
throw new IllegalArgumentException(bs.length |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
160 |
+ " != " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
161 |
+ bytesPerChar); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
162 |
if (refBytes.remaining() < bytesPerChar) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
163 |
refBytes = expand(refBytes); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
164 |
refBytes.put(bs); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
165 |
if (refChars.remaining() < cc.length) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
166 |
refChars = expand(refChars); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
167 |
refChars.put(cc); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
168 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
169 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
170 |
private boolean decode(ByteBuffer refBytes, CharBuffer refChars) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
171 |
throws Exception { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
172 |
log.println(" decode" + (refBytes.isDirect()?" (direct)":"")); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
173 |
CharBuffer out = decoder.decode(refBytes); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
174 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
175 |
refBytes.rewind(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
176 |
byte[] bs = new byte[bytesPerChar]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
177 |
int e = 0; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
178 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
179 |
if (shiftHackDBCS && bytesPerChar == 2 && refBytes.get() != (byte)0x0e) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
180 |
log.println("Missing leading byte"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
181 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
182 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
183 |
while (refChars.hasRemaining()) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
184 |
refBytes.get(bs); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
185 |
int rcp = getCodePoint(refChars); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
186 |
int ocp = getCodePoint(out); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
187 |
if (rcp != ocp) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
188 |
log.println(" Error: " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
189 |
+ printBytes(bs) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
190 |
+ " --> " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
191 |
+ printCodePoint(ocp) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
192 |
+ ", expected " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
193 |
+ printCodePoint(rcp)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
194 |
if (++e >= MAXERRS) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
195 |
log.println(" Too many errors, giving up"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
196 |
break; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
197 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
198 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
199 |
if (verbose) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
200 |
log.println(" " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
201 |
+ printBytes(bs) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
202 |
+ " --> " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
203 |
+ printCodePoint(rcp)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
204 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
205 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
206 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
207 |
if (shiftHackDBCS && bytesPerChar == 2 && refBytes.get() != (byte)0x0f) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
208 |
log.println("Missing trailing byte"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
209 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
210 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
211 |
if (e == 0 && (refChars.hasRemaining() || out.hasRemaining())) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
212 |
// Paranoia: Didn't consume everything |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
213 |
throw new IllegalStateException(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
214 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
215 |
refBytes.rewind(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
216 |
refChars.rewind(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
217 |
return (e == 0); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
218 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
219 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
220 |
private boolean encode(ByteBuffer refBytes, CharBuffer refChars) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
221 |
throws Exception { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
222 |
log.println(" encode" + (refBytes.isDirect()?" (direct)":"")); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
223 |
ByteBuffer out = encoder.encode(refChars); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
224 |
refChars.rewind(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
225 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
226 |
if (shiftHackDBCS && bytesPerChar == 2 && out.get() != refBytes.get()) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
227 |
log.println("Missing leading byte"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
228 |
return false; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
229 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
230 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
231 |
byte[] rbs = new byte[bytesPerChar]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
232 |
byte[] obs = new byte[bytesPerChar]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
233 |
int e = 0; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
234 |
while (refChars.hasRemaining()) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
235 |
int cp = getCodePoint(refChars); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
236 |
refBytes.get(rbs); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
237 |
out.get(obs); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
238 |
boolean eq = true; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
239 |
for (int i = 0; i < bytesPerChar; i++) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
240 |
eq &= rbs[i] == obs[i]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
241 |
if (!eq) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
242 |
log.println(" Error: " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
243 |
+ printCodePoint(cp) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
244 |
+ " --> " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
245 |
+ printBytes(obs) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
246 |
+ ", expected " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
247 |
+ printBytes(rbs)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
248 |
if (++e >= MAXERRS) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
249 |
log.println(" Too many errors, giving up"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
250 |
break; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
251 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
252 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
253 |
if (verbose) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
254 |
log.println(" " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
255 |
+ printCodePoint(cp) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
256 |
+ " --> " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
257 |
+ printBytes(rbs)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
258 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
259 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
260 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
261 |
if (shiftHackDBCS && bytesPerChar == 2 && out.get() != refBytes.get()) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
262 |
log.println("Missing trailing byte"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
263 |
return false; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
264 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
265 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
266 |
if (e == 0 && (refBytes.hasRemaining() || out.hasRemaining())) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
267 |
// Paranoia: Didn't consume everything |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
268 |
throw new IllegalStateException(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
269 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
270 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
271 |
refBytes.rewind(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
272 |
refChars.rewind(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
273 |
return (e == 0); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
274 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
275 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
276 |
private boolean run(int mode) throws Exception { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
277 |
log.println(" " + bytesPerChar |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
278 |
+ " byte" + plural(bytesPerChar) + "/char"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
279 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
280 |
if (dRefBytes.capacity() < refBytes.capacity()) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
281 |
dRefBytes = ByteBuffer.allocateDirect(refBytes.capacity()); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
282 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
283 |
if (dRefChars.capacity() < refChars.capacity()) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
284 |
dRefChars = ByteBuffer.allocateDirect(refChars.capacity()*2) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
285 |
.asCharBuffer(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
286 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
287 |
refBytes.flip(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
288 |
refChars.flip(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
289 |
dRefBytes.clear(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
290 |
dRefChars.clear(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
291 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
292 |
dRefBytes.put(refBytes).flip(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
293 |
dRefChars.put(refChars).flip(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
294 |
refBytes.flip(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
295 |
refChars.flip(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
296 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
297 |
boolean rv = true; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
298 |
if (mode != ENCODE) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
299 |
rv &= decode(refBytes, refChars); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
300 |
rv &= decode(dRefBytes, dRefChars); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
301 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
302 |
if (mode != DECODE) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
303 |
rv &= encode(refBytes, refChars); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
304 |
rv &= encode(dRefBytes, dRefChars); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
305 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
306 |
return rv; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
307 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
308 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
309 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
310 |
// Maximum bytes/char being tested |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
311 |
private int maxBytesPerChar = 0; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
312 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
313 |
// Tests, indexed by bytesPerChar - 1 |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
314 |
private Test[] tests; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
315 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
316 |
private void clearTests() { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
317 |
maxBytesPerChar = 0; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
318 |
tests = new Test[0]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
319 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
320 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
321 |
// Find the test for the given bytes/char value, |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
322 |
// expanding the test array if needed |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
323 |
// |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
324 |
private Test testFor(int bpc) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
325 |
if (bpc > maxBytesPerChar) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
326 |
Test[] ts = new Test[bpc]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
327 |
System.arraycopy(tests, 0, ts, 0, maxBytesPerChar); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
328 |
for (int i = maxBytesPerChar; i < bpc; i++) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
329 |
ts[i] = new Test(i + 1); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
330 |
tests = ts; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
331 |
maxBytesPerChar = bpc; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
332 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
333 |
return tests[bpc - 1]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
334 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
335 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
336 |
private boolean testStringConv() throws Exception { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
337 |
if (shiftHackDBCS) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
338 |
log.println(" string de/encoding skipped for ebcdic"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
339 |
return true; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
340 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
341 |
boolean rv = true; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
342 |
log.println(" string de/encoding"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
343 |
// for new String() |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
344 |
ByteArrayOutputStream baosDec = new ByteArrayOutputStream(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
345 |
StringBuilder sbDec = new StringBuilder(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
346 |
// for String.getBytes() |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
347 |
ByteArrayOutputStream baosEnc = new ByteArrayOutputStream(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
348 |
StringBuilder sbEnc = new StringBuilder(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
349 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
350 |
for (Entry e : csinfo.mappings) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
351 |
baosDec.write(e.bs); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
352 |
sbDec.append(Character.toChars(e.cp)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
353 |
if (e.cp2 != 0) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
354 |
sbDec.append(e.cp2); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
355 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
356 |
// non-roundtrip b2c, and c2b |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
357 |
if (csinfo.nr != null && csinfo.nr.containsKey(e.bb) || |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
358 |
csinfo.c2b != null && !csinfo.c2b.containsKey(e.cp)) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
359 |
continue; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
360 |
baosEnc.write(e.bs); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
361 |
sbEnc.append(Character.toChars(e.cp)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
362 |
if (e.cp2 != 0) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
363 |
sbEnc.append(e.cp2); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
364 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
365 |
log.println(" new String()"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
366 |
if (!new String(baosDec.toByteArray(), csinfo.csName).equals(sbDec.toString())) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
367 |
log.println(" Error: new String() failed"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
368 |
rv = false; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
369 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
370 |
log.println(" String.getBytes()"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
371 |
if (!Arrays.equals(baosEnc.toByteArray(), sbEnc.toString().getBytes(csinfo.csName))) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
372 |
log.println(" Error: String().getBytes() failed"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
373 |
rv = false; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
374 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
375 |
return rv; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
376 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
377 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
378 |
private boolean run() throws Exception { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
379 |
boolean rv = true; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
380 |
shiftHackDBCS = csinfo.type.equals("ebcdic"); // isStateful; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
381 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
382 |
// (1) new String()/String.getBytes() |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
383 |
rv &= testStringConv(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
384 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
385 |
// (2) DECODE: |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
386 |
clearTests(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
387 |
if (shiftHackDBCS) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
388 |
testFor(2).put(new byte[] { 0x0e }); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
389 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
390 |
csinfo.mappings.forEach(e -> { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
391 |
if (e.cp2 != 0) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
392 |
return; // skip composite (base+cc) for now |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
393 |
byte[] bs = e.bs; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
394 |
char[] cc = Character.toChars(e.cp); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
395 |
testFor(bs.length).put(bs, cc); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
396 |
}); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
397 |
if (shiftHackDBCS) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
398 |
testFor(2).put(new byte[] { 0x0f }); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
399 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
400 |
for (int i = 0; i < maxBytesPerChar; i++) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
401 |
rv &= tests[i].run(DECODE); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
402 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
403 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
404 |
// (3) ENCODE: |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
405 |
clearTests(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
406 |
if (shiftHackDBCS) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
407 |
testFor(2).put(new byte[] { 0x0e }); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
408 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
409 |
csinfo.mappings.forEach(e -> { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
410 |
if (e.cp2 != 0) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
411 |
return; // skip composite (base+cc) for now |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
412 |
if (csinfo.nr != null && csinfo.nr.containsKey(e.bb)) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
413 |
return; // non-roundtrip b2c |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
414 |
if (csinfo.c2b != null && csinfo.c2b.containsKey(e.cp)) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
415 |
return; // c2b only mapping |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
416 |
byte[] bs = e.bs; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
417 |
char[] cc = Character.toChars(e.cp); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
418 |
testFor(bs.length).put(bs, cc); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
419 |
}); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
420 |
if (csinfo.c2b != null) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
421 |
csinfo.c2b.values().forEach(e -> { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
422 |
byte[] bs = e.bs; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
423 |
char[] cc = Character.toChars(e.cp); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
424 |
testFor(bs.length).put(bs, cc); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
425 |
}); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
426 |
if (shiftHackDBCS) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
427 |
testFor(2).put(new byte[] { 0x0f }); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
428 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
429 |
for (int i = 0; i < maxBytesPerChar; i++) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
430 |
rv &= tests[i].run(ENCODE); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
431 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
432 |
return rv; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
433 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
434 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
435 |
private static class Entry { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
436 |
byte[] bs; // byte sequence reps |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
437 |
int cp; // Unicode codepoint |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
438 |
int cp2; // CC of composite |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
439 |
long bb; // bs in "long" form for nr lookup; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
440 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
441 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
442 |
private final static int UNMAPPABLE = 0xFFFD; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
443 |
private static final Pattern ptn = Pattern.compile("(?:0x)?(\\p{XDigit}++)\\s++(?:U\\+|0x)?(\\p{XDigit}++)(?:\\s++#.*)?"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
444 |
private static final int G_BS = 1; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
445 |
private static final int G_CP = 2; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
446 |
private static final int G_CP2 = 3; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
447 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
448 |
private static class CharsetInfo { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
449 |
Charset cs; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
450 |
String pkgName; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
451 |
String clzName; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
452 |
String csName; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
453 |
String hisName; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
454 |
String type; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
455 |
boolean isInternal; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
456 |
Set<String> aliases = new HashSet<>(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
457 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
458 |
// mapping entries |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
459 |
List<Entry> mappings; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
460 |
Map<Long, Entry> nr; // bytes -> entry |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
461 |
Map<Integer, Entry> c2b; // cp -> entry |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
462 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
463 |
CharsetInfo(String csName, String clzName) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
464 |
this.csName = csName; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
465 |
this.clzName = clzName; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
466 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
467 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
468 |
private Entry parse(Matcher m) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
469 |
Entry e = new Entry(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
470 |
e.bb = Long.parseLong(m.group(G_BS), 16); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
471 |
if (e.bb < 0x100) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
472 |
e.bs = new byte[] { (byte)e.bb }; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
473 |
else |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
474 |
e.bs = parseBytes(m.group(G_BS)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
475 |
e.cp = Integer.parseInt(m.group(G_CP), 16); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
476 |
if (G_CP2 <= m.groupCount() && m.group(G_CP2) != null) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
477 |
e.cp2 = Integer.parseInt(m.group(G_CP2), 16); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
478 |
else |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
479 |
e.cp2 = 0; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
480 |
return e; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
481 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
482 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
483 |
boolean loadMappings(Path dir) throws IOException { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
484 |
// xxx.map |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
485 |
Path path = dir.resolve(clzName + ".map"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
486 |
if (!Files.exists(path)) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
487 |
return false; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
488 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
489 |
Matcher m = ptn.matcher(""); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
490 |
mappings = Files.lines(path) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
491 |
.filter(ln -> !ln.startsWith("#") && m.reset(ln).lookingAt()) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
492 |
.map(ln -> parse(m)) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
493 |
.filter(e -> e.cp != UNMAPPABLE) // non-mapping |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
494 |
.collect(Collectors.toList()); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
495 |
// xxx.nr |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
496 |
path = dir.resolve(clzName + ".nr"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
497 |
if (Files.exists(path)) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
498 |
nr = Files.lines(path) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
499 |
.filter(ln -> !ln.startsWith("#") && m.reset(ln).lookingAt()) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
500 |
.map(ln -> parse(m)) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
501 |
.collect(Collectors.toMap(e -> e.bb, Function.identity())); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
502 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
503 |
// xxx.c2b |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
504 |
path = dir.resolve(clzName + ".c2b"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
505 |
if (Files.exists(path)) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
506 |
c2b = Files.lines(path) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
507 |
.filter(ln -> !ln.startsWith("#") && m.reset(ln).lookingAt()) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
508 |
.map(ln -> parse(m)) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
509 |
.collect(Collectors.toMap(e -> e.cp, Function.identity())); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
510 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
511 |
return true; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
512 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
513 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
514 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
515 |
private static Set<CharsetInfo> charsets(Path cslist) throws IOException { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
516 |
Set<CharsetInfo> charsets = new LinkedHashSet<>(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
517 |
Iterator<String> itr = Files.readAllLines(cslist).iterator(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
518 |
CharsetInfo cs = null; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
519 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
520 |
while (itr.hasNext()) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
521 |
String line = itr.next(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
522 |
if (line.startsWith("#") || line.length() == 0) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
523 |
continue; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
524 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
525 |
String[] tokens = line.split("\\s+"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
526 |
if (tokens.length < 2) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
527 |
continue; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
528 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
529 |
if ("charset".equals(tokens[0])) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
530 |
if (cs != null) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
531 |
charsets.add(cs); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
532 |
cs = null; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
533 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
534 |
if (tokens.length < 3) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
535 |
throw new RuntimeException("Error: incorrect charset line [" + line + "]"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
536 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
537 |
cs = new CharsetInfo(tokens[1], tokens[2]); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
538 |
} else { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
539 |
String key = tokens[1]; // leading empty str |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
540 |
switch (key) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
541 |
case "alias": |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
542 |
if (tokens.length < 3) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
543 |
throw new RuntimeException("Error: incorrect alias line [" + line + "]"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
544 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
545 |
cs.aliases.add(tokens[2]); // ALIAS_NAME |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
546 |
break; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
547 |
case "package": |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
548 |
cs.pkgName = tokens[2]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
549 |
break; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
550 |
case "type": |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
551 |
cs.type = tokens[2]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
552 |
break; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
553 |
case "hisname": |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
554 |
cs.hisName = tokens[2]; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
555 |
break; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
556 |
case "internal": |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
557 |
cs.isInternal = Boolean.parseBoolean(tokens[2]); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
558 |
break; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
559 |
default: // ignore |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
560 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
561 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
562 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
563 |
if (cs != null) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
564 |
charsets.add(cs); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
565 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
566 |
return charsets; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
567 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
568 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
569 |
public static void main(String args[]) throws Exception { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
570 |
Path dir = Paths.get(System.getProperty("test.src", ".") + |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
571 |
"/../../../../make/data/charsetmapping"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
572 |
if (!Files.exists(dir)) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
573 |
// not inside jdk repo, no mappings, exit silently |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
574 |
log.println("Nothing done, not in a jdk repo: "); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
575 |
return; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
576 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
577 |
if (args.length > 0 && "-v".equals(args[0])) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
578 |
// For debugging: java CoderTest [-v] |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
579 |
verbose = true; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
580 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
581 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
582 |
int errors = 0; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
583 |
int tested = 0; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
584 |
int skipped = 0; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
585 |
int known = 0; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
586 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
587 |
for (CharsetInfo csinfo : charsets(dir.resolve("charsets"))) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
588 |
String csname = csinfo.csName; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
589 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
590 |
if (csinfo.isInternal) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
591 |
continue; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
592 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
593 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
594 |
log.printf("%ntesting: %-16s", csname); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
595 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
596 |
if (!Charset.isSupported(csname)) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
597 |
errors++; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
598 |
log.println(" [error: charset is not supported]"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
599 |
continue; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
600 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
601 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
602 |
Charset cs = csinfo.cs = Charset.forName(csinfo.csName); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
603 |
// test name() |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
604 |
if (!cs.name().equals(csinfo.csName)) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
605 |
errors++; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
606 |
log.printf(" [error: wrong csname: " + csinfo.csName |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
607 |
+ " vs " + cs.name() + "]"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
608 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
609 |
// test aliases() |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
610 |
if (!cs.aliases().equals(csinfo.aliases)) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
611 |
errors++; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
612 |
log.printf(" [error wrong aliases]"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
613 |
if (verbose) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
614 |
log.println(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
615 |
log.println(" expected: " + csinfo.aliases); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
616 |
log.println(" got: " + cs.aliases()); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
617 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
618 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
619 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
620 |
if (csinfo.type.equals("source")) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
621 |
log.println(" [skipped: source based]"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
622 |
skipped++; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
623 |
continue; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
624 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
625 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
626 |
if (!csinfo.loadMappings(dir)) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
627 |
log.println(" [error loading mappings failed]"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
628 |
errors++; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
629 |
continue; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
630 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
631 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
632 |
tested++; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
633 |
log.println(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
634 |
if (!new TestCharsetMapping(csinfo).run()) { |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
635 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
636 |
/////////////// known nr/c2b issues //////////////// |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
637 |
if (csinfo.csName.equals("x-IBM948") || |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
638 |
csinfo.csName.equals("x-IBM950") || |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
639 |
csinfo.csName.equals("x-IBM937") || |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
640 |
csinfo.csName.equals("x-IBM1383")) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
641 |
{ |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
642 |
log.println(" [**** skipped, KNOWN nr/c2b mapping issue]"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
643 |
known++; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
644 |
continue; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
645 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
646 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
647 |
errors++; |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
648 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
649 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
650 |
|
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
651 |
log.println(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
652 |
log.println(tested + " charset" + plural(tested) + " tested, " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
653 |
+ skipped + " skipped, " + known + " known issue(s)"); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
654 |
log.println(); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
655 |
if (errors > 0) |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
656 |
throw new Exception("Errors detected in " |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
657 |
+ errors + " charset" + plural(errors)); |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
658 |
} |
e78bddc74bf5
8186801: Add regression test to test mapping based charsets (generated at build time)
sherman
parents:
diff
changeset
|
659 |
} |