Path: blob/master/test/jdk/java/util/Locale/bcp47u/DisplayNameTests.java
41153 views
/*1* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24*25* @test26* @bug 8176841 820253727* @summary Tests the display names for BCP 47 U extensions28* @modules jdk.localedata29* @run testng/othervm -Djava.locale.providers=CLDR DisplayNameTests30*/3132import static org.testng.Assert.assertEquals;3334import java.util.Locale;3536import org.testng.annotations.DataProvider;37import org.testng.annotations.Test;3839/**40* Test Locale.getDisplayName() with BCP47 U extensions. Note that the41* result may change depending on the CLDR releases.42*/43@Test44public class DisplayNameTests {45private static final Locale loc1 = Locale.forLanguageTag("en-Latn-US-u" +46"-ca-japanese" +47"-cf-account" +48"-co-pinyin" +49"-cu-jpy" +50"-em-emoji" +51"-fw-wed" +52"-hc-h23" +53"-lb-loose" +54"-lw-breakall" +55"-ms-uksystem" +56"-nu-roman" +57"-rg-gbzzzz" +58"-sd-gbsct" +59"-ss-standard" +60"-tz-jptyo" +61"-va-posix");62private static final Locale loc2 = new Locale("ja", "JP", "JP");63private static final Locale loc3 = new Locale.Builder()64.setRegion("US")65.setScript("Latn")66.setUnicodeLocaleKeyword("ca", "japanese")67.build();68private static final Locale loc4 = new Locale.Builder()69.setRegion("US")70.setUnicodeLocaleKeyword("ca", "japanese")71.build();72private static final Locale loc5 = new Locale.Builder()73.setUnicodeLocaleKeyword("ca", "japanese")74.build();75private static final Locale loc6 = Locale.forLanguageTag( "zh-CN-u-ca-dddd-nu-ddd-cu-ddd-fw-moq-tz-unknown-rg-twzz");7677@DataProvider(name="locales")78Object[][] tz() {79return new Object[][] {80// Locale for display, Test Locale, Expected output,81{Locale.US, loc1,82"English (Latin, United States, Japanese Calendar, Accounting Currency Format, Pinyin Sort Order, Currency: Japanese Yen, Prefer Emoji Presentation For Emoji Characters, First Day of Week Is Wednesday, 24 Hour System (0\u201323), Loose Line Break Style, Allow Line Breaks In All Words, Imperial Measurement System, Roman Numerals, Region For Supplemental Data: United Kingdom, Region Subdivision: gbsct, Suppress Sentence Breaks After Standard Abbreviations, Time Zone: Japan Time, POSIX Compliant Locale)"},83{Locale.JAPAN, loc1,84"\u82f1\u8a9e (\u30e9\u30c6\u30f3\u6587\u5b57\u3001\u30a2\u30e1\u30ea\u30ab\u5408\u8846\u56fd\u3001\u548c\u66a6\u3001\u4f1a\u8a08\u901a\u8ca8\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3001\u30d4\u30f3\u30a4\u30f3\u9806\u3001\u901a\u8ca8: \u65e5\u672c\u5186\u3001em: emoji\u3001fw: wed\u300124\u6642\u9593\u5236(0\u301c23)\u3001\u7981\u5247\u51e6\u7406(\u5f31)\u3001lw: breakall\u3001\u30e4\u30fc\u30c9\u30fb\u30dd\u30f3\u30c9\u6cd5\u3001\u30ed\u30fc\u30de\u6570\u5b57\u3001rg: \u30a4\u30ae\u30ea\u30b9\u3001sd: gbsct\u3001ss: standard\u3001\u30bf\u30a4\u30e0\u30be\u30fc\u30f3: \u65e5\u672c\u6642\u9593\u3001\u30ed\u30b1\u30fc\u30eb\u306e\u30d0\u30ea\u30a2\u30f3\u30c8: posix)"},85{Locale.forLanguageTag("hi-IN"), loc1,86"\u0905\u0902\u0917\u094d\u0930\u0947\u091c\u093c\u0940 (\u0932\u0948\u091f\u093f\u0928, \u0938\u0902\u092f\u0941\u0915\u094d\u0924 \u0930\u093e\u091c\u094d\u092f, \u091c\u093e\u092a\u093e\u0928\u0940 \u092a\u0902\u091a\u093e\u0902\u0917, \u0932\u0947\u0916\u093e\u0902\u0915\u0928 \u092e\u0941\u0926\u094d\u0930\u093e \u092a\u094d\u0930\u093e\u0930\u0942\u092a, \u092a\u093f\u0928\u092f\u0940\u0928 \u0935\u0930\u094d\u0917\u0940\u0915\u0930\u0923, \u092e\u0941\u0926\u094d\u0930\u093e: \u091c\u093e\u092a\u093e\u0928\u0940 \u092f\u0947\u0928, em: emoji, fw: wed, 24 \u0918\u0902\u091f\u094b\u0902 \u0915\u0940 \u092a\u094d\u0930\u0923\u093e\u0932\u0940 (0\u201323), \u0922\u0940\u0932\u0940 \u092a\u0902\u0915\u094d\u0924\u093f \u0935\u093f\u091a\u094d\u091b\u0947\u0926 \u0936\u0948\u0932\u0940, lw: breakall, \u0907\u092e\u094d\u092a\u0940\u0930\u093f\u092f\u0932 \u092e\u093e\u092a\u0928 \u092a\u094d\u0930\u0923\u093e\u0932\u0940, \u0930\u094b\u092e\u0928 \u0938\u0902\u0916\u094d\u092f\u093e\u090f\u0901, rg: \u092f\u0942\u0928\u093e\u0907\u091f\u0947\u0921 \u0915\u093f\u0902\u0917\u0921\u092e, sd: gbsct, ss: standard, \u0938\u092e\u092f \u0915\u094d\u0937\u0947\u0924\u094d\u0930: \u091c\u093e\u092a\u093e\u0928 \u0938\u092e\u092f, \u0938\u094d\u0925\u093e\u0928\u0940\u092f \u092a\u094d\u0930\u0915\u093e\u0930: posix)"},8788// cases where no localized types are available. fall back to "key: type"89{Locale.US, Locale.forLanguageTag("en-u-ca-unknown"), "English (Calendar: unknown)"},9091// cases with variant, w/o language, script92{Locale.US, loc2, "Japanese (Japan, JP, Japanese Calendar)"},93{Locale.US, loc3, "Latin (United States, Japanese Calendar)"},94{Locale.US, loc4, "United States (Japanese Calendar)"},95{Locale.US, loc5, ""},9697// invalid cases98{loc6, loc6, "\u4e2d\u6587 (\u4e2d\u56fd\uff0c\u65e5\u5386\uff1adddd\uff0c\u8d27\u5e01\uff1addd\uff0cfw\uff1amoq\uff0c\u6570\u5b57\uff1addd\uff0crg\uff1atwzz\uff0c\u65f6\u533a\uff1aunknown)"},99{Locale.US, loc6, "Chinese (China, Calendar: dddd, Currency: ddd, First day of week: moq, Numbers: ddd, Region For Supplemental Data: twzz, Time Zone: unknown)"},100};101}102103@Test(dataProvider="locales")104public void test_locales(Locale inLocale, Locale testLocale, String expected) {105String result = testLocale.getDisplayName(inLocale);106assertEquals(result, expected);107}108}109110111