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