< prev index next >

test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java

Print this page




   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  * @test
  26  * @bug 8005471 8008577 8129881 8130845 8136518 8181157
  27  * @modules jdk.localedata
  28  * @run main/othervm -Djava.locale.providers=CLDR CLDRDisplayNamesTest
  29  * @summary Make sure that localized time zone names of CLDR are used
  30  * if specified.
  31  */
  32 
  33 import java.text.*;
  34 import java.util.*;
  35 import static java.util.TimeZone.*;
  36 
  37 public class CLDRDisplayNamesTest {
  38     /*
  39      * The first element is a language tag. The rest are localized
  40      * display names of America/Los_Angeles copied from the CLDR
  41      * resources data. If data change in CLDR, test data below will
  42      * need to be changed accordingly.
  43      *
  44      * Generic names are NOT tested (until they are supported by API).
  45      */
  46     static final String[][] CLDR_DATA = {


 100             errors++;
 101         }
 102 
 103         // for 8130845
 104         SimpleDateFormat fmtROOT = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.ROOT);
 105         SimpleDateFormat fmtUS = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.US);
 106         SimpleDateFormat fmtUK = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.UK);
 107         Locale originalLocale = Locale.getDefault();
 108         try {
 109             Locale.setDefault(Locale.ROOT);
 110             fmtROOT.parse("Thu Nov 13 04:35:51 AKST 2008");
 111             fmtUS.parse("Thu Nov 13 04:35:51 AKST 2008");
 112             fmtUK.parse("Thu Nov 13 04:35:51 GMT-09:00 2008");
 113         } catch (ParseException pe) {
 114             System.err.println(pe);
 115             errors++;
 116         } finally {
 117             Locale.setDefault(originalLocale);
 118         }
 119 











 120         if (errors > 0) {
 121             throw new RuntimeException("test failed");
 122         }
 123     }
 124 }


   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  * @test
  26  * @bug 8005471 8008577 8129881 8130845 8136518 8181157 8210490
  27  * @modules jdk.localedata
  28  * @run main/othervm -Djava.locale.providers=CLDR CLDRDisplayNamesTest
  29  * @summary Make sure that localized time zone names of CLDR are used
  30  * if specified.
  31  */
  32 
  33 import java.text.*;
  34 import java.util.*;
  35 import static java.util.TimeZone.*;
  36 
  37 public class CLDRDisplayNamesTest {
  38     /*
  39      * The first element is a language tag. The rest are localized
  40      * display names of America/Los_Angeles copied from the CLDR
  41      * resources data. If data change in CLDR, test data below will
  42      * need to be changed accordingly.
  43      *
  44      * Generic names are NOT tested (until they are supported by API).
  45      */
  46     static final String[][] CLDR_DATA = {


 100             errors++;
 101         }
 102 
 103         // for 8130845
 104         SimpleDateFormat fmtROOT = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.ROOT);
 105         SimpleDateFormat fmtUS = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.US);
 106         SimpleDateFormat fmtUK = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.UK);
 107         Locale originalLocale = Locale.getDefault();
 108         try {
 109             Locale.setDefault(Locale.ROOT);
 110             fmtROOT.parse("Thu Nov 13 04:35:51 AKST 2008");
 111             fmtUS.parse("Thu Nov 13 04:35:51 AKST 2008");
 112             fmtUK.parse("Thu Nov 13 04:35:51 GMT-09:00 2008");
 113         } catch (ParseException pe) {
 114             System.err.println(pe);
 115             errors++;
 116         } finally {
 117             Locale.setDefault(originalLocale);
 118         }
 119         
 120         // for 8210490
 121         // Check that TimeZone.getDisplayName should honor passed locale parameter,
 122         // even if default locale is set to some other locale.
 123         Locale.setDefault(Locale.forLanguageTag("ar-PK"));
 124         TimeZone zi = TimeZone.getTimeZone("Etc/GMT-5");
 125         String displayName = zi.getDisplayName(false, TimeZone.SHORT, Locale.US);
 126         Locale.setDefault(originalLocale);
 127         if (!displayName.equals("GMT+05:00")) {
 128             System.err.printf("Wrong display name for timezone Etc/GMT-5 : expected GMT+05:00,  Actual " + displayName);
 129             errors++;
 130         }
 131         if (errors > 0) {
 132             throw new RuntimeException("test failed");
 133         }
 134     }
 135 }
< prev index next >