1 /* 2 * Copyright (c) 2017, 2018, 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 /* 25 * 26 * @test 27 * @bug 8176841 8194148 28 * @summary Tests *FormatSymbols class deals with Unicode extensions 29 * correctly. 30 * @modules jdk.localedata 31 * @run testng/othervm -Djava.locale.providers=CLDR SymbolsTests 32 */ 33 34 import static org.testng.Assert.assertEquals; 35 36 import java.text.DateFormatSymbols; 37 import java.text.DecimalFormatSymbols; 38 import java.util.Locale; 39 40 import org.testng.annotations.DataProvider; 41 import org.testng.annotations.Test; 42 43 /** 44 * Test *FormatSymbols classes with BCP47 U extensions 45 */ 46 @Test 47 public class SymbolsTests { 48 49 private static final Locale RG_GB = Locale.forLanguageTag("en-US-u-rg-gbzzzz"); 50 private static final Locale RG_IE = Locale.forLanguageTag("en-US-u-rg-iezzzz"); 51 private static final Locale RG_AT = Locale.forLanguageTag("en-US-u-rg-atzzzz"); 52 53 @DataProvider(name="dateFormatSymbolsData") 54 Object[][] dateFormatSymbolsData() { 55 return new Object[][] { 56 // Locale, expected AM string, expected PM string 57 58 {RG_GB, "am", "pm"}, 59 {RG_IE, "a.m.", "p.m."}, 60 {Locale.US, "AM", "PM"}, 61 }; 62 } 63 64 @DataProvider(name="decimalFormatSymbolsData") 65 Object[][] decimalFormatSymbolsData() { 66 return new Object[][] { 67 // Locale, expected decimal separator, expected grouping separator 68 69 {RG_AT, ',', '.'}, 70 {Locale.US, '.', ','}, 71 72 // -nu & -rg mixed. -nu should win 73 {Locale.forLanguageTag("ar-EG-u-nu-latn-rg-mazzzz"), '.', ','}, 74 }; 75 } 76 77 @Test(dataProvider="dateFormatSymbolsData") 78 public void test_DateFormatSymbols(Locale locale, String amExpected, String pmExpected) { 79 DateFormatSymbols dfs = DateFormatSymbols.getInstance(locale); 80 String[] ampm = dfs.getAmPmStrings(); 81 assertEquals(ampm[0], amExpected); 82 assertEquals(ampm[1], pmExpected); 83 } 84 85 @Test(dataProvider="decimalFormatSymbolsData") 86 public void test_DecimalFormatSymbols(Locale locale, char decimal, char grouping) { 87 DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(locale); 88 assertEquals(dfs.getDecimalSeparator(), decimal); 89 assertEquals(dfs.getGroupingSeparator(), grouping); 90 } 91 }