test/jdk/java/lang/String/ICCBasher.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.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) 1998, 2002, 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
 * @bug 4152868
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary test Case Insensitive Comparator in String
30046
cf2c86e1819e 8078334: Mark regression tests using randomness
darcy
parents: 5506
diff changeset
    28
 * @key randomness
2
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.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class ICCBasher {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    static final int TEST_SIZE = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    static final int STRING_SIZE = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    static final int CHAR_VALUE_LIMIT = 128;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        LinkedList L1 = new LinkedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        LinkedList L2 = new LinkedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        LinkedList L3 = new LinkedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        LinkedList L4 = new LinkedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        // First generate L1 and L2 with random lower case chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        //System.out.println("Generate L1 and L2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        Random generator = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        int achar=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        StringBuffer entryBuffer = new StringBuffer(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        String snippet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        for (int x=0; x<TEST_SIZE * 2; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            for(int y=0; y<STRING_SIZE; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                achar = generator.nextInt(CHAR_VALUE_LIMIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                char test = (char)(achar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                entryBuffer.append(test);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            snippet = entryBuffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            snippet.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            if (x < TEST_SIZE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                L1.add(snippet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                L2.add(snippet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        // Concatenate L1 and L2 to form L3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        //System.out.println("Generate L3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        for (int x=0; x<TEST_SIZE; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            String entry = (String)L1.get(x) + (String)L2.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            L3.add(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        // Randomly toUpper L1 and L2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        //System.out.println("Modify L1 and L2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        for (int x=0; x<TEST_SIZE; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            achar = generator.nextInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            if (achar > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                String mod = (String)L1.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                mod = mod.toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                L1.set(x, mod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            achar = generator.nextInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            if (achar > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                String mod = (String)L2.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                mod = mod.toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                L2.set(x, mod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // Concatenate L1 and L2 to form L4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        //System.out.println("Generate L4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        for (int x=0; x<TEST_SIZE; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            String entry = (String)L1.get(x) + (String)L2.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            L4.add(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // Sort L3 and L4 using case insensitive comparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        //System.out.println("Sort L3 and L4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        Collections.sort(L3, String.CASE_INSENSITIVE_ORDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        Collections.sort(L4, String.CASE_INSENSITIVE_ORDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // Check to see that order of L3 and L4 are identical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // ignoring case considerations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        //System.out.println("Check order of L3 and L4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        for (int x=0; x<TEST_SIZE; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            String one = (String)L3.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            String two = (String)L4.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            if (!one.equalsIgnoreCase(two))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                throw new RuntimeException("Case Insensitive Sort Failure.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
}