Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/DateFormat/Bug6683975.java
41152 views
1
/*
2
* Copyright (c) 2008, 2016, 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
* @modules jdk.localedata
29
* @run main/othervm -Djava.locale.providers=JRE,SPI Bug6683975
30
*/
31
import java.text.*;
32
import java.util.*;
33
34
public class Bug6683975 {
35
36
private static boolean err = false;
37
38
private static Locale th = new Locale("th", "");
39
private static Locale th_TH = new Locale("th", "TH");
40
private static String expected_th[] = {
41
"\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
42
"30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2008, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG
43
"30 \u0e01.\u0e22. 2008, 8:00:00", // 2: MEDIUM
44
"30/9/2008, 8:00 \u0e19.", // 3: SHORT
45
};
46
private static String expected_th_TH[] = {
47
"\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
48
"30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2551, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG
49
"30 \u0e01.\u0e22. 2551, 8:00:00", // 2: MEDIUM
50
"30/9/2551, 8:00 \u0e19." // 3: SHORT
51
};
52
private static String stylePattern[] = {
53
"FULL", "LONG", "MEDIUM", "SHORT"
54
};
55
56
private static void test(int style) {
57
DateFormat df_th = DateFormat.getDateTimeInstance(style, style, th);
58
DateFormat df_th_TH = DateFormat.getDateTimeInstance(style, style, th_TH);
59
60
String str_th = ((SimpleDateFormat)df_th).toPattern();
61
String str_th_TH = ((SimpleDateFormat)df_th_TH).toPattern();
62
if (!str_th.equals(str_th_TH)) {
63
err = true;
64
System.err.println("Error: Pattern for th locale should be the same as pattern for th_TH locale. (" + stylePattern[style] + ")");
65
System.err.println("\tth: " + str_th);
66
System.err.println("\tth_TH: " + str_th_TH);
67
}
68
69
@SuppressWarnings("deprecation")
70
Date date = new Date(2008-1900, Calendar.SEPTEMBER, 30, 8, 0, 0);
71
str_th = df_th.format(date);
72
if (!expected_th[style].equals(str_th)) {
73
err = true;
74
System.err.println("Error: Formatted date in th locale is incorrect in " + stylePattern[style] + " pattern.");
75
System.err.println("\tExpected: " + expected_th[style]);
76
System.err.println("\tGot: " + str_th);
77
}
78
79
str_th_TH = df_th_TH.format(date);
80
if (!expected_th_TH[style].equals(str_th_TH)) {
81
err = true;
82
System.err.println("Error: Formatted date in th_TH locale is incorrect in " + stylePattern[style] + " pattern.");
83
System.err.println("\tExpected: " + expected_th_TH[style]);
84
System.err.println("\tGot: " + str_th_TH);
85
}
86
}
87
88
public static void main(String[] args) {
89
TimeZone timezone = TimeZone.getDefault();
90
Locale locale = Locale.getDefault();
91
92
TimeZone.setDefault(TimeZone.getTimeZone("US/Pacific"));
93
Locale.setDefault(Locale.US);
94
95
try {
96
test(DateFormat.FULL);
97
test(DateFormat.LONG);
98
test(DateFormat.MEDIUM);
99
test(DateFormat.SHORT);
100
}
101
catch (Exception e) {
102
err = true;
103
System.err.println("Unexpected exception was thrown: " + e);
104
}
105
finally {
106
TimeZone.setDefault(timezone);
107
Locale.setDefault(locale);
108
109
if (err) {
110
throw new RuntimeException("Failed.");
111
} else {
112
System.out.println("Passed.");
113
}
114
}
115
}
116
117
}
118
119