jdk/test/java/util/Locale/LocaleProviders.java
changeset 17476 6a5362307fc3
parent 17440 fb37aa6b305e
child 17944 bbd67fc49daa
equal deleted inserted replaced
17475:24f8cffd7390 17476:6a5362307fc3
   116     // This test assumes Windows localized language/country display names.
   116     // This test assumes Windows localized language/country display names.
   117     static void bug8010666Test() {
   117     static void bug8010666Test() {
   118         if (System.getProperty("os.name").startsWith("Windows")) {
   118         if (System.getProperty("os.name").startsWith("Windows")) {
   119             NumberFormat nf = NumberFormat.getInstance(Locale.US);
   119             NumberFormat nf = NumberFormat.getInstance(Locale.US);
   120             try {
   120             try {
   121                 double ver = nf.parse(System.getProperty("os.version")).doubleValue();
   121                 double ver = nf.parse(System.getProperty("os.version"))
       
   122                                .doubleValue();
   122                 System.out.printf("Windows version: %.1f\n", ver);
   123                 System.out.printf("Windows version: %.1f\n", ver);
   123                 if (ver >= 6.0) {
   124                 if (ver >= 6.0) {
   124                     LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(LocaleNameProvider.class, Locale.ENGLISH);
   125                     LocaleProviderAdapter lda =
       
   126                         LocaleProviderAdapter.getAdapter(
       
   127                             LocaleNameProvider.class, Locale.ENGLISH);
   125                     LocaleProviderAdapter.Type type = lda.getAdapterType();
   128                     LocaleProviderAdapter.Type type = lda.getAdapterType();
   126                     if (type == LocaleProviderAdapter.Type.HOST) {
   129                     if (type == LocaleProviderAdapter.Type.HOST) {
       
   130                         LocaleNameProvider lnp = lda.getLocaleNameProvider();
   127                         Locale mkmk = Locale.forLanguageTag("mk-MK");
   131                         Locale mkmk = Locale.forLanguageTag("mk-MK");
   128                         String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
   132                         String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
   129                         if (!"Macedonian (FYROM)".equals(result)) {
   133                         String hostResult =
   130                             throw new RuntimeException("Windows locale name provider did not return expected localized language name for \"mk\". Returned name was \"" + result + "\"");
   134                             lnp.getDisplayLanguage(mkmk.getLanguage(),
       
   135                                                    Locale.ENGLISH);
       
   136                         System.out.printf("  Display language name for" +
       
   137                             " (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
       
   138                             hostResult, result);
       
   139                         if (result == null ||
       
   140                             hostResult != null &&
       
   141                             !result.equals(hostResult)) {
       
   142                             throw new RuntimeException("Display language name" +
       
   143                                 " mismatch for \"mk\". Returned name was" +
       
   144                                 " \"" + result + "\", result(HOST): \"" +
       
   145                                 hostResult + "\"");
   131                         }
   146                         }
   132                         result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
   147                         result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
   133                         if (!"English".equals(result)) {
   148                         hostResult =
   134                             throw new RuntimeException("Windows locale name provider did not return expected localized language name for \"en\". Returned name was \"" + result + "\"");
   149                             lnp.getDisplayLanguage(Locale.US.getLanguage(),
       
   150                                                    Locale.ENGLISH);
       
   151                         System.out.printf("  Display language name for" +
       
   152                             " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
       
   153                             hostResult, result);
       
   154                         if (result == null ||
       
   155                             hostResult != null &&
       
   156                             !result.equals(hostResult)) {
       
   157                             throw new RuntimeException("Display language name" +
       
   158                                 " mismatch for \"en\". Returned name was" +
       
   159                                 " \"" + result + "\", result(HOST): \"" +
       
   160                                 hostResult + "\"");
   135                         }
   161                         }
   136                         result = Locale.US.getDisplayCountry(Locale.ENGLISH);
   162                         if (ver >= 6.1) {
   137                         if (ver >= 6.1 && !"United States".equals(result)) {
   163                             result = Locale.US.getDisplayCountry(Locale.ENGLISH);
   138                             throw new RuntimeException("Windows locale name provider did not return expected localized country name for \"US\". Returned name was \"" + result + "\"");
   164                             hostResult = lnp.getDisplayCountry(
       
   165                                 Locale.US.getCountry(), Locale.ENGLISH);
       
   166                             System.out.printf("  Display country name for" +
       
   167                                 " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
       
   168                                 hostResult, result);
       
   169                             if (result == null ||
       
   170                                 hostResult != null &&
       
   171                                 !result.equals(hostResult)) {
       
   172                                 throw new RuntimeException("Display country name" +
       
   173                                     " mismatch for \"US\". Returned name was" +
       
   174                                     " \"" + result + "\", result(HOST): \"" +
       
   175                                     hostResult + "\"");
       
   176                             }
   139                         }
   177                         }
   140                     } else {
   178                     } else {
   141                         throw new RuntimeException("Windows Host LocaleProviderAdapter was not selected for English locale.");
   179                         throw new RuntimeException("Windows Host" +
       
   180                             " LocaleProviderAdapter was not selected for" +
       
   181                             " English locale.");
   142                     }
   182                     }
   143                 }
   183                 }
   144             } catch (ParseException pe) {
   184             } catch (ParseException pe) {
   145                 throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
   185                 throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
   146             }
   186             }