author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 3055 | 54b677070c61 |
permissions | -rw-r--r-- |
3055
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
3055
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
4 |
* |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
8 |
* |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
13 |
* accompanied this code). |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
14 |
* |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
3055
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
22 |
*/ |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
23 |
|
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
24 |
/* @test |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
25 |
* @bug 6847092 |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
26 |
* @summary test if isLegalReplacement() works correctly for ascii charsets |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
27 |
*/ |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
28 |
|
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
29 |
import java.util.*; |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
30 |
import java.nio.*; |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
31 |
import java.nio.charset.*; |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
32 |
|
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
33 |
public class FindASCIIReplBugs { |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
34 |
private static int failures = 0; |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
35 |
|
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
36 |
public static void main(String[] args) throws Exception { |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
37 |
Charset ascii = Charset.forName("ASCII"); |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
38 |
for (Map.Entry<String,Charset> e |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
39 |
: Charset.availableCharsets().entrySet()) { |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
40 |
String csn = e.getKey(); |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
41 |
Charset cs = e.getValue(); |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
42 |
if (!cs.contains(ascii) || |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
43 |
csn.matches(".*2022.*") || //iso2022 family |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
44 |
csn.matches(".*UTF-[16|32].*")) //multi-bytes |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
45 |
continue; |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
46 |
if (! cs.canEncode()) continue; |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
47 |
|
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
48 |
byte[] sc_subs = { 'A'}; |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
49 |
byte[] mc_subs = { 'A', 'S'}; |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
50 |
if (!cs.newEncoder().isLegalReplacement (sc_subs) || |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
51 |
!cs.newEncoder().isLegalReplacement (mc_subs)) { |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
52 |
System.out.printf(" %s: isLegalReplacement failed!%n", csn); |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
53 |
failures++; |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
54 |
} |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
55 |
} |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
56 |
if (failures > 0) |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
57 |
throw new Exception(failures + "tests failed"); |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
58 |
} |
54b677070c61
6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents:
diff
changeset
|
59 |
} |