jdk/test/java/util/Locale/LocaleTest.java
author naoto
Wed, 21 Jan 2009 13:58:46 -0800
changeset 1848 6ecbe9158c6e
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6627549: ISO 3166 code addition: Saint Barthelemy and Saint Martin 6786276: Locale.getISOCountries() still contains country code "CS" Reviewed-by: okutsu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4052404 4052440 4084688 4092475 4101316 4105828 4107014 4107953 4110613
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * 4118587 4118595 4122371 4126371 4126880 4135316 4135752 4139504 4139940 4143951
1848
6ecbe9158c6e 6627549: ISO 3166 code addition: Saint Barthelemy and Saint Martin
naoto
parents: 2
diff changeset
    27
 * 4147315 4147317 4147552 4335196 4778440 5010672 6475525 6544471 6627549 6786276
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary test Locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Portions copyright (c) 2007 Sun Microsystems, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The original version of this source code and documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * is copyrighted and owned by Taligent, Inc., a wholly-owned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * subsidiary of IBM. These materials are provided under terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * of a License Agreement between Taligent and Sun. This technology
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * is protected by multiple US and International patents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Permission to use, copy, modify, and distribute this software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * and its documentation for NON-COMMERCIAL purposes and without
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * fee is hereby granted provided that this copyright notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * appears in all copies. Please refer to the file "copyright.html"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * for further important copyright and licensing information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import java.util.Calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public class LocaleTest extends LocaleTestFmwk {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public LocaleTest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private int ENGLISH = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private int FRENCH = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private int CROATIAN = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private int GREEK = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private int NORWEGIAN = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private int ITALIAN = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private int DUMMY = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private int MAX_LOCALES = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private int LANG = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private int CTRY = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private int VAR = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private int NAME = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private int LANG3 = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private int CTRY3 = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private int LCID = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private int DLANG_EN = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private int DCTRY_EN = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private int DVAR_EN = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private int DNAME_EN = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private int DLANG_FR = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private int DCTRY_FR = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private int DVAR_FR = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private int DNAME_FR = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private int DLANG_HR = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private int DCTRY_HR = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private int DVAR_HR = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private int DNAME_HR = 18;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private int DLANG_EL = 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private int DCTRY_EL = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private int DVAR_EL = 21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private int DNAME_EL = 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private int DLANG_ROOT = 23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private int DCTRY_ROOT = 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private int DVAR_ROOT = 25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private int DNAME_ROOT = 26;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private String[][] dataTable = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // language code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        {   "en",   "fr",   "hr",   "el",   "no",   "it",   "xx"    },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // country code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        {   "US",   "FR",   "HR",   "GR",   "NO",   "",   "YY"    },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // variant code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        {   "",     "",     "",     "",     "NY",   "",   ""    },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        // full name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        {   "en_US",    "fr_FR",    "hr_HR",    "el_GR",    "no_NO_NY", "it",   "xx_YY"  },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // ISO-3 language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        {   "eng",  "fra",  "hrv",  "ell",  "nor",  "ita",  ""   },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // ISO-3 country
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        {   "USA",  "FRA",  "HRV",  "GRC",  "NOR",  "",     ""   },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // LCID (not currently public)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        {   "0409", "040c", "041a", "0408", "0814", "",     ""  },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // display language (English)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        {   "English",  "French",   "Croatian", "Greek",    "Norwegian",    "Italian",  "xx" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // display country (English)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        {   "United States",    "France",   "Croatia",  "Greece",   "Norway",   "",     "YY" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        // display variant (English)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        {   "",     "",     "",     "",     "Nynorsk",   "",     ""},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // display name (English)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // Updated no_NO_NY English display name for new pattern-based algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // (part of Euro support).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        {   "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // display langage (French)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        {   "anglais",  "fran\u00e7ais",   "croate", "grec",    "norv\u00e9gien",    "italien", "xx" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // display country (French)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        {   "Etats-Unis",    "France",   "Croatie",  "Gr\u00e8ce",   "Norv\u00e8ge", "",     "YY" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // display variant (French)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        {   "",     "",     "",     "",     "",     "",    "" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // display name (French)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        {   "anglais (Etats-Unis)", "fran\u00e7ais (France)", "croate (Croatie)", "grec (Gr\u00e8ce)", "norv\u00e9gien (Norv\u00e8ge,Nynorsk)", "italien", "xx (YY)" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // display langage (Croatian)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        {   "",  "", "hrvatski", "",    "", "", "xx" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        // display country (Croatian)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        {   "",    "",   "Hrvatska",  "",   "", "", "YY" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // display variant (Croatian)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        {   "",     "",     "",     "",     "", "", ""},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        // display name (Croatian)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        {   "", "", "hrvatski (Hrvatska)", "", "", "", "xx (YY)" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // display langage (Greek)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        {   "\u0391\u03b3\u03b3\u03bb\u03b9\u03ba\u03ac",  "\u0393\u03b1\u03bb\u03bb\u03b9\u03ba\u03ac", "\u039a\u03c1\u03bf\u03b1\u03c4\u03b9\u03ba\u03ac", "\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac",    "\u039d\u03bf\u03c1\u03b2\u03b7\u03b3\u03b9\u03ba\u03ac", "\u0399\u03c4\u03b1\u03bb\u03b9\u03ba\u03ac", "xx" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        // display country (Greek)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        {   "\u0397\u03bd\u03c9\u03bc\u03ad\u03bd\u03b5\u03c2 \u03a0\u03bf\u03bb\u03b9\u03c4\u03b5\u03af\u03b5\u03c2",    "\u0393\u03b1\u03bb\u03bb\u03af\u03b1",   "\u039a\u03c1\u03bf\u03b1\u03c4\u03af\u03b1",  "\u0395\u03bb\u03bb\u03ac\u03b4\u03b1",   "\u039d\u03bf\u03c1\u03b2\u03b7\u03b3\u03af\u03b1", "", "YY" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // display variant (Greek)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        {   "",     "",     "",     "",     "", "", "" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // display name (Greek)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        {   "\u0391\u03b3\u03b3\u03bb\u03b9\u03ba\u03ac (\u0397\u03bd\u03c9\u03bc\u03ad\u03bd\u03b5\u03c2 \u03a0\u03bf\u03bb\u03b9\u03c4\u03b5\u03af\u03b5\u03c2)", "\u0393\u03b1\u03bb\u03bb\u03b9\u03ba\u03ac (\u0393\u03b1\u03bb\u03bb\u03af\u03b1)", "\u039a\u03c1\u03bf\u03b1\u03c4\u03b9\u03ba\u03ac (\u039a\u03c1\u03bf\u03b1\u03c4\u03af\u03b1)", "\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac (\u0395\u03bb\u03bb\u03ac\u03b4\u03b1)", "\u039d\u03bf\u03c1\u03b2\u03b7\u03b3\u03b9\u03ba\u03ac (\u039d\u03bf\u03c1\u03b2\u03b7\u03b3\u03af\u03b1,Nynorsk)", "\u0399\u03c4\u03b1\u03bb\u03b9\u03ba\u03ac", "xx (YY)" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        // display langage (<root>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        {   "English",  "French",   "Croatian", "Greek",    "Norwegian",  "Italian",  "xx" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        // display country (<root>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        {   "United States",    "France",   "Croatia",  "Greece",   "Norway",  "",     "YY" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        // display variant (<root>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        {   "",     "",     "",     "",     "Nynorsk",   "",     ""},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        // display name (<root>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        {   "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        new LocaleTest().run(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public void TestBasicGetters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        for (int i = 0; i <= MAX_LOCALES; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            logln("Testing " + testLocale + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (!testLocale.getLanguage().equals(dataTable[LANG][i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                errln("  Language code mismatch: " + testLocale.getLanguage() + " versus "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                            + dataTable[LANG][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (!testLocale.getCountry().equals(dataTable[CTRY][i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                errln("  Country code mismatch: " + testLocale.getCountry() + " versus "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                            + dataTable[CTRY][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            if (!testLocale.getVariant().equals(dataTable[VAR][i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                errln("  Variant code mismatch: " + testLocale.getVariant() + " versus "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                            + dataTable[VAR][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if (!testLocale.toString().equals(dataTable[NAME][i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                errln("  Locale name mismatch: " + testLocale.toString() + " versus "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                            + dataTable[NAME][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        logln("Same thing without variant codes...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        for (int i = 0; i <= MAX_LOCALES; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            logln("Testing " + testLocale + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            if (!testLocale.getLanguage().equals(dataTable[LANG][i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                errln("  Language code mismatch: " + testLocale.getLanguage() + " versus "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                            + dataTable[LANG][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if (!testLocale.getCountry().equals(dataTable[CTRY][i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                errln("  Country code mismatch: " + testLocale.getCountry() + " versus "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                            + dataTable[CTRY][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if (!testLocale.getVariant().equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                errln("  Variant code mismatch: " + testLocale.getVariant() + " versus \"\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public void TestSimpleResourceInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        for (int i = 0; i <= MAX_LOCALES; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            if (dataTable[LANG][i].equals("xx"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            logln("Testing " + testLocale + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (!testLocale.getISO3Language().equals(dataTable[LANG3][i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                errln("  ISO-3 language code mismatch: " + testLocale.getISO3Language()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                            + " versus " + dataTable[LANG3][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if (!testLocale.getISO3Country().equals(dataTable[CTRY3][i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                errln("  ISO-3 country code mismatch: " + testLocale.getISO3Country()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                            + " versus " + dataTable[CTRY3][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            // getLCID() is currently private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            if (!String.valueOf(testLocale.getLCID()).equals(dataTable[LCID][i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                errln("  LCID mismatch: " + testLocale.getLCID() + " versus "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                            + dataTable[LCID][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @bug 4101316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @bug 4084688 (This bug appears to be a duplicate of something, because it was fixed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *              between 1.1.5 and 1.1.6, but I included a new test for it anyway)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @bug 4052440 Stop falling back to the default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public void TestDisplayNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        Locale  saveDefault = Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        Locale  english = new Locale("en", "US");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        Locale  french = new Locale("fr", "FR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        Locale  croatian = new Locale("hr", "HR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        Locale  greek = new Locale("el", "GR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        Locale.setDefault(english);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        logln("With default = en_US...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        logln("  In default locale...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        doTestDisplayNames(null, DLANG_EN, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        logln("  In locale = en_US...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        doTestDisplayNames(english, DLANG_EN, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        logln("  In locale = fr_FR...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        doTestDisplayNames(french, DLANG_FR, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        logln("  In locale = hr_HR...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        doTestDisplayNames(croatian, DLANG_HR, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        logln("  In locale = el_GR...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        doTestDisplayNames(greek, DLANG_EL, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        Locale.setDefault(french);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        logln("With default = fr_FR...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        logln("  In default locale...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        doTestDisplayNames(null, DLANG_FR, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        logln("  In locale = en_US...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        doTestDisplayNames(english, DLANG_EN, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        logln("  In locale = fr_FR...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        doTestDisplayNames(french, DLANG_FR, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        logln("  In locale = hr_HR...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        doTestDisplayNames(croatian, DLANG_HR, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        logln("  In locale = el_GR...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        doTestDisplayNames(greek, DLANG_EL, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        Locale.setDefault(saveDefault);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    private void doTestDisplayNames(Locale inLocale, int compareIndex, boolean defaultIsFrench) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (defaultIsFrench && !Locale.getDefault().getLanguage().equals("fr"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            errln("Default locale should be French, but it's really " + Locale.getDefault().getLanguage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        else if (!defaultIsFrench && !Locale.getDefault().getLanguage().equals("en"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            errln("Default locale should be English, but it's really " + Locale.getDefault().getLanguage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        for (int i = 0; i <= MAX_LOCALES; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            logln("  Testing " + testLocale + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            String  testLang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            String  testCtry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            String  testVar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            String  testName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if (inLocale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                testLang = testLocale.getDisplayLanguage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                testCtry = testLocale.getDisplayCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                testVar = testLocale.getDisplayVariant();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                testName = testLocale.getDisplayName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                testLang = testLocale.getDisplayLanguage(inLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                testCtry = testLocale.getDisplayCountry(inLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                testVar = testLocale.getDisplayVariant(inLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                testName = testLocale.getDisplayName(inLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            String  expectedLang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            String  expectedCtry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            String  expectedVar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            String  expectedName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            expectedLang = dataTable[compareIndex][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (expectedLang.equals("") && defaultIsFrench)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                expectedLang = dataTable[DLANG_EN][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            if (expectedLang.equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                expectedLang = dataTable[DLANG_ROOT][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            expectedCtry = dataTable[compareIndex + 1][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            if (expectedCtry.equals("") && defaultIsFrench)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                expectedCtry = dataTable[DCTRY_EN][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            if (expectedCtry.equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                expectedCtry = dataTable[DCTRY_ROOT][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            expectedVar = dataTable[compareIndex + 2][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            if (expectedVar.equals("") && defaultIsFrench)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                expectedVar = dataTable[DVAR_EN][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            if (expectedVar.equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                expectedVar = dataTable[DVAR_ROOT][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            expectedName = dataTable[compareIndex + 3][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (expectedName.equals("") && defaultIsFrench)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                expectedName = dataTable[DNAME_EN][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            if (expectedName.equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                expectedName = dataTable[DNAME_ROOT][i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            if (!testLang.equals(expectedLang))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                errln("Display language mismatch: " + testLang + " versus " + expectedLang);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            if (!testCtry.equals(expectedCtry))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                errln("Display country mismatch: " + testCtry + " versus " + expectedCtry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            if (!testVar.equals(expectedVar))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                errln("Display variant mismatch: " + testVar + " versus " + expectedVar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            if (!testName.equals(expectedName))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                errln("Display name mismatch: " + testName + " versus " + expectedName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public void TestSimpleObjectStuff() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        Locale  test1 = new Locale("aa", "AA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        Locale  test2 = new Locale("aa", "AA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        Locale  test3 = (Locale)test1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        Locale  test4 = new Locale("zz", "ZZ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            errln("Some of the test variables point to the same locale!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (test3 == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            errln("clone() failed to produce a valid object!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            errln("clone() or equals() failed: objects that should compare equal don't");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            errln("equals() failed: objects that shouldn't compare equal do");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        int hash1 = test1.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        int hash2 = test2.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        int hash3 = test3.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            errln("hashCode() failed: objects that should have the same hash code don't");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @bug 4011756 4011380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public void TestISO3Fallback() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        Locale test = new Locale("xx", "YY", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        boolean gotException = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        String result = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            result = test.getISO3Language();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            gotException = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (!gotException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            errln("getISO3Language() on xx_YY returned " + result + " instead of throwing an exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        gotException = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            result = test.getISO3Country();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            gotException = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if (!gotException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            errln("getISO3Country() on xx_YY returned " + result + " instead of throwing an exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @bug 4106155 4118587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public void TestGetLangsAndCountries() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        // It didn't seem right to just do an exhaustive test of everything here, so I check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        // for the following things:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        // 1) Does each list have the right total number of entries?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        // 2) Does each list contain certain language and country codes we think are important
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        //     (the G7 countries, plus a couple others)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        // 3) Does each list have every entry formatted correctly? (i.e., two characters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        //     all lower case for the language codes, all upper case for the country codes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        // 4) Is each list in sorted order?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        String[] test = Locale.getISOLanguages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        String[] spotCheck1 = { "en", "es", "fr", "de", "it", "ja", "ko", "zh", "th",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                "he", "id", "iu", "ug", "yi", "za" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (test.length != 188)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            errln("Expected getISOLanguages() to return 188 languages; it returned " + test.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            for (int i = 0; i < spotCheck1.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                for (j = 0; j < test.length; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    if (test[j].equals(spotCheck1[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                if (j == test.length || !test[j].equals(spotCheck1[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    errln("Couldn't find " + spotCheck1[i] + " in language list.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        for (int i = 0; i < test.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            if (!test[i].equals(test[i].toLowerCase()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                errln(test[i] + " is not all lower case.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            if (test[i].length() != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                errln(test[i] + " is not two characters long.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            if (i > 0 && test[i].compareTo(test[i - 1]) <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                errln(test[i] + " appears in an out-of-order position in the list.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        test = Locale.getISOCountries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        String[] spotCheck2 = { "US", "CA", "GB", "FR", "DE", "IT", "JP", "KR", "CN", "TW", "TH" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
1848
6ecbe9158c6e 6627549: ISO 3166 code addition: Saint Barthelemy and Saint Martin
naoto
parents: 2
diff changeset
   442
        if (test.length != 246)
6ecbe9158c6e 6627549: ISO 3166 code addition: Saint Barthelemy and Saint Martin
naoto
parents: 2
diff changeset
   443
            errln("Expected getISOCountries to return 246 countries; it returned " + test.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            for (int i = 0; i < spotCheck2.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                for (j = 0; j < test.length; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    if (test[j].equals(spotCheck2[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                if (j == test.length || !test[j].equals(spotCheck2[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    errln("Couldn't find " + spotCheck2[i] + " in country list.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        for (int i = 0; i < test.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            if (!test[i].equals(test[i].toUpperCase()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                errln(test[i] + " is not all upper case.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (test[i].length() != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                errln(test[i] + " is not two characters long.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (i > 0 && test[i].compareTo(test[i - 1]) <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                errln(test[i] + " appears in an out-of-order position in the list.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @bug 4126880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    void Test4126880() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        String[] test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        test = Locale.getISOCountries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        test[0] = "SUCKER!!!";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        test = Locale.getISOCountries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (test[0].equals("SUCKER!!!"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            errln("Changed internal country code list!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        test = Locale.getISOLanguages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        test[0] = "HAHAHAHA!!!";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        test = Locale.getISOLanguages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (test[0].equals("HAHAHAHA!!!")) // Fixed typo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            errln("Changes internal language code list!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @bug 4107014
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public void TestGetAvailableLocales() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        Locale[] locales = Locale.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (locales == null || locales.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            errln("Locale.getAvailableLocales() returned no installed locales!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            logln("Locale.getAvailableLocales() returned a list of " + locales.length + " locales.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            for (int i = 0; i < locales.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                logln(locales[i].toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @bug 4135316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public void TestBug4135316() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        Locale[] locales1 = Locale.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        Locale[] locales2 = Locale.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (locales1 == locales2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            errln("Locale.getAvailableLocales() doesn't clone its internal storage!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @bug 4107953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
test commented out pending API-change approval
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    public void TestGetLanguagesForCountry() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        String[] languages = Locale.getLanguagesForCountry("US");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        if (!searchStringArrayFor("en", languages))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            errln("Didn't get en as a language for US");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        languages = Locale.getLanguagesForCountry("FR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (!searchStringArrayFor("fr", languages))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            errln("Didn't get fr as a language for FR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        languages = Locale.getLanguagesForCountry("CH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        if (!searchStringArrayFor("fr", languages))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            errln("Didn't get fr as a language for CH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if (!searchStringArrayFor("it", languages))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            errln("Didn't get it as a language for CH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (!searchStringArrayFor("de", languages))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            errln("Didn't get de as a language for CH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        languages = Locale.getLanguagesForCountry("JP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if (!searchStringArrayFor("ja", languages))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            errln("Didn't get ja as a language for JP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    private boolean searchStringArrayFor(String s, String[] array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        for (int i = 0; i < array.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            if (s.equals(array[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @bug 4110613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void TestSerialization() throws ClassNotFoundException, OptionalDataException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    IOException, StreamCorruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        ObjectOutputStream ostream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        ByteArrayOutputStream obstream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        byte[] bytes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        obstream = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        ostream = new ObjectOutputStream(obstream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        Locale test1 = new Locale("zh", "TW", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        int dummy = test1.hashCode();   // fill in the cached hash-code value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        ostream.writeObject(test1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        bytes = obstream.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        Locale test2 = (Locale)(istream.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            errln("Locale failed to deserialize correctly.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @bug 4118587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public void TestSimpleDisplayNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        // This test is different from TestDisplayNames because TestDisplayNames checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        // fallback behavior, combination of language and country names to form locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        // names, and other stuff like that.  This test just checks specific language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        // and country codes to make sure we have the correct names for them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        String[] languageCodes = { "he", "id", "iu", "ug", "yi", "za" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        String[] languageNames = { "Hebrew", "Indonesian", "Inuktitut", "Uighur", "Yiddish",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                                   "Zhuang" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        for (int i = 0; i < languageCodes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            String test = (new Locale(languageCodes[i], "", "")).getDisplayLanguage(Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            if (!test.equals(languageNames[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                errln("Got wrong display name for " + languageCodes[i] + ": Expected \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                      languageNames[i] + "\", got \"" + test + "\".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @bug 4118595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    public void TestUninstalledISO3Names() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        // This test checks to make sure getISO3Language and getISO3Country work right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        // even for locales that are not installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        String[] iso2Languages = { "am", "ba", "fy", "mr", "rn", "ss", "tw", "zu" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        String[] iso3Languages = { "amh", "bak", "fry", "mar", "run", "ssw", "twi", "zul" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        for (int i = 0; i < iso2Languages.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            String test = (new Locale(iso2Languages[i], "", "")).getISO3Language();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            if (!test.equals(iso3Languages[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                errln("Got wrong ISO3 code for " + iso2Languages[i] + ": Expected \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                        iso3Languages[i] + "\", got \"" + test + "\".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        String[] iso2Countries = { "AF", "BW", "KZ", "MO", "MN", "SB", "TC", "ZW" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        String[] iso3Countries = { "AFG", "BWA", "KAZ", "MAC", "MNG", "SLB", "TCA", "ZWE" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        for (int i = 0; i < iso2Countries.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            String test = (new Locale("", iso2Countries[i], "")).getISO3Country();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            if (!test.equals(iso3Countries[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                errln("Got wrong ISO3 code for " + iso2Countries[i] + ": Expected \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                        iso3Countries[i] + "\", got \"" + test + "\".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @bug 4052404 4778440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    public void TestChangedISO639Codes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        Locale hebrewOld = new Locale("iw", "IL", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        Locale hebrewNew = new Locale("he", "IL", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        Locale yiddishOld = new Locale("ji", "IL", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        Locale yiddishNew = new Locale("yi", "IL", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        Locale indonesianOld = new Locale("in", "", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        Locale indonesianNew = new Locale("id", "", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        if (!hebrewNew.getLanguage().equals("iw"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            errln("Got back wrong language code for Hebrew: expected \"iw\", got \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                            hebrewNew.getLanguage() + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        if (!yiddishNew.getLanguage().equals("ji"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            errln("Got back wrong language code for Yiddish: expected \"ji\", got \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                            yiddishNew.getLanguage() + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        if (!indonesianNew.getLanguage().equals("in"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            errln("Got back wrong language code for Indonesian: expected \"in\", got \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                            indonesianNew.getLanguage() + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @bug 4092475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * I could not reproduce this bug.  I'm pretty convinced it was fixed with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * big locale-data reorg of 10/28/97.  The lookup logic for language and country
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * display names was also changed at that time in that check-in.    --rtg 3/20/98
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * This test is not designed to work in any other locale but en_US.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * Most of the LocaleElements do not contain display names for other languages,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * so this test fails (bug 4289223) when run under different locales. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * LocaleElements_es as of kestrel does not have a localized name for Japanese, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * the getDisplayName method asks the default locale for a display name. The Japanese
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * localized name for "Japanese" does not equal "Japanese" so this test fails for es
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * display names if run under a ja locale. Eventually, he LocaleElements should probably
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * be updated to contain more localized language and region display names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * 1999-11-19 joconner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    public void TestAtypicalLocales() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        Locale[] localesToTest = { new Locale("de", "CA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                                   new Locale("ja", "ZA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                                   new Locale("ru", "MX"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                                   new Locale("en", "FR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                                   new Locale("es", "DE"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                                   new Locale("", "HR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                                   new Locale("", "SE"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                                   new Locale("", "DO"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                                   new Locale("", "BE") };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        String[] englishDisplayNames = { "German (Canada)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                                         "Japanese (South Africa)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                                         "Russian (Mexico)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                                         "English (France)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                                         "Spanish (Germany)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                                         "Croatia",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                                         "Sweden",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                                         "Dominican Republic",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                                         "Belgium" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        String[] frenchDisplayNames = { "allemand (Canada)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                                        "japonais (Afrique du Sud)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                                        "russe (Mexique)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                                         "anglais (France)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                                         "espagnol (Allemagne)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                                        "Croatie",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                                        "Su\u00e8de",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                                        "R\u00e9publique Dominicaine",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                                        "Belgique" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        String[] spanishDisplayNames = { "alem\u00E1n (Canad\u00E1)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                                         "japon\u00E9s (Sud\u00E1frica)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                         "ruso (M\u00e9xico)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                                         "ingl\u00E9s (Francia)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                                         "espa\u00f1ol (Alemania)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                                         "Croacia",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                                         "Suecia",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                                         "Rep\u00fablica Dominicana",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                                         "B\u00E9lgica" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        // save the default locale and set to the new default to en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        Locale defaultLocale = Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        Locale.setDefault(Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        for (int i = 0; i < localesToTest.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            String name = localesToTest[i].getDisplayName(Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            logln(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            if (!name.equals(englishDisplayNames[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                errln("Lookup in English failed: expected \"" + englishDisplayNames[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                            + "\", got \"" + name + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        for (int i = 0; i < localesToTest.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            String name = localesToTest[i].getDisplayName(new Locale("es", "ES"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            logln(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            if (!name.equals(spanishDisplayNames[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                errln("Lookup in Spanish failed: expected \"" + spanishDisplayNames[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                            + "\", got \"" + name + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        for (int i = 0; i < localesToTest.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            String name = localesToTest[i].getDisplayName(Locale.FRANCE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            logln(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            if (!name.equals(frenchDisplayNames[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                errln("Lookup in French failed: expected \"" + frenchDisplayNames[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                            + "\", got \"" + name + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        // restore the default locale for other tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        Locale.setDefault(defaultLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @bug 4126371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    public void TestNullDefault() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        // why on earth anyone would ever try to do this is beyond me, but we should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        // definitely make sure we don't let them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        boolean gotException = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            Locale.setDefault(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        catch (NullPointerException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            // all other exception types propagate through here back to the test harness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            gotException = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        if (Locale.getDefault() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            errln("Locale.getDefault() allowed us to set default to NULL!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        if (!gotException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            errln("Trying to set default locale to NULL didn't throw exception!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @bug 4135752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * This would be better tested by the LocaleDataTest.  Will move it when I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * get the LocaleDataTest working again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    public void TestThaiCurrencyFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        DecimalFormat thaiCurrency = (DecimalFormat)NumberFormat.getCurrencyInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                        new Locale("th", "TH"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        if (!thaiCurrency.getPositivePrefix().equals("\u0e3f"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            errln("Thai currency prefix wrong: expected \"\u0e3f\", got \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                            thaiCurrency.getPositivePrefix() + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        if (!thaiCurrency.getPositiveSuffix().equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            errln("Thai currency suffix wrong: expected \"\", got \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                            thaiCurrency.getPositiveSuffix() + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * @bug 4122371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * Confirm that Euro support works.  This test is pretty rudimentary; all it does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * is check that any locales with the EURO variant format a number using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * Euro currency symbol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * ASSUME: All locales encode the Euro character "\u20AC".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * If this is changed to use the single-character Euro symbol, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * test must be updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * DON'T ASSUME: Any specific countries support the Euro.  Instead,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * iterate through all locales.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    public void TestEuroSupport() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        final String EURO_VARIANT  = "EURO";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        final String EURO_CURRENCY = "\u20AC"; // Look for this string in formatted Euro currency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        Locale[] locales = NumberFormat.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        for (int i=0; i<locales.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            Locale loc = locales[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            if (loc.getVariant().indexOf(EURO_VARIANT) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                NumberFormat nf = NumberFormat.getCurrencyInstance(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                String pos = nf.format(271828.182845);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                String neg = nf.format(-271828.182845);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                if (pos.indexOf(EURO_CURRENCY) >= 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    neg.indexOf(EURO_CURRENCY) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                    logln("Ok: " + loc.toString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                          ": " + pos + " / " + neg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                    errln("Fail: " + loc.toString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                          " formats without " + EURO_CURRENCY +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                          ": " + pos + " / " + neg +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                          "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @bug 4139504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * toString() doesn't work with language_VARIANT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    public void TestToString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        Object[] DATA = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            new Locale("xx", "", ""), "xx",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            new Locale("", "YY", ""), "_YY",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        new Locale("", "", "ZZ"), "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            new Locale("xx", "YY", ""), "xx_YY",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            new Locale("xx", "", "ZZ"), "xx__ZZ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            new Locale("", "YY", "ZZ"), "_YY_ZZ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            new Locale("xx", "YY", "ZZ"), "xx_YY_ZZ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        for (int i=0; i<DATA.length; i+=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            Locale loc = (Locale)DATA[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            String fmt = (String)DATA[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            if (!loc.toString().equals(fmt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                errln("Fail: Locale.toString(" + fmt + ")=>" + loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * @bug 4105828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * Currency symbol in zh is wrong.  We will test this at the NumberFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * end to test the whole pipe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    public void Test4105828() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        Locale[] LOC = { Locale.CHINESE, new Locale("zh", "CN", ""),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                         new Locale("zh", "TW", ""), new Locale("zh", "HK", "") };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        for (int i=0; i<LOC.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            NumberFormat fmt = NumberFormat.getPercentInstance(LOC[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            String result = fmt.format(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            if (!result.equals("100%")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                errln("Percent for " + LOC[i] + " should be 100%, got " + result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * @bug 4139940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * Couldn't reproduce this bug -- probably was fixed earlier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * ORIGINAL BUG REPORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * -- basically, hungarian for monday shouldn't have an \u00f4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * (o circumflex)in it instead it should be an o with 2 inclined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * (right) lines over it..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * You may wonder -- why do all this -- why not just add a line to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * LocaleData?  Well, I could see by inspection that the locale file had the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * right character in it, so I wanted to check the rest of the pipeline -- a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * very remote possibility, but I wanted to be sure.  The other possibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * is that something is wrong with the font mapping subsystem, but we can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * test that here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    public void Test4139940() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        Locale mylocale=new Locale("hu", "", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        Date mydate = new Date(98,3,13); // A Monday
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        DateFormat df_full = new SimpleDateFormat("EEEE", mylocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        String str = df_full.format(mydate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        // Make sure that o circumflex (\u00F4) is NOT there, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        // o double acute (\u0151) IS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        if (str.indexOf('\u0151') < 0 || str.indexOf('\u00F4') >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            errln("Fail: Monday in Hungarian is wrong");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * @bug 4143951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * Russian first day of week should be Monday. Confirmed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    public void Test4143951() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        Calendar cal = Calendar.getInstance(new Locale("ru", "", ""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        if (cal.getFirstDayOfWeek() != Calendar.MONDAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            errln("Fail: First day of week in Russia should be Monday");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @bug 4147315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * Should throw an exception for unknown locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    public void Test4147315() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        // Try with codes that are the wrong length but happen to match text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        // at a valid offset in the mapping table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        Locale locale = new Locale("aaa", "CCC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            String result = locale.getISO3Country();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            errln("ERROR: getISO3Country() returns: " + result +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                " for locale '" + locale + "' rather than exception" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        } catch(MissingResourceException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @bug 4147317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * java.util.Locale.getISO3Language() works wrong for non ISO-3166 codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * Should throw an exception for unknown locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    public void Test4147317() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        // Try with codes that are the wrong length but happen to match text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        // at a valid offset in the mapping table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        Locale locale = new Locale("aaa", "CCC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            String result = locale.getISO3Language();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            errln("ERROR: getISO3Language() returns: " + result +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                " for locale '" + locale + "' rather than exception" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        } catch(MissingResourceException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * @bug 4147552 4778440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    public void Test4147552() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        Locale[] locales = { new Locale("no", "NO"), new Locale("no", "NO", "B"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                             new Locale("no", "NO", "NY") };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        String[] englishDisplayNames = { "Norwegian (Norway)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                     "Norwegian (Norway,Bokm\u00e5l)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                     "Norwegian (Norway,Nynorsk)" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        String[] norwegianDisplayNames = { "norsk (Norge)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                     "norsk (Norge,bokm\u00e5l)", "norsk (Norge,nynorsk)" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        for (int i = 0; i < locales.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            Locale loc = locales[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            if (!loc.getDisplayName(Locale.US).equals(englishDisplayNames[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
               errln("English display-name mismatch: expected " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                       englishDisplayNames[i] + ", got " + loc.getDisplayName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            if (!loc.getDisplayName(loc).equals(norwegianDisplayNames[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                errln("Norwegian display-name mismatch: expected " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                       norwegianDisplayNames[i] + ", got " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                       loc.getDisplayName(loc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    static String escapeUnicode(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        StringBuffer buf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        for (int i=0; i<s.length(); ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            char c = s.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            if (c >= 0x20 && c <= 0x7F) buf.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                buf.append("\\u");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                String h = "000" + Integer.toHexString(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                if (h.length() > 4) h = h.substring(h.length() - 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                buf.append(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
}