test/java/util/Locale/LocaleProviders.java

Print this page
rev 5994 : imported patch 8001205


  34             case "getPlatformLocale":
  35                 if (args[1].equals("format")) {
  36                     getPlatformLocale(Locale.Category.FORMAT);
  37                 } else {
  38                     getPlatformLocale(Locale.Category.DISPLAY);
  39                 }
  40                 break;
  41 
  42             case "adapterTest":
  43                 adapterTest(args[1], args[2], (args.length >= 4 ? args[3] : ""));
  44                 break;
  45 
  46             case "bug7198834Test":
  47                 bug7198834Test();
  48                 break;
  49 
  50             case "tzNameTest":
  51                 tzNameTest(args[1]);
  52                 break;
  53 




  54             default:
  55                 throw new RuntimeException("Test method '"+methodName+"' not found.");
  56         }
  57     }
  58 
  59     static void getPlatformLocale(Locale.Category cat) {
  60         Locale defloc = Locale.getDefault(cat);
  61         System.out.printf("%s,%s\n", defloc.getLanguage(), defloc.getCountry());
  62     }
  63 
  64     static void adapterTest(String expected, String lang, String ctry) {
  65         Locale testLocale = new Locale(lang, ctry);
  66         String preference = System.getProperty("java.locale.providers", "");
  67         LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
  68         LocaleProviderAdapter.Type type = lda.getAdapterType();
  69         System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
  70         if (!type.toString().equals(expected)) {
  71             throw new RuntimeException("Returned locale data adapter is not correct.");
  72         }
  73     }


  76         LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
  77         LocaleProviderAdapter.Type type = lda.getAdapterType();
  78         if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
  79             DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
  80             String date = df.format(new Date());
  81             if (date.charAt(date.length()-1) == ' ') {
  82                 throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
  83             }
  84         } else {
  85             System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
  86         }
  87     }
  88 
  89     static void tzNameTest(String id) {
  90         TimeZone tz = TimeZone.getTimeZone(id);
  91         String tzName = tz.getDisplayName(false, TimeZone.SHORT, Locale.US);
  92         if (tzName.startsWith("GMT")) {
  93             throw new RuntimeException("JRE's localized time zone name for "+id+" could not be retrieved. Returned name was: "+tzName);
  94         }
  95     }









  96 }


  34             case "getPlatformLocale":
  35                 if (args[1].equals("format")) {
  36                     getPlatformLocale(Locale.Category.FORMAT);
  37                 } else {
  38                     getPlatformLocale(Locale.Category.DISPLAY);
  39                 }
  40                 break;
  41 
  42             case "adapterTest":
  43                 adapterTest(args[1], args[2], (args.length >= 4 ? args[3] : ""));
  44                 break;
  45 
  46             case "bug7198834Test":
  47                 bug7198834Test();
  48                 break;
  49 
  50             case "tzNameTest":
  51                 tzNameTest(args[1]);
  52                 break;
  53 
  54             case "bug8001205Test":
  55                 bug8001205Test();
  56                 break;
  57 
  58             default:
  59                 throw new RuntimeException("Test method '"+methodName+"' not found.");
  60         }
  61     }
  62 
  63     static void getPlatformLocale(Locale.Category cat) {
  64         Locale defloc = Locale.getDefault(cat);
  65         System.out.printf("%s,%s\n", defloc.getLanguage(), defloc.getCountry());
  66     }
  67 
  68     static void adapterTest(String expected, String lang, String ctry) {
  69         Locale testLocale = new Locale(lang, ctry);
  70         String preference = System.getProperty("java.locale.providers", "");
  71         LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
  72         LocaleProviderAdapter.Type type = lda.getAdapterType();
  73         System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
  74         if (!type.toString().equals(expected)) {
  75             throw new RuntimeException("Returned locale data adapter is not correct.");
  76         }
  77     }


  80         LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
  81         LocaleProviderAdapter.Type type = lda.getAdapterType();
  82         if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
  83             DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
  84             String date = df.format(new Date());
  85             if (date.charAt(date.length()-1) == ' ') {
  86                 throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
  87             }
  88         } else {
  89             System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
  90         }
  91     }
  92 
  93     static void tzNameTest(String id) {
  94         TimeZone tz = TimeZone.getTimeZone(id);
  95         String tzName = tz.getDisplayName(false, TimeZone.SHORT, Locale.US);
  96         if (tzName.startsWith("GMT")) {
  97             throw new RuntimeException("JRE's localized time zone name for "+id+" could not be retrieved. Returned name was: "+tzName);
  98         }
  99     }
 100 
 101     static void bug8001205Test() {
 102         Calendar cal = Calendar.getInstance();
 103         cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
 104         String sunday = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT_STANDALONE, Locale.CHINA);
 105         if (sunday == null) {
 106             throw new RuntimeException("Calendar.getDisplayName(DAY_OF_WEEK/SHORT_STANDALONE) returned null.");
 107         }
 108     }
 109 }