1 /* 2 * Copyright (c) 2013, 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 import java.util.*; 25 import java.util.logging.*; 26 27 /* 28 * @test 29 * @bug 8016127 30 * @summary test logging.properties localized 31 * @run main/othervm LocalizedLevelName 32 */ 33 34 public class LocalizedLevelName { 35 private static Object[] namesMap = { 36 "SEVERE", Locale.ENGLISH, "Severe", Level.SEVERE, 37 "WARNING", Locale.FRENCH, "Avertissement", Level.WARNING, 38 "INFO", Locale.ITALIAN, "Informazioni", Level.INFO, 39 "SEVERE", Locale.FRENCH, "Grave", Level.SEVERE, 40 "CONFIG", Locale.GERMAN, "Konfiguration", Level.CONFIG, 41 "ALL", Locale.ROOT, "All", Level.ALL, 42 "SEVERE", Locale.ROOT, "Severe", Level.SEVERE, 43 "WARNING", Locale.ROOT, "Warning", Level.WARNING, 44 "CONFIG", Locale.ROOT, "Config", Level.CONFIG, 45 "INFO", Locale.ROOT, "Info", Level.INFO, 46 "FINE", Locale.ROOT, "Fine", Level.FINE, 47 "FINER", Locale.ROOT, "Finer", Level.FINER, 48 "FINEST", Locale.ROOT, "Finest", Level.FINEST 49 }; 50 51 public static void main(String args[]) throws Exception { 52 Locale defaultLocale = Locale.getDefault(); 53 for (int i=0; i<namesMap.length; i += 4) { 54 final String key = (String) namesMap[i]; 55 final Locale locale = (Locale) namesMap[i+1]; 56 final String expectedTranslation = (String) namesMap[i+2]; 57 final Level level = (Level) namesMap[i+3]; 58 59 final String en = getLocalizedMessage(Locale.ENGLISH, key); 60 final String other = getLocalizedMessage(locale, key); 61 62 System.out.println(locale + ": " + key + "=" + expectedTranslation 63 + ", (Level." + level.getName() + ")"); 64 System.out.println(" => localized(" + Locale.ENGLISH + ", " 65 + key + ")=" + en); 66 System.out.println(" => localized(" + locale + ", " + key 67 + ")=" + other); 68 if (!key.equals(en.toUpperCase(Locale.ROOT))) { 69 throw new RuntimeException("Expect " + key 70 + " equals upperCase(" + en + ")"); 71 } 72 if (!Locale.ENGLISH.equals(locale) && !Locale.ROOT.equals(locale) 73 && key.equals(other.toUpperCase(Locale.ROOT))) { 74 throw new RuntimeException("Expect " + key 75 + " not equals upperCase(" + other +")"); 76 } 77 if ((Locale.ENGLISH.equals(locale) || Locale.ROOT.equals(locale)) 78 && !key.equals(other.toUpperCase(Locale.ROOT))) { 79 throw new RuntimeException("Expect " + key 80 + " equals upperCase(" + other +")"); 81 } 82 if (!other.equals(expectedTranslation)) { 83 throw new RuntimeException("Expected \"" + expectedTranslation 84 + "\" for '" + locale + "' but got \"" + other + "\""); 85 } 86 Locale.setDefault(locale); 87 final String levelName = level.getLocalizedName(); 88 System.out.println("Level.getLocalizedName() is: " + levelName); 89 if (!levelName.equals(other.toUpperCase(locale))) { 90 throw new RuntimeException("Expected \"" 91 + other.toUpperCase(locale) + "\" for '" 92 + locale + "' but got \"" + levelName + "\""); 93 } 94 Locale.setDefault(defaultLocale); 95 } 96 } 97 98 private static final String RBNAME = "sun.util.logging.resources.logging"; 99 private static String getLocalizedMessage(Locale locale, String key) { 100 ResourceBundle rb = ResourceBundle.getBundle(RBNAME, locale); 101 return rb.getString(key); 102 } 103 }