Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Collator/Regression.java
47182 views
/*1* Copyright (c) 1997, 2016, 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 4048446 4051866 4053636 4054238 4054734 4054736 4058613 4059820 406015426* 4062418 4065540 4066189 4066696 4076676 4078588 4079231 4081866 408724127* 4087243 4092260 4095316 4101940 4103436 4114076 4114077 4124632 413273628* 4133509 4139572 4141640 4179126 4179686 4244884 466322029* @library /java/text/testlib30* @summary Regression tests for Collation and associated classes31*/32/*33(C) Copyright Taligent, Inc. 1996 - All Rights Reserved34(C) Copyright IBM Corp. 1996 - All Rights Reserved3536The original version of this source code and documentation is copyrighted and37owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are38provided under terms of a License Agreement between Taligent and Sun. This39technology is protected by multiple US and International patents. This notice and40attribution to Taligent may not be removed.41Taligent is a registered trademark of Taligent, Inc.42*/4344import java.text.*;45import java.util.Locale;46import java.util.Vector;474849public class Regression extends CollatorTest {5051public static void main(String[] args) throws Exception {52new Regression().run(args);53}5455// CollationElementIterator.reset() doesn't work56//57public void Test4048446() {58CollationElementIterator i1 = en_us.getCollationElementIterator(test1);59CollationElementIterator i2 = en_us.getCollationElementIterator(test1);6061while ( i1.next() != CollationElementIterator.NULLORDER ) {62}63i1.reset();6465assertEqual(i1, i2);66}676869// Collator -> rules -> Collator round-trip broken for expanding characters70//71public void Test4051866() throws ParseException {72// Build a collator containing expanding characters73RuleBasedCollator c1 = new RuleBasedCollator("< o "74+"& oe ,o\u3080"75+"& oe ,\u1530 ,O"76+"& OE ,O\u3080"77+"& OE ,\u1520"78+"< p ,P");7980// Build another using the rules from the first81RuleBasedCollator c2 = new RuleBasedCollator(c1.getRules());8283// Make sure they're the same84if (!c1.getRules().equals(c2.getRules())) {85errln("Rules are not equal");86}87}8889// Collator thinks "black-bird" == "black"90//91public void Test4053636() {92if (en_us.equals("black-bird","black")) {93errln("black-bird == black");94}95}969798// CollationElementIterator will not work correctly if the associated99// Collator object's mode is changed100//101public void Test4054238() {102RuleBasedCollator c = (RuleBasedCollator) en_us.clone();103104c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);105CollationElementIterator i1 = en_us.getCollationElementIterator(test3);106107c.setDecomposition(Collator.NO_DECOMPOSITION);108CollationElementIterator i2 = en_us.getCollationElementIterator(test3);109110// At this point, BOTH iterators should use NO_DECOMPOSITION, since the111// collator itself is in that mode112assertEqual(i1, i2);113}114115// Collator.IDENTICAL documented but not implemented116//117public void Test4054734() {118RuleBasedCollator c = (RuleBasedCollator) en_us.clone();119try {120c.setStrength(Collator.IDENTICAL);121}122catch (Exception e) {123errln("Caught " + e.toString() + " setting Collator.IDENTICAL");124}125126String[] decomp = {127"\u0001", "<", "\u0002",128"\u0001", "=", "\u0001",129"A\u0001", ">", "~\u0002", // Ensure A and ~ are not compared bitwise130"\u00C0", "=", "A\u0300" // Decomp should make these equal131};132c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);133compareArray(c, decomp);134135String[] nodecomp = {136"\u00C0", ">", "A\u0300" // A-grave vs. A combining-grave137};138c.setDecomposition(Collator.NO_DECOMPOSITION);139compareArray(c, nodecomp);140}141142// Full Decomposition mode not implemented143//144public void Test4054736() {145RuleBasedCollator c = (RuleBasedCollator) en_us.clone();146c.setDecomposition(Collator.FULL_DECOMPOSITION);147148String[] tests = {149"\uFB4f", "=", "\u05D0\u05DC", // Alef-Lamed vs. Alef, Lamed150};151152compareArray(c, tests);153}154155// Collator.getInstance() causes an ArrayIndexOutofBoundsException for Korean156//157public void Test4058613() {158// Creating a default collator doesn't work when Korean is the default159// locale160161Locale oldDefault = Locale.getDefault();162163Locale.setDefault( Locale.KOREAN );164try {165Collator c = Collator.getInstance();166167// Since the fix to this bug was to turn of decomposition for Korean collators,168// ensure that's what we got169if (c.getDecomposition() != Collator.NO_DECOMPOSITION) {170errln("Decomposition is not set to NO_DECOMPOSITION");171}172}173finally {174Locale.setDefault(oldDefault);175}176}177178// RuleBasedCollator.getRules does not return the exact pattern as input179// for expanding character sequences180//181public void Test4059820() {182RuleBasedCollator c = null;183try {184c = new RuleBasedCollator("< a < b , c/a < d < z");185} catch (ParseException e) {186errln("Exception building collator: " + e.toString());187return;188}189if ( c.getRules().indexOf("c/a") == -1) {190errln("returned rules do not contain 'c/a'");191}192}193194// MergeCollation::fixEntry broken for "& H < \u0131, \u0130, i, I"195//196public void Test4060154() {197RuleBasedCollator c = null;198try {199c = new RuleBasedCollator("< g, G < h, H < i, I < j, J"200+ " & H < \u0131, \u0130, i, I" );201} catch (ParseException e) {202errln("Exception building collator: " + e.toString());203return;204}205c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);206207String[] tertiary = {208"A", "<", "B",209"H", "<", "\u0131",210"H", "<", "I",211"\u0131", "<", "\u0130",212"\u0130", "<", "i",213"\u0130", ">", "H",214};215c.setStrength(Collator.TERTIARY);216compareArray(c, tertiary);217218String[] secondary = {219"H", "<", "I",220"\u0131", "=", "\u0130",221};222c.setStrength(Collator.PRIMARY);223compareArray(c, secondary);224};225226// Secondary/Tertiary comparison incorrect in French Secondary227//228public void Test4062418() throws ParseException {229RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.FRANCE);230c.setStrength(Collator.SECONDARY);231232String[] tests = {233"p\u00eache", "<", "p\u00e9ch\u00e9", // Comparing accents from end, p\u00e9ch\u00e9 is greater234};235236compareArray(c, tests);237}238239// Collator.compare() method broken if either string contains spaces240//241public void Test4065540() {242if (en_us.compare("abcd e", "abcd f") == 0) {243errln("'abcd e' == 'abcd f'");244}245}246247// Unicode characters need to be recursively decomposed to get the248// correct result. For example,249// u1EB1 -> \u0103 + \u0300 -> a + \u0306 + \u0300.250//251public void Test4066189() {252String test1 = "\u1EB1";253String test2 = "a\u0306\u0300";254255RuleBasedCollator c1 = (RuleBasedCollator) en_us.clone();256c1.setDecomposition(Collator.FULL_DECOMPOSITION);257CollationElementIterator i1 = en_us.getCollationElementIterator(test1);258259RuleBasedCollator c2 = (RuleBasedCollator) en_us.clone();260c2.setDecomposition(Collator.NO_DECOMPOSITION);261CollationElementIterator i2 = en_us.getCollationElementIterator(test2);262263assertEqual(i1, i2);264}265266// French secondary collation checking at the end of compare iteration fails267//268public void Test4066696() {269RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.FRANCE);270c.setStrength(Collator.SECONDARY);271272String[] tests = {273"\u00e0", "<", "\u01fa", // a-grave < A-ring-acute274};275276compareArray(c, tests);277}278279280// Bad canonicalization of same-class combining characters281//282public void Test4076676() {283// These combining characters are all in the same class, so they should not284// be reordered, and they should compare as unequal.285String s1 = "A\u0301\u0302\u0300";286String s2 = "A\u0302\u0300\u0301";287288RuleBasedCollator c = (RuleBasedCollator) en_us.clone();289c.setStrength(Collator.TERTIARY);290291if (c.compare(s1,s2) == 0) {292errln("Same-class combining chars were reordered");293}294}295296297// RuleBasedCollator.equals(null) throws NullPointerException298//299public void Test4079231() {300try {301if (en_us.equals(null)) {302errln("en_us.equals(null) returned true");303}304}305catch (Exception e) {306errln("en_us.equals(null) threw " + e.toString());307}308}309310// RuleBasedCollator breaks on "< a < bb" rule311//312public void Test4078588() throws ParseException {313RuleBasedCollator rbc=new RuleBasedCollator("< a < bb");314315int result = rbc.compare("a","bb");316317if (result != -1) {318errln("Compare(a,bb) returned " + result + "; expected -1");319}320}321322// Combining characters in different classes not reordered properly.323//324public void Test4081866() throws ParseException {325// These combining characters are all in different classes,326// so they should be reordered and the strings should compare as equal.327String s1 = "A\u0300\u0316\u0327\u0315";328String s2 = "A\u0327\u0316\u0315\u0300";329330RuleBasedCollator c = (RuleBasedCollator) en_us.clone();331c.setStrength(Collator.TERTIARY);332333// Now that the default collators are set to NO_DECOMPOSITION334// (as a result of fixing bug 4114077), we must set it explicitly335// when we're testing reordering behavior. -- lwerner, 5/5/98336c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);337338if (c.compare(s1,s2) != 0) {339errln("Combining chars were not reordered");340}341}342343// string comparison errors in Scandinavian collators344//345public void Test4087241() {346RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(347new Locale("da", "DK"));348c.setStrength(Collator.SECONDARY);349350String[] tests = {351"\u007a", "<", "\u00e6", // z < ae352"a\u0308", "<", "a\u030a", // a-unlaut < a-ring353"Y", "<", "u\u0308", // Y < u-umlaut354};355356compareArray(c, tests);357}358359// CollationKey takes ignorable strings into account when it shouldn't360//361public void Test4087243() {362RuleBasedCollator c = (RuleBasedCollator) en_us.clone();363c.setStrength(Collator.TERTIARY);364365String[] tests = {366"123", "=", "123\u0001", // 1 2 3 = 1 2 3 ctrl-A367};368369compareArray(c, tests);370}371372// Mu/micro conflict373// Micro symbol and greek lowercase letter Mu should sort identically374//375public void Test4092260() {376Collator c = Collator.getInstance(new Locale("el", ""));377378// will only be equal when FULL_DECOMPOSITION is used379c.setDecomposition(Collator.FULL_DECOMPOSITION);380381String[] tests = {382"\u00B5", "=", "\u03BC",383};384385compareArray(c, tests);386}387388void Test4095316() {389Collator c = Collator.getInstance(new Locale("el", "GR"));390c.setStrength(Collator.TERTIARY);391// javadocs for RuleBasedCollator clearly specify that characters containing compatability392// chars MUST use FULL_DECOMPOSITION to get accurate comparisons.393c.setDecomposition(Collator.FULL_DECOMPOSITION);394395String[] tests = {396"\u03D4", "=", "\u03AB",397};398399compareArray(c, tests);400}401402public void Test4101940() {403try {404RuleBasedCollator c = new RuleBasedCollator("< a < b");405CollationElementIterator i = c.getCollationElementIterator("");406i.reset();407408if (i.next() != i.NULLORDER) {409errln("next did not return NULLORDER");410}411}412catch (Exception e) {413errln("Caught " + e );414}415}416417// Collator.compare not handling spaces properly418//419public void Test4103436() {420RuleBasedCollator c = (RuleBasedCollator) en_us.clone();421c.setStrength(Collator.TERTIARY);422423String[] tests = {424"file", "<", "file access",425"file", "<", "fileaccess",426};427428compareArray(c, tests);429}430431// Collation not Unicode conformant with Hangul syllables432//433public void Test4114076() {434RuleBasedCollator c = (RuleBasedCollator) en_us.clone();435c.setStrength(Collator.TERTIARY);436437//438// With Canonical decomposition, Hangul syllables should get decomposed439// into Jamo, but Jamo characters should not be decomposed into440// conjoining Jamo441//442c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);443String[] test1 = {444"\ud4db", "=", "\u1111\u1171\u11b6",445};446compareArray(c, test1);447448// Full decomposition result should be the same as canonical decomposition449// for all hangul.450c.setDecomposition(Collator.FULL_DECOMPOSITION);451compareArray(c, test1);452453}454455456// Collator.getCollationKey was hanging on certain character sequences457//458public void Test4124632() throws Exception {459Collator coll = Collator.getInstance(Locale.JAPAN);460461try {462coll.getCollationKey("A\u0308bc");463} catch (OutOfMemoryError e) {464errln("Ran out of memory -- probably an infinite loop");465}466}467468// sort order of french words with multiple accents has errors469//470public void Test4132736() {471Collator c = Collator.getInstance(Locale.FRANCE);472473String[] test1 = {474"e\u0300e\u0301", "<", "e\u0301e\u0300",475"e\u0300\u0301", ">", "e\u0301\u0300",476};477compareArray(c, test1);478}479480// The sorting using java.text.CollationKey is not in the exact order481//482public void Test4133509() {483String[] test1 = {484"Exception", "<", "ExceptionInInitializerError",485"Graphics", "<", "GraphicsEnvironment",486"String", "<", "StringBuffer",487};488compareArray(en_us, test1);489}490491// Collation with decomposition off doesn't work for Europe492//493public void Test4114077() {494// Ensure that we get the same results with decomposition off495// as we do with it on....496497RuleBasedCollator c = (RuleBasedCollator) en_us.clone();498c.setStrength(Collator.TERTIARY);499500String[] test1 = {501"\u00C0", "=", "A\u0300", // Should be equivalent502"p\u00eache", ">", "p\u00e9ch\u00e9",503"\u0204", "=", "E\u030F",504"\u01fa", "=", "A\u030a\u0301", // a-ring-acute -> a-ring, acute505// -> a, ring, acute506"A\u0300\u0316", "<", "A\u0316\u0300", // No reordering --> unequal507};508c.setDecomposition(Collator.NO_DECOMPOSITION);509compareArray(c, test1);510511String[] test2 = {512"A\u0300\u0316", "=", "A\u0316\u0300", // Reordering --> equal513};514c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);515compareArray(c, test2);516}517518// Support for Swedish gone in 1.1.6 (Can't create Swedish collator)519//520public void Test4141640() {521//522// Rather than just creating a Swedish collator, we might as well523// try to instantiate one for every locale available on the system524// in order to prevent this sort of bug from cropping up in the future525//526Locale[] locales = Collator.getAvailableLocales();527528for (int i = 0; i < locales.length; i++) {529try {530Collator c = Collator.getInstance(locales[i]);531} catch (Exception e) {532errln("Caught " + e + " creating collator for " + locales[i]);533}534}535}536537// getCollationKey throws exception for spanish text538// Cannot reproduce this bug on 1.2, however it DOES fail on 1.1.6539//540public void Test4139572() {541//542// Code pasted straight from the bug report543//544// create spanish locale and collator545Locale l = new Locale("es", "es");546Collator col = Collator.getInstance(l);547548// this spanish phrase kills it!549col.getCollationKey("Nombre De Objeto");550}551552// RuleBasedCollator doesn't use getCollationElementIterator internally553//554public void Test4146160() throws ParseException {555//556// Use a custom collator class whose getCollationElementIterator557// methods increment a count....558//559My4146160Collator.count = 0;560new My4146160Collator().getCollationKey("1");561if (My4146160Collator.count < 1) {562errln("getCollationElementIterator not called");563}564565My4146160Collator.count = 0;566new My4146160Collator().compare("1", "2");567if (My4146160Collator.count < 1) {568errln("getCollationElementIterator not called");569}570}571572static class My4146160Collator extends RuleBasedCollator {573public My4146160Collator() throws ParseException {574super(Regression.en_us.getRules());575}576577public CollationElementIterator getCollationElementIterator(578String text) {579count++;580return super.getCollationElementIterator(text);581}582public CollationElementIterator getCollationElementIterator(583CharacterIterator text) {584count++;585return super.getCollationElementIterator(text);586}587588public static int count = 0;589};590591// CollationElementIterator.previous broken for expanding char sequences592//593public void Test4179686() throws ParseException {594595// Create a collator with a few expanding character sequences in it....596RuleBasedCollator coll = new RuleBasedCollator(en_us.getRules()597+ " & ae ; \u00e4 & AE ; \u00c4"598+ " & oe ; \u00f6 & OE ; \u00d6"599+ " & ue ; \u00fc & UE ; \u00dc");600601String text = "T\u00f6ne"; // o-umlaut602603CollationElementIterator iter = coll.getCollationElementIterator(text);604Vector elements = new Vector();605int elem;606607// Iterate forward and collect all of the elements into a Vector608while ((elem = iter.next()) != iter.NULLORDER) {609elements.addElement(new Integer(elem));610}611612// Now iterate backward and make sure they're the same613int index = elements.size() - 1;614while ((elem = iter.previous()) != iter.NULLORDER) {615int expect = ((Integer)elements.elementAt(index)).intValue();616617if (elem != expect) {618errln("Mismatch at index " + index619+ ": got " + Integer.toString(elem,16)620+ ", expected " + Integer.toString(expect,16));621}622index--;623}624}625626public void Test4244884() throws ParseException {627RuleBasedCollator coll = (RuleBasedCollator)Collator.getInstance(Locale.US);628coll = new RuleBasedCollator(coll.getRules()629+ " & C < ch , cH , Ch , CH < cat < crunchy");630631String[] testStrings = new String[] {632"car",633"cave",634"clamp",635"cramp",636"czar",637"church",638"catalogue",639"crunchy",640"dog"641};642643for (int i = 1; i < testStrings.length; i++) {644if (coll.compare(testStrings[i - 1], testStrings[i]) >= 0) {645errln("error: \"" + testStrings[i - 1]646+ "\" is greater than or equal to \"" + testStrings[i]647+ "\".");648}649}650}651652public void Test4179216() throws ParseException {653// you can position a CollationElementIterator in the middle of654// a contracting character sequence, yielding a bogus collation655// element656RuleBasedCollator coll = (RuleBasedCollator)Collator.getInstance(Locale.US);657coll = new RuleBasedCollator(coll.getRules()658+ " & C < ch , cH , Ch , CH < cat < crunchy");659String testText = "church church catcatcher runcrunchynchy";660CollationElementIterator iter = coll.getCollationElementIterator(661testText);662663// test that the "ch" combination works properly664iter.setOffset(4);665int elt4 = CollationElementIterator.primaryOrder(iter.next());666667iter.reset();668int elt0 = CollationElementIterator.primaryOrder(iter.next());669670iter.setOffset(5);671int elt5 = CollationElementIterator.primaryOrder(iter.next());672673if (elt4 != elt0 || elt5 != elt0)674errln("The collation elements at positions 0 (" + elt0 + "), 4 ("675+ elt4 + "), and 5 (" + elt5 + ") don't match.");676677// test that the "cat" combination works properly678iter.setOffset(14);679int elt14 = CollationElementIterator.primaryOrder(iter.next());680681iter.setOffset(15);682int elt15 = CollationElementIterator.primaryOrder(iter.next());683684iter.setOffset(16);685int elt16 = CollationElementIterator.primaryOrder(iter.next());686687iter.setOffset(17);688int elt17 = CollationElementIterator.primaryOrder(iter.next());689690iter.setOffset(18);691int elt18 = CollationElementIterator.primaryOrder(iter.next());692693iter.setOffset(19);694int elt19 = CollationElementIterator.primaryOrder(iter.next());695696if (elt14 != elt15 || elt14 != elt16 || elt14 != elt17697|| elt14 != elt18 || elt14 != elt19)698errln("\"cat\" elements don't match: elt14 = " + elt14 + ", elt15 = "699+ elt15 + ", elt16 = " + elt16 + ", elt17 = " + elt17700+ ", elt18 = " + elt18 + ", elt19 = " + elt19);701702// now generate a complete list of the collation elements,703// first using next() and then using setOffset(), and704// make sure both interfaces return the same set of elements705iter.reset();706707int elt = iter.next();708int count = 0;709while (elt != CollationElementIterator.NULLORDER) {710++count;711elt = iter.next();712}713714String[] nextElements = new String[count];715String[] setOffsetElements = new String[count];716int lastPos = 0;717718iter.reset();719elt = iter.next();720count = 0;721while (elt != CollationElementIterator.NULLORDER) {722nextElements[count++] = testText.substring(lastPos, iter.getOffset());723lastPos = iter.getOffset();724elt = iter.next();725}726count = 0;727for (int i = 0; i < testText.length(); ) {728iter.setOffset(i);729lastPos = iter.getOffset();730elt = iter.next();731setOffsetElements[count++] = testText.substring(lastPos, iter.getOffset());732i = iter.getOffset();733}734for (int i = 0; i < nextElements.length; i++) {735if (nextElements[i].equals(setOffsetElements[i])) {736logln(nextElements[i]);737} else {738errln("Error: next() yielded " + nextElements[i] + ", but setOffset() yielded "739+ setOffsetElements[i]);740}741}742}743744public void Test4216006() throws Exception {745// rule parser barfs on "<\u00e0=a\u0300", and on other cases746// where the same token (after normalization) appears twice in a row747boolean caughtException = false;748try {749RuleBasedCollator dummy = new RuleBasedCollator("\u00e0<a\u0300");750}751catch (ParseException e) {752caughtException = true;753}754if (!caughtException) {755throw new Exception("\"a<a\" collation sequence didn't cause parse error!");756}757758RuleBasedCollator collator = new RuleBasedCollator("<\u00e0=a\u0300");759collator.setDecomposition(Collator.FULL_DECOMPOSITION);760collator.setStrength(Collator.IDENTICAL);761762String[] tests = {763"a\u0300", "=", "\u00e0",764"\u00e0", "=", "a\u0300"765};766767compareArray(collator, tests);768}769770public void Test4171974() {771// test French accent ordering more thoroughly772String[] frenchList = {773"\u0075\u0075", // u u774"\u00fc\u0075", // u-umlaut u775"\u01d6\u0075", // u-umlaut-macron u776"\u016b\u0075", // u-macron u777"\u1e7b\u0075", // u-macron-umlaut u778"\u0075\u00fc", // u u-umlaut779"\u00fc\u00fc", // u-umlaut u-umlaut780"\u01d6\u00fc", // u-umlaut-macron u-umlaut781"\u016b\u00fc", // u-macron u-umlaut782"\u1e7b\u00fc", // u-macron-umlaut u-umlaut783"\u0075\u01d6", // u u-umlaut-macron784"\u00fc\u01d6", // u-umlaut u-umlaut-macron785"\u01d6\u01d6", // u-umlaut-macron u-umlaut-macron786"\u016b\u01d6", // u-macron u-umlaut-macron787"\u1e7b\u01d6", // u-macron-umlaut u-umlaut-macron788"\u0075\u016b", // u u-macron789"\u00fc\u016b", // u-umlaut u-macron790"\u01d6\u016b", // u-umlaut-macron u-macron791"\u016b\u016b", // u-macron u-macron792"\u1e7b\u016b", // u-macron-umlaut u-macron793"\u0075\u1e7b", // u u-macron-umlaut794"\u00fc\u1e7b", // u-umlaut u-macron-umlaut795"\u01d6\u1e7b", // u-umlaut-macron u-macron-umlaut796"\u016b\u1e7b", // u-macron u-macron-umlaut797"\u1e7b\u1e7b" // u-macron-umlaut u-macron-umlaut798};799Collator french = Collator.getInstance(Locale.FRENCH);800801logln("Testing French order...");802checkListOrder(frenchList, french);803804logln("Testing French order without decomposition...");805french.setDecomposition(Collator.NO_DECOMPOSITION);806checkListOrder(frenchList, french);807808String[] englishList = {809"\u0075\u0075", // u u810"\u0075\u00fc", // u u-umlaut811"\u0075\u01d6", // u u-umlaut-macron812"\u0075\u016b", // u u-macron813"\u0075\u1e7b", // u u-macron-umlaut814"\u00fc\u0075", // u-umlaut u815"\u00fc\u00fc", // u-umlaut u-umlaut816"\u00fc\u01d6", // u-umlaut u-umlaut-macron817"\u00fc\u016b", // u-umlaut u-macron818"\u00fc\u1e7b", // u-umlaut u-macron-umlaut819"\u01d6\u0075", // u-umlaut-macron u820"\u01d6\u00fc", // u-umlaut-macron u-umlaut821"\u01d6\u01d6", // u-umlaut-macron u-umlaut-macron822"\u01d6\u016b", // u-umlaut-macron u-macron823"\u01d6\u1e7b", // u-umlaut-macron u-macron-umlaut824"\u016b\u0075", // u-macron u825"\u016b\u00fc", // u-macron u-umlaut826"\u016b\u01d6", // u-macron u-umlaut-macron827"\u016b\u016b", // u-macron u-macron828"\u016b\u1e7b", // u-macron u-macron-umlaut829"\u1e7b\u0075", // u-macron-umlaut u830"\u1e7b\u00fc", // u-macron-umlaut u-umlaut831"\u1e7b\u01d6", // u-macron-umlaut u-umlaut-macron832"\u1e7b\u016b", // u-macron-umlaut u-macron833"\u1e7b\u1e7b" // u-macron-umlaut u-macron-umlaut834};835Collator english = Collator.getInstance(Locale.ENGLISH);836837logln("Testing English order...");838checkListOrder(englishList, english);839840logln("Testing English order without decomposition...");841english.setDecomposition(Collator.NO_DECOMPOSITION);842checkListOrder(englishList, english);843}844845private void checkListOrder(String[] sortedList, Collator c) {846// this function uses the specified Collator to make sure the847// passed-in list is already sorted into ascending order848for (int i = 0; i < sortedList.length - 1; i++) {849if (c.compare(sortedList[i], sortedList[i + 1]) >= 0) {850errln("List out of order at element #" + i + ": "851+ prettify(sortedList[i]) + " >= "852+ prettify(sortedList[i + 1]));853}854}855}856857// CollationElementIterator set doesn't work propertly with next/prev858public void Test4663220() {859RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(Locale.US);860CharacterIterator stringIter = new StringCharacterIterator("fox");861CollationElementIterator iter = collator.getCollationElementIterator(stringIter);862863int[] elements_next = new int[3];864logln("calling next:");865for (int i = 0; i < 3; ++i) {866logln("[" + i + "] " + (elements_next[i] = iter.next()));867}868869int[] elements_fwd = new int[3];870logln("calling set/next:");871for (int i = 0; i < 3; ++i) {872iter.setOffset(i);873logln("[" + i + "] " + (elements_fwd[i] = iter.next()));874}875876for (int i = 0; i < 3; ++i) {877if (elements_next[i] != elements_fwd[i]) {878errln("mismatch at position " + i +879": " + elements_next[i] +880" != " + elements_fwd[i]);881}882}883}884885//------------------------------------------------------------------------886// Internal utilities887//888private void compareArray(Collator c, String[] tests) {889for (int i = 0; i < tests.length; i += 3) {890891int expect = 0;892if (tests[i+1].equals("<")) {893expect = -1;894} else if (tests[i+1].equals(">")) {895expect = 1;896} else if (tests[i+1].equals("=")) {897expect = 0;898} else {899expect = Integer.decode(tests[i+1]).intValue();900}901902int result = c.compare(tests[i], tests[i+2]);903if (sign(result) != sign(expect))904{905errln( i/3 + ": compare(" + prettify(tests[i])906+ " , " + prettify(tests[i+2])907+ ") got " + result + "; expected " + expect);908}909else910{911// Collator.compare worked OK; now try the collation keys912CollationKey k1 = c.getCollationKey(tests[i]);913CollationKey k2 = c.getCollationKey(tests[i+2]);914915result = k1.compareTo(k2);916if (sign(result) != sign(expect)) {917errln( i/3 + ": key(" + prettify(tests[i])918+ ").compareTo(key(" + prettify(tests[i+2])919+ ")) got " + result + "; expected " + expect);920921errln(" " + prettify(k1) + " vs. " + prettify(k2));922}923}924}925}926927private static final int sign(int i) {928if (i < 0) return -1;929if (i > 0) return 1;930return 0;931}932933934static RuleBasedCollator en_us = (RuleBasedCollator)Collator.getInstance(Locale.US);935936String test1 = "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?";937String test2 = "Xf ile What subset of all possible test cases has the lowest probability of detecting the least errors?";938String test3 = "a\u00FCbeck Gr\u00F6\u00DFe L\u00FCbeck";939}940941942