|
1 | 1 | /* |
2 | | - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
25 | 25 | * @bug 4626545 4696726 |
26 | 26 | * @summary Checks the inter containment relationships between NIO charsets |
27 | 27 | * @modules jdk.charsets |
| 28 | + * @run junit CharsetContainmentTest |
28 | 29 | */ |
29 | 30 |
|
30 | | -import java.nio.charset.*; |
| 31 | +import java.nio.charset.Charset; |
| 32 | +import java.util.ArrayList; |
| 33 | +import java.util.List; |
| 34 | +import java.util.stream.Stream; |
31 | 35 |
|
32 | | -public class CharsetContainmentTest { |
33 | | - static String[] encodings = |
34 | | - { "US-ASCII", "UTF-16", "UTF-16BE", "UTF-16LE", "UTF-8", |
35 | | - "windows-1252", "ISO-8859-1", "ISO-8859-2", "ISO-8859-3", |
36 | | - "ISO-8859-4", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", |
37 | | - "ISO-8859-8", "ISO-8859-9", "ISO-8859-13", "ISO-8859-15", "ISO-8859-16", |
38 | | - "ISO-2022-JP", "ISO-2022-KR", |
| 36 | +import org.junit.jupiter.params.ParameterizedTest; |
| 37 | +import org.junit.jupiter.params.provider.Arguments; |
| 38 | +import org.junit.jupiter.params.provider.MethodSource; |
39 | 39 |
|
40 | | - // Temporarily remove ISO-2022-CN-* charsets until full encoder/decoder |
41 | | - // support is added (4673614) |
42 | | - // "x-ISO-2022-CN-CNS", "x-ISO-2022-CN-GB", |
| 40 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
43 | 41 |
|
44 | | - "x-ISCII91", "GBK", "GB18030", "Big5", |
45 | | - "x-EUC-TW", "GB2312", "EUC-KR", "x-Johab", "Big5-HKSCS", |
46 | | - "x-MS950-HKSCS", "windows-1251", "windows-1253", "windows-1254", |
47 | | - "windows-1255", "windows-1256", "windows-1257", "windows-1258", |
48 | | - "x-mswin-936", "x-windows-949", "x-windows-950", "windows-31j", |
49 | | - "Shift_JIS", "EUC-JP", "KOI8-R", "TIS-620" |
50 | | - }; |
| 42 | +public class CharsetContainmentTest { |
51 | 43 |
|
52 | | - static String[][] contains = { |
53 | | - { "US-ASCII"}, |
54 | | - encodings, |
55 | | - encodings, |
56 | | - encodings, |
57 | | - encodings, |
58 | | - {"US-ASCII", "windows-1252"}, |
59 | | - {"US-ASCII", "ISO-8859-1"}, |
60 | | - {"US-ASCII", "ISO-8859-2"}, |
61 | | - {"US-ASCII", "ISO-8859-3"}, |
62 | | - {"US-ASCII", "ISO-8859-4"}, |
63 | | - {"US-ASCII", "ISO-8859-5"}, |
64 | | - {"US-ASCII", "ISO-8859-6"}, |
65 | | - {"US-ASCII", "ISO-8859-7"}, |
66 | | - {"US-ASCII", "ISO-8859-8"}, |
67 | | - {"US-ASCII", "ISO-8859-9"}, |
68 | | - {"US-ASCII", "ISO-8859-13"}, |
69 | | - {"US-ASCII", "ISO-8859-15"}, |
70 | | - {"US-ASCII", "ISO-8859-16"}, |
71 | | - {"ISO-2022-JP"}, |
72 | | - {"ISO-2022-KR"}, |
73 | | - // Temporarily remove ISO-2022-CN-* charsets until full encoder/decoder |
74 | | - // support is added (4673614) |
75 | | - //{"x-ISO-2022-CN-CNS"}, |
76 | | - //{"x-ISO-2022-CN-GB"}, |
77 | | - {"US-ASCII", "x-ISCII91"}, |
78 | | - {"US-ASCII", "GBK"}, |
79 | | - encodings, |
80 | | - {"US-ASCII", "Big5"}, |
81 | | - {"US-ASCII", "x-EUC-TW"}, |
82 | | - {"US-ASCII", "GB2312"}, |
83 | | - {"US-ASCII", "EUC-KR"}, |
84 | | - {"US-ASCII", "x-Johab"}, |
85 | | - {"US-ASCII", "Big5-HKSCS", "Big5"}, |
86 | | - {"US-ASCII", "x-MS950-HKSCS", "x-windows-950"}, |
87 | | - {"US-ASCII", "windows-1251"}, |
88 | | - {"US-ASCII", "windows-1253"}, |
89 | | - {"US-ASCII", "windows-1254"}, |
90 | | - {"US-ASCII", "windows-1255"}, |
91 | | - {"US-ASCII", "windows-1256"}, |
92 | | - {"US-ASCII", "windows-1257"}, |
93 | | - {"US-ASCII", "windows-1258"}, |
94 | | - {"US-ASCII", "x-mswin-936"}, |
95 | | - {"US-ASCII", "x-windows-949"}, |
96 | | - {"US-ASCII", "x-windows-950"}, |
97 | | - {"US-ASCII", "windows-31j" }, |
98 | | - {"US-ASCII", "Shift_JIS"}, |
99 | | - {"US-ASCII", "EUC-JP"}, |
100 | | - {"US-ASCII", "KOI8-R"}, |
101 | | - {"US-ASCII", "TIS-620"}}; |
| 44 | + /** |
| 45 | + * Test that the charsets in 'encodings' contain the charsets |
| 46 | + * inside 'contains'. Each value in 'encodings' is mapped to a String |
| 47 | + * array in 'contains'. For example, the value, "TIS-620" in 'encodings' |
| 48 | + * should contain "US-ASCII", "TIS-620". |
| 49 | + */ |
| 50 | + @ParameterizedTest |
| 51 | + @MethodSource("charsets") |
| 52 | + public void interContainmentTest(String containerName, String containedName) { |
| 53 | + Charset container = Charset.forName(containerName); |
| 54 | + Charset contained = Charset.forName(containedName); |
| 55 | + assertTrue(container.contains(contained), |
| 56 | + String.format("Charset: %s does not contain: %s", containerName, containedName)); |
| 57 | + } |
102 | 58 |
|
| 59 | + private static Stream<Arguments> charsets() { |
| 60 | + String[] encodings = { |
| 61 | + "US-ASCII", "UTF-16", "UTF-16BE", "UTF-16LE", "UTF-8", |
| 62 | + "windows-1252", "ISO-8859-1", "ISO-8859-2", "ISO-8859-3", |
| 63 | + "ISO-8859-4", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", |
| 64 | + "ISO-8859-8", "ISO-8859-9", "ISO-8859-13", "ISO-8859-15", "ISO-8859-16", |
| 65 | + "ISO-2022-JP", "ISO-2022-KR", |
| 66 | + // Temporarily remove ISO-2022-CN-* charsets until full encoder/decoder |
| 67 | + // support is added (4673614) |
| 68 | + // "x-ISO-2022-CN-CNS", "x-ISO-2022-CN-GB", |
| 69 | + "x-ISCII91", "GBK", "GB18030", "Big5", |
| 70 | + "x-EUC-TW", "GB2312", "EUC-KR", "x-Johab", "Big5-HKSCS", |
| 71 | + "x-MS950-HKSCS", "windows-1251", "windows-1253", "windows-1254", |
| 72 | + "windows-1255", "windows-1256", "windows-1257", "windows-1258", |
| 73 | + "x-mswin-936", "x-windows-949", "x-windows-950", "windows-31j", |
| 74 | + "Shift_JIS", "EUC-JP", "KOI8-R", "TIS-620" |
| 75 | + }; |
103 | 76 |
|
104 | | - public static void main(String[] args) throws Exception { |
| 77 | + String[][] contains = { |
| 78 | + {"US-ASCII"}, |
| 79 | + encodings, |
| 80 | + encodings, |
| 81 | + encodings, |
| 82 | + encodings, |
| 83 | + {"US-ASCII", "windows-1252"}, |
| 84 | + {"US-ASCII", "ISO-8859-1"}, |
| 85 | + {"US-ASCII", "ISO-8859-2"}, |
| 86 | + {"US-ASCII", "ISO-8859-3"}, |
| 87 | + {"US-ASCII", "ISO-8859-4"}, |
| 88 | + {"US-ASCII", "ISO-8859-5"}, |
| 89 | + {"US-ASCII", "ISO-8859-6"}, |
| 90 | + {"US-ASCII", "ISO-8859-7"}, |
| 91 | + {"US-ASCII", "ISO-8859-8"}, |
| 92 | + {"US-ASCII", "ISO-8859-9"}, |
| 93 | + {"US-ASCII", "ISO-8859-13"}, |
| 94 | + {"US-ASCII", "ISO-8859-15"}, |
| 95 | + {"US-ASCII", "ISO-8859-16"}, |
| 96 | + {"ISO-2022-JP"}, |
| 97 | + {"ISO-2022-KR"}, |
| 98 | + // Temporarily remove ISO-2022-CN-* charsets until full encoder/decoder |
| 99 | + // support is added (4673614) |
| 100 | + //{"x-ISO-2022-CN-CNS"}, |
| 101 | + //{"x-ISO-2022-CN-GB"}, |
| 102 | + {"US-ASCII", "x-ISCII91"}, |
| 103 | + {"US-ASCII", "GBK"}, |
| 104 | + encodings, |
| 105 | + {"US-ASCII", "Big5"}, |
| 106 | + {"US-ASCII", "x-EUC-TW"}, |
| 107 | + {"US-ASCII", "GB2312"}, |
| 108 | + {"US-ASCII", "EUC-KR"}, |
| 109 | + {"US-ASCII", "x-Johab"}, |
| 110 | + {"US-ASCII", "Big5-HKSCS", "Big5"}, |
| 111 | + {"US-ASCII", "x-MS950-HKSCS", "x-windows-950"}, |
| 112 | + {"US-ASCII", "windows-1251"}, |
| 113 | + {"US-ASCII", "windows-1253"}, |
| 114 | + {"US-ASCII", "windows-1254"}, |
| 115 | + {"US-ASCII", "windows-1255"}, |
| 116 | + {"US-ASCII", "windows-1256"}, |
| 117 | + {"US-ASCII", "windows-1257"}, |
| 118 | + {"US-ASCII", "windows-1258"}, |
| 119 | + {"US-ASCII", "x-mswin-936"}, |
| 120 | + {"US-ASCII", "x-windows-949"}, |
| 121 | + {"US-ASCII", "x-windows-950"}, |
| 122 | + {"US-ASCII", "windows-31j"}, |
| 123 | + {"US-ASCII", "Shift_JIS"}, |
| 124 | + {"US-ASCII", "EUC-JP"}, |
| 125 | + {"US-ASCII", "KOI8-R"}, |
| 126 | + {"US-ASCII", "TIS-620"}}; |
| 127 | + |
| 128 | + // Length of encodings and contains should always be equal |
| 129 | + if (encodings.length != contains.length) { |
| 130 | + throw new RuntimeException("Testing data is not set up correctly"); |
| 131 | + } |
| 132 | + List<Arguments> charsetList = new ArrayList<Arguments>(); |
105 | 133 | for (int i = 0; i < encodings.length; i++) { |
106 | | - Charset c = Charset.forName(encodings[i]); |
107 | | - for (int j = 0 ; j < contains[i].length; j++) { |
108 | | - if (c.contains(Charset.forName(contains[i][j]))) |
109 | | - continue; |
110 | | - else { |
111 | | - throw new Exception ("Error: charset " + encodings[i] + |
112 | | - "doesn't contain " + contains[i][j]); |
113 | | - } |
114 | | - } |
| 134 | + for (int j = 0 ; j < contains[i].length; j++) { |
| 135 | + charsetList.add(Arguments.of(encodings[i], contains[i][j])); |
| 136 | + } |
115 | 137 | } |
| 138 | + return charsetList.stream(); |
116 | 139 | } |
117 | 140 | } |
0 commit comments