< prev index next >

test/jdk/java/util/Locale/bcp47u/DisplayNameTests.java

Print this page


   1 /*
   2  * Copyright (c) 2017, 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
  28  * @summary Tests the display names for BCP 47 U extensions
  29  * @modules jdk.localedata
  30  * @run testng/othervm -Djava.locale.providers=CLDR DisplayNameTests
  31  */
  32 
  33 import static org.testng.Assert.assertEquals;
  34 
  35 import java.util.Locale;
  36 
  37 import org.testng.annotations.DataProvider;
  38 import org.testng.annotations.Test;
  39 
  40 /**
  41  * Test Locale.getDisplayName() with BCP47 U extensions. Note that the
  42  * result may change depending on the CLDR releases.
  43  */
  44 @Test
  45 public class DisplayNameTests {
  46     private static final Locale loc1 = Locale.forLanguageTag("en-Latn-US-u" +
  47                                                              "-ca-japanese" +


  65                                             .setRegion("US")
  66                                             .setScript("Latn")
  67                                             .setUnicodeLocaleKeyword("ca", "japanese")
  68                                             .build();
  69     private static final Locale loc4 = new Locale.Builder()
  70                                             .setRegion("US")
  71                                             .setUnicodeLocaleKeyword("ca", "japanese")
  72                                             .build();
  73     private static final Locale loc5 = new Locale.Builder()
  74                                             .setUnicodeLocaleKeyword("ca", "japanese")
  75                                             .build();
  76     private static final Locale loc6 = Locale.forLanguageTag( "zh-CN-u-ca-dddd-nu-ddd-cu-ddd-fw-moq-tz-unknown-rg-twzz");
  77 
  78     @DataProvider(name="locales")
  79     Object[][] tz() {
  80         return new Object[][] {
  81             // Locale for display, Test Locale, Expected output,
  82             {Locale.US, loc1,
  83             "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)"},
  84             {Locale.JAPAN, loc1,
  85             "\u82f1\u8a9e (\u30e9\u30c6\u30f3\u6587\u5b57\u3001\u30a2\u30e1\u30ea\u30ab\u5408\u8846\u56fd\u3001\u548c\u66a6\u3001cf: account\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)"},
  86             {Locale.forLanguageTag("hi-IN"), loc1,
  87             "\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, cf: account, \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)"},
  88 
  89             // cases where no localized types are available. fall back to "key: type"
  90             {Locale.US, Locale.forLanguageTag("en-u-ca-unknown"), "English (Calendar: unknown)"},
  91 
  92             // cases with variant, w/o language, script
  93             {Locale.US, loc2, "Japanese (Japan, JP, Japanese Calendar)"},
  94             {Locale.US, loc3, "Latin (United States, Japanese Calendar)"},
  95             {Locale.US, loc4, "United States (Japanese Calendar)"},
  96             {Locale.US, loc5, ""},
  97 
  98             // invalid cases
  99             {loc6, loc6, "\u4e2d\u6587 (\u4e2d\u56fd\u3001\u65e5\u5386\uff1adddd\u3001\u8d27\u5e01\uff1addd\u3001fw\uff1amoq\u3001\u6570\u5b57\uff1addd\u3001rg\uff1atwzz\u3001\u65f6\u533a\uff1aunknown)"},
 100             {Locale.US, loc6, "Chinese (China, Calendar: dddd, Currency: ddd, First day of week: moq, Numbers: ddd, Region For Supplemental Data: twzz, Time Zone: unknown)"},
 101         };
 102     }
 103 
 104     @Test(dataProvider="locales")
 105     public void test_locales(Locale inLocale, Locale testLocale, String expected) {
 106         String result = testLocale.getDisplayName(inLocale);
 107         assertEquals(result, expected);
 108     }
 109 }
   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 8202537
  28  * @summary Tests the display names for BCP 47 U extensions
  29  * @modules jdk.localedata
  30  * @run testng/othervm -Djava.locale.providers=CLDR DisplayNameTests
  31  */
  32 
  33 import static org.testng.Assert.assertEquals;
  34 
  35 import java.util.Locale;
  36 
  37 import org.testng.annotations.DataProvider;
  38 import org.testng.annotations.Test;
  39 
  40 /**
  41  * Test Locale.getDisplayName() with BCP47 U extensions. Note that the
  42  * result may change depending on the CLDR releases.
  43  */
  44 @Test
  45 public class DisplayNameTests {
  46     private static final Locale loc1 = Locale.forLanguageTag("en-Latn-US-u" +
  47                                                              "-ca-japanese" +


  65                                             .setRegion("US")
  66                                             .setScript("Latn")
  67                                             .setUnicodeLocaleKeyword("ca", "japanese")
  68                                             .build();
  69     private static final Locale loc4 = new Locale.Builder()
  70                                             .setRegion("US")
  71                                             .setUnicodeLocaleKeyword("ca", "japanese")
  72                                             .build();
  73     private static final Locale loc5 = new Locale.Builder()
  74                                             .setUnicodeLocaleKeyword("ca", "japanese")
  75                                             .build();
  76     private static final Locale loc6 = Locale.forLanguageTag( "zh-CN-u-ca-dddd-nu-ddd-cu-ddd-fw-moq-tz-unknown-rg-twzz");
  77 
  78     @DataProvider(name="locales")
  79     Object[][] tz() {
  80         return new Object[][] {
  81             // Locale for display, Test Locale, Expected output,
  82             {Locale.US, loc1,
  83             "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)"},
  84             {Locale.JAPAN, loc1,
  85             "\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)"},
  86             {Locale.forLanguageTag("hi-IN"), loc1,
  87             "\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)"},
  88 
  89             // cases where no localized types are available. fall back to "key: type"
  90             {Locale.US, Locale.forLanguageTag("en-u-ca-unknown"), "English (Calendar: unknown)"},
  91 
  92             // cases with variant, w/o language, script
  93             {Locale.US, loc2, "Japanese (Japan, JP, Japanese Calendar)"},
  94             {Locale.US, loc3, "Latin (United States, Japanese Calendar)"},
  95             {Locale.US, loc4, "United States (Japanese Calendar)"},
  96             {Locale.US, loc5, ""},
  97 
  98             // invalid cases
  99             {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)"},
 100             {Locale.US, loc6, "Chinese (China, Calendar: dddd, Currency: ddd, First day of week: moq, Numbers: ddd, Region For Supplemental Data: twzz, Time Zone: unknown)"},
 101         };
 102     }
 103 
 104     @Test(dataProvider="locales")
 105     public void test_locales(Locale inLocale, Locale testLocale, String expected) {
 106         String result = testLocale.getDisplayName(inLocale);
 107         assertEquals(result, expected);
 108     }
 109 }
< prev index next >