Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Locale/ThaiGov.java
38813 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/**23* @test24* @bug 447440925* @author John O'Conner26*27*/2829import java.util.*;30import java.text.*;3132public class ThaiGov {3334char[] hex = {'0', '1', '2', '3',35'4', '5', '6', '7',36'8', '9', 'A', 'B',37'C', 'D', 'E', 'F'};3839ThaiGov() {40System.out.println("ThaiGov locale test...");4142}4344String toHex(String str) {45StringBuffer buff = new StringBuffer();46int y=0;47for(int x=0; x < str.length(); ++x) {48buff.append("\\u");49buff.append(toHex(str.charAt(x)));50}51return buff.toString();52}5354String toHex(char ch) {55StringBuffer buff = new StringBuffer();56buff.append(hex[ch>>12]);57buff.append(hex[(ch>>8) & 0x0F]);58buff.append(hex[(ch>>4) & 0x0F]);59buff.append(hex[ch & 0x0F]);60return buff.toString();61}626364void numberTest() throws RuntimeException {65final String strExpected = "\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53\u0E54";66final double value = 12345678.234;6768Locale locTH = new Locale("th", "TH", "TH");6970// th_TH_TH test71NumberFormat nf = NumberFormat.getInstance(locTH);72String str = nf.format(value);7374if (!strExpected.equals(str)) {75throw new RuntimeException();76}7778}7980void currencyTest() throws RuntimeException {81final String strExpected = "\u0E3F\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53";82final double value = 12345678.234;8384Locale locTH = new Locale("th", "TH", "TH");8586// th_TH_TH test87NumberFormat nf = NumberFormat.getCurrencyInstance(locTH);88String str = nf.format(value);8990if (!strExpected.equals(str)) {91throw new RuntimeException();92}9394}9596void dateTest() throws RuntimeException {97Locale locTH = new Locale("th", "TH", "TH");98TimeZone tz = TimeZone.getTimeZone("PST");99100Calendar calGregorian = Calendar.getInstance(tz, Locale.US);101calGregorian.clear();102calGregorian.set(2002, 4, 1, 8, 30);103final Date date = calGregorian.getTime();104Calendar cal = Calendar.getInstance(tz, locTH);105cal.clear();106cal.setTime(date);107108109final 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";110Date value = cal.getTime();111112// th_TH_TH test113DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locTH);114df.setTimeZone(tz);115String str = df.format(value);116117if (!strExpected.equals(str)) {118throw new RuntimeException();119}120121}122123public static void main(String[] args) {124125ThaiGov app = new ThaiGov();126System.out.print("Running numberTest...");127app.numberTest();128System.out.print("Finished\n");129System.out.print("Running currencyTest...");130app.currencyTest();131System.out.print("Finished\n");132System.out.print("Running dateTest...");133app.dateTest();134System.out.print("Finished\n");135136System.out.println("PASSED");137}138139140}141142143