jdk/test/sun/net/idn/PunycodeTest.java
author mchung
Thu, 28 May 2015 10:54:48 -0700
changeset 30820 0d4717a011d3
parent 5506 202f599c92aa
permissions -rw-r--r--
8081347: Add @modules to jdk_core tests Reviewed-by: alanb, joehw, lancea Contributed-by: alexander.kulyakhtin@oracle.com, alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 2006, 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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Unit test for sun.net.idn.Punycode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @bug 4737170
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 5506
diff changeset
    28
 * @modules java.base/sun.net.idn
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @compile -XDignore.symbol.file PunycodeTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run main/othervm -ea PunycodeTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @author Edward Wang
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.util.Scanner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.text.ParseException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.net.idn.Punycode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * unit test for Punycode that is also originated from the sample code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * provided in rfc3492.txt
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class PunycodeTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /* For testing, we'll just set some compile-time limits rather than */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /* use malloc(), and set a compile-time option rather than using a  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /* command-line option.                                             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static final int  unicode_max_length = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static final int  ace_max_length = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static final String too_big =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            "input or output is too large, recompile with larger limits\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static final String invalid_input = "invalid input\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static final String overflow = "arithmetic overflow\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static final String io_error = "I/O error\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /* The following string is used to convert printable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /* characters between ASCII and the native charset:  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static void fail(String msg, String input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        System.out.println(msg+" input: "+input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        throw new RuntimeException(msg+" input: "+input);
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
    public int testCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private int input_length, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private int output_length[] = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private boolean case_flags[] = new boolean[unicode_max_length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public String testEncoding(String inputS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        char input[] = new char[unicode_max_length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        int codept = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        char uplus[] = new char[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        StringBuffer output;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        /* Read the input code points: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        input_length = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        Scanner sc = new Scanner(inputS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        while (sc.hasNext()) {  // need to stop at end of line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                String next = sc.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                uplus[0] = next.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                uplus[1] = next.charAt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                codept = Integer.parseInt(next.substring(2), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                fail(invalid_input, inputS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                fail(invalid_input, inputS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            if (input_length == unicode_max_length) fail(too_big, inputS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (uplus[0] == 'u') case_flags[input_length] = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            else if (uplus[0] == 'U') case_flags[input_length] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            else fail(invalid_input, inputS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            input[input_length++] = (char)codept;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        /* Encode: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        output_length[0] = ace_max_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            fail(invalid_input, inputS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            // never reach here, just to make compiler happy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return output.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public String testDecoding(String inputS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        char input[] = new char[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        int pp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        StringBuffer output;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        /* Read the Punycode input string and convert to ASCII: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (inputS.length() <= ace_max_length+2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            input = inputS.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            fail(invalid_input, inputS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        input_length = input.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        /* Decode: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        output_length[0] = unicode_max_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            output = Punycode.decode((new StringBuffer()).append(input, 0, input_length), case_flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            fail(invalid_input, inputS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            // never reach here, just to make compiler happy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        /* Output the result: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        StringBuffer result = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        for (j = 0;  j < output.length();  ++j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            result.append(String.format("%s+%04X ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    case_flags[j] ? "U" : "u",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    (int)output.charAt(j) ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        testCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return result.substring(0, result.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  // test data from rfc3492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  static String[][] testdata = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    {"(A) Arabic (Egyptian):",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     "u+0644 u+064A u+0647 u+0645 u+0627 u+0628 u+062A u+0643 u+0644 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     "u+0645 u+0648 u+0634 u+0639 u+0631 u+0628 u+064A u+061F",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     "egbpdaj6bu4bxfgehfvwxn"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    {"(B) Chinese (simplified):",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     "u+4ED6 u+4EEC u+4E3A u+4EC0 u+4E48 u+4E0D u+8BF4 u+4E2D u+6587",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     "ihqwcrb4cv8a8dqg056pqjye"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    {"(C) Chinese (traditional):",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    "u+4ED6 u+5011 u+7232 u+4EC0 u+9EBD u+4E0D u+8AAA u+4E2D u+6587",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    "ihqwctvzc91f659drss3x8bo0yb"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    {"(D) Czech: Pro<ccaron>prost<ecaron>nemluv<iacute><ccaron>esky",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    "U+0050 u+0072 u+006F u+010D u+0070 u+0072 u+006F u+0073 u+0074 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     "u+011B u+006E u+0065 u+006D u+006C u+0075 u+0076 u+00ED u+010D "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     "u+0065 u+0073 u+006B u+0079",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    "Proprostnemluvesky-uyb24dma41a"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    {"(E) Hebrew:",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    "u+05DC u+05DE u+05D4 u+05D4 u+05DD u+05E4 u+05E9 u+05D5 u+05D8 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     "u+05DC u+05D0 u+05DE u+05D3 u+05D1 u+05E8 u+05D9 u+05DD u+05E2 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     "u+05D1 u+05E8 u+05D9 u+05EA",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    "4dbcagdahymbxekheh6e0a7fei0b"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    {"(F) Hindi (Devanagari):",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    "u+092F u+0939 u+0932 u+094B u+0917 u+0939 u+093F u+0928 u+094D "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     "u+0926 u+0940 u+0915 u+094D u+092F u+094B u+0902 u+0928 u+0939 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     "u+0940 u+0902 u+092C u+094B u+0932 u+0938 u+0915 u+0924 u+0947 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     "u+0939 u+0948 u+0902",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    "i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    {"(G) Japanese (kanji and hiragana):",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    "u+306A u+305C u+307F u+3093 u+306A u+65E5 u+672C u+8A9E u+3092 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     "u+8A71 u+3057 u+3066 u+304F u+308C u+306A u+3044 u+306E u+304B",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    "n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    {"(H) Korean (Hangul syllables):",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    "u+C138 u+ACC4 u+C758 u+BAA8 u+B4E0 u+C0AC u+B78C u+B4E4 u+C774 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     "u+D55C u+AD6D u+C5B4 u+B97C u+C774 u+D574 u+D55C u+B2E4 u+BA74 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     "u+C5BC u+B9C8 u+B098 u+C88B u+C744 u+AE4C",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    "989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5j"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    "psd879ccm6fea98c"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    {"(I) Russian (Cyrillic):",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    "U+043F u+043E u+0447 u+0435 u+043C u+0443 u+0436 u+0435 u+043E "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     "u+043D u+0438 u+043D u+0435 u+0433 u+043E u+0432 u+043E u+0440 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     "u+044F u+0442 u+043F u+043E u+0440 u+0443 u+0441 u+0441 u+043A "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     "u+0438",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    "b1abfaaepdrnnbgefbaDotcwatmq2g4l"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    {"(J) Spanish: Porqu<eacute>nopuedensimplementehablarenEspa<ntilde>ol",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    "U+0050 u+006F u+0072 u+0071 u+0075 u+00E9 u+006E u+006F u+0070 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     "u+0075 u+0065 u+0064 u+0065 u+006E u+0073 u+0069 u+006D u+0070 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     "u+006C u+0065 u+006D u+0065 u+006E u+0074 u+0065 u+0068 u+0061 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     "u+0062 u+006C u+0061 u+0072 u+0065 u+006E U+0045 u+0073 u+0070 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     "u+0061 u+00F1 u+006F u+006C",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    "PorqunopuedensimplementehablarenEspaol-fmd56a"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    {"(K) Vietnamese:"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     "T<adotbelow>isaoh<odotbelow>kh<ocirc>ngth<ecirchookabove>ch"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     "<ihookabove>n<oacute>iti<ecircacute>ngVi<ecircdotbelow>t",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    "U+0054 u+1EA1 u+0069 u+0073 u+0061 u+006F u+0068 u+1ECD u+006B "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     "u+0068 u+00F4 u+006E u+0067 u+0074 u+0068 u+1EC3 u+0063 u+0068 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     "u+1EC9 u+006E u+00F3 u+0069 u+0074 u+0069 u+1EBF u+006E u+0067 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     "U+0056 u+0069 u+1EC7 u+0074",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    "TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    {"(L) 3<nen>B<gumi><kinpachi><sensei>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     "u+0033 u+5E74 U+0042 u+7D44 u+91D1 u+516B u+5148 u+751F",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    "3B-ww4c5e180e575a65lsy2b"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    {"(M) <amuro><namie>-with-SUPER-MONKEYS",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     "u+5B89 u+5BA4 u+5948 u+7F8E u+6075 u+002D u+0077 u+0069 u+0074 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     "u+0068 u+002D U+0053 U+0055 U+0050 U+0045 U+0052 u+002D U+004D "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     "U+004F U+004E U+004B U+0045 U+0059 U+0053",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    "-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    {"(N) Hello-Another-Way-<sorezore><no><basho>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    "U+0048 u+0065 u+006C u+006C u+006F u+002D U+0041 u+006E u+006F "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     "u+0074 u+0068 u+0065 u+0072 u+002D U+0057 u+0061 u+0079 u+002D "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     "u+305D u+308C u+305E u+308C u+306E u+5834 u+6240",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    "Hello-Another-Way--fc4qua05auwb3674vfr0b"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    {"(O) <hitotsu><yane><no><shita>2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     "u+3072 u+3068 u+3064 u+5C4B u+6839 u+306E u+4E0B u+0032",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    "2-u9tlzr9756bt3uc0v"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    {"(P) Maji<de>Koi<suru>5<byou><mae>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     "U+004D u+0061 u+006A u+0069 u+3067 U+004B u+006F u+0069 u+3059 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     "u+308B u+0035 u+79D2 u+524D",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    "MajiKoi5-783gue6qz075azm5e"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    {"(Q) <pafii>de<runba>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     "u+30D1 u+30D5 u+30A3 u+30FC u+0064 u+0065 u+30EB u+30F3 u+30D0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    "de-jg4avhby1noc0d"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    {"(R) <sono><supiido><de>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     "u+305D u+306E u+30B9 u+30D4 u+30FC u+30C9 u+3067",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    "d9juau41awczczp"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    {"(S) -> $1.00 <-",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     "u+002D u+003E u+0020 u+0024 u+0031 u+002E u+0030 u+0030 u+0020 "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     "u+003C u+002D",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    "-> $1.00 <--"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  public static void main(String[] argv) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      PunycodeTest mytest = new PunycodeTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      for (int i = 0; i < testdata.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
          String encodeResult = mytest.testEncoding(testdata[i][1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
          String decodeResult = mytest.testDecoding(testdata[i][2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
          checkResult(encodeResult, testdata[i][2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
          checkResult(decodeResult, testdata[i][1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      System.out.println("Test cases: " + mytest.testCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
  public static void checkResult(String actual, String expected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
      if (!actual.equals(expected)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
          System.out.printf("\n%15s: %s\n", "FAILED", actual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
          System.out.printf("%15s: %s\n\n", "should be", expected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
          throw new RuntimeException("Punycode test failed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
          System.out.printf("%15s: %s\n", "SUCCEEDED", actual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
}