Path: blob/master/test/jdk/java/util/Locale/ThaiGov.java
41149 views
/*1* Copyright (c) 2007, 2020, 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* @modules jdk.localedata27* @run main/othervm -Djava.locale.providers=COMPAT ThaiGov28*/2930import java.util.*;31import java.text.*;3233public class ThaiGov {3435ThaiGov() {36System.out.println("ThaiGov locale test...");3738}3940void numberTest() throws RuntimeException {41final String strExpected = "\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53\u0E54";42final double value = 12345678.234;4344Locale locTH = new Locale("th", "TH", "TH");4546// th_TH_TH test47NumberFormat nf = NumberFormat.getInstance(locTH);48String str = nf.format(value);4950if (!strExpected.equals(str)) {51throw new RuntimeException();52}5354}5556void currencyTest() throws RuntimeException {57final String strExpected = "\u0E3F\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53";58final double value = 12345678.234;5960Locale locTH = new Locale("th", "TH", "TH");6162// th_TH_TH test63NumberFormat nf = NumberFormat.getCurrencyInstance(locTH);64String str = nf.format(value);6566if (!strExpected.equals(str)) {67throw new RuntimeException();68}6970}7172void dateTest() throws RuntimeException {73Locale locTH = new Locale("th", "TH", "TH");74TimeZone tz = TimeZone.getTimeZone("PST");7576Calendar calGregorian = Calendar.getInstance(tz, Locale.US);77calGregorian.clear();78calGregorian.set(2002, 4, 1, 8, 30);79final Date date = calGregorian.getTime();80Calendar cal = Calendar.getInstance(tz, locTH);81cal.clear();82cal.setTime(date);838485final 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";86Date value = cal.getTime();8788// th_TH_TH test89DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locTH);90df.setTimeZone(tz);91String str = df.format(value);9293if (!strExpected.equals(str)) {94throw new RuntimeException();95}9697}9899public static void main(String[] args) {100101ThaiGov app = new ThaiGov();102System.out.print("Running numberTest...");103app.numberTest();104System.out.print("Finished\n");105System.out.print("Running currencyTest...");106app.currencyTest();107System.out.print("Finished\n");108System.out.print("Running dateTest...");109app.dateTest();110System.out.print("Finished\n");111112System.out.println("PASSED");113}114115116}117118119