test/java/util/Locale/LocaleProviders.java

Print this page
rev 7043 : imported patch 8013086
rev 7044 : imported patch 8013233


 107         }
 108     }
 109 
 110     static void bug8001440Test() {
 111         Locale locale = Locale.forLanguageTag("th-TH-u-nu-hoge");
 112         NumberFormat nf = NumberFormat.getInstance(locale);
 113         String nu = nf.format(1234560);
 114     }
 115 
 116     // This test assumes Windows localized language/country display names.
 117     static void bug8010666Test() {
 118         if (System.getProperty("os.name").startsWith("Windows")) {
 119             NumberFormat nf = NumberFormat.getInstance(Locale.US);
 120             try {
 121                 double ver = nf.parse(System.getProperty("os.version")).doubleValue();
 122                 System.out.printf("Windows version: %.1f\n", ver);
 123                 if (ver >= 6.0) {
 124                     LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(LocaleNameProvider.class, Locale.ENGLISH);
 125                     LocaleProviderAdapter.Type type = lda.getAdapterType();
 126                     if (type == LocaleProviderAdapter.Type.HOST) {

 127                         Locale mkmk = Locale.forLanguageTag("mk-MK");
 128                         String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
 129                         if (!"Macedonian (FYROM)".equals(result)) {
 130                             throw new RuntimeException("Windows locale name provider did not return expected localized language name for \"mk\". Returned name was \"" + result + "\"");




 131                         }
 132                         result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
 133                         if (!"English".equals(result)) {
 134                             throw new RuntimeException("Windows locale name provider did not return expected localized language name for \"en\". Returned name was \"" + result + "\"");




 135                         }

 136                         result = Locale.US.getDisplayCountry(Locale.ENGLISH);
 137                         if (ver >= 6.1 && !"United States".equals(result)) {
 138                             throw new RuntimeException("Windows locale name provider did not return expected localized country name for \"US\". Returned name was \"" + result + "\"");




 139                         }

 140                     } else {
 141                         throw new RuntimeException("Windows Host LocaleProviderAdapter was not selected for English locale.");
 142                     }
 143                 }
 144             } catch (ParseException pe) {
 145                 throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
 146             }
 147         }
 148     }
 149 
 150     static void bug8013086Test(String lang, String ctry) {
 151         try {
 152             // Throws a NullPointerException if the test fails.
 153             System.out.println(new SimpleDateFormat("z", new Locale(lang, ctry)).parse("UTC"));
 154         } catch (ParseException pe) {
 155             // ParseException is fine in this test, as it's not "UTC"
 156         }
 157     }
 158 }


 107         }
 108     }
 109 
 110     static void bug8001440Test() {
 111         Locale locale = Locale.forLanguageTag("th-TH-u-nu-hoge");
 112         NumberFormat nf = NumberFormat.getInstance(locale);
 113         String nu = nf.format(1234560);
 114     }
 115 
 116     // This test assumes Windows localized language/country display names.
 117     static void bug8010666Test() {
 118         if (System.getProperty("os.name").startsWith("Windows")) {
 119             NumberFormat nf = NumberFormat.getInstance(Locale.US);
 120             try {
 121                 double ver = nf.parse(System.getProperty("os.version")).doubleValue();
 122                 System.out.printf("Windows version: %.1f\n", ver);
 123                 if (ver >= 6.0) {
 124                     LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(LocaleNameProvider.class, Locale.ENGLISH);
 125                     LocaleProviderAdapter.Type type = lda.getAdapterType();
 126                     if (type == LocaleProviderAdapter.Type.HOST) {
 127                         LocaleNameProvider lnp = lda.getLocaleNameProvider();
 128                         Locale mkmk = Locale.forLanguageTag("mk-MK");
 129                         String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
 130                         String expected = lnp.getDisplayLanguage(mkmk.getLanguage(), Locale.ENGLISH);
 131                         System.out.printf("  Display language name for (mk_MK): expected: \"%s\", returned: \"%s\"\n", expected, result);
 132                         if (result != null &&
 133                             expected != null &&
 134                             !result.equals(expected)) {
 135                             throw new RuntimeException("Windows locale name provider did not return expected localized language name for \"mk\". Returned name was \"" + result + "\", expected: \"" + expected +  "\"");
 136                         }
 137                         result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
 138                         expected = lnp.getDisplayLanguage(Locale.US.getLanguage(), Locale.ENGLISH);
 139                         System.out.printf("  Display language name for (en_US): expected: \"%s\", returned: \"%s\"\n", expected, result);
 140                         if (result != null &&
 141                             expected != null &&
 142                             !result.equals(expected)) {
 143                             throw new RuntimeException("Windows locale name provider did not return expected localized language name for \"en\". Returned name was \"" + result + "\", expected: \"" + expected +  "\"");
 144                         }
 145                         if (ver >= 6.1) {
 146                             result = Locale.US.getDisplayCountry(Locale.ENGLISH);
 147                             expected = lnp.getDisplayCountry(Locale.US.getCountry(), Locale.ENGLISH);
 148                             System.out.printf("  Display country name for (en_US): expected: \"%s\", returned: \"%s\"\n", expected, result);
 149                             if (result != null &&
 150                                 expected != null &&
 151                                 !result.equals(expected)) {
 152                                 throw new RuntimeException("Windows locale name provider did not return expected localized country name for \"US\". Returned name was \"" + result + "\", expected: \"" + expected + "\"");
 153                             }
 154                         }
 155                     } else {
 156                         throw new RuntimeException("Windows Host LocaleProviderAdapter was not selected for English locale.");
 157                     }
 158                 }
 159             } catch (ParseException pe) {
 160                 throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
 161             }
 162         }
 163     }
 164 
 165     static void bug8013086Test(String lang, String ctry) {
 166         try {
 167             // Throws a NullPointerException if the test fails.
 168             System.out.println(new SimpleDateFormat("z", new Locale(lang, ctry)).parse("UTC"));
 169         } catch (ParseException pe) {
 170             // ParseException is fine in this test, as it's not "UTC"
 171         }
 172     }
 173 }