test/jdk/java/util/TimeZone/Bug8167143.java
author naoto
Fri, 26 Jul 2019 08:56:28 -0700
changeset 57544 99d2dd7b84a8
parent 47216 71c04702a3d5
permissions -rw-r--r--
8212970: TZ database in "vanguard" format support Reviewed-by: rriggs, joehw, erikj, scolebourne
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42930
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
     1
/*
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
     4
 *
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
     8
 *
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    13
 * accompanied this code).
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    14
 *
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    18
 *
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    21
 * questions.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    22
 */
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    23
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    24
/*
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    25
 * @test
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    26
 * @bug 8167143
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    27
 * @summary Test
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    28
 * Timezone parsing works for all locales for default providers prefernce
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    29
 * as well as when  prefernce list is [COMPAT, CLDR],
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    30
 * CLDR implict locales are correctly reflected,
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    31
 * th_TH bundle is not wrongly cached in DateFormatSymbols,
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    32
 * correct candidate locale list is retrieved for
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    33
 * zh_Hant and zh_Hans and
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    34
 * Implict COMPAT Locales nn-NO, nb-NO are reflected in available locales
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    35
 * for all Providers for COMPAT.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    36
 * @modules java.base/sun.util.locale.provider
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    37
 *          java.base/sun.util.spi
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    38
 *          jdk.localedata
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    39
 * @run main/othervm -Djava.locale.providers=COMPAT,CLDR Bug8167143 testTimeZone
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    40
 * @run main/othervm  Bug8167143 testTimeZone
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    41
 * @run main/othervm -Djava.locale.providers=CLDR Bug8167143 testCldr
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    42
 * @run main/othervm  Bug8167143 testCache
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    43
 * @run main/othervm  Bug8167143 testCandidateLocales
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    44
 * @run main/othervm  -Djava.locale.providers=COMPAT Bug8167143 testCompat
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    45
 */
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    46
import java.text.ParseException;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    47
import java.text.SimpleDateFormat;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    48
import java.util.ArrayList;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    49
import java.util.Arrays;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    50
import java.util.List;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    51
import java.util.Locale;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    52
import java.util.ResourceBundle;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    53
import java.util.Set;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    54
import java.util.TimeZone;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    55
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    56
import sun.util.locale.provider.LocaleProviderAdapter;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    57
import sun.util.locale.provider.LocaleProviderAdapter.Type;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    58
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    59
public class Bug8167143 {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    60
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    61
    private static final TimeZone REYKJAVIK = TimeZone.getTimeZone("Atlantic/Reykjavik");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    62
    private static final TimeZone NEW_YORK = TimeZone.getTimeZone("America/New_York");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    63
    private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    64
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    65
    private static final List<Locale> CLDR_IMPLICIT_LOCS = List.of(Locale.forLanguageTag("zh-Hans-CN"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    66
            Locale.forLanguageTag("zh-Hans-SG"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    67
            Locale.forLanguageTag("zh-Hant-HK"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    68
            Locale.forLanguageTag("zh-Hant-TW"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    69
            Locale.forLanguageTag("zh-Hant-MO"));
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    70
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    71
    private static final List<Locale> COMPAT_IMPLICIT_LOCS = List.of(Locale.forLanguageTag("nn-NO"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    72
            Locale.forLanguageTag("nb-NO"));
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    73
    /**
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    74
     * List of candidate locales for zh_Hant
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    75
     */
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    76
    private static final List<Locale> ZH_HANT_CANDLOCS = List.of(
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    77
            Locale.forLanguageTag("zh-Hant"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    78
            Locale.forLanguageTag("zh-TW"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    79
            Locale.forLanguageTag("zh"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    80
            Locale.ROOT);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    81
    /**
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    82
     * List of candidate locales for zh_Hans
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    83
     */
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    84
    private static final List<Locale> ZH_HANS_CANDLOCS = List.of(
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    85
            Locale.forLanguageTag("zh-Hans"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    86
            Locale.forLanguageTag("zh-CN"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    87
            Locale.forLanguageTag("zh"),
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    88
            Locale.ROOT);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    89
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    90
    public static void main(String[] args) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    91
        switch (args[0]) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    92
            case "testTimeZone":
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    93
                testTimeZoneParsing();
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    94
                break;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    95
            case "testCldr":
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    96
                testImplicitCldrLocales();
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    97
                break;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    98
            case "testCache":
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
    99
                testDateFormatSymbolsCache();
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   100
                break;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   101
            case "testCandidateLocales":
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   102
                testCandidateLocales();
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   103
                break;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   104
            case "testCompat":
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   105
                testImplicitCompatLocales();
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   106
                break;
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   107
            default:
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   108
                throw new RuntimeException("no test was specified.");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   109
        }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   110
    }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   111
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   112
    /**
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   113
     * Check that if Locale Provider Preference list is Default, or if Locale
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   114
     * Provider Preference List is COMPAT,CLDR SimplDateFormat parsing works for
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   115
     * all Available Locales.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   116
     */
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   117
    private static void testTimeZoneParsing() {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   118
        Set<Locale> locales = Set.of(Locale.forLanguageTag("zh-hant"), new Locale("no", "NO", "NY"));
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   119
        // Set<Locale> locales = Set.of(Locale.getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   120
        locales.forEach((locale) -> {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   121
            final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd z", locale);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   122
            for (final TimeZone tz : new TimeZone[]{REYKJAVIK, GMT, NEW_YORK}) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   123
                try {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   124
                    sdf.parse("2000/02/10 " + tz.getDisplayName(locale));
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   125
                } catch (ParseException e) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   126
                    throw new RuntimeException("TimeZone Parsing failed with Locale "
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   127
                            + locale + " for TimeZone  " + tz.getDisplayName(), e);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   128
                }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   129
            }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   130
        });
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   131
    }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   132
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   133
    /**
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   134
     * Check that locales implicitly supported from CLDR are reflected in output
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   135
     * from getAvailbleLocales() for each bundle.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   136
     *
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   137
     */
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   138
    private static void testImplicitCldrLocales() {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   139
        LocaleProviderAdapter cldr = LocaleProviderAdapter.forType(Type.CLDR);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   140
        checkPresenceCldr("CurrencyNameProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   141
                cldr.getCurrencyNameProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   142
        checkPresenceCldr("LocaleNameProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   143
                cldr.getLocaleNameProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   144
        checkPresenceCldr("TimeZoneNameProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   145
                cldr.getTimeZoneNameProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   146
        checkPresenceCldr("CalendarDataProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   147
                cldr.getCalendarDataProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   148
        checkPresenceCldr("CalendarNameProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   149
                cldr.getCalendarProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   150
    }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   151
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   152
    private static void checkPresenceCldr(String testName, Locale[] got) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   153
        List<Locale> gotLocalesList = Arrays.asList(got);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   154
        List<Locale> gotList = new ArrayList<>(gotLocalesList);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   155
        if (!testName.equals("TimeZoneNameProvider")) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   156
            if (!gotList.removeAll(CLDR_IMPLICIT_LOCS)) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   157
                // check which locale are not present in retrievedLocales List.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   158
                List<Locale> expectedLocales = new ArrayList<>(CLDR_IMPLICIT_LOCS);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   159
                expectedLocales.removeAll(gotList);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   160
                throw new RuntimeException("Locales those not correctly reflected are "
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   161
                        + expectedLocales + " for test " + testName);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   162
            }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   163
        } else {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   164
            // check one extra locale zh_HK for TimeZoneNameProvider
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   165
            Locale zh_HK = Locale.forLanguageTag("zh-HK");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   166
            if (!gotList.removeAll(CLDR_IMPLICIT_LOCS) && gotList.remove(zh_HK)) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   167
                //check which locale are not present in retrievedLocales List
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   168
                List<Locale> expectedLocales = new ArrayList<>(CLDR_IMPLICIT_LOCS);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   169
                expectedLocales.add(zh_HK);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   170
                expectedLocales.removeAll(gotList);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   171
                throw new RuntimeException("Locales those not correctly reflected are "
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   172
                        + expectedLocales + " for test " + testName);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   173
            }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   174
        }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   175
    }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   176
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   177
    /**
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   178
     * Check that if Locale Provider Preference list is default and if
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   179
     * SimpleDateFormat instance for th-TH-TH is created first, then JRE bundle
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   180
     * for th-TH should not be cached in cache of DateFormatSymbols class.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   181
     */
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   182
    private static void testDateFormatSymbolsCache() {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   183
        Locale th_TH_TH = new Locale("th", "TH", "TH");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   184
        Locale th_TH = new Locale("th", "TH");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   185
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd z", th_TH_TH);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   186
        String[][] thTHTHZoneStrings = sdf.getDateFormatSymbols().getZoneStrings();
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   187
        String[][] thTHZoneStrings = sdf.getDateFormatSymbols().getZoneStrings();
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   188
        if (Arrays.equals(thTHTHZoneStrings, thTHZoneStrings)) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   189
            throw new RuntimeException("th_TH bundle still cached with DateFormatSymbols"
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   190
                    + "cache for locale  " + th_TH
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   191
            );
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   192
        }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   193
    }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   194
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   195
    /**
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   196
     * Check that candidate locales list retrieved for zh__Hant and for zh__Hans
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   197
     * do not have first candidate locale as zh_TW_Hant and zh_CN_Hans
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   198
     * respectively.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   199
     */
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   200
    private static void testCandidateLocales() {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   201
        ResourceBundle.Control Control = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   202
        Locale zh_Hant = Locale.forLanguageTag("zh-Hant");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   203
        Locale zh_Hans = Locale.forLanguageTag("zh-Hans");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   204
        List<Locale> zhHantCandidateLocs = Control.getCandidateLocales("", zh_Hant);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   205
        List<Locale> zhHansCandidateLocs = Control.getCandidateLocales("", zh_Hans);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   206
        if (!zhHantCandidateLocs.equals(ZH_HANT_CANDLOCS)) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   207
            reportDifference(zhHantCandidateLocs, ZH_HANT_CANDLOCS, "zh_Hant");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   208
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   209
        }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   210
        if (!zhHansCandidateLocs.equals(ZH_HANS_CANDLOCS)) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   211
            reportDifference(zhHansCandidateLocs, ZH_HANS_CANDLOCS, "zh_Hans");
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   212
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   213
        }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   214
    }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   215
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   216
    private static void reportDifference(List<Locale> got, List<Locale> expected, String locale) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   217
        List<Locale> retrievedList = new ArrayList<>(got);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   218
        List<Locale> expectedList = new ArrayList<>(expected);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   219
        retrievedList.removeAll(expectedList);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   220
        expectedList.removeAll(retrievedList);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   221
        if ((retrievedList.size() > 0) && (expectedList.size() > 0)) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   222
            throw new RuntimeException(" retrievedList contain extra candidate locales " + retrievedList
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   223
                    + " and missing candidate locales " + expectedList
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   224
                    + "for locale " + locale);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   225
        }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   226
        if ((retrievedList.size() > 0)) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   227
            throw new RuntimeException(" retrievedList contain extra candidate locales " + retrievedList
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   228
                    + "for locale " + locale);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   229
        }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   230
        if ((expectedList.size() > 0)) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   231
            throw new RuntimeException(" retrievedList contain extra candidate locales " + expectedList
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   232
                    + "for locale " + locale);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   233
        }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   234
    }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   235
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   236
    /**
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   237
     * checks that locales nn-NO  and nb-NO should be present in list of supported locales for
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   238
     * all Providers for COMPAT.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   239
     */
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   240
    private static void testImplicitCompatLocales() {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   241
        LocaleProviderAdapter jre = LocaleProviderAdapter.forJRE();
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   242
        checkPresenceCompat("BreakIteratorProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   243
            jre.getBreakIteratorProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   244
        checkPresenceCompat("CollatorProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   245
            jre.getCollatorProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   246
        checkPresenceCompat("DateFormatProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   247
            jre.getDateFormatProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   248
        checkPresenceCompat("DateFormatSymbolsProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   249
            jre.getDateFormatSymbolsProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   250
        checkPresenceCompat("DecimalFormatSymbolsProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   251
            jre.getDecimalFormatSymbolsProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   252
        checkPresenceCompat("NumberFormatProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   253
            jre.getNumberFormatProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   254
        checkPresenceCompat("CurrencyNameProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   255
            jre.getCurrencyNameProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   256
        checkPresenceCompat("LocaleNameProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   257
            jre.getLocaleNameProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   258
        checkPresenceCompat("TimeZoneNameProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   259
            jre.getTimeZoneNameProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   260
        checkPresenceCompat("CalendarDataProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   261
            jre.getCalendarDataProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   262
        checkPresenceCompat("CalendarNameProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   263
            jre.getCalendarNameProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   264
        checkPresenceCompat("CalendarProvider",
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   265
            jre.getCalendarProvider().getAvailableLocales());
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   266
    }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   267
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   268
    private static void checkPresenceCompat(String testName, Locale[] got) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   269
        List<Locale> gotLocalesList = Arrays.asList(got);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   270
        List<Locale> gotList = new ArrayList<>(gotLocalesList);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   271
            if (!gotList.removeAll(COMPAT_IMPLICIT_LOCS)) {
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   272
                // check which Implicit locale are not present in retrievedLocales List.
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   273
                List<Locale> implicitLocales = new ArrayList<>(COMPAT_IMPLICIT_LOCS);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   274
                implicitLocales.removeAll(gotList);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   275
                throw new RuntimeException("Locales those not correctly reflected are "
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   276
                        + implicitLocales + " for test " + testName);
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   277
            }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   278
    }
b878b7b2788e 8167143: CLDR timezone parsing does not work for all locales
rgoel
parents:
diff changeset
   279
}