jdk/test/sun/util/resources/Locale/Bug4429024.java
author duke
Wed, 05 Jul 2017 16:48:18 +0200
changeset 2092 b86b8d6d48bd
parent 2 90ce3da70b43
child 4606 c79bb9876373
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
    @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
    @summary checking localised language/country names in finnish
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
    @bug 4429024 4964035 6558856
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
public class Bug4429024 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
        int errors=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        String [][] fiLocales = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
                    { "ar", "arabia" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
                    { "ba", "baski" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                    { "bg", "bulgaria" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                    { "ca", "katalaani" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                    { "cs", "tsekki" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
                    { "da", "tanska" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                    { "de", "saksa" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                    { "el", "kreikka" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                    { "en", "englanti" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                    { "es", "espanja" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                    { "fi", "suomi" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                    { "fr", "franska" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                    { "he", "heprea" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                    { "hi", "hindi" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                    { "it", "italia" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                    { "ja", "japani" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                    { "lt", "liettua" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                    { "lv", "latvia" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                    { "nl", "hollanti" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                    { "no", "norja" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                    { "pl", "puola" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                    { "pt", "portugali" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                    { "ru", "ven\u00e4j\u00e4" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                    { "sv", "ruotsi" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                    { "th", "thai" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                    { "tr", "turkki" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                    { "zh", "kiina" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        String[][] fiCountries = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                    { "BE", "Belgia" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                    { "BR", "Brasilia" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    { "CA", "Kanada" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    { "CH", "Sveitsi" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                    { "CN", "Kiina" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                    { "CZ", "Tsekin tasavalta" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    { "DE", "Saksa" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    { "DK", "Tanska" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                    { "ES", "Espanja" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                    { "FI", "Suomi" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    { "FR", "Franska" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                    { "GB", "Iso-Britannia" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                    { "GR", "Kreikka" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                    { "IE", "Irlanti" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    { "IT", "Italia" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    { "JP", "Japani" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                    { "KR", "Korea" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    { "NL", "Alankomaat" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    { "NO", "Norja" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    { "PL", "Puola" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    { "PT", "Portugali" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    { "RU", "Ven\u00e4j\u00e4" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    { "SE", "Ruotsi" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    { "TR", "Turkki" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    { "US", "Yhdysvallat" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        for (int i=0; i < fiLocales.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            errors += getLanguage(fiLocales[i][0], fiLocales[i][1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        for (int i=0; i < fiCountries.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            errors += getCountry(fiCountries[i][0], fiCountries[i][1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if(errors > 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new RuntimeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        static int getLanguage(String inLang, String localizedName){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            Locale fiLocale = new Locale("fi", "FI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            Locale inLocale = new Locale (inLang, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            if (!inLocale.getDisplayLanguage(fiLocale).equals(localizedName)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                System.out.println("Language " + inLang +" should be \"" + localizedName  + "\", not \"" + inLocale.getDisplayLanguage(fiLocale) + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    static int getCountry(String inCountry, String localizedName){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            Locale fiLocale = new Locale("fi", "FI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            Locale inLocale = new Locale ("", inCountry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            if (!inLocale.getDisplayCountry(fiLocale).equals(localizedName)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                System.out.println("Country " + inCountry + " should be \"" + localizedName + "\", not \"" + inLocale.getDisplayCountry(fiLocale) + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}