Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Format/DateFormat/Bug6683975.java
47182 views
/*1* Copyright (c) 2008, 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 668397526* @summary Make sure that date is formatted correctlyin th locale.27*/28import java.text.*;29import java.util.*;3031public class Bug6683975 {3233private static boolean err = false;3435private static Locale th = new Locale("th", "");36private static Locale th_TH = new Locale("th", "TH");37private static String expected_th[] = {38"\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: FULL39"30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2008, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG40"30 \u0e01.\u0e22. 2008, 8:00:00", // 2: MEDIUM41"30/9/2008, 8:00 \u0e19.", // 3: SHORT42};43private static String expected_th_TH[] = {44"\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: FULL45"30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2551, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG46"30 \u0e01.\u0e22. 2551, 8:00:00", // 2: MEDIUM47"30/9/2551, 8:00 \u0e19." // 3: SHORT48};49private static String stylePattern[] = {50"FULL", "LONG", "MEDIUM", "SHORT"51};5253private static void test(int style) {54DateFormat df_th = DateFormat.getDateTimeInstance(style, style, th);55DateFormat df_th_TH = DateFormat.getDateTimeInstance(style, style, th_TH);5657String str_th = ((SimpleDateFormat)df_th).toPattern();58String str_th_TH = ((SimpleDateFormat)df_th_TH).toPattern();59if (!str_th.equals(str_th_TH)) {60err = true;61System.err.println("Error: Pattern for th locale should be the same as pattern for th_TH locale. (" + stylePattern[style] + ")");62System.err.println("\tth: " + str_th);63System.err.println("\tth_TH: " + str_th_TH);64}6566Date date = new Date(2008-1900, Calendar.SEPTEMBER, 30, 8, 0, 0);67str_th = df_th.format(date);68if (!expected_th[style].equals(str_th)) {69err = true;70System.err.println("Error: Formatted date in th locale is incorrect in " + stylePattern[style] + " pattern.");71System.err.println("\tExpected: " + expected_th[style]);72System.err.println("\tGot: " + str_th);73}7475str_th_TH = df_th_TH.format(date);76if (!expected_th_TH[style].equals(str_th_TH)) {77err = true;78System.err.println("Error: Formatted date in th_TH locale is incorrect in " + stylePattern[style] + " pattern.");79System.err.println("\tExpected: " + expected_th_TH[style]);80System.err.println("\tGot: " + str_th_TH);81}82}8384public static void main(String[] args) {85TimeZone timezone = TimeZone.getDefault();86Locale locale = Locale.getDefault();8788TimeZone.setDefault(TimeZone.getTimeZone("US/Pacific"));89Locale.setDefault(Locale.US);9091try {92test(DateFormat.FULL);93test(DateFormat.LONG);94test(DateFormat.MEDIUM);95test(DateFormat.SHORT);96}97catch (Exception e) {98err = true;99System.err.println("Unexpected exception was thrown: " + e);100}101finally {102TimeZone.setDefault(timezone);103Locale.setDefault(locale);104105if (err) {106throw new RuntimeException("Failed.");107} else {108System.out.println("Passed.");109}110}111}112113}114115116