changeset 14028:5f3d5ae5f1ea

7198834: HOST Adapter: one extra empty space in the end of the pattern string Reviewed-by: okutsu
author naoto
date Fri, 05 Oct 2012 09:57:50 -0700
parents 9c48ad0b8972
children c684694164c2
files jdk/src/share/classes/sun/util/locale/provider/JRELocaleProviderAdapter.java jdk/src/windows/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c jdk/test/java/util/Locale/LocaleProviders.java jdk/test/java/util/Locale/LocaleProviders.sh
diffstat 4 files changed, 137 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/share/classes/sun/util/locale/provider/JRELocaleProviderAdapter.java	Thu Oct 04 21:05:06 2012 -0700
+++ b/jdk/src/share/classes/sun/util/locale/provider/JRELocaleProviderAdapter.java	Fri Oct 05 09:57:50 2012 -0700
@@ -125,7 +125,7 @@
     public BreakIteratorProvider getBreakIteratorProvider() {
         if (breakIteratorProvider == null) {
             BreakIteratorProvider provider = new BreakIteratorProviderImpl(getAdapterType(),
-                                                            getLanguateTagSet("FormatData"));
+                                                            getLanguageTagSet("FormatData"));
             synchronized (this) {
                 if (breakIteratorProvider == null) {
                     breakIteratorProvider = provider;
@@ -139,7 +139,7 @@
     public CollatorProvider getCollatorProvider() {
         if (collatorProvider == null) {
             CollatorProvider provider = new CollatorProviderImpl(getAdapterType(),
-                                                getLanguateTagSet("CollationData"));
+                                                getLanguageTagSet("CollationData"));
             synchronized (this) {
                 if (collatorProvider == null) {
                     collatorProvider = provider;
@@ -153,7 +153,7 @@
     public DateFormatProvider getDateFormatProvider() {
         if (dateFormatProvider == null) {
             DateFormatProvider provider = new DateFormatProviderImpl(getAdapterType(),
-                                                    getLanguateTagSet("FormatData"));
+                                                    getLanguageTagSet("FormatData"));
             synchronized (this) {
                 if (dateFormatProvider == null) {
                     dateFormatProvider = provider;
@@ -167,7 +167,7 @@
     public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
         if (dateFormatSymbolsProvider == null) {
             DateFormatSymbolsProvider provider = new DateFormatSymbolsProviderImpl(getAdapterType(),
-                                                                getLanguateTagSet("FormatData"));
+                                                                getLanguageTagSet("FormatData"));
             synchronized (this) {
                 if (dateFormatSymbolsProvider == null) {
                     dateFormatSymbolsProvider = provider;
@@ -180,7 +180,7 @@
     @Override
     public DecimalFormatSymbolsProvider getDecimalFormatSymbolsProvider() {
         if (decimalFormatSymbolsProvider == null) {
-            DecimalFormatSymbolsProvider provider = new DecimalFormatSymbolsProviderImpl(getAdapterType(), getLanguateTagSet("FormatData"));
+            DecimalFormatSymbolsProvider provider = new DecimalFormatSymbolsProviderImpl(getAdapterType(), getLanguageTagSet("FormatData"));
             synchronized (this) {
                 if (decimalFormatSymbolsProvider == null) {
                     decimalFormatSymbolsProvider = provider;
@@ -194,7 +194,7 @@
     public NumberFormatProvider getNumberFormatProvider() {
         if (numberFormatProvider == null) {
             NumberFormatProvider provider = new NumberFormatProviderImpl(getAdapterType(),
-                                                        getLanguateTagSet("FormatData"));
+                                                        getLanguageTagSet("FormatData"));
             synchronized (this) {
                 if (numberFormatProvider == null) {
                     numberFormatProvider = provider;
@@ -211,7 +211,7 @@
     public CurrencyNameProvider getCurrencyNameProvider() {
         if (currencyNameProvider == null) {
             CurrencyNameProvider provider = new CurrencyNameProviderImpl(getAdapterType(),
-                                            getLanguateTagSet("CurrencyNames"));
+                                            getLanguageTagSet("CurrencyNames"));
             synchronized (this) {
                 if (currencyNameProvider == null) {
                     currencyNameProvider = provider;
@@ -225,7 +225,7 @@
     public LocaleNameProvider getLocaleNameProvider() {
         if (localeNameProvider == null) {
             LocaleNameProvider provider = new LocaleNameProviderImpl(getAdapterType(),
-                                                    getLanguateTagSet("LocaleNames"));
+                                                    getLanguageTagSet("LocaleNames"));
             synchronized (this) {
                 if (localeNameProvider == null) {
                     localeNameProvider = provider;
@@ -239,7 +239,7 @@
     public TimeZoneNameProvider getTimeZoneNameProvider() {
         if (timeZoneNameProvider == null) {
             TimeZoneNameProvider provider = new TimeZoneNameProviderImpl(getAdapterType(),
-                                                    getLanguateTagSet("TimeZoneNames"));
+                                                    getLanguageTagSet("TimeZoneNames"));
             synchronized (this) {
                 if (timeZoneNameProvider == null) {
                     timeZoneNameProvider = provider;
@@ -253,8 +253,8 @@
     public CalendarDataProvider getCalendarDataProvider() {
         if (calendarDataProvider == null) {
             Set<String> set = new HashSet<>();
-            set.addAll(getLanguateTagSet("FormatData"));
-            set.addAll(getLanguateTagSet("CalendarData"));
+            set.addAll(getLanguageTagSet("FormatData"));
+            set.addAll(getLanguageTagSet("CalendarData"));
             CalendarDataProvider provider = new CalendarDataProviderImpl(getAdapterType(),
                                                                          set);
             synchronized (this) {
@@ -302,7 +302,7 @@
         return AvailableJRELocales.localeList.clone();
     }
 
-    public Set<String> getLanguateTagSet(String category) {
+    public Set<String> getLanguageTagSet(String category) {
         Set<String> tagset = langtagSets.get(category);
         if (tagset == null) {
             tagset = createLanguageTagSet(category);
--- a/jdk/src/windows/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c	Thu Oct 04 21:05:06 2012 -0700
+++ b/jdk/src/windows/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c	Fri Oct 05 09:57:50 2012 -0700
@@ -209,31 +209,26 @@
  */
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDateTimePattern
   (JNIEnv *env, jclass cls, jint dateStyle, jint timeStyle, jstring jlangtag) {
-    WCHAR datePattern[BUFLEN];
-    WCHAR timePattern[BUFLEN];
+    WCHAR pattern[BUFLEN];
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
 
-    datePattern[0] = L'\0';
-    timePattern[0] = L'\0';
+    pattern[0] = L'\0';
 
     if (dateStyle == 0 || dateStyle == 1) {
-        getLocaleInfoWrapper(langtag, LOCALE_SLONGDATE, datePattern, BUFLEN);
+        getLocaleInfoWrapper(langtag, LOCALE_SLONGDATE, pattern, BUFLEN);
     } else if (dateStyle == 2 || dateStyle == 3) {
-        getLocaleInfoWrapper(langtag, LOCALE_SSHORTDATE, datePattern, BUFLEN);
+        getLocaleInfoWrapper(langtag, LOCALE_SSHORTDATE, pattern, BUFLEN);
     }
 
     if (timeStyle == 0 || timeStyle == 1) {
-        getLocaleInfoWrapper(langtag, LOCALE_STIMEFORMAT, timePattern, BUFLEN);
+        getLocaleInfoWrapper(langtag, LOCALE_STIMEFORMAT, pattern, BUFLEN);
     } else if (timeStyle == 2 || timeStyle == 3) {
-        getLocaleInfoWrapper(langtag, LOCALE_SSHORTTIME, timePattern, BUFLEN);
+        getLocaleInfoWrapper(langtag, LOCALE_SSHORTTIME, pattern, BUFLEN);
     }
 
-    wcscat(datePattern, L" ");
-    wcscat(datePattern, timePattern);
-
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
-    return (*env)->NewString(env, datePattern, wcslen(datePattern));
+    return (*env)->NewString(env, pattern, wcslen(pattern));
 }
 
 /*
--- a/jdk/test/java/util/Locale/LocaleProviders.java	Thu Oct 04 21:05:06 2012 -0700
+++ b/jdk/test/java/util/Locale/LocaleProviders.java	Fri Oct 05 09:57:50 2012 -0700
@@ -20,27 +20,65 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
-import java.text.spi.DateFormatProvider;
-import java.util.Locale;
+import java.text.*;
+import java.text.spi.*;
+import java.util.*;
 import sun.util.locale.provider.LocaleProviderAdapter;
 
 public class LocaleProviders {
 
     public static void main(String[] args) {
-        if (args.length == 0) {
-            // no args indicates that the caller is asking the platform default locale.
-            Locale defloc = Locale.getDefault();
-            System.out.printf("%s,%s\n", defloc.getLanguage(), defloc.getCountry());
+        String methodName = args[0];
+
+        switch (methodName) {
+            case "getPlatformLocale":
+                if (args[1].equals("format")) {
+                    getPlatformLocale(Locale.Category.FORMAT);
+                } else {
+                    getPlatformLocale(Locale.Category.DISPLAY);
+                }
+                break;
+
+            case "adapterTest":
+                adapterTest(args[1], args[2], (args.length >= 4 ? args[3] : ""));
+                break;
+
+            case "bug7198834Test":
+                bug7198834Test();
+                break;
+
+            default:
+                throw new RuntimeException("Test method '"+methodName+"' not found.");
+        }
+    }
+
+    static void getPlatformLocale(Locale.Category cat) {
+        Locale defloc = Locale.getDefault(cat);
+        System.out.printf("%s,%s\n", defloc.getLanguage(), defloc.getCountry());
+    }
+
+    static void adapterTest(String expected, String lang, String ctry) {
+        Locale testLocale = new Locale(lang, ctry);
+        String preference = System.getProperty("java.locale.providers", "");
+        LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
+        LocaleProviderAdapter.Type type = lda.getAdapterType();
+        System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
+        if (!type.toString().equals(expected)) {
+            throw new RuntimeException("Returned locale data adapter is not correct.");
+        }
+    }
+
+    static void bug7198834Test() {
+        LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
+        LocaleProviderAdapter.Type type = lda.getAdapterType();
+        if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
+            DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
+            String date = df.format(new Date());
+            if (date.charAt(date.length()-1) == ' ') {
+                throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
+            }
         } else {
-            String expected = args[0];
-            Locale testLocale = new Locale(args[1], (args.length >= 3 ? args[2] : ""));
-            String preference = System.getProperty("java.locale.providers", "");
-            LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
-            LocaleProviderAdapter.Type type = lda.getAdapterType();
-            System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
-            if (!type.toString().equals(expected)) {
-                throw new RuntimeException("Returned locale data adapter is not correct.");
-            }
+            System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
         }
     }
 }
--- a/jdk/test/java/util/Locale/LocaleProviders.sh	Thu Oct 04 21:05:06 2012 -0700
+++ b/jdk/test/java/util/Locale/LocaleProviders.sh	Fri Oct 05 09:57:50 2012 -0700
@@ -23,7 +23,7 @@
 #!/bin/sh
 #
 # @test
-# @bug 6336885 7196799 7197573
+# @bug 6336885 7196799 7197573 7198834
 # @summary tests for "java.locale.providers" system property
 # @compile -XDignore.symbol.file LocaleProviders.java
 # @run shell/timeout=600 LocaleProviders.sh
@@ -65,16 +65,21 @@
     ;;
 esac
 
-# get the platform default locale
-PLATDEF=`${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} LocaleProviders`
+# get the platform default locales
+PLATDEF=`${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale display`
 DEFLANG=`echo ${PLATDEF} | sed -e "s/,.*//"`
 DEFCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"`
 echo "DEFLANG=${DEFLANG}"
 echo "DEFCTRY=${DEFCTRY}"
+PLATDEF=`${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale format`
+DEFFMTLANG=`echo ${PLATDEF} | sed -e "s/,.*//"`
+DEFFMTCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"`
+echo "DEFFMTLANG=${DEFFMTLANG}"
+echo "DEFFMTCTRY=${DEFFMTCTRY}"
 
 runTest()
 {
-    RUNCMD="${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} -Djava.locale.providers=$PREFLIST LocaleProviders $EXPECTED $TESTLANG $TESTCTRY"
+    RUNCMD="${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} -Djava.locale.providers=$PREFLIST LocaleProviders $METHODNAME $PARAM1 $PARAM2 $PARAM3"
     echo ${RUNCMD}
     ${RUNCMD}
     result=$?
@@ -88,91 +93,110 @@
 }
 
 # testing HOST is selected for the default locale, if specified on Windows or MacOSX
+METHODNAME=adapterTest
 PREFLIST=HOST,JRE
 case "$OS" in
   Windows_NT* )
     WINVER=`uname -r`
     if [ "${WINVER}" = "5" ]
     then
-      EXPECTED=JRE
+      PARAM1=JRE
     else
-      EXPECTED=HOST
+      PARAM1=HOST
     fi
     ;;
   CYGWIN_NT-6* | Darwin )
-    EXPECTED=HOST
+    PARAM1=HOST
     ;;
   * )
-    EXPECTED=JRE
+    PARAM1=JRE
     ;;
 esac
-TESTLANG=${DEFLANG}
-TESTCTRY=${DEFCTRY}
+PARAM2=${DEFLANG}
+PARAM3=${DEFCTRY}
 runTest
 
 # testing HOST is NOT selected for the non-default locale, if specified
+METHODNAME=adapterTest
 PREFLIST=HOST,JRE
-EXPECTED=JRE
-if [ "${DEFLANG}" = "en" ]
-then
-  TESTLANG=ja
-  TESTCTRY=JP
+PARAM1=JRE
+# Try to find the locale JRE supports which is not the platform default (HOST supports that one)
+if [ "${DEFLANG}" != "en" ] && [ "${DEFFMTLANG}" != "en" ]; then
+  PARAM2=en
+  PARAM3=US
+elif [ "${DEFLANG}" != "ja" ] && [ "${DEFFMTLANG}" != "ja" ]; then 
+  PARAM2=ja
+  PARAM3=JP
 else
-  TESTLANG=en
-  TESTCTRY=US
+  PARAM2=zh
+  PARAM3=CN
 fi
 runTest
 
 # testing SPI is NOT selected, as there is none.
+METHODNAME=adapterTest
 PREFLIST=SPI,JRE
-EXPECTED=JRE
-TESTLANG=en
-TESTCTRY=US
+PARAM1=JRE
+PARAM2=en
+PARAM3=US
 runTest
 
 # testing the order, variaton #1. This assumes en_GB DateFormat data are available both in JRE & CLDR
+METHODNAME=adapterTest
 PREFLIST=CLDR,JRE
-EXPECTED=CLDR
-TESTLANG=en
-TESTCTRY=GB
+PARAM1=CLDR
+PARAM2=en
+PARAM3=GB
 runTest
 
 # testing the order, variaton #2. This assumes en_GB DateFormat data are available both in JRE & CLDR
+METHODNAME=adapterTest
 PREFLIST=JRE,CLDR
-EXPECTED=JRE
-TESTLANG=en
-TESTCTRY=GB
+PARAM1=JRE
+PARAM2=en
+PARAM3=GB
 runTest
 
 # testing the order, variaton #3 for non-existent locale in JRE assuming "haw" is not in JRE.
+METHODNAME=adapterTest
 PREFLIST=JRE,CLDR
-EXPECTED=CLDR
-TESTLANG=haw
-TESTCTRY=GB
+PARAM1=CLDR
+PARAM2=haw
+PARAM3=GB
 runTest
 
 # testing the order, variaton #4 for the bug 7196799. CLDR's "zh" data should be used in "zh_CN"
+METHODNAME=adapterTest
 PREFLIST=CLDR
-EXPECTED=CLDR
-TESTLANG=zh
-TESTCTRY=CN
+PARAM1=CLDR
+PARAM2=zh
+PARAM3=CN
 runTest
 
 # testing FALLBACK provider. SPI and invalid one cases.
+METHODNAME=adapterTest
 PREFLIST=SPI
-EXPECTED=FALLBACK
-TESTLANG=en
-TESTCTRY=US
+PARAM1=FALLBACK
+PARAM2=en
+PARAM3=US
 runTest
 PREFLIST=FOO
-EXPECTED=JRE
-TESTLANG=en
-TESTCTRY=US
+PARAM1=JRE
+PARAM2=en
+PARAM3=US
 runTest
 PREFLIST=BAR,SPI
-EXPECTED=FALLBACK
-TESTLANG=en
-TESTCTRY=US
+PARAM1=FALLBACK
+PARAM2=en
+PARAM3=US
+runTest
+
+# testing 7198834 fix. Only works on Windows Vista or upper.
+METHODNAME=bug7198834Test
+PREFLIST=HOST
+PARAM1=
+PARAM2=
+PARAM3=
 runTest
 
 exit $result