0N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A/**
0N/A * @test
0N/A * @bug 4474409
0N/A * @author John O'Conner
0N/A *
0N/A */
0N/A
0N/Aimport java.util.*;
0N/Aimport java.text.*;
0N/A
0N/Apublic class ThaiGov {
0N/A
0N/A char[] hex = {'0', '1', '2', '3',
0N/A '4', '5', '6', '7',
0N/A '8', '9', 'A', 'B',
0N/A 'C', 'D', 'E', 'F'};
0N/A
0N/A ThaiGov() {
0N/A System.out.println("ThaiGov locale test...");
0N/A
0N/A }
0N/A
0N/A String toHex(String str) {
0N/A StringBuffer buff = new StringBuffer();
0N/A int y=0;
0N/A for(int x=0; x < str.length(); ++x) {
0N/A buff.append("\\u");
0N/A buff.append(toHex(str.charAt(x)));
0N/A }
0N/A return buff.toString();
0N/A }
0N/A
0N/A String toHex(char ch) {
0N/A StringBuffer buff = new StringBuffer();
0N/A buff.append(hex[ch>>12]);
0N/A buff.append(hex[(ch>>8) & 0x0F]);
0N/A buff.append(hex[(ch>>4) & 0x0F]);
0N/A buff.append(hex[ch & 0x0F]);
0N/A return buff.toString();
0N/A }
0N/A
0N/A
0N/A void numberTest() throws RuntimeException {
0N/A final String strExpected = "\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53\u0E54";
0N/A final double value = 12345678.234;
0N/A
0N/A Locale locTH = new Locale("th", "TH", "TH");
0N/A
0N/A // th_TH_TH test
0N/A NumberFormat nf = NumberFormat.getInstance(locTH);
0N/A String str = nf.format(value);
0N/A
0N/A if (!strExpected.equals(str)) {
0N/A throw new RuntimeException();
0N/A }
0N/A
0N/A }
0N/A
0N/A void currencyTest() throws RuntimeException {
0N/A final String strExpected = "\u0E3F\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53";
0N/A final double value = 12345678.234;
0N/A
0N/A Locale locTH = new Locale("th", "TH", "TH");
0N/A
0N/A // th_TH_TH test
0N/A NumberFormat nf = NumberFormat.getCurrencyInstance(locTH);
0N/A String str = nf.format(value);
0N/A
0N/A if (!strExpected.equals(str)) {
0N/A throw new RuntimeException();
0N/A }
0N/A
0N/A }
0N/A
0N/A void dateTest() throws RuntimeException {
0N/A Locale locTH = new Locale("th", "TH", "TH");
0N/A TimeZone tz = TimeZone.getTimeZone("PST");
0N/A
0N/A Calendar calGregorian = Calendar.getInstance(tz, Locale.US);
0N/A calGregorian.clear();
0N/A calGregorian.set(2002, 4, 1, 8, 30);
0N/A final Date date = calGregorian.getTime();
0N/A Calendar cal = Calendar.getInstance(tz, locTH);
0N/A cal.clear();
0N/A cal.setTime(date);
0N/A
0N/A
0N/A 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";
0N/A Date value = cal.getTime();
0N/A
0N/A // th_TH_TH test
0N/A DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locTH);
0N/A df.setTimeZone(tz);
0N/A String str = df.format(value);
0N/A
0N/A if (!strExpected.equals(str)) {
0N/A throw new RuntimeException();
0N/A }
0N/A
0N/A }
0N/A
0N/A public static void main(String[] args) {
0N/A
0N/A ThaiGov app = new ThaiGov();
0N/A System.out.print("Running numberTest...");
0N/A app.numberTest();
0N/A System.out.print("Finished\n");
0N/A System.out.print("Running currencyTest...");
0N/A app.currencyTest();
0N/A System.out.print("Finished\n");
0N/A System.out.print("Running dateTest...");
0N/A app.dateTest();
0N/A System.out.print("Finished\n");
0N/A
0N/A System.out.println("PASSED");
0N/A }
0N/A
0N/A
0N/A}