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