--- old/test/TEST.groups 2017-06-07 13:53:32.000000000 +0800 +++ new/test/TEST.groups 2017-06-07 13:53:32.000000000 +0800 @@ -554,7 +554,6 @@ java/nio/charset/Charset/NIOCharsetAvailabilityTest.java \ java/nio/charset/Charset/RegisteredCharsets.java \ java/nio/charset/CharsetEncoder/Flush.java \ - java/nio/charset/coders/CheckSJISMappingProp.sh \ java/nio/charset/coders/ResetISO2022JP.java \ java/util/Locale/InternationalBAT.java \ java/util/Locale/LocaleProviders.sh \ --- old/test/java/nio/charset/coders/SJISPropTest.java 2017-06-07 13:53:33.000000000 +0800 +++ new/test/java/nio/charset/coders/SJISPropTest.java 2017-06-07 13:53:32.000000000 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,12 +22,9 @@ */ /* - * - * - * Regression test class run by CheckSJISMappingProp.sh to verify + * Regression test class run by SJISMappingPropTest.java to verify * that sun.nio.cs.map property is correctly interpreted in * multibyte Japanese locales - * */ public class SJISPropTest { --- old/test/java/nio/file/Path/MacPathTest.java 2017-06-07 13:53:33.000000000 +0800 +++ new/test/java/nio/file/Path/MacPathTest.java 2017-06-07 13:53:33.000000000 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,29 +21,43 @@ * questions. */ -/* @test +/* + * @test * @bug 7130915 * @summary Tests file path with nfc/nfd forms on MacOSX - * @library ../ - * @build MacPathTest - * @run shell MacPathTest.sh + * @requires (os.family == "mac") + * @library /java/nio/file + * @run main/othervm -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 MacPathTest */ -import java.nio.file.*; -import java.nio.file.attribute.*; -import java.text.*; -import java.util.*; -import java.util.regex.*; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.PosixFilePermission; +import java.text.Normalizer; +import java.util.Locale; +import java.util.Set; +import java.util.regex.Pattern; public class MacPathTest { + private static final String JNU_ENCODING = System.getProperty("sun.jnu.encoding"); + private static final String FILE_ENCODING = System.getProperty("file.encoding"); public static void main(String args[]) throws Throwable { - String osname = System.getProperty("os.name"); - if (!osname.contains("OS X") && !osname.contains("Darwin")) + if (!(FILE_ENCODING.equals("UTF-8") && JNU_ENCODING.equals("UTF-8"))) { + System.out.println("Warning: This test requires UTF-8, current encoding:" + + " sun.jnu.encoding = " + JNU_ENCODING + "," + + " file.encoding = " + FILE_ENCODING + "\n" + + "Test skipped.\n" + + "\nRun test with:\n" + + "java -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 MacPathTest"); return; - System.out.printf("sun.jnu.encoding=%s, file.encoding=%s%n", - System.getProperty("file.encoding"), - System.getProperty("sun.jnu.encoding")); + } + + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.US); + // English test("TestDir_apple", // test dir "dir_macosx", // dir @@ -67,6 +81,8 @@ test("TestDir_\uac00\uac01\uac02", "dir_\uac20\uac21\uac22", "file_\uacc0\uacc1\uacc2"); + + Locale.setDefault(defaultLocale); //restore } private static boolean equal(Object x, Object y) { --- /dev/null 2017-06-07 13:53:35.000000000 +0800 +++ new/test/java/nio/charset/Charset/DefaultCharsetTest.java 2017-06-07 13:53:34.000000000 +0800 @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4772857 + * @summary Unit test for Charset.defaultCharset + * @requires (os.family == "linux" | os.family == "solaris") + * @library /test/lib + * @build Default + * @run testng DefaultCharsetTest + */ + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import jdk.test.lib.Platform; +import jdk.test.lib.process.ProcessTools; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertTrue; + +public class DefaultCharsetTest { + + private static final ProcessBuilder pb + = ProcessTools.createJavaProcessBuilder(Default.class.getName()); + private static final Map env = pb.environment(); + private static String UNSUPPORTED = null; + + @BeforeClass + public static void checkSupports() throws Exception { + UNSUPPORTED = runWithLocale("nonexist"); + } + + @DataProvider + public static Iterator locales() { + List data = new ArrayList<>(); + data.add(new String[]{"en_US", "iso-8859-1"}); + data.add(new String[]{"ja_JP.utf8", "utf-8"}); + data.add(new String[]{"tr_TR", "iso-8859-9"}); + data.add(new String[]{"C", "us-ascii"}); + if (Platform.isLinux()) { + data.add(new String[]{"ja_JP", "x-euc-jp-linux"}); + data.add(new String[]{"ja_JP.eucjp", "x-euc-jp-linux"}); + data.add(new String[]{"ja_JP.ujis", "x-euc-jp-linux"}); + data.add(new String[]{"ja_JP.utf8", "utf-8"}); + } + if (Platform.isSolaris()) { + data.add(new String[]{"ja", "x-eucjp-open"}); + data.add(new String[]{"ja_JP.eucJP", "x-eucjp-open"}); + data.add(new String[]{"ja_JP.PCK", "x-PCK"}); + data.add(new String[]{"ja_JP.UTF-8", "utf-8"}); + } + return data.iterator(); + } + + @Test(dataProvider = "locales") + public void testDefaultCharset(String locale, String expectedCharset) + throws Exception { + String actual = runWithLocale(locale); + if (UNSUPPORTED.equals(actual)) { + System.out.println(locale + ": Locale not supported, skipping..."); + } else { + assertTrue(actual.equalsIgnoreCase(expectedCharset), + String.format("LC_ALL = %s, got defaultCharset = %s, " + + "NOT as expected %s", + locale, actual, expectedCharset)); + } + } + + private static String runWithLocale(String locale) throws Exception { + env.remove("LC_ALL"); + env.put("LC_ALL", locale); + return ProcessTools.executeProcess(pb) + .shouldHaveExitValue(0) + .getStdout() + .replace(System.lineSeparator(), ""); + } +} --- /dev/null 2017-06-07 13:53:35.000000000 +0800 +++ new/test/java/nio/charset/coders/SJISMappingPropTest.java 2017-06-07 13:53:35.000000000 +0800 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4879123 + * @summary Verify that sun.nio.cs.map property interpreted in ja multibyte locales + * @requires (os.family != "windows") + * @library /test/lib + * @build SJISPropTest + * @run testng SJISMappingPropTest + */ + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +public class SJISMappingPropTest { + + @DataProvider + public static Iterator locales() { + List data = new ArrayList<>(); + data.add(new String[]{"ja"}); + data.add(new String[]{"ja_JP.PCK"}); + data.add(new String[]{"ja_JP.eucJP"}); + return data.iterator(); + } + + @Test(dataProvider = "locales") + public void testWithProperty(String locale) throws Exception { + // with property set, shift_jis should map to windows-31J charset + runTest(locale, + "-Dsun.nio.cs.map=Windows-31J/Shift_JIS", + SJISPropTest.class.getName(), + "MS932"); + } + + @Test(dataProvider = "locales") + public void testWithoutProperty(String locale) throws Exception { + // without property set - "shift_jis" follows IANA conventions + // and should map to the sun.nio.cs.ext.Shift_JIS charset + runTest(locale, + SJISPropTest.class.getName(), + "Shift_JIS"); + } + + private void runTest(String locale, String... cmd) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmd); + Map env = pb.environment(); + env.put("LC_ALL", locale); + OutputAnalyzer out = ProcessTools.executeProcess(pb) + .outputTo(System.out) + .errorTo(System.err); + assertEquals(out.getExitValue(), 0); + } +} --- old/test/java/nio/charset/Charset/default.sh 2017-06-07 13:53:36.000000000 +0800 +++ /dev/null 2017-06-07 13:53:36.000000000 +0800 @@ -1,97 +0,0 @@ -#!/bin/sh - -# -# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. -# - -# @test -# @bug 4772857 -# @summary Unit test for Charset.defaultCharset -# -# @build Default -# @run shell default.sh -# - -# Command-line usage: sh default.sh [/path/to/build] - -if [ -z "$TESTJAVA" ]; then - if [ $# -lt 1 ]; then exit 1; fi - TESTJAVA=$1; shift - TESTSRC=`pwd` - TESTCLASSES=`pwd` -fi - -s="`uname -s`" -if [ "$s" != Linux -a "$s" != SunOS ]; then - echo "$s: locale command not supported on this system, skipping..." - exit 0 -fi - -JAVA=$TESTJAVA/bin/java - -tolower() { - echo "$1" | tr '[A-Z]' '[a-z]' -} - -go() { - - L="$1" - shift - if [ "x`locale -a | grep \^$L\$`" != "x$L" ]; then - echo "$L: Locale not supported, skipping..." - return - fi - - ecs="$1"; shift - - echo -n "$L: " - cs="`LC_ALL=$L $JAVA ${TESTVMOPTS} -cp $TESTCLASSES Default`" - if [ $? != 0 ]; then - exit 1 - elif [ "`tolower $cs`" != "`tolower $ecs`" ]; then - echo "$cs, expected $ecs -- ERROR" - exit 1 - else - echo "$cs, as expected" - fi - -} - -go en_US iso-8859-1 -go ja_JP.utf8 utf-8 -go tr_TR iso-8859-9 -go C us-ascii - -if [ "$s" = Linux ]; then - go ja_JP x-euc-jp-linux - go ja_JP.eucjp x-euc-jp-linux - go ja_JP.ujis x-euc-jp-linux - go ja_JP.utf8 utf-8 -fi - -# Solaris -if [ "$s" = SunOS ]; then - go ja x-eucjp-open - go ja_JP.eucJP x-eucjp-open - go ja_JP.PCK x-PCK - go ja_JP.UTF-8 utf-8 -fi --- old/test/java/nio/charset/coders/CheckSJISMappingProp.sh 2017-06-07 13:53:37.000000000 +0800 +++ /dev/null 2017-06-07 13:53:37.000000000 +0800 @@ -1,76 +0,0 @@ -#!/bin/sh - -# -# Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. -# - -# @test -# @summary Verify that sun.nio.cs.map property interpreted in ja multibyte locales -# @bug 4879123 -# @build SJISPropTest -# -# @run shell/timeout=300 CheckSJISMappingProp.sh - -# set platform-dependent variables - -OS=`uname -s` -case "$OS" in - SunOS | Linux | Darwin | AIX ) ;; - # Skip locale test for Windows - Windows* | CYGWIN* ) - echo "Passed"; exit 0 ;; - * ) echo "Unrecognized system!" ; exit 1 ;; -esac - -expectPass() { - if [ $1 -eq 0 ] - then echo "--- passed as expected" - else - echo "--- failed" - exit $1 - fi -} - - -JAVA="${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ${TESTCLASSES}" -runTest() { - echo "Testing:" ${1} - LC_ALL="$1" ; export LC_ALL - locale - # Firstly, test with property set - # (shift_jis should map to windows-31J charset) - ${JAVA} -Dsun.nio.cs.map="Windows-31J/Shift_JIS" SJISPropTest MS932 - expectPass $? - - # Next, test without property set - "shift_jis" follows IANA conventions - # and should map to the sun.nio.cs.ext.Shift_JIS charset - ${JAVA} SJISPropTest Shift_JIS - expectPass $? -} - -# Run the test in the common Solaris/Linux/Mac OS locales -# Tests will simply run in current locale if locale isn't supported -# on the test machine/platform - -for i in "ja" "ja_JP.PCK" "ja_JP.eucJP" ; do - runTest ${i} -done --- old/test/java/nio/file/Path/MacPathTest.sh 2017-06-07 13:53:37.000000000 +0800 +++ /dev/null 2017-06-07 13:53:37.000000000 +0800 @@ -1,39 +0,0 @@ -#! /bin/sh - -# -# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. -# -# -OS=`uname -s` -case "$OS" in - Darwin ) ;; - * ) - exit 0 - ;; -esac - -if [ "x$TESTJAVA" = x ]; then - TESTJAVA=$1; shift - TESTCLASSES=. -fi - -export LC_ALL=en_US.UTF-8; ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ${TESTCLASSES} MacPathTest