2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
22 |
*/
|
|
23 |
/**
|
|
24 |
* @test
|
|
25 |
* @bug 4474409
|
|
26 |
* @author John O'Conner
|
|
27 |
*
|
|
28 |
*/
|
|
29 |
|
|
30 |
import java.util.*;
|
|
31 |
import java.text.*;
|
|
32 |
|
|
33 |
public class ThaiGov {
|
|
34 |
|
|
35 |
char[] hex = {'0', '1', '2', '3',
|
|
36 |
'4', '5', '6', '7',
|
|
37 |
'8', '9', 'A', 'B',
|
|
38 |
'C', 'D', 'E', 'F'};
|
|
39 |
|
|
40 |
ThaiGov() {
|
|
41 |
System.out.println("ThaiGov locale test...");
|
|
42 |
|
|
43 |
}
|
|
44 |
|
|
45 |
String toHex(String str) {
|
|
46 |
StringBuffer buff = new StringBuffer();
|
|
47 |
int y=0;
|
|
48 |
for(int x=0; x < str.length(); ++x) {
|
|
49 |
buff.append("\\u");
|
|
50 |
buff.append(toHex(str.charAt(x)));
|
|
51 |
}
|
|
52 |
return buff.toString();
|
|
53 |
}
|
|
54 |
|
|
55 |
String toHex(char ch) {
|
|
56 |
StringBuffer buff = new StringBuffer();
|
|
57 |
buff.append(hex[ch>>12]);
|
|
58 |
buff.append(hex[(ch>>8) & 0x0F]);
|
|
59 |
buff.append(hex[(ch>>4) & 0x0F]);
|
|
60 |
buff.append(hex[ch & 0x0F]);
|
|
61 |
return buff.toString();
|
|
62 |
}
|
|
63 |
|
|
64 |
|
|
65 |
void numberTest() throws RuntimeException {
|
|
66 |
final String strExpected = "\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53\u0E54";
|
|
67 |
final double value = 12345678.234;
|
|
68 |
|
|
69 |
Locale locTH = new Locale("th", "TH", "TH");
|
|
70 |
|
|
71 |
// th_TH_TH test
|
|
72 |
NumberFormat nf = NumberFormat.getInstance(locTH);
|
|
73 |
String str = nf.format(value);
|
|
74 |
|
|
75 |
if (!strExpected.equals(str)) {
|
|
76 |
throw new RuntimeException();
|
|
77 |
}
|
|
78 |
|
|
79 |
}
|
|
80 |
|
|
81 |
void currencyTest() throws RuntimeException {
|
|
82 |
final String strExpected = "\u0E3F\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53";
|
|
83 |
final double value = 12345678.234;
|
|
84 |
|
|
85 |
Locale locTH = new Locale("th", "TH", "TH");
|
|
86 |
|
|
87 |
// th_TH_TH test
|
|
88 |
NumberFormat nf = NumberFormat.getCurrencyInstance(locTH);
|
|
89 |
String str = nf.format(value);
|
|
90 |
|
|
91 |
if (!strExpected.equals(str)) {
|
|
92 |
throw new RuntimeException();
|
|
93 |
}
|
|
94 |
|
|
95 |
}
|
|
96 |
|
|
97 |
void dateTest() throws RuntimeException {
|
|
98 |
Locale locTH = new Locale("th", "TH", "TH");
|
|
99 |
TimeZone tz = TimeZone.getTimeZone("PST");
|
|
100 |
|
|
101 |
Calendar calGregorian = Calendar.getInstance(tz, Locale.US);
|
|
102 |
calGregorian.clear();
|
|
103 |
calGregorian.set(2002, 4, 1, 8, 30);
|
|
104 |
final Date date = calGregorian.getTime();
|
|
105 |
Calendar cal = Calendar.getInstance(tz, locTH);
|
|
106 |
cal.clear();
|
|
107 |
cal.setTime(date);
|
|
108 |
|
|
109 |
|
|
110 |
final String strExpected = "\u0E27\u0E31\u0E19\u0E1E\u0E38\u0E18\u0E17\u0E35\u0E48\u0020\u0E51\u0020\u0E1E\u0E24\u0E29\u0E20\u0E32\u0E04\u0E21\u0020\u0E1E\u002E\u0E28\u002E\u0020\u0E52\u0E55\u0E54\u0E55\u002C\u0020\u0E58\u0020\u0E19\u0E32\u0E2C\u0E34\u0E01\u0E32\u0020\u0E53\u0E50\u0020\u0E19\u0E32\u0E17\u0E35\u0020\u0E50\u0E50\u0020\u0E27\u0E34\u0E19\u0E32\u0E17\u0E35";
|
|
111 |
Date value = cal.getTime();
|
|
112 |
|
|
113 |
// th_TH_TH test
|
|
114 |
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locTH);
|
|
115 |
df.setTimeZone(tz);
|
|
116 |
String str = df.format(value);
|
|
117 |
|
|
118 |
if (!strExpected.equals(str)) {
|
|
119 |
throw new RuntimeException();
|
|
120 |
}
|
|
121 |
|
|
122 |
}
|
|
123 |
|
|
124 |
public static void main(String[] args) {
|
|
125 |
|
|
126 |
ThaiGov app = new ThaiGov();
|
|
127 |
System.out.print("Running numberTest...");
|
|
128 |
app.numberTest();
|
|
129 |
System.out.print("Finished\n");
|
|
130 |
System.out.print("Running currencyTest...");
|
|
131 |
app.currencyTest();
|
|
132 |
System.out.print("Finished\n");
|
|
133 |
System.out.print("Running dateTest...");
|
|
134 |
app.dateTest();
|
|
135 |
System.out.print("Finished\n");
|
|
136 |
|
|
137 |
System.out.println("PASSED");
|
|
138 |
}
|
|
139 |
|
|
140 |
|
|
141 |
}
|