jdk/test/java/util/Locale/ThaiGov.java
author duke
Wed, 05 Jul 2017 22:06:37 +0200
changeset 40471 ad45133ff99e
parent 38747 469920616f3a
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4474409
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
469920616f3a 8145136: Upgrade CLDR locale data
rgoel
parents: 35768
diff changeset
    28
 * @run main/othervm -Djava.locale.providers=COMPAT ThaiGov
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
public class ThaiGov {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    char[] hex = {'0', '1', '2', '3',
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
                  '4', '5', '6', '7',
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
                  '8', '9', 'A', 'B',
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
                  'C', 'D', 'E', 'F'};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    ThaiGov() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        System.out.println("ThaiGov locale test...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    String toHex(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        StringBuffer buff = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        int y=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        for(int x=0; x < str.length(); ++x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            buff.append("\\u");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            buff.append(toHex(str.charAt(x)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        return buff.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    String toHex(char ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        StringBuffer buff = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        buff.append(hex[ch>>12]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        buff.append(hex[(ch>>8) & 0x0F]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        buff.append(hex[(ch>>4) & 0x0F]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        buff.append(hex[ch & 0x0F]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        return buff.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    void numberTest() throws RuntimeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        final String strExpected = "\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53\u0E54";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        final double value =  12345678.234;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        Locale locTH = new Locale("th", "TH", "TH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        // th_TH_TH test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        NumberFormat nf = NumberFormat.getInstance(locTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        String str = nf.format(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (!strExpected.equals(str)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            throw new RuntimeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    void currencyTest() throws RuntimeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        final String strExpected = "\u0E3F\u0E51\u0E52\u002C\u0E53\u0E54\u0E55\u002C\u0E56\u0E57\u0E58\u002E\u0E52\u0E53";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        final double value =  12345678.234;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        Locale locTH = new Locale("th", "TH", "TH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // th_TH_TH test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        NumberFormat nf = NumberFormat.getCurrencyInstance(locTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        String str = nf.format(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (!strExpected.equals(str)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            throw new RuntimeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    void dateTest() throws RuntimeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        Locale locTH = new Locale("th", "TH", "TH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        TimeZone tz = TimeZone.getTimeZone("PST");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        Calendar calGregorian = Calendar.getInstance(tz, Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        calGregorian.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        calGregorian.set(2002, 4, 1, 8, 30);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        final Date date = calGregorian.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        Calendar cal = Calendar.getInstance(tz, locTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        cal.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        cal.setTime(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        Date value =  cal.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // th_TH_TH test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        df.setTimeZone(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        String str = df.format(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (!strExpected.equals(str)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new RuntimeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        ThaiGov app = new ThaiGov();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        System.out.print("Running numberTest...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        app.numberTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        System.out.print("Finished\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        System.out.print("Running currencyTest...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        app.currencyTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        System.out.print("Finished\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        System.out.print("Running dateTest...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        app.dateTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        System.out.print("Finished\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        System.out.println("PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}