1 /* 2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 6683975 8008577 27 * @summary Make sure that date is formatted correctlyin th locale. 28 * @run main/othervm -Djava.locale.providers=JRE,SPI Bug6683975 29 */ 30 import java.text.*; 31 import java.util.*; 32 33 public class Bug6683975 { 34 35 private static boolean err = false; 36 37 private static Locale th = new Locale("th", ""); 38 private static Locale th_TH = new Locale("th", "TH"); 39 private 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: FULL 41 "30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2008, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG 42 "30 \u0e01.\u0e22. 2008, 8:00:00", // 2: MEDIUM 43 "30/9/2008, 8:00 \u0e19.", // 3: SHORT 44 }; 45 private 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: FULL 47 "30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2551, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG 48 "30 \u0e01.\u0e22. 2551, 8:00:00", // 2: MEDIUM 49 "30/9/2551, 8:00 \u0e19." // 3: SHORT 50 }; 51 private static String stylePattern[] = { 52 "FULL", "LONG", "MEDIUM", "SHORT" 53 }; 54 55 private static void test(int style) { 56 DateFormat df_th = DateFormat.getDateTimeInstance(style, style, th); 57 DateFormat df_th_TH = DateFormat.getDateTimeInstance(style, style, th_TH); 58 59 String str_th = ((SimpleDateFormat)df_th).toPattern(); 60 String str_th_TH = ((SimpleDateFormat)df_th_TH).toPattern(); 61 if (!str_th.equals(str_th_TH)) { 62 err = true; 63 System.err.println("Error: Pattern for th locale should be the same as pattern for th_TH locale. (" + stylePattern[style] + ")"); 64 System.err.println("\tth: " + str_th); 65 System.err.println("\tth_TH: " + str_th_TH); 66 } 67 68 Date date = new Date(2008-1900, Calendar.SEPTEMBER, 30, 8, 0, 0); 69 str_th = df_th.format(date); 70 if (!expected_th[style].equals(str_th)) { 71 err = true; 72 System.err.println("Error: Formatted date in th locale is incorrect in " + stylePattern[style] + " pattern."); 73 System.err.println("\tExpected: " + expected_th[style]); 74 System.err.println("\tGot: " + str_th); 75 } 76 77 str_th_TH = df_th_TH.format(date); 78 if (!expected_th_TH[style].equals(str_th_TH)) { 79 err = true; 80 System.err.println("Error: Formatted date in th_TH locale is incorrect in " + stylePattern[style] + " pattern."); 81 System.err.println("\tExpected: " + expected_th_TH[style]); 82 System.err.println("\tGot: " + str_th_TH); 83 } 84 } 85 86 public static void main(String[] args) { 87 TimeZone timezone = TimeZone.getDefault(); 88 Locale locale = Locale.getDefault(); 89 90 TimeZone.setDefault(TimeZone.getTimeZone("US/Pacific")); 91 Locale.setDefault(Locale.US); 92 93 try { 94 test(DateFormat.FULL); 95 test(DateFormat.LONG); 96 test(DateFormat.MEDIUM); 97 test(DateFormat.SHORT); 98 } 99 catch (Exception e) { 100 err = true; 101 System.err.println("Unexpected exception was thrown: " + e); 102 } 103 finally { 104 TimeZone.setDefault(timezone); 105 Locale.setDefault(locale); 106 107 if (err) { 108 throw new RuntimeException("Failed."); 109 } else { 110 System.out.println("Passed."); 111 } 112 } 113 } 114 115 }