author | duke |
Wed, 05 Jul 2017 22:06:37 +0200 | |
changeset 40471 | ad45133ff99e |
parent 38747 | 469920616f3a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
35768
7066da300a08
8149391: Fix module dependences in java/util tests
shurailine
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2007, 2016, 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 |
|
35768
7066da300a08
8149391: Fix module dependences in java/util tests
shurailine
parents:
5506
diff
changeset
|
27 |
* @modules jdk.localedata |
38747 | 28 |
* @run main/othervm -Djava.locale.providers=COMPAT ThaiGov |
2 | 29 |
*/ |
30 |
||
31 |
import java.util.*; |
|
32 |
import java.text.*; |
|
33 |
||
34 |
public class ThaiGov { |
|
35 |
||
36 |
char[] hex = {'0', '1', '2', '3', |
|
37 |
'4', '5', '6', '7', |
|
38 |
'8', '9', 'A', 'B', |
|
39 |
'C', 'D', 'E', 'F'}; |
|
40 |
||
41 |
ThaiGov() { |
|
42 |
System.out.println("ThaiGov locale test..."); |
|
43 |
||
44 |
} |
|
45 |
||
46 |
String toHex(String str) { |
|
47 |
StringBuffer buff = new StringBuffer(); |
|
48 |
int y=0; |
|
49 |
for(int x=0; x < str.length(); ++x) { |
|
50 |
buff.append("\\u"); |
|
51 |
buff.append(toHex(str.charAt(x))); |
|
52 |
} |
|
53 |
return buff.toString(); |
|
54 |
} |
|
55 |
||
56 |
String toHex(char ch) { |
|
57 |
StringBuffer buff = new StringBuffer(); |
|
58 |
buff.append(hex[ch>>12]); |
|
59 |
buff.append(hex[(ch>>8) & 0x0F]); |
|
60 |
buff.append(hex[(ch>>4) & 0x0F]); |
|
61 |
buff.append(hex[ch & 0x0F]); |
|
62 |
return buff.toString(); |
|
63 |
} |
|
64 |
||
65 |
||
66 |
void numberTest() throws RuntimeException { |
|
67 |
final String strExpected = "\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53\u0E54"; |
|
68 |
final double value = 12345678.234; |
|
69 |
||
70 |
Locale locTH = new Locale("th", "TH", "TH"); |
|
71 |
||
72 |
// th_TH_TH test |
|
73 |
NumberFormat nf = NumberFormat.getInstance(locTH); |
|
74 |
String str = nf.format(value); |
|
75 |
||
76 |
if (!strExpected.equals(str)) { |
|
77 |
throw new RuntimeException(); |
|
78 |
} |
|
79 |
||
80 |
} |
|
81 |
||
82 |
void currencyTest() throws RuntimeException { |
|
83 |
final String strExpected = "\u0E3F\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53"; |
|
84 |
final double value = 12345678.234; |
|
85 |
||
86 |
Locale locTH = new Locale("th", "TH", "TH"); |
|
87 |
||
88 |
// th_TH_TH test |
|
89 |
NumberFormat nf = NumberFormat.getCurrencyInstance(locTH); |
|
90 |
String str = nf.format(value); |
|
91 |
||
92 |
if (!strExpected.equals(str)) { |
|
93 |
throw new RuntimeException(); |
|
94 |
} |
|
95 |
||
96 |
} |
|
97 |
||
98 |
void dateTest() throws RuntimeException { |
|
99 |
Locale locTH = new Locale("th", "TH", "TH"); |
|
100 |
TimeZone tz = TimeZone.getTimeZone("PST"); |
|
101 |
||
102 |
Calendar calGregorian = Calendar.getInstance(tz, Locale.US); |
|
103 |
calGregorian.clear(); |
|
104 |
calGregorian.set(2002, 4, 1, 8, 30); |
|
105 |
final Date date = calGregorian.getTime(); |
|
106 |
Calendar cal = Calendar.getInstance(tz, locTH); |
|
107 |
cal.clear(); |
|
108 |
cal.setTime(date); |
|
109 |
||
110 |
||
111 |
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"; |
|
112 |
Date value = cal.getTime(); |
|
113 |
||
114 |
// th_TH_TH test |
|
115 |
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locTH); |
|
116 |
df.setTimeZone(tz); |
|
117 |
String str = df.format(value); |
|
118 |
||
119 |
if (!strExpected.equals(str)) { |
|
120 |
throw new RuntimeException(); |
|
121 |
} |
|
122 |
||
123 |
} |
|
124 |
||
125 |
public static void main(String[] args) { |
|
126 |
||
127 |
ThaiGov app = new ThaiGov(); |
|
128 |
System.out.print("Running numberTest..."); |
|
129 |
app.numberTest(); |
|
130 |
System.out.print("Finished\n"); |
|
131 |
System.out.print("Running currencyTest..."); |
|
132 |
app.currencyTest(); |
|
133 |
System.out.print("Finished\n"); |
|
134 |
System.out.print("Running dateTest..."); |
|
135 |
app.dateTest(); |
|
136 |
System.out.print("Finished\n"); |
|
137 |
||
138 |
System.out.println("PASSED"); |
|
139 |
} |
|
140 |
||
141 |
||
142 |
} |