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