test/java/util/PluggableLocale/TimeZoneNameProviderTest.java

Print this page
rev 5957 : imported patch 8000245.8000273.8000615


  28 import java.util.*;
  29 import sun.util.locale.provider.*;
  30 import sun.util.resources.*;
  31 
  32 public class TimeZoneNameProviderTest extends ProviderTest {
  33 
  34     com.bar.TimeZoneNameProviderImpl tznp = new com.bar.TimeZoneNameProviderImpl();
  35 
  36     public static void main(String[] s) {
  37         new TimeZoneNameProviderTest();
  38     }
  39 
  40     TimeZoneNameProviderTest() {
  41         test1();
  42         test2();
  43         aliasTest();
  44     }
  45 
  46     void test1() {
  47         Locale[] available = Locale.getAvailableLocales();

  48         List<Locale> providerLocales = Arrays.asList(tznp.getAvailableLocales());
  49         String[] ids = TimeZone.getAvailableIDs();
  50 
  51         for (Locale target: available) {
  52             // pure JRE implementation
  53             OpenListResourceBundle rb = LocaleProviderAdapter.forJRE().getLocaleData().getTimeZoneNames(target);
  54             boolean jreHasBundle = rb.getLocale().equals(target);
  55 
  56             for (String id: ids) {
  57                 // the time zone
  58                 TimeZone tz = TimeZone.getTimeZone(id);
  59 
  60                 // JRE string array for the id
  61                 String[] jrearray = null;
  62                 if (jreHasBundle) {
  63                     try {
  64                         jrearray = rb.getStringArray(id);
  65                     } catch (MissingResourceException mre) {}
  66                 }
  67 
  68                 for (int i = 1; i <=(tz.useDaylightTime()?4:2); i++) {
  69                     // the localized name
  70                     String name = tz.getDisplayName(i>=3, i%2, target);
  71 
  72                     // provider's name (if any)
  73                     String providersname = null;
  74                     if (providerLocales.contains(target)) {
  75                         providersname = tznp.getDisplayName(id, i>=3, i%2, target);
  76                     }
  77 
  78                     // JRE's name (if any)
  79                     String jresname = null;
  80                     if (jrearray != null) {
  81                         jresname = jrearray[i];
  82                     }
  83 
  84                     checkValidity(target, jresname, providersname, name,
  85                         jreHasBundle && rb.handleGetKeys().contains(id));
  86                 }
  87             }
  88         }
  89     }
  90 
  91     final String pattern = "z";
  92     final Locale OSAKA = new Locale("ja", "JP", "osaka");
  93     final Locale KYOTO = new Locale("ja", "JP", "kyoto");
  94 
  95     final String[] TIMEZONES = {
  96         "GMT", "America/Los_Angeles", "SystemV/PST8",
  97         "SystemV/PST8PDT", "PST8PDT",
  98     };
  99     final String[] DISPLAY_NAMES_OSAKA = {
 100         tznp.getDisplayName(TIMEZONES[0], false, TimeZone.SHORT, OSAKA),
 101         tznp.getDisplayName(TIMEZONES[1], false, TimeZone.SHORT, OSAKA),
 102         tznp.getDisplayName(TIMEZONES[2], false, TimeZone.SHORT, OSAKA),
 103         tznp.getDisplayName(TIMEZONES[3], false, TimeZone.SHORT, OSAKA),
 104         tznp.getDisplayName(TIMEZONES[4], false, TimeZone.SHORT, OSAKA)
 105     };




  28 import java.util.*;
  29 import sun.util.locale.provider.*;
  30 import sun.util.resources.*;
  31 
  32 public class TimeZoneNameProviderTest extends ProviderTest {
  33 
  34     com.bar.TimeZoneNameProviderImpl tznp = new com.bar.TimeZoneNameProviderImpl();
  35 
  36     public static void main(String[] s) {
  37         new TimeZoneNameProviderTest();
  38     }
  39 
  40     TimeZoneNameProviderTest() {
  41         test1();
  42         test2();
  43         aliasTest();
  44     }
  45 
  46     void test1() {
  47         Locale[] available = Locale.getAvailableLocales();
  48         List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getTimeZoneNameProvider().getAvailableLocales());
  49         List<Locale> providerLocales = Arrays.asList(tznp.getAvailableLocales());
  50         String[] ids = TimeZone.getAvailableIDs();
  51 
  52         for (Locale target: available) {
  53             // pure JRE implementation
  54             OpenListResourceBundle rb = LocaleProviderAdapter.forJRE().getLocaleData().getTimeZoneNames(target);
  55             boolean jreSupportsTarget = jreimplloc.contains(target);
  56 
  57             for (String id: ids) {
  58                 // the time zone
  59                 TimeZone tz = TimeZone.getTimeZone(id);
  60 
  61                 // JRE string array for the id
  62                 String[] jrearray = null;
  63                 if (jreSupportsTarget) {
  64                     try {
  65                         jrearray = rb.getStringArray(id);
  66                     } catch (MissingResourceException mre) {}
  67                 }
  68 
  69                 for (int i = 1; i <=(tz.useDaylightTime()?4:2); i++) {
  70                     // the localized name
  71                     String name = tz.getDisplayName(i>=3, i%2, target);
  72 
  73                     // provider's name (if any)
  74                     String providersname = null;
  75                     if (providerLocales.contains(target)) {
  76                         providersname = tznp.getDisplayName(id, i>=3, i%2, target);
  77                     }
  78 
  79                     // JRE's name
  80                     String jresname = null;
  81                     if (jrearray != null) {
  82                         jresname = jrearray[i];
  83                     }
  84 
  85                     checkValidity(target, jresname, providersname, name,
  86                         jreSupportsTarget && jresname != null);
  87                 }
  88             }
  89         }
  90     }
  91 
  92     final String pattern = "z";
  93     final Locale OSAKA = new Locale("ja", "JP", "osaka");
  94     final Locale KYOTO = new Locale("ja", "JP", "kyoto");
  95 
  96     final String[] TIMEZONES = {
  97         "GMT", "America/Los_Angeles", "SystemV/PST8",
  98         "SystemV/PST8PDT", "PST8PDT",
  99     };
 100     final String[] DISPLAY_NAMES_OSAKA = {
 101         tznp.getDisplayName(TIMEZONES[0], false, TimeZone.SHORT, OSAKA),
 102         tznp.getDisplayName(TIMEZONES[1], false, TimeZone.SHORT, OSAKA),
 103         tznp.getDisplayName(TIMEZONES[2], false, TimeZone.SHORT, OSAKA),
 104         tznp.getDisplayName(TIMEZONES[3], false, TimeZone.SHORT, OSAKA),
 105         tznp.getDisplayName(TIMEZONES[4], false, TimeZone.SHORT, OSAKA)
 106     };