jdk/test/java/util/PluggableLocale/LocaleNameProviderTest.java
author naoto
Tue, 16 Oct 2012 10:59:21 -0700
changeset 14185 916ec0a4d039
parent 13583 dc0017b1a452
child 15260 7af2d7a87806
permissions -rw-r--r--
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions 8000273: java.util.Locale.getDisplayVariant(Locale l) isn't transferred to the custom service provider 8000615: JRE adapter: timezone name of en_US is changed when extension directory is added Reviewed-by: okutsu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 5506
diff changeset
     2
 * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 5506
diff changeset
    29
import sun.util.locale.provider.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.util.resources.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
public class LocaleNameProviderTest extends ProviderTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    public static void main(String[] s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
        new LocaleNameProviderTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    LocaleNameProviderTest() {
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    39
        checkAvailLocValidityTest();
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    40
        variantFallbackTest();
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    41
    }
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    42
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    43
    void checkAvailLocValidityTest() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        com.bar.LocaleNameProviderImpl lnp = new com.bar.LocaleNameProviderImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        Locale[] availloc = Locale.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        Locale[] testloc = availloc.clone();
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    47
        List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getLocaleNameProvider().getAvailableLocales());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        List<Locale> providerloc = Arrays.asList(lnp.getAvailableLocales());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        for (Locale target: availloc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            // pure JRE implementation
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 5506
diff changeset
    52
            OpenListResourceBundle rb = LocaleProviderAdapter.forJRE().getLocaleData().getLocaleNames(target);
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    53
            boolean jreSupportsTarget = jreimplloc.contains(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            for (Locale test: testloc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                // codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                String lang = test.getLanguage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                String ctry = test.getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                String vrnt = test.getVariant();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                // the localized name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                String langresult = test.getDisplayLanguage(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                String ctryresult = test.getDisplayCountry(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                String vrntresult = test.getDisplayVariant(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                // provider's name (if any)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                String providerslang = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                String providersctry = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                String providersvrnt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                if (providerloc.contains(target)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    providerslang = lnp.getDisplayLanguage(lang, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                    providersctry = lnp.getDisplayCountry(ctry, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                    providersvrnt = lnp.getDisplayVariant(vrnt, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    76
                // JRE's name
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                String jreslang = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                String jresctry = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                String jresvrnt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                if (!lang.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                        jreslang = rb.getString(lang);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    } catch (MissingResourceException mre) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                if (!ctry.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                        jresctry = rb.getString(ctry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    } catch (MissingResourceException mre) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                if (!vrnt.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                        jresvrnt = rb.getString("%%"+vrnt);
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    93
                    } catch (MissingResourceException mre) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    96
                System.out.print("For key: "+lang+" ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                checkValidity(target, jreslang, providerslang, langresult,
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    98
                    jreSupportsTarget && jreslang != null);
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
    99
                System.out.print("For key: "+ctry+" ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                checkValidity(target, jresctry, providersctry, ctryresult,
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   101
                    jreSupportsTarget && jresctry != null);
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   102
                System.out.print("For key: "+vrnt+" ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                checkValidity(target, jresvrnt, providersvrnt, vrntresult,
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   104
                    jreSupportsTarget && jresvrnt != null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   108
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   109
    void variantFallbackTest() {
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   110
        Locale YY = new Locale("yy", "YY", "YYYY");
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   111
        Locale YY_suffix = new Locale("yy", "YY", "YYYY_suffix");
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   112
        String retVrnt = null;
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   113
        String message = "variantFallbackTest() succeeded.";
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   114
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   115
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   116
        try {
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   117
            YY.getDisplayVariant(YY_suffix);
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   118
            message = "variantFallbackTest() failed. Either provider wasn't invoked, or invoked without suffix.";
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   119
        } catch (RuntimeException re) {
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   120
            retVrnt = re.getMessage();
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   121
            if (YY_suffix.getVariant().equals(retVrnt)) {
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   122
                System.out.println(message);
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   123
                return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}
14185
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   125
            message = "variantFallbackTest() failed. Returned variant: "+retVrnt;
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   126
        }
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   127
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   128
        throw new RuntimeException(message);
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   129
    }
916ec0a4d039 8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents: 13583
diff changeset
   130
}