test/jdk/java/text/Collator/CollationKeyTestImpl.java
author tschatzl
Wed, 24 Jul 2019 11:49:39 +0200
changeset 57508 28ab01c06755
parent 47216 71c04702a3d5
permissions -rw-r--r--
8228388: Add information about dirty/skipped card for Merge HCC in G1 log Summary: Collect and print informatio about the number of processed cards during the Merge HCC phase to improve log output. Reviewed-by: kbarrett, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38581
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
     1
/*
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
     4
 *
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
     8
 *
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    13
 * accompanied this code).
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    14
 *
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    18
 *
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    21
 * questions.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    22
 */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    23
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    24
/*
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    25
 *
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    26
 * A part of tests on the bug 4106263. CollationKey became non-final extendable class.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    27
 *          The implementation of CollationKey is moved to the new private class,
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    28
 *          RuleBasedCollationKey. This test basically tests on the two features:
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    29
 *          1. Existing code using CollationKey works (backward compatiblility)
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    30
 *          2. CollationKey can be extended by its subclass.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    31
 */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    32
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    33
import java.util.Locale;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    34
import java.text.Collator;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    35
import java.text.CollationKey;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    36
import java.io.*;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    37
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    38
import java.text.*;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    39
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    40
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    41
public class CollationKeyTestImpl extends CollationKey {
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    42
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    43
    private static String[] sourceData_ja = {
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    44
        "\u3042\u3044\u3046\u3048\u3048",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    45
        "\u3041\u3043\u3045\u3047\u3049",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    46
        "\u3052\u3054\u3056\u3058\u3058",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    47
        "\u3051\u3053\u3055\u3057\u3059",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    48
        "\u3062\u3064\u3066\u3068\u3068",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    49
        "\u3061\u3063\u3065\u3067\u3069",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    50
        "\u3072\u3074\u3075\u3078\u3078",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    51
        "\u3071\u3073\u3075\u3077\u3079",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    52
        "\u3082\u3084\u3085\u3088\u3088",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    53
        "\u3081\u3083\u3085\u3087\u3089",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    54
        "\u30a2\u30a4\u30a6\u30a8\u30aa",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    55
        "\u30a1\u30a3\u30a5\u30a7\u30a9",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    56
        "\u30c2\u30c4\u30c6\u30c8\u30ca",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    57
        "\u30c1\u30c3\u30c5\u30c7\u30c9",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    58
        "\u30b2\u30b4\u30b6\u30b8\u30ba",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    59
        "\u30b1\u30b3\u30b5\u30b7\u30b9",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    60
        "\u30d2\u30d4\u30d6\u30d8\u30da",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    61
        "\u30d1\u30d3\u30d5\u30d7\u30d9",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    62
        "\u30e2\u30e4\u30e6\u30e8\u30ea",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    63
        "\u30e1\u30e3\u30e5\u30e7\u30e9"
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    64
        };
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    65
    private static final String[] targetData_ja = {
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    66
        "\u3042\u3044\u3046\u3048\u3048",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    67
        "\u3041\u3043\u3045\u3047\u3049",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    68
        "\u30a2\u30a4\u30a6\u30a8\u30aa",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    69
        "\u30a1\u30a3\u30a5\u30a7\u30a9",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    70
        "\u3052\u3054\u3056\u3058\u3058",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    71
        "\u3051\u3053\u3055\u3057\u3059",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    72
        "\u30b1\u30b3\u30b5\u30b7\u30b9",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    73
        "\u30b2\u30b4\u30b6\u30b8\u30ba",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    74
        "\u3061\u3063\u3065\u3067\u3069",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    75
        "\u30c1\u30c3\u30c5\u30c7\u30c9",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    76
        "\u3062\u3064\u3066\u3068\u3068",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    77
        "\u30c2\u30c4\u30c6\u30c8\u30ca",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    78
        "\u3071\u3073\u3075\u3077\u3079",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    79
        "\u30d1\u30d3\u30d5\u30d7\u30d9",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    80
        "\u3072\u3074\u3075\u3078\u3078",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    81
        "\u30d2\u30d4\u30d6\u30d8\u30da",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    82
        "\u3081\u3083\u3085\u3087\u3089",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    83
        "\u30e1\u30e3\u30e5\u30e7\u30e9",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    84
        "\u3082\u3084\u3085\u3088\u3088",
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    85
        "\u30e2\u30e4\u30e6\u30e8\u30ea"
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    86
        };
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    87
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    88
    public void run() {
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    89
        /** debug: printout the test data
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    90
        for (int i=0; i<sourceData_ja.length; i++){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    91
                System.out.println(i+": "+sourceData_ja[i]);
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    92
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    93
        **/
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    94
       /*
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    95
        * 1. Test the backward compatibility
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    96
        *    note: targetData_ja.length is equal to sourceData_ja.length
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    97
        */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    98
        Collator myCollator = Collator.getInstance(Locale.JAPAN);
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
    99
        CollationKey[] keys = new CollationKey[sourceData_ja.length];
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   100
        CollationKey[] target_keys = new CollationKey[targetData_ja.length];
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   101
        for (int i=0; i<sourceData_ja.length; i++){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   102
                keys[i] = myCollator.getCollationKey(sourceData_ja[i]);
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   103
                target_keys[i] = myCollator.getCollationKey(targetData_ja[i]); //used later
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   104
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   105
        /* Sort the string using CollationKey */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   106
        InsertionSort(keys);
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   107
        /** debug: printout the result after sort
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   108
        System.out.println("--- After Sorting ---");
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   109
        for (int i=0; i<sourceData_ja.length; i++){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   110
                System.out.println(i+" :"+keys[i].getSourceString());
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   111
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   112
        **/
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   113
       /*
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   114
        * Compare the result using equals method and getSourceString method.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   115
        */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   116
        boolean pass = true;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   117
        for (int i=0; i<sourceData_ja.length; i++){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   118
                /* Comparing using String.equals: in order to use getStringSource() */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   119
                if (! targetData_ja[i].equals(keys[i].getSourceString())){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   120
                        throw new RuntimeException("FAILED: CollationKeyTest backward compatibility "
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   121
                                  +"while comparing" +targetData_ja[i]+" vs "
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   122
                                  +keys[i].getSourceString());
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   123
                }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   124
                /* Comparing using CollaionKey.equals: in order to use equals() */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   125
                if (! target_keys[i].equals(keys[i])){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   126
                        throw new RuntimeException("FAILED: CollationKeyTest backward compatibility."
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   127
                                  +" Using CollationKey.equals " +targetData_ja[i]
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   128
                                  +" vs " +keys[i].getSourceString());
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   129
                }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   130
                /* Comparing using CollaionKey.hashCode(): in order to use hashCode() */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   131
                if (target_keys[i].hashCode() != keys[i].hashCode()){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   132
                        throw new RuntimeException("FAILED: CollationKeyTest backward compatibility."
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   133
                                  +" Using CollationKey.hashCode " +targetData_ja[i]
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   134
                                  +" vs " +keys[i].getSourceString());
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   135
                }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   136
                /* Comparing using CollaionKey.toByteArray(): in order to use toByteArray() */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   137
                byte[] target_bytes = target_keys[i].toByteArray();
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   138
                byte[] source_bytes = keys[i].toByteArray();
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   139
                for (int j=0; j<target_bytes.length; j++){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   140
                        Byte targetByte = new Byte(target_bytes[j]);
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   141
                        Byte sourceByte = new Byte(source_bytes[j]);
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   142
                        if (targetByte.compareTo(sourceByte)!=0){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   143
                            throw new RuntimeException("FAILED: CollationKeyTest backward "
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   144
                                  +"compatibility. Using Byte.compareTo from CollationKey.toByteArray "
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   145
                                  +targetData_ja[i]
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   146
                                  +" vs " +keys[i].getSourceString());
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   147
                        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   148
                }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   149
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   150
        testSubclassMethods();
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   151
        testConstructor();
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   152
    }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   153
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   154
   /*
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   155
    * Sort the array of CollationKey using compareTo method in insertion sort.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   156
    */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   157
    private  void  InsertionSort(CollationKey[] keys){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   158
        int f, i;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   159
        CollationKey tmp;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   160
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   161
        for (f=1; f < keys.length; f++){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   162
            if(keys[f].compareTo( keys[f-1]) > 0){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   163
                continue;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   164
            }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   165
            tmp = keys[f];
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   166
            i = f-1;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   167
            while ( (i>=0) && (keys[i].compareTo(tmp) > 0) ) {
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   168
                keys[i+1] = keys[i];
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   169
                i--;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   170
            }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   171
            keys[i+1]=tmp;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   172
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   173
    }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   174
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   175
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   176
  /*
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   177
   * From here is the bogus methods to test the subclass of
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   178
   * the CollationKey class.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   179
   */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   180
    public CollationKeyTestImpl(String str){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   181
        super (str);
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   182
        // debug: System.out.println("CollationKeyTest extends CollationKey class: "+str);
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   183
    }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   184
    /* abstract method: needs to be implemented */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   185
    public byte[] toByteArray(){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   186
        String foo= "Hello";
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   187
        return foo.getBytes();
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   188
    }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   189
   /* abstract method: needs to be implemented */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   190
   public int compareTo(CollationKey target){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   191
        return 0;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   192
   }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   193
   public boolean equals(Object target){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   194
        return true;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   195
   }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   196
   public String getSourceString(){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   197
        return "CollationKeyTestImpl";
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   198
   }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   199
  /*
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   200
   * This method tests the collection of bugus methods from the extended
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   201
   * subclass of CollationKey class.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   202
   */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   203
   private void testSubclassMethods() {
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   204
        CollationKeyTestImpl clt1  = new CollationKeyTestImpl("testSubclassMethods-1");
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   205
        CollationKeyTestImpl clt2  = new CollationKeyTestImpl("testSubclassMethods-2");
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   206
        // extended method, equals always returns true
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   207
        if (!clt1.equals(clt2)){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   208
            throw new RuntimeException("Failed: equals(CollationKeySubClass)");
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   209
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   210
        // extended method, compareTo always returns 0
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   211
        if (clt1.compareTo(clt2)!=0){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   212
            throw new RuntimeException("Failed: compareTo(CollationKeySubClass)");
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   213
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   214
        // overriding extended method, getSourceString always returns "CollationKeyTestImpl"
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   215
        if (! clt1.getSourceString().equals("CollationKeyTestImpl")){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   216
            throw new RuntimeException("Failed: CollationKey subclass overriding getSourceString()");
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   217
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   218
        // extended method, toByteArray always returns bytes from "Hello"
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   219
        String str2 = new String( clt2.toByteArray());
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   220
        if (! clt2.equals("Hello")){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   221
            throw new RuntimeException("Failed: CollationKey subclass toByteArray()");
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   222
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   223
    }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   224
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   225
  /*
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   226
   * This method tests CollationKey constructor with null source string.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   227
   * It should throw NPE.
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   228
   */
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   229
   private void testConstructor() {
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   230
       boolean npe=false;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   231
       try{
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   232
            CollationKeyTestImpl cltNull  = new CollationKeyTestImpl(null);
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   233
        } catch (NullPointerException npException){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   234
            npe=true;
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   235
            // debug: System.out.println("--- NPE is thrown with NULL arguement: PASS ---");
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   236
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   237
        if(!npe){
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   238
           throw new RuntimeException("Failed: CollationKey Constructor with null source"+
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   239
                                   " didn't throw NPE!");
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   240
        }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   241
    }
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   242
e761c1ccd13e 8031145: Re-examine closed i18n tests to see it they can be moved to the jdk repository.
okutsu
parents:
diff changeset
   243
}