jdk/test/java/util/Locale/InternationalBAT.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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 4449637
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.
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.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.text.DateFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.TimeZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class InternationalBAT {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        boolean pass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        if (!testRequiredLocales()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        if (!testRequiredEncodings()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
            pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        if (!pass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            System.out.println("\nSome tests failed.\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                    + "If you installed the US-only J2RE for Windows, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                    + "failures are expected and OK.\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                    + "If you installed the international J2RE, or any J2SDK, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                    + "or if this occurs on any platform other than Windows, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                    + "please file a bug report.\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                    + "Unfortunately, this test cannot determine whether you "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                    + "installed a US-only J2RE, an international J2RE, or "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                    + "a J2SDK.\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            throw new RuntimeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // We require the "fully supported locales" for java.util and java.text:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // http://webwork.eng/j2se/1.4/docs/guide/intl/locale.doc.html#util-text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static Locale[] requiredLocales = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        new Locale("ar", "SA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        new Locale("zh", "TW"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        new Locale("nl", "NL"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        new Locale("en", "AU"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        new Locale("en", "CA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        new Locale("en", "GB"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        new Locale("en", "US"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        new Locale("fr", "CA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        new Locale("fr", "FR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        new Locale("de", "DE"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        new Locale("iw", "IL"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        new Locale("hi", "IN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        new Locale("it", "IT"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        new Locale("ja", "JP"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        new Locale("ko", "KR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        new Locale("pt", "BR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        new Locale("es", "ES"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        new Locale("sv", "SE"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        new Locale("th", "TH"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // Date strings for May 10, 2001, for the required locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static String[] requiredLocaleDates = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        "10 \u0645\u0627\u064A\u0648, 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        "2001\u5E745\u670810\u65E5 \u661F\u671F\u56DB",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        "2001\u5E745\u670810\u65E5 \u661F\u671F\u56DB",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        "donderdag 10 mei 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        "Thursday, 10 May 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        "Thursday, May 10, 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        "Thursday, 10 May 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        "Thursday, May 10, 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        "jeudi 10 mai 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        "jeudi 10 mai 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        "Donnerstag, 10. Mai 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        "\u05D9\u05D5\u05DD \u05D7\u05DE\u05D9\u05E9\u05D9 10 \u05DE\u05D0\u05D9 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        "\u0917\u0941\u0930\u0941\u0935\u093E\u0930, \u0967\u0966 \u092E\u0908, \u0968\u0966\u0966\u0967",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        "gioved\u00EC 10 maggio 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        "2001\u5E745\u670810\u65E5", // ja_JP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        "2001\uB144 5\uC6D4 10\uC77C \uBAA9\uC694\uC77C",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        "Quinta-feira, 10 de Maio de 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        "jueves 10 de mayo de 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        "den 10 maj 2001",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        "\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
   111
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static boolean testRequiredLocales() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        boolean pass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        Calendar calendar = Calendar.getInstance(Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        calendar.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        calendar.set(2001, 4, 10, 12, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        Date date = calendar.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        Locale[] available = Locale.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        for (int i = 0; i < requiredLocales.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            Locale locale = requiredLocales[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            for (int j = 0; j < available.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                if (available[j].equals(locale)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                System.out.println("Locale not available: " + locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                DateFormat format =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                        DateFormat.getDateInstance(DateFormat.FULL, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                String dateString = format.format(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                if (!dateString.equals(requiredLocaleDates[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    System.out.println("Incorrect date string for locale "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                            + locale + ". Expected: " + requiredLocaleDates[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                            + ", got: " + dateString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return pass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    // We require the encodings of the fully supported writing systems:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    // http://webwork.eng/j2se/1.4/docs/guide/intl/locale.doc.html#jfc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private static String[] requiredEncodings = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        "Cp1256",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        "MS936",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        "MS950",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        "Cp1255",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        "MS932",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        "MS949",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        "Cp1252",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        "MS874",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        "ISO8859_6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        "EUC_CN",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        "UTF8",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        "GBK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        "EUC_TW",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        "ISO8859_8",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        "EUC_JP",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        "PCK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        "EUC_KR",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        "ISO8859_1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        "ISO8859_15",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        "TIS620",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    // one sample locale each for the required encodings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static Locale[] sampleLocales = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        new Locale("ar", "SA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        new Locale("zh", "TW"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        new Locale("iw", "IL"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        new Locale("ja", "JP"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        new Locale("ko", "KR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        new Locale("it", "IT"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        new Locale("th", "TH"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        new Locale("ar", "SA"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        new Locale("zh", "TW"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        new Locale("iw", "IL"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        new Locale("ja", "JP"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        new Locale("ja", "JP"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        new Locale("ko", "KR"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        new Locale("it", "IT"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        new Locale("it", "IT"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        new Locale("th", "TH"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    // expected conversion results for the date strings of the sample locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private static byte[][] expectedBytes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        { 0x31, 0x30, 0x20, (byte) 0xE3, (byte) 0xC7, (byte) 0xED, (byte) 0xE6, 0x2C, 0x20, 0x32, 0x30, 0x30, 0x31, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        { 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
   206
        { 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
   207
        { (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
   208
        { 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
   209
        { 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
   210
        { 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
   211
        { (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
   212
        { 0x31, 0x30, 0x20, (byte) 0xE5, (byte) 0xC7, (byte) 0xEA, (byte) 0xE8, 0x2C, 0x20, 0x32, 0x30, 0x30, 0x31, },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        { 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
   214
        { 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
   215
        { 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
   216
        { 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
   217
        { (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
   218
        { 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
   219
        { 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
   220
        { 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
   221
        { 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
   222
        { 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
   223
        { (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
   224
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private static boolean testRequiredEncodings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        boolean pass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        for (int i = 0; i < requiredEncodings.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            String encoding = requiredEncodings[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            Locale sampleLocale = sampleLocales[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                while (!sampleLocale.equals(requiredLocales[index])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                byte[] out = requiredLocaleDates[index].getBytes(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                byte[] expected = expectedBytes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                if (out.length != expected.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    reportConversionError(encoding, expected, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    for (int j = 0; j < out.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        if (out[j] != expected[j]) {
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
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            } catch (UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                System.out.println("Encoding not available: " + encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return pass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private static void reportConversionError(String encoding,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            byte[] expected, byte[] actual) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        System.out.println("Incorrect conversion for encoding: " + encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        System.out.println("Expected output:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        dumpBytes(expected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        System.out.println("Actual output:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        dumpBytes(actual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private static void dumpBytes(byte[] bytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        System.out.print("        { ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        for (int i = 0; i < bytes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
             byte b = bytes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
             if (b < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                 System.out.print("(byte) ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
             System.out.print("0x" + toHex((b & 0x00F0) >> 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                     + toHex((b & 0x000F)) + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        System.out.println("},");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private static char toHex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (i <= 9) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return (char) ('0' + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            return (char) ('A' + i - 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
}