Path: blob/master/test/jdk/java/lang/String/ICCBasher.java
41149 views
/*1* Copyright (c) 1998, 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 415286826* @summary test Case Insensitive Comparator in String27* @key randomness28*/2930import java.util.*;3132public class ICCBasher {3334static final int TEST_SIZE = 20;35static final int STRING_SIZE = 5;36static final int CHAR_VALUE_LIMIT = 128;3738public static void main(String[] args) throws Exception {39LinkedList L1 = new LinkedList();40LinkedList L2 = new LinkedList();41LinkedList L3 = new LinkedList();42LinkedList L4 = new LinkedList();4344// First generate L1 and L2 with random lower case chars45//System.out.println("Generate L1 and L2");46Random generator = new Random();47int achar=0;48StringBuffer entryBuffer = new StringBuffer(10);49String snippet = null;50for (int x=0; x<TEST_SIZE * 2; x++) {51for(int y=0; y<STRING_SIZE; y++) {52achar = generator.nextInt(CHAR_VALUE_LIMIT);53char test = (char)(achar);54entryBuffer.append(test);55}56snippet = entryBuffer.toString();57snippet.toLowerCase();58if (x < TEST_SIZE)59L1.add(snippet);60else61L2.add(snippet);62}6364// Concatenate L1 and L2 to form L365//System.out.println("Generate L3");66for (int x=0; x<TEST_SIZE; x++) {67String entry = (String)L1.get(x) + (String)L2.get(x);68L3.add(entry);69}7071// Randomly toUpper L1 and L272//System.out.println("Modify L1 and L2");73for (int x=0; x<TEST_SIZE; x++) {74achar = generator.nextInt();75if (achar > 0) {76String mod = (String)L1.get(x);77mod = mod.toUpperCase();78L1.set(x, mod);79}80achar = generator.nextInt();81if (achar > 0) {82String mod = (String)L2.get(x);83mod = mod.toUpperCase();84L2.set(x, mod);85}86}8788// Concatenate L1 and L2 to form L489//System.out.println("Generate L4");90for (int x=0; x<TEST_SIZE; x++) {91String entry = (String)L1.get(x) + (String)L2.get(x);92L4.add(entry);93}9495// Sort L3 and L4 using case insensitive comparator96//System.out.println("Sort L3 and L4");97Collections.sort(L3, String.CASE_INSENSITIVE_ORDER);98Collections.sort(L4, String.CASE_INSENSITIVE_ORDER);99100// Check to see that order of L3 and L4 are identical101// ignoring case considerations102//System.out.println("Check order of L3 and L4");103for (int x=0; x<TEST_SIZE; x++) {104String one = (String)L3.get(x);105String two = (String)L4.get(x);106if (!one.equalsIgnoreCase(two))107throw new RuntimeException("Case Insensitive Sort Failure.");108}109110}111}112113114