changeset 53163:5bd3a6017943

8210407: Refactor java.util.Calendar:i18n shell tests to plain java tests Reviewed-by: naoto
author mli
date Wed, 24 Oct 2018 17:52:06 +0800
parents d682023cdd8c
children 876e91d9bb13 da2ddafdd4e1
files test/jdk/java/util/Calendar/GenericTimeZoneNamesTest.java test/jdk/java/util/Calendar/GenericTimeZoneNamesTest.sh test/jdk/java/util/Calendar/NarrowNamesTest.java test/jdk/java/util/Calendar/NarrowNamesTest.sh test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.java test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.sh test/jdk/java/util/Calendar/SupplementalJapaneseEraTestRun.java
diffstat 7 files changed, 161 insertions(+), 192 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/util/Calendar/GenericTimeZoneNamesTest.java	Wed Oct 24 10:42:12 2018 +0200
+++ b/test/jdk/java/util/Calendar/GenericTimeZoneNamesTest.java	Wed Oct 24 17:52:06 2018 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018 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,7 +21,22 @@
  * questions.
  */
 
-import java.util.*;
+/*
+ * @test
+ * @bug 8003267
+ * @summary Unit test for generic time zone names support. This test is locale
+ *          data-dependent and assumes that both JRE and CLDR have the same
+ *          geneic time zone names in English.
+ * @modules java.base/sun.util.locale.provider
+ * @comment Locale providers: default
+ * @run main GenericTimeZoneNamesTest en-US
+ * @comment Locale providers: CLDR
+ * @run main/othervm -Djava.locale.providers=CLDR GenericTimeZoneNamesTest en-US
+*/
+
+import java.util.Locale;
+import java.util.TimeZone;
+
 import sun.util.locale.provider.TimeZoneNameUtility;
 
 public class GenericTimeZoneNamesTest {
--- a/test/jdk/java/util/Calendar/GenericTimeZoneNamesTest.sh	Wed Oct 24 10:42:12 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-#
-# Copyright (c) 2012, 2013, 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 8003267
-# @summary Unit test for generic time zone names support
-# @modules java.base/sun.util.locale.provider
-# @compile GenericTimeZoneNamesTest.java
-# @run shell GenericTimeZoneNamesTest.sh
-
-# This test is locale data-dependent and assumes that both JRE and CLDR
-# have the same geneic time zone names in English.
-
-EXTRAOPTS="--add-exports java.base/sun.util.locale.provider=ALL-UNNAMED"
-STATUS=0
-echo "Locale providers: default"
-if ! ${TESTJAVA}/bin/java -esa ${TESTVMOPTS} ${EXTRAOPTS} -cp "${TESTCLASSES}" GenericTimeZoneNamesTest en-US; then
-    STATUS=1
-fi
-
-echo "Locale providers: CLDR"
-if ! ${TESTJAVA}/bin/java -esa ${TESTVMOPTS} ${EXTRAOPTS} -cp "${TESTCLASSES}" -Djava.locale.providers=CLDR GenericTimeZoneNamesTest en-US; then
-   STATUS=1
-fi
-exit ${STATUS}
-
--- a/test/jdk/java/util/Calendar/NarrowNamesTest.java	Wed Oct 24 10:42:12 2018 +0200
+++ b/test/jdk/java/util/Calendar/NarrowNamesTest.java	Wed Oct 24 17:52:06 2018 +0800
@@ -21,8 +21,24 @@
  * questions.
  */
 
+/*
+ * @test
+ * @bug 8000983 8008577
+ * @summary Unit test for narrow names support. This test is locale data-dependent
+ *          and assumes that both JRE and CLDR have the same narrow names.
+ * @modules jdk.localedata
+ * @comment Locale providers: JRE,SPI
+ * @run main/othervm -Djava.locale.providers=JRE,SPI NarrowNamesTest JRE,SPI
+ * @comment Locale providers: CLDR
+ * @run main/othervm -Djava.locale.providers=CLDR NarrowNamesTest CLDR
+ */
+
 import java.time.LocalDateTime;
-import java.util.*;
+import java.util.Calendar;
+import java.util.Comparator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TreeMap;
 import static java.util.GregorianCalendar.*;
 
 public class NarrowNamesTest {
--- a/test/jdk/java/util/Calendar/NarrowNamesTest.sh	Wed Oct 24 10:42:12 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-#
-# Copyright (c) 2012, 2015, 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 8000983 8008577
-# @summary Unit test for narrow names support
-# @build NarrowNamesTest
-# @run shell NarrowNamesTest.sh
-
-# This test is locale data-dependent and assumes that both JRE and CLDR
-# have the same narrow names.
-
-STATUS=0
-for P in "JRE,SPI" "CLDR"
-do
-    echo "Locale providers: $P"
-    if ! ${TESTJAVA}/bin/java -esa ${TESTVMOPTS} -cp "${TESTCLASSES}" -Djava.locale.providers="${P}" NarrowNamesTest ${P}; then
-        STATUS=1
-    fi
-done
-exit ${STATUS}
--- a/test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.java	Wed Oct 24 10:42:12 2018 +0200
+++ b/test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.java	Wed Oct 24 17:52:06 2018 +0800
@@ -32,20 +32,13 @@
 import java.util.GregorianCalendar;
 import static java.util.GregorianCalendar.*;
 import java.util.Locale;
-import java.util.TimeZone;
 
 /*
  * Usage:
- *   java SupplementalJapaneseEraTest <flag>
- *    <flag>
- *      -s   prints start time for a test era
- *      -e   prints the English name of the last predefined era
- *
  *   java -Djdk.calendar.japanese.supplemental.era=... SupplementalJapaneseEraTest <flag>
  *      -t   executes tests with a valid property value
  *      -b <eraname>
  *           executes tests with an invalid property value
- *           <eraname> must be the output with -e
  */
 
 public class SupplementalJapaneseEraTest {
@@ -57,26 +50,6 @@
     public static void main(String[] args) {
         // args[0] is a flag.
         switch (args[0]) {
-        case "-s":
-            // print the start time of the new era for testing
-            Calendar cal = new Calendar.Builder()
-                .setCalendarType("japanese")
-                .setTimeZone(TimeZone.getTimeZone("GMT"))
-                .setFields(ERA, 5)
-                .setDate(200, FEBRUARY, 11)
-                .build();
-            System.out.println(cal.getTimeInMillis());
-            break;
-
-        case "-e":
-            // print the current era name in English
-            Calendar jcal = new Calendar.Builder()
-                .setCalendarType("japanese")
-                .setFields(YEAR, 1, DAY_OF_YEAR, 1)
-                .build();
-            System.out.println(jcal.getDisplayName(ERA, LONG, Locale.US));
-            break;
-
         case "-t":
             // test with a valid property value
             testProperty();
@@ -84,7 +57,7 @@
 
         case "-b":
             // test with an invalid property value
-            // args[1] is the current era name given by -e.
+            // args[1] is the current era name.
             testValidation(args[1].replace("\r", "")); // remove any CR for Cygwin
             break;
         }
--- a/test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.sh	Wed Oct 24 10:42:12 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-#
-# Copyright (c) 2014, 2018, 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 8048123 8054214 8173423
-# @summary Test for jdk.calendar.japanese.supplemental.era support
-# @build SupplementalJapaneseEraTest
-# @run shell SupplementalJapaneseEraTest.sh
-
-PROPERTY=jdk.calendar.japanese.supplemental.era
-STATUS=0
-
-# get the start time of the fictional next era
-SINCE=`${TESTJAVA}/bin/java -cp "${TESTCLASSES}" SupplementalJapaneseEraTest -s`
-
-echo "Tests with valid property values..."
-for P in "name=SupEra,abbr=S.E.,since=$SINCE" \
-         "name = SupEra, abbr = S.E., since = $SINCE"
-do
-    if ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp "${TESTCLASSES}" \
-           -D$PROPERTY="$P" SupplementalJapaneseEraTest -t; then
-        echo "$P: passed"
-    else
-        echo "$P: failed"
-        STATUS=1
-    fi
-done
-
-# get the name of the current era to be used to confirm that
-# invalid property values are ignored.
-ERA=`${TESTJAVA}/bin/java -cp "${TESTCLASSES}" SupplementalJapaneseEraTest -e`
-
-echo "Tests with invalid property values..."
-for P in "foo=Bar,name=SupEra,abbr=S.E.,since=$SINCE" \
-         "=SupEra,abbr=S.E.,since=$SINCE" \
-         "=,abbr=S.E.,since=$SINCE" \
-         "name,abbr=S.E.,since=$SINCE" \
-         "abbr=S.E.,since=$SINCE" \
-         "name=SupEra,since=$SINCE" \
-         "name=,abbr=S.E.,since=$SINCE" \
-         "name=SupEra,abbr=,since=$SINCE" \
-         "name=SupEra,abbr=S.E." \
-         "name=SupEra,abbr=S.E.,since=0" \
-         "name=SupEra,abbr=S.E.,since=9223372036854775808" # Long.MAX_VALUE+1
-do
-    if ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp "${TESTCLASSES}" \
-           -D$PROPERTY="$P" SupplementalJapaneseEraTest -b "$ERA"; then
-        echo "$P: passed"
-    else
-        echo "$P: failed"
-        STATUS=1
-    fi
-done
-exit $STATUS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Calendar/SupplementalJapaneseEraTestRun.java	Wed Oct 24 17:52:06 2018 +0800
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2014, 2018, 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 8048123 8054214 8173423
+ * @summary Test for jdk.calendar.japanese.supplemental.era support
+ * @library /test/lib
+ * @build SupplementalJapaneseEraTest
+ * @run testng/othervm SupplementalJapaneseEraTestRun
+ */
+
+import java.util.Calendar;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+import static java.util.Calendar.*;
+
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Utils;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+public class SupplementalJapaneseEraTestRun {
+    @DataProvider(name = "validprop")
+    Object[][] validPropertyData() {
+        return new Object[][] {
+                //Tests with valid property values
+                {"name=SupEra,abbr=S.E.,since="},
+                {"name = SupEra, abbr = S.E., since = "},
+        };
+    }
+
+    @DataProvider(name = "invalidprop")
+    Object[][] invalidPropertyData() {
+        return new Object[][] {
+                //Tests with invalid property values
+                {"=SupEra,abbr=S.E.,since="},
+                {"=,abbr=S.E.,since="},
+                {"name,abbr=S.E.,since="},
+                {"abbr=S.E.,since="},
+                {"name=SupEra,since="},
+                {"name=,abbr=S.E.,since"},
+                {"name=SupEra,abbr=,since="},
+                {"name=SupEra,abbr=S.E."},
+                {"name=SupEra,abbr=S.E.,since=0"},
+                //since=9223372036854775808 the number means Long.MAX_VALUE+1
+                {"name=SupEra,abbr=S.E.,since=9223372036854775808"},
+        };
+    }
+
+    @Test(dataProvider = "validprop")
+    public void ValidPropertyValuesTest(String prop)
+            throws Throwable {
+        //get the start time of the fictional next era
+        String startTime = getStartTime();
+        testRun(prop + startTime, List.of("-t"));
+    }
+
+    @Test(dataProvider = "invalidprop")
+    public void InvalidPropertyValuesTest(String prop)
+            throws Throwable {
+        //get the start time of the fictional next era
+        String startTime = getStartTime();
+        //get the name of the current era to be used to confirm that
+        //invalid property values are ignored.
+        String currentEra = getCurrentEra();
+        testRun(prop + startTime, List.of("-b", currentEra));
+    }
+
+    private static void testRun(String property, List<String> javaParam)
+            throws Throwable{
+        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
+        launcher.addToolArg("-cp")
+                .addToolArg(Utils.TEST_CLASS_PATH)
+                .addToolArg("-Djdk.calendar.japanese.supplemental.era=" + property)
+                .addToolArg("SupplementalJapaneseEraTest");
+        for (String para: javaParam) {
+            launcher.addToolArg(para);
+        }
+        int exitCode = ProcessTools.executeCommand(launcher.getCommand())
+                .getExitValue();
+        System.out.println(property + ":pass");
+        if (exitCode != 0) {
+            System.out.println(property + ":fail");
+            throw new RuntimeException("Unexpected exit code: " + exitCode);
+        }
+    }
+
+    private static String getStartTime(){
+        Calendar cal = new Calendar.Builder().setCalendarType("japanese")
+                .setTimeZone(TimeZone.getTimeZone("GMT")).setFields(ERA, 5)
+                .setDate(200, FEBRUARY, 11).build();
+        return String.valueOf(cal.getTimeInMillis());
+    }
+
+    private static String getCurrentEra(){
+        Calendar jcal = new Calendar.Builder()
+                .setCalendarType("japanese")
+                .setFields(YEAR, 1, DAY_OF_YEAR, 1)
+                .build();
+        return jcal.getDisplayName(ERA, LONG, Locale.US);
+    }
+}