1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package libcore.icu; 18 19 import java.util.Locale; 20 21 public class LocaleDataTest extends junit.framework.TestCase { 22 public void testAll() throws Exception { 23 // Test that we can get the locale data for all known locales. 24 for (Locale l : Locale.getAvailableLocales()) { 25 LocaleData d = LocaleData.get(l); 26 // System.err.format("%20s %s %s %s\n", l, d.yesterday, d.today, d.tomorrow); 27 // System.err.format("%20s %10s %10s\n", l, d.timeFormat_hm, d.timeFormat_Hm); 28 } 29 } 30 31 public void test_en_US() throws Exception { 32 LocaleData l = LocaleData.get(Locale.US); 33 assertEquals("AM", l.amPm[0]); 34 assertEquals("a", l.narrowAm); 35 36 assertEquals("BC", l.eras[0]); 37 38 assertEquals("January", l.longMonthNames[0]); 39 assertEquals("Jan", l.shortMonthNames[0]); 40 assertEquals("J", l.tinyMonthNames[0]); 41 42 assertEquals("January", l.longStandAloneMonthNames[0]); 43 assertEquals("Jan", l.shortStandAloneMonthNames[0]); 44 assertEquals("J", l.tinyStandAloneMonthNames[0]); 45 46 assertEquals("Sunday", l.longWeekdayNames[1]); 47 assertEquals("Sun", l.shortWeekdayNames[1]); 48 assertEquals("S", l.tinyWeekdayNames[1]); 49 50 assertEquals("Sunday", l.longStandAloneWeekdayNames[1]); 51 assertEquals("Sun", l.shortStandAloneWeekdayNames[1]); 52 assertEquals("S", l.tinyStandAloneWeekdayNames[1]); 53 54 assertEquals("Yesterday", l.yesterday); 55 assertEquals("Today", l.today); 56 assertEquals("Tomorrow", l.tomorrow); 57 } 58 59 public void test_de_DE() throws Exception { 60 LocaleData l = LocaleData.get(new Locale("de", "DE")); 61 62 assertEquals("Gestern", l.yesterday); 63 assertEquals("Heute", l.today); 64 assertEquals("Morgen", l.tomorrow); 65 } 66 67 public void test_cs_CZ() throws Exception { 68 LocaleData l = LocaleData.get(new Locale("cs", "CZ")); 69 70 assertEquals("ledna", l.longMonthNames[0]); 71 assertEquals("led", l.shortMonthNames[0]); 72 assertEquals("1", l.tinyMonthNames[0]); 73 74 assertEquals("leden", l.longStandAloneMonthNames[0]); 75 assertEquals("led", l.shortStandAloneMonthNames[0]); 76 assertEquals("1", l.tinyStandAloneMonthNames[0]); 77 } 78 79 public void test_ko_KR() throws Exception { 80 LocaleData l = LocaleData.get(new Locale("ko", "KR")); 81 82 // Ensure the fix for http://b/14493853 doesn't mangle Hangul. 83 assertEquals("", l.yesterday); 84 assertEquals("", l.today); 85 assertEquals("", l.tomorrow); 86 } 87 88 public void test_ru_RU() throws Exception { 89 LocaleData l = LocaleData.get(new Locale("ru", "RU")); 90 91 assertEquals("", l.longWeekdayNames[1]); 92 assertEquals("", l.shortWeekdayNames[1]); 93 assertEquals("", l.tinyWeekdayNames[1]); 94 95 // Russian stand-alone weekday names have no initial capital since CLDR 28/ICU 56. 96 assertEquals("", l.longStandAloneWeekdayNames[1]); 97 assertEquals("", l.shortStandAloneWeekdayNames[1]); 98 assertEquals("", l.tinyStandAloneWeekdayNames[1]); 99 } 100 101 // http://code.google.com/p/android/issues/detail?id=38844 102 public void testDecimalFormatSymbols_es() throws Exception { 103 LocaleData es = LocaleData.get(new Locale("es")); 104 assertEquals(',', es.decimalSeparator); 105 assertEquals('.', es.groupingSeparator); 106 107 LocaleData es_419 = LocaleData.get(new Locale("es", "419")); 108 assertEquals('.', es_419.decimalSeparator); 109 assertEquals(',', es_419.groupingSeparator); 110 111 LocaleData es_US = LocaleData.get(new Locale("es", "US")); 112 assertEquals('.', es_US.decimalSeparator); 113 assertEquals(',', es_US.groupingSeparator); 114 115 LocaleData es_MX = LocaleData.get(new Locale("es", "MX")); 116 assertEquals('.', es_MX.decimalSeparator); 117 assertEquals(',', es_MX.groupingSeparator); 118 119 LocaleData es_AR = LocaleData.get(new Locale("es", "AR")); 120 assertEquals(',', es_AR.decimalSeparator); 121 assertEquals('.', es_AR.groupingSeparator); 122 } 123 124 // http://b/7924970 125 public void testTimeFormat12And24() throws Exception { 126 LocaleData en_US = LocaleData.get(Locale.US); 127 assertEquals("h:mm a", en_US.timeFormat_hm); 128 assertEquals("HH:mm", en_US.timeFormat_Hm); 129 130 LocaleData ja_JP = LocaleData.get(Locale.JAPAN); 131 assertEquals("aK:mm", ja_JP.timeFormat_hm); 132 assertEquals("H:mm", ja_JP.timeFormat_Hm); 133 } 134 } 135