Path: blob/master/test/jdk/java/text/Format/DateFormat/Bug6683975.java
41152 views
/*1* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 6683975 800857726* @summary Make sure that date is formatted correctlyin th locale.27* @modules jdk.localedata28* @run main/othervm -Djava.locale.providers=JRE,SPI Bug668397529*/30import java.text.*;31import java.util.*;3233public class Bug6683975 {3435private static boolean err = false;3637private static Locale th = new Locale("th", "");38private static Locale th_TH = new Locale("th", "TH");39private static String expected_th[] = {40"\u0e27\u0e31\u0e19\u0e2d\u0e31\u0e07\u0e04\u0e32\u0e23\u0e17\u0e35\u0e48 30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 \u0e04.\u0e28. 2008, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35 00 \u0e27\u0e34\u0e19\u0e32\u0e17\u0e35", // 0: FULL41"30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2008, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG42"30 \u0e01.\u0e22. 2008, 8:00:00", // 2: MEDIUM43"30/9/2008, 8:00 \u0e19.", // 3: SHORT44};45private static String expected_th_TH[] = {46"\u0e27\u0e31\u0e19\u0e2d\u0e31\u0e07\u0e04\u0e32\u0e23\u0e17\u0e35\u0e48 30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 \u0e1e.\u0e28. 2551, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35 00 \u0e27\u0e34\u0e19\u0e32\u0e17\u0e35", // 0: FULL47"30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2551, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG48"30 \u0e01.\u0e22. 2551, 8:00:00", // 2: MEDIUM49"30/9/2551, 8:00 \u0e19." // 3: SHORT50};51private static String stylePattern[] = {52"FULL", "LONG", "MEDIUM", "SHORT"53};5455private static void test(int style) {56DateFormat df_th = DateFormat.getDateTimeInstance(style, style, th);57DateFormat df_th_TH = DateFormat.getDateTimeInstance(style, style, th_TH);5859String str_th = ((SimpleDateFormat)df_th).toPattern();60String str_th_TH = ((SimpleDateFormat)df_th_TH).toPattern();61if (!str_th.equals(str_th_TH)) {62err = true;63System.err.println("Error: Pattern for th locale should be the same as pattern for th_TH locale. (" + stylePattern[style] + ")");64System.err.println("\tth: " + str_th);65System.err.println("\tth_TH: " + str_th_TH);66}6768@SuppressWarnings("deprecation")69Date date = new Date(2008-1900, Calendar.SEPTEMBER, 30, 8, 0, 0);70str_th = df_th.format(date);71if (!expected_th[style].equals(str_th)) {72err = true;73System.err.println("Error: Formatted date in th locale is incorrect in " + stylePattern[style] + " pattern.");74System.err.println("\tExpected: " + expected_th[style]);75System.err.println("\tGot: " + str_th);76}7778str_th_TH = df_th_TH.format(date);79if (!expected_th_TH[style].equals(str_th_TH)) {80err = true;81System.err.println("Error: Formatted date in th_TH locale is incorrect in " + stylePattern[style] + " pattern.");82System.err.println("\tExpected: " + expected_th_TH[style]);83System.err.println("\tGot: " + str_th_TH);84}85}8687public static void main(String[] args) {88TimeZone timezone = TimeZone.getDefault();89Locale locale = Locale.getDefault();9091TimeZone.setDefault(TimeZone.getTimeZone("US/Pacific"));92Locale.setDefault(Locale.US);9394try {95test(DateFormat.FULL);96test(DateFormat.LONG);97test(DateFormat.MEDIUM);98test(DateFormat.SHORT);99}100catch (Exception e) {101err = true;102System.err.println("Unexpected exception was thrown: " + e);103}104finally {105TimeZone.setDefault(timezone);106Locale.setDefault(locale);107108if (err) {109throw new RuntimeException("Failed.");110} else {111System.out.println("Passed.");112}113}114}115116}117118119