blob: e564d965387c801420fc4cbfb615226da1409207 [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2002 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 4152868
27 * @summary test Case Insensitive Comparator in String
28 */
29
30import java.util.*;
31
32public class ICCBasher {
33
34 static final int TEST_SIZE = 20;
35 static final int STRING_SIZE = 5;
36 static final int CHAR_VALUE_LIMIT = 128;
37
38 public static void main(String[] args) throws Exception {
39 LinkedList L1 = new LinkedList();
40 LinkedList L2 = new LinkedList();
41 LinkedList L3 = new LinkedList();
42 LinkedList L4 = new LinkedList();
43
44 // First generate L1 and L2 with random lower case chars
45 //System.out.println("Generate L1 and L2");
46 Random generator = new Random();
47 int achar=0;
48 StringBuffer entryBuffer = new StringBuffer(10);
49 String snippet = null;
50 for (int x=0; x<TEST_SIZE * 2; x++) {
51 for(int y=0; y<STRING_SIZE; y++) {
52 achar = generator.nextInt(CHAR_VALUE_LIMIT);
53 char test = (char)(achar);
54 entryBuffer.append(test);
55 }
56 snippet = entryBuffer.toString();
57 snippet.toLowerCase();
58 if (x < TEST_SIZE)
59 L1.add(snippet);
60 else
61 L2.add(snippet);
62 }
63
64 // Concatenate L1 and L2 to form L3
65 //System.out.println("Generate L3");
66 for (int x=0; x<TEST_SIZE; x++) {
67 String entry = (String)L1.get(x) + (String)L2.get(x);
68 L3.add(entry);
69 }
70
71 // Randomly toUpper L1 and L2
72 //System.out.println("Modify L1 and L2");
73 for (int x=0; x<TEST_SIZE; x++) {
74 achar = generator.nextInt();
75 if (achar > 0) {
76 String mod = (String)L1.get(x);
77 mod = mod.toUpperCase();
78 L1.set(x, mod);
79 }
80 achar = generator.nextInt();
81 if (achar > 0) {
82 String mod = (String)L2.get(x);
83 mod = mod.toUpperCase();
84 L2.set(x, mod);
85 }
86 }
87
88 // Concatenate L1 and L2 to form L4
89 //System.out.println("Generate L4");
90 for (int x=0; x<TEST_SIZE; x++) {
91 String entry = (String)L1.get(x) + (String)L2.get(x);
92 L4.add(entry);
93 }
94
95 // Sort L3 and L4 using case insensitive comparator
96 //System.out.println("Sort L3 and L4");
97 Collections.sort(L3, String.CASE_INSENSITIVE_ORDER);
98 Collections.sort(L4, String.CASE_INSENSITIVE_ORDER);
99
100 // Check to see that order of L3 and L4 are identical
101 // ignoring case considerations
102 //System.out.println("Check order of L3 and L4");
103 for (int x=0; x<TEST_SIZE; x++) {
104 String one = (String)L3.get(x);
105 String two = (String)L4.get(x);
106 if (!one.equalsIgnoreCase(two))
107 throw new RuntimeException("Case Insensitive Sort Failure.");
108 }
109
110 }
111}