jdk/test/java/util/Locale/InternationalBAT.java
author shurailine
Mon, 08 Feb 2016 18:14:48 -0800
changeset 35768 7066da300a08
parent 31263 a81a0af34ca0
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: 31263
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
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 23010
diff changeset
    25
 * @bug 4449637 8008577
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Basic acceptance test for international J2RE. Verifies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * most important locale data and character converters exist and are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * minimally functional.
35768
7066da300a08 8149391: Fix module dependences in java/util tests
shurailine
parents: 31263
diff changeset
    29
 * @modules jdk.localedata
7066da300a08 8149391: Fix module dependences in java/util tests
shurailine
parents: 31263
diff changeset
    30
 *          jdk.charsets
31263
a81a0af34ca0 8008577: Use CLDR Locale Data by Default
naoto
parents: 23010
diff changeset
    31
 * @run main/othervm -Djava.locale.providers=JRE,SPI InternationalBAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.text.DateFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.TimeZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class InternationalBAT {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        boolean pass = true;
21830
668b2337f339 8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents: 5506
diff changeset
    45
668b2337f339 8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents: 5506
diff changeset
    46
        TimeZone tz = TimeZone.getDefault();
668b2337f339 8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents: 5506
diff changeset
    47
        try {
668b2337f339 8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents: 5506
diff changeset
    48
            pass &= testRequiredLocales();
668b2337f339 8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents: 5506
diff changeset
    49
            pass &= testRequiredEncodings();
668b2337f339 8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents: 5506
diff changeset
    50
        } finally {
668b2337f339 8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents: 5506
diff changeset
    51
            TimeZone.setDefault(tz);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        if (!pass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            System.out.println("\nSome tests failed.\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                    + "If you installed the US-only J2RE for Windows, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                    + "failures are expected and OK.\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                    + "If you installed the international J2RE, or any J2SDK, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                    + "or if this occurs on any platform other than Windows, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                    + "please file a bug report.\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                    + "Unfortunately, this test cannot determine whether you "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                    + "installed a US-only J2RE, an international J2RE, or "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                    + "a J2SDK.\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            throw new RuntimeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // We require the "fully supported locales" for java.util and java.text:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // http://webwork.eng/j2se/1.4/docs/guide/intl/locale.doc.html#util-text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static Locale[] requiredLocales = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        new Locale("ar", "SA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        new Locale("zh", "TW"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        new Locale("nl", "NL"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        new Locale("en", "AU"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        new Locale("en", "CA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        new Locale("en", "GB"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        new Locale("en", "US"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        new Locale("fr", "CA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        new Locale("fr", "FR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        new Locale("de", "DE"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        new Locale("iw", "IL"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        new Locale("hi", "IN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        new Locale("it", "IT"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        new Locale("ja", "JP"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        new Locale("ko", "KR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        new Locale("pt", "BR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        new Locale("es", "ES"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        new Locale("sv", "SE"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        new Locale("th", "TH"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // Date strings for May 10, 2001, for the required locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static String[] requiredLocaleDates = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        "10 \u0645\u0627\u064A\u0648, 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        "2001\u5E745\u670810\u65E5 \u661F\u671F\u56DB",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        "2001\u5E745\u670810\u65E5 \u661F\u671F\u56DB",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        "donderdag 10 mei 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        "Thursday, 10 May 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        "Thursday, May 10, 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        "Thursday, 10 May 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        "Thursday, May 10, 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        "jeudi 10 mai 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        "jeudi 10 mai 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        "Donnerstag, 10. Mai 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        "\u05D9\u05D5\u05DD \u05D7\u05DE\u05D9\u05E9\u05D9 10 \u05DE\u05D0\u05D9 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        "\u0917\u0941\u0930\u0941\u0935\u093E\u0930, \u0967\u0966 \u092E\u0908, \u0968\u0966\u0966\u0967",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        "gioved\u00EC 10 maggio 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        "2001\u5E745\u670810\u65E5", // ja_JP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        "2001\uB144 5\uC6D4 10\uC77C \uBAA9\uC694\uC77C",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        "Quinta-feira, 10 de Maio de 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        "jueves 10 de mayo de 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        "den 10 maj 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        "\u0E27\u0E31\u0E19\u0E1E\u0E24\u0E2B\u0E31\u0E2A\u0E1A\u0E14\u0E35\u0E17\u0E35\u0E48 10 \u0E1E\u0E24\u0E29\u0E20\u0E32\u0E04\u0E21 \u0E1E.\u0E28. 2544",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private static boolean testRequiredLocales() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        boolean pass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        Calendar calendar = Calendar.getInstance(Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        calendar.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        calendar.set(2001, 4, 10, 12, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        Date date = calendar.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Locale[] available = Locale.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        for (int i = 0; i < requiredLocales.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            Locale locale = requiredLocales[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            for (int j = 0; j < available.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                if (available[j].equals(locale)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                System.out.println("Locale not available: " + locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                DateFormat format =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        DateFormat.getDateInstance(DateFormat.FULL, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                String dateString = format.format(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                if (!dateString.equals(requiredLocaleDates[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    System.out.println("Incorrect date string for locale "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                            + locale + ". Expected: " + requiredLocaleDates[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                            + ", got: " + dateString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return pass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    // We require the encodings of the fully supported writing systems:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    // http://webwork.eng/j2se/1.4/docs/guide/intl/locale.doc.html#jfc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private static String[] requiredEncodings = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        "Cp1256",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        "MS936",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        "MS950",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        "Cp1255",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        "MS932",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        "MS949",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        "Cp1252",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        "MS874",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        "ISO8859_6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        "EUC_CN",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        "UTF8",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        "GBK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        "EUC_TW",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        "ISO8859_8",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        "EUC_JP",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        "PCK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        "EUC_KR",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        "ISO8859_1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        "ISO8859_15",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        "TIS620",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    // one sample locale each for the required encodings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    private static Locale[] sampleLocales = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        new Locale("ar", "SA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        new Locale("zh", "TW"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        new Locale("iw", "IL"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        new Locale("ja", "JP"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        new Locale("ko", "KR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        new Locale("it", "IT"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        new Locale("th", "TH"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        new Locale("ar", "SA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        new Locale("zh", "TW"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        new Locale("iw", "IL"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        new Locale("ja", "JP"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        new Locale("ja", "JP"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        new Locale("ko", "KR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        new Locale("it", "IT"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        new Locale("it", "IT"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        new Locale("th", "TH"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    // expected conversion results for the date strings of the sample locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    private static byte[][] expectedBytes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        { 0x31, 0x30, 0x20, (byte) 0xE3, (byte) 0xC7, (byte) 0xED, (byte) 0xE6, 0x2C, 0x20, 0x32, 0x30, 0x30, 0x31, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        { 0x32, 0x30, 0x30, 0x31, (byte) 0xC4, (byte) 0xEA, 0x35, (byte) 0xD4, (byte) 0xC2, 0x31, 0x30, (byte) 0xC8, (byte) 0xD5, 0x20, (byte) 0xD0, (byte) 0xC7, (byte) 0xC6, (byte) 0xDA, (byte) 0xCB, (byte) 0xC4},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        { 0x32, 0x30, 0x30, 0x31, (byte) 0xA6, 0x7E, 0x35, (byte) 0xA4, (byte) 0xEB, 0x31, 0x30, (byte) 0xA4, (byte) 0xE9, 0x20, (byte) 0xAC, (byte)0x50, (byte) 0xB4, (byte) 0xC1, (byte) 0xA5, (byte) 0x7C},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        { (byte) 0xE9, (byte) 0xE5, (byte) 0xED, 0x20, (byte) 0xE7, (byte) 0xEE, (byte) 0xE9, (byte) 0xF9, (byte) 0xE9, 0x20, 0x31, 0x30, 0x20, (byte) 0xEE, (byte) 0xE0, (byte) 0xE9, 0x20, 0x32, 0x30, 0x30, 0x31, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        { 0x32, 0x30, 0x30, 0x31, (byte) 0x94, 0x4E, 0x35, (byte) 0x8C, (byte) 0x8E, 0x31, 0x30, (byte) 0x93, (byte) 0xFA, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        { 0x32, 0x30, 0x30, 0x31, (byte) 0xB3, (byte) 0xE2, 0x20, 0x35, (byte) 0xBF, (byte) 0xF9, 0x20, 0x31, 0x30, (byte) 0xC0, (byte) 0xCF, 0x20, (byte) 0xB8, (byte) 0xF1, (byte) 0xBF, (byte) 0xE4, (byte) 0xC0, (byte) 0xCF, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        { 0x67, 0x69, 0x6F, 0x76, 0x65, 0x64, (byte) 0xEC, 0x20, 0x31, 0x30, 0x20, 0x6D, 0x61, 0x67, 0x67, 0x69, 0x6F, 0x20, 0x32, 0x30, 0x30, 0x31, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        { (byte) 0xC7, (byte) 0xD1, (byte) 0xB9, (byte) 0xBE, (byte) 0xC4, (byte) 0xCB, (byte) 0xD1, (byte) 0xCA, (byte) 0xBA, (byte) 0xB4, (byte) 0xD5, (byte) 0xB7, (byte) 0xD5, (byte) 0xE8, 0x20, 0x31, 0x30, 0x20, (byte) 0xBE, (byte) 0xC4, (byte) 0xC9, (byte) 0xC0, (byte) 0xD2, (byte) 0xA4, (byte) 0xC1, 0x20, (byte) 0xBE, 0x2E, (byte) 0xC8, 0x2E, 0x20, 0x32, 0x35, 0x34, 0x34, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        { 0x31, 0x30, 0x20, (byte) 0xE5, (byte) 0xC7, (byte) 0xEA, (byte) 0xE8, 0x2C, 0x20, 0x32, 0x30, 0x30, 0x31, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        { 0x32, 0x30, 0x30, 0x31, (byte) 0xC4, (byte) 0xEA, 0x35, (byte) 0xD4, (byte) 0xC2, 0x31, 0x30, (byte) 0xC8, (byte) 0xD5, 0x20, (byte) 0xD0, (byte) 0xC7, (byte) 0xC6, (byte) 0xDA, (byte) 0xCB, (byte) 0xC4},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        { 0x32, 0x30, 0x30, 0x31, (byte) 0xE5, (byte) 0xB9, (byte) 0xB4, 0x35, (byte) 0xE6, (byte) 0x9C, (byte) 0x88, 0x31, 0x30, (byte) 0xE6, (byte) 0x97, (byte) 0xA5, 0x20, (byte) 0xE6, (byte)0x98, (byte) 0x9F, (byte) 0xE6, (byte) 0x9C, (byte) 0x9F, (byte) 0xE5, (byte) 0x9B, (byte) 0x9B},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        { 0x32, 0x30, 0x30, 0x31, (byte) 0xC4, (byte) 0xEA, 0x35, (byte) 0xD4, (byte) 0xC2, 0x31, 0x30, (byte) 0xC8, (byte) 0xD5, 0x20, (byte) 0xD0, (byte) 0xC7, (byte) 0xC6, (byte) 0xDA, (byte) 0xCB, (byte) 0xC4},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        { 0x32, 0x30, 0x30, 0x31, (byte) 0xC8, (byte) 0xA1, 0x35, (byte) 0xC5, (byte) 0xCC, 0x31, 0x30, (byte) 0xC5, (byte) 0xCA, 0x20, (byte) 0xD1, (byte) 0xD3, (byte) 0xDF, (byte) 0xE6, (byte) 0xC6, (byte) 0xBE},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        { (byte) 0xE9, (byte) 0xE5, (byte) 0xED, 0x20, (byte) 0xE7, (byte) 0xEE, (byte) 0xE9, (byte) 0xF9, (byte) 0xE9, 0x20, 0x31, 0x30, 0x20, (byte) 0xEE, (byte) 0xE0, (byte) 0xE9, 0x20, 0x32, 0x30, 0x30, 0x31, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        { 0x32, 0x30, 0x30, 0x31, (byte) 0xC7, (byte) 0xAF, 0x35, (byte) 0xB7, (byte) 0xEE, 0x31, 0x30, (byte) 0xC6, (byte) 0xFC, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        { 0x32, 0x30, 0x30, 0x31, (byte) 0x94, 0x4E, 0x35, (byte) 0x8C, (byte) 0x8E, 0x31, 0x30, (byte) 0x93, (byte) 0xFA, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        { 0x32, 0x30, 0x30, 0x31, (byte) 0xB3, (byte) 0xE2, 0x20, 0x35, (byte) 0xBF, (byte) 0xF9, 0x20, 0x31, 0x30, (byte) 0xC0, (byte) 0xCF, 0x20, (byte) 0xB8, (byte) 0xF1, (byte) 0xBF, (byte) 0xE4, (byte) 0xC0, (byte) 0xCF, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        { 0x67, 0x69, 0x6F, 0x76, 0x65, 0x64, (byte) 0xEC, 0x20, 0x31, 0x30, 0x20, 0x6D, 0x61, 0x67, 0x67, 0x69, 0x6F, 0x20, 0x32, 0x30, 0x30, 0x31, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        { 0x67, 0x69, 0x6F, 0x76, 0x65, 0x64, (byte) 0xEC, 0x20, 0x31, 0x30, 0x20, 0x6D, 0x61, 0x67, 0x67, 0x69, 0x6F, 0x20, 0x32, 0x30, 0x30, 0x31, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        { (byte) 0xC7, (byte) 0xD1, (byte) 0xB9, (byte) 0xBE, (byte) 0xC4, (byte) 0xCB, (byte) 0xD1, (byte) 0xCA, (byte) 0xBA, (byte) 0xB4, (byte) 0xD5, (byte) 0xB7, (byte) 0xD5, (byte) 0xE8, 0x20, 0x31, 0x30, 0x20, (byte) 0xBE, (byte) 0xC4, (byte) 0xC9, (byte) 0xC0, (byte) 0xD2, (byte) 0xA4, (byte) 0xC1, 0x20, (byte) 0xBE, 0x2E, (byte) 0xC8, 0x2E, 0x20, 0x32, 0x35, 0x34, 0x34, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private static boolean testRequiredEncodings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        boolean pass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        for (int i = 0; i < requiredEncodings.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            String encoding = requiredEncodings[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            Locale sampleLocale = sampleLocales[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                while (!sampleLocale.equals(requiredLocales[index])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                byte[] out = requiredLocaleDates[index].getBytes(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                byte[] expected = expectedBytes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                if (out.length != expected.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    reportConversionError(encoding, expected, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    for (int j = 0; j < out.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        if (out[j] != expected[j]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                            reportConversionError(encoding, expected, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                            pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            } catch (UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                System.out.println("Encoding not available: " + encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return pass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    private static void reportConversionError(String encoding,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            byte[] expected, byte[] actual) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        System.out.println("Incorrect conversion for encoding: " + encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        System.out.println("Expected output:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        dumpBytes(expected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        System.out.println("Actual output:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        dumpBytes(actual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private static void dumpBytes(byte[] bytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        System.out.print("        { ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        for (int i = 0; i < bytes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
             byte b = bytes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
             if (b < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                 System.out.print("(byte) ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
             System.out.print("0x" + toHex((b & 0x00F0) >> 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                     + toHex((b & 0x000F)) + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        System.out.println("},");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private static char toHex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (i <= 9) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return (char) ('0' + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            return (char) ('A' + i - 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}