test/jdk/java/util/Locale/LocaleProviders.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 34878 jdk/test/java/util/Locale/LocaleProviders.java@7d7e55ff253a
child 53163 76f7dbf458fe
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     1
/*
34878
7d7e55ff253a 8039301: [ja] Host Locale Provider uses non-translated Calendar field names
naoto
parents: 22989
diff changeset
     2
 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     4
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     8
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    13
 * accompanied this code).
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    14
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    18
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    21
 * questions.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    22
 */
14028
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    23
import java.text.*;
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    24
import java.text.spi.*;
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    25
import java.util.*;
17169
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
    26
import java.util.spi.*;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    27
import sun.util.locale.provider.LocaleProviderAdapter;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    28
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    29
public class LocaleProviders {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    30
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    31
    public static void main(String[] args) {
14028
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    32
        String methodName = args[0];
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    33
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    34
        switch (methodName) {
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    35
            case "getPlatformLocale":
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    36
                if (args[1].equals("format")) {
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    37
                    getPlatformLocale(Locale.Category.FORMAT);
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    38
                } else {
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    39
                    getPlatformLocale(Locale.Category.DISPLAY);
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    40
                }
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    41
                break;
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    42
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    43
            case "adapterTest":
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    44
                adapterTest(args[1], args[2], (args.length >= 4 ? args[3] : ""));
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    45
                break;
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    46
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    47
            case "bug7198834Test":
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    48
                bug7198834Test();
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    49
                break;
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    50
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
    51
            case "tzNameTest":
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
    52
                tzNameTest(args[1]);
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
    53
                break;
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
    54
14336
4a3418a2c07f 8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
naoto
parents: 14185
diff changeset
    55
            case "bug8001440Test":
4a3418a2c07f 8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
naoto
parents: 14185
diff changeset
    56
                bug8001440Test();
4a3418a2c07f 8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
naoto
parents: 14185
diff changeset
    57
                break;
4a3418a2c07f 8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
naoto
parents: 14185
diff changeset
    58
17169
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
    59
            case "bug8010666Test":
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
    60
                bug8010666Test();
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
    61
                break;
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
    62
17440
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
    63
            case "bug8013086Test":
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
    64
                bug8013086Test(args[1], args[2]);
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
    65
                break;
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
    66
17944
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
    67
            case "bug8013903Test":
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
    68
                bug8013903Test();
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
    69
                break;
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
    70
22989
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
    71
            case "bug8027289Test":
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
    72
                bug8027289Test(args[1]);
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
    73
                break;
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
    74
14028
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    75
            default:
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    76
                throw new RuntimeException("Test method '"+methodName+"' not found.");
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    77
        }
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    78
    }
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    79
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    80
    static void getPlatformLocale(Locale.Category cat) {
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    81
        Locale defloc = Locale.getDefault(cat);
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    82
        System.out.printf("%s,%s\n", defloc.getLanguage(), defloc.getCountry());
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    83
    }
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    84
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    85
    static void adapterTest(String expected, String lang, String ctry) {
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    86
        Locale testLocale = new Locale(lang, ctry);
21853
8aa7444a01a8 8028771: regression test java/util/Locale/LocaleProviders.sh failed
naoto
parents: 18539
diff changeset
    87
        LocaleProviderAdapter ldaExpected =
8aa7444a01a8 8028771: regression test java/util/Locale/LocaleProviders.sh failed
naoto
parents: 18539
diff changeset
    88
            LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
8aa7444a01a8 8028771: regression test java/util/Locale/LocaleProviders.sh failed
naoto
parents: 18539
diff changeset
    89
        if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
8aa7444a01a8 8028771: regression test java/util/Locale/LocaleProviders.sh failed
naoto
parents: 18539
diff changeset
    90
            System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
8aa7444a01a8 8028771: regression test java/util/Locale/LocaleProviders.sh failed
naoto
parents: 18539
diff changeset
    91
            return;
8aa7444a01a8 8028771: regression test java/util/Locale/LocaleProviders.sh failed
naoto
parents: 18539
diff changeset
    92
        }
14028
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    93
        String preference = System.getProperty("java.locale.providers", "");
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    94
        LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    95
        LocaleProviderAdapter.Type type = lda.getAdapterType();
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    96
        System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    97
        if (!type.toString().equals(expected)) {
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    98
            throw new RuntimeException("Returned locale data adapter is not correct.");
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
    99
        }
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   100
    }
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   101
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   102
    static void bug7198834Test() {
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   103
        LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   104
        LocaleProviderAdapter.Type type = lda.getAdapterType();
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   105
        if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   106
            DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   107
            String date = df.format(new Date());
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   108
            if (date.charAt(date.length()-1) == ' ') {
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   109
                throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   110
            }
14024
694c379c2958 7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents: 13583
diff changeset
   111
        } else {
14028
5f3d5ae5f1ea 7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents: 14024
diff changeset
   112
            System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   113
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   114
    }
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
   115
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
   116
    static void tzNameTest(String id) {
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
   117
        TimeZone tz = TimeZone.getTimeZone(id);
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
   118
        String tzName = tz.getDisplayName(false, TimeZone.SHORT, Locale.US);
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
   119
        if (tzName.startsWith("GMT")) {
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
   120
            throw new RuntimeException("JRE's localized time zone name for "+id+" could not be retrieved. Returned name was: "+tzName);
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
   121
        }
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 14028
diff changeset
   122
    }
14336
4a3418a2c07f 8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
naoto
parents: 14185
diff changeset
   123
4a3418a2c07f 8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
naoto
parents: 14185
diff changeset
   124
    static void bug8001440Test() {
4a3418a2c07f 8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
naoto
parents: 14185
diff changeset
   125
        Locale locale = Locale.forLanguageTag("th-TH-u-nu-hoge");
4a3418a2c07f 8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
naoto
parents: 14185
diff changeset
   126
        NumberFormat nf = NumberFormat.getInstance(locale);
4a3418a2c07f 8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
naoto
parents: 14185
diff changeset
   127
        String nu = nf.format(1234560);
4a3418a2c07f 8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
naoto
parents: 14185
diff changeset
   128
    }
17169
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   129
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   130
    // This test assumes Windows localized language/country display names.
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   131
    static void bug8010666Test() {
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   132
        if (System.getProperty("os.name").startsWith("Windows")) {
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   133
            NumberFormat nf = NumberFormat.getInstance(Locale.US);
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   134
            try {
17476
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   135
                double ver = nf.parse(System.getProperty("os.version"))
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   136
                               .doubleValue();
17169
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   137
                System.out.printf("Windows version: %.1f\n", ver);
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   138
                if (ver >= 6.0) {
17476
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   139
                    LocaleProviderAdapter lda =
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   140
                        LocaleProviderAdapter.getAdapter(
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   141
                            LocaleNameProvider.class, Locale.ENGLISH);
17169
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   142
                    LocaleProviderAdapter.Type type = lda.getAdapterType();
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   143
                    if (type == LocaleProviderAdapter.Type.HOST) {
17476
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   144
                        LocaleNameProvider lnp = lda.getLocaleNameProvider();
17169
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   145
                        Locale mkmk = Locale.forLanguageTag("mk-MK");
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   146
                        String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
17476
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   147
                        String hostResult =
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   148
                            lnp.getDisplayLanguage(mkmk.getLanguage(),
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   149
                                                   Locale.ENGLISH);
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   150
                        System.out.printf("  Display language name for" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   151
                            " (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   152
                            hostResult, result);
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   153
                        if (result == null ||
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   154
                            hostResult != null &&
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   155
                            !result.equals(hostResult)) {
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   156
                            throw new RuntimeException("Display language name" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   157
                                " mismatch for \"mk\". Returned name was" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   158
                                " \"" + result + "\", result(HOST): \"" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   159
                                hostResult + "\"");
17169
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   160
                        }
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   161
                        result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
17476
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   162
                        hostResult =
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   163
                            lnp.getDisplayLanguage(Locale.US.getLanguage(),
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   164
                                                   Locale.ENGLISH);
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   165
                        System.out.printf("  Display language name for" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   166
                            " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   167
                            hostResult, result);
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   168
                        if (result == null ||
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   169
                            hostResult != null &&
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   170
                            !result.equals(hostResult)) {
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   171
                            throw new RuntimeException("Display language name" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   172
                                " mismatch for \"en\". Returned name was" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   173
                                " \"" + result + "\", result(HOST): \"" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   174
                                hostResult + "\"");
17169
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   175
                        }
17476
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   176
                        if (ver >= 6.1) {
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   177
                            result = Locale.US.getDisplayCountry(Locale.ENGLISH);
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   178
                            hostResult = lnp.getDisplayCountry(
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   179
                                Locale.US.getCountry(), Locale.ENGLISH);
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   180
                            System.out.printf("  Display country name for" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   181
                                " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   182
                                hostResult, result);
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   183
                            if (result == null ||
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   184
                                hostResult != null &&
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   185
                                !result.equals(hostResult)) {
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   186
                                throw new RuntimeException("Display country name" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   187
                                    " mismatch for \"US\". Returned name was" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   188
                                    " \"" + result + "\", result(HOST): \"" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   189
                                    hostResult + "\"");
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   190
                            }
17169
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   191
                        }
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   192
                    } else {
17476
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   193
                        throw new RuntimeException("Windows Host" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   194
                            " LocaleProviderAdapter was not selected for" +
6a5362307fc3 8013233: java/util/Locale/LocaleProviders.sh fails
naoto
parents: 17440
diff changeset
   195
                            " English locale.");
17169
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   196
                    }
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   197
                }
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   198
            } catch (ParseException pe) {
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   199
                throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   200
            }
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   201
        }
5e5039c3181d 8010666: Implement Currency/LocaleNameProvider in Windows Host LocaleProviderAdapter
naoto
parents: 14336
diff changeset
   202
    }
17440
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
   203
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
   204
    static void bug8013086Test(String lang, String ctry) {
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
   205
        try {
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
   206
            // Throws a NullPointerException if the test fails.
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
   207
            System.out.println(new SimpleDateFormat("z", new Locale(lang, ctry)).parse("UTC"));
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
   208
        } catch (ParseException pe) {
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
   209
            // ParseException is fine in this test, as it's not "UTC"
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   210
}
17440
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
   211
    }
17944
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   212
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   213
    static void bug8013903Test() {
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   214
        if (System.getProperty("os.name").startsWith("Windows")) {
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   215
            Date sampleDate = new Date(0x10000000000L);
34878
7d7e55ff253a 8039301: [ja] Host Locale Provider uses non-translated Calendar field names
naoto
parents: 22989
diff changeset
   216
            String hostResult = "\u5e73\u6210 16.11.03 (Wed) AM 11:53:47";
17944
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   217
            String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47";
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   218
            Locale l = new Locale("ja", "JP", "JP");
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   219
            SimpleDateFormat sdf = new SimpleDateFormat("GGGG yyyy.MMM.dd '('E')' a hh:mm:ss", l);
18539
cc30fa6fcf7c 6863624: java/util/Currency/PropertiesTest.sh writable check is incorrect
naoto
parents: 18162
diff changeset
   220
            sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
17944
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   221
            String result = sdf.format(sampleDate);
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   222
            System.out.println(result);
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   223
            if (LocaleProviderAdapter.getAdapterPreference()
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   224
                .contains(LocaleProviderAdapter.Type.JRE)) {
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   225
                if (!jreResult.equals(result)) {
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   226
                    throw new RuntimeException("Format failed. result: \"" +
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   227
                        result + "\", expected: \"" + jreResult);
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   228
                }
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   229
            } else {
34878
7d7e55ff253a 8039301: [ja] Host Locale Provider uses non-translated Calendar field names
naoto
parents: 22989
diff changeset
   230
                // Windows display names. Subject to change if Windows changes its format.
7d7e55ff253a 8039301: [ja] Host Locale Provider uses non-translated Calendar field names
naoto
parents: 22989
diff changeset
   231
                if (!hostResult.equals(result)) {
17944
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   232
                    throw new RuntimeException("Format failed. result: \"" +
34878
7d7e55ff253a 8039301: [ja] Host Locale Provider uses non-translated Calendar field names
naoto
parents: 22989
diff changeset
   233
                        result + "\", expected: \"" + hostResult);
17944
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   234
                }
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   235
            }
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   236
        }
bbd67fc49daa 8013903: Japanese calendar field names are not displayed with -Djava.locale.providers=HOST on Windows
naoto
parents: 17476
diff changeset
   237
    }
22989
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
   238
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
   239
    static void bug8027289Test(String expectedCodePoint) {
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
   240
        char[] expectedSymbol = Character.toChars(Integer.valueOf(expectedCodePoint, 16));
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
   241
        NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.CHINA);
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
   242
        char formatted = nf.format(7000).charAt(0);
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
   243
        System.out.println("returned: " + formatted + ", expected: " + expectedSymbol[0]);
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
   244
        if (formatted != expectedSymbol[0]) {
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
   245
            throw new RuntimeException("Unexpected Chinese currency symbol. returned: " + formatted + ", expected: " + expectedSymbol[0]);
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
   246
        }
2d6804cfdc0e 8027289: [Windows zh_CN] NumberFormat: Incorrect sequence of loading currency symbol
naoto
parents: 21853
diff changeset
   247
    }
17440
fb37aa6b305e 8013086: NPE thrown by SimpleDateFormat with TimeZoneNameProvider supplied
naoto
parents: 17169
diff changeset
   248
}