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 * @library /test/lib 30 * @build SJISPropTest 31 * @run testng SJISMappingPropTest 32 */ 33 34 import java.util.ArrayList; 35 import java.util.Iterator; 36 import java.util.List; 37 import java.util.Map; 38 39 import jdk.test.lib.process.OutputAnalyzer; 40 import jdk.test.lib.process.ProcessTools; 41 42 import org.testng.annotations.DataProvider; 43 import org.testng.annotations.Test; 44 45 import static org.testng.Assert.assertEquals; 46 47 public class SJISMappingPropTest { 48 49 @DataProvider 50 public static Iterator<Object[]> locales() { 51 List<Object[]> data = new ArrayList<>(); 52 data.add(new String[]{"ja"}); 53 data.add(new String[]{"ja_JP.PCK"}); 54 data.add(new String[]{"ja_JP.eucJP"}); 55 return data.iterator(); 56 } 57 58 @Test(dataProvider = "locales") 59 public void testWithProperty(String locale) throws Exception { 60 // with property set, shift_jis should map to windows-31J charset 61 runTest(locale, 62 "-Dsun.nio.cs.map=Windows-31J/Shift_JIS", 63 SJISPropTest.class.getName(), 64 "MS932"); 65 } 66 67 @Test(dataProvider = "locales") 68 public void testWithoutProperty(String locale) throws Exception { 69 // without property set - "shift_jis" follows IANA conventions 70 // and should map to the sun.nio.cs.ext.Shift_JIS charset 71 runTest(locale, 72 SJISPropTest.class.getName(), 73 "Shift_JIS"); 74 } 75 76 private void runTest(String locale, String... cmd) throws Exception { 77 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmd); 78 Map<String, String> env = pb.environment(); 79 env.put("LC_ALL", locale); 80 OutputAnalyzer out = ProcessTools.executeProcess(pb) 81 .outputTo(System.out) 82 .errorTo(System.err); 83 assertEquals(out.getExitValue(), 0); 84 } 85 }