1 /* |
|
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 4879123 |
|
27 * @summary Verify that sun.nio.cs.map property interpreted in ja multibyte locales |
|
28 * @requires (os.family != "windows") |
|
29 * @modules jdk.charsets |
|
30 * @library /test/lib |
|
31 * @build jdk.test.lib.Utils |
|
32 * jdk.test.lib.Asserts |
|
33 * jdk.test.lib.JDKToolFinder |
|
34 * jdk.test.lib.JDKToolLauncher |
|
35 * jdk.test.lib.Platform |
|
36 * jdk.test.lib.process.* |
|
37 * SJISPropTest |
|
38 * @run testng SJISMappingPropTest |
|
39 */ |
|
40 |
|
41 import java.util.ArrayList; |
|
42 import java.util.Iterator; |
|
43 import java.util.List; |
|
44 import java.util.Map; |
|
45 |
|
46 import jdk.test.lib.process.OutputAnalyzer; |
|
47 import jdk.test.lib.process.ProcessTools; |
|
48 |
|
49 import org.testng.annotations.DataProvider; |
|
50 import org.testng.annotations.Test; |
|
51 |
|
52 import static org.testng.Assert.assertEquals; |
|
53 |
|
54 public class SJISMappingPropTest { |
|
55 |
|
56 @DataProvider |
|
57 public static Iterator<Object[]> locales() { |
|
58 List<Object[]> data = new ArrayList<>(); |
|
59 data.add(new String[]{"ja"}); |
|
60 data.add(new String[]{"ja_JP.PCK"}); |
|
61 data.add(new String[]{"ja_JP.eucJP"}); |
|
62 return data.iterator(); |
|
63 } |
|
64 |
|
65 @Test(dataProvider = "locales") |
|
66 public void testWithProperty(String locale) throws Exception { |
|
67 // with property set, shift_jis should map to windows-31J charset |
|
68 runTest(locale, |
|
69 "-Dsun.nio.cs.map=Windows-31J/Shift_JIS", |
|
70 SJISPropTest.class.getName(), |
|
71 "MS932"); |
|
72 } |
|
73 |
|
74 @Test(dataProvider = "locales") |
|
75 public void testWithoutProperty(String locale) throws Exception { |
|
76 // without property set - "shift_jis" follows IANA conventions |
|
77 // and should map to the sun.nio.cs.ext.Shift_JIS charset |
|
78 runTest(locale, |
|
79 SJISPropTest.class.getName(), |
|
80 "Shift_JIS"); |
|
81 } |
|
82 |
|
83 private void runTest(String locale, String... cmd) throws Exception { |
|
84 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmd); |
|
85 Map<String, String> env = pb.environment(); |
|
86 env.put("LC_ALL", locale); |
|
87 OutputAnalyzer out = ProcessTools.executeProcess(pb) |
|
88 .outputTo(System.out) |
|
89 .errorTo(System.err); |
|
90 assertEquals(out.getExitValue(), 0); |
|
91 } |
|
92 } |
|