3 *******************************************************************************
4 * Copyright (C) 2002-2012, International Business Machines Corporation and *
5 * others. All Rights Reserved. *
6 *******************************************************************************
10 * Port From: ICU4C v2.1 : cintltest
11 * Source File: $ICU4CRoot/source/test/cintltest/cmsccoll.c
14 package com.ibm.icu.dev.test.collator;
16 import java.util.Arrays;
17 import java.util.Locale;
19 import java.util.TreeSet;
21 import com.ibm.icu.dev.test.TestFmwk;
22 import com.ibm.icu.impl.ICUResourceBundle;
23 import com.ibm.icu.impl.ImplicitCEGenerator;
24 import com.ibm.icu.impl.Utility;
25 import com.ibm.icu.lang.UCharacter;
26 import com.ibm.icu.lang.UProperty;
27 import com.ibm.icu.lang.UScript;
28 import com.ibm.icu.text.CollationElementIterator;
29 import com.ibm.icu.text.CollationKey;
30 import com.ibm.icu.text.CollationKey.BoundMode;
31 import com.ibm.icu.text.Collator;
32 import com.ibm.icu.text.Collator.ReorderCodes;
33 import com.ibm.icu.text.Normalizer;
34 import com.ibm.icu.text.RawCollationKey;
35 import com.ibm.icu.text.RuleBasedCollator;
36 import com.ibm.icu.text.UTF16;
37 import com.ibm.icu.text.UnicodeSet;
38 import com.ibm.icu.text.UnicodeSetIterator;
39 import com.ibm.icu.util.ULocale;
40 import com.ibm.icu.util.UResourceBundle;
42 public class CollationMiscTest extends TestFmwk {
44 public static void main(String[] args) throws Exception {
45 new CollationMiscTest().run(args);
46 // new CollationMiscTest().TestLocaleRuleBasedCollators();
49 //private static final int NORM_BUFFER_TEST_LEN_ = 32;
50 private static final class Tester
57 private static final boolean hasCollationElements(Locale locale)
59 ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,locale);
62 String collkey = rb.getStringWithFallback("collations/default");
63 ICUResourceBundle elements = rb.getWithFallback("collations/" + collkey);
64 if (elements != null) {
67 } catch (Exception e) {
73 public void TestComposeDecompose()
75 Tester t[] = new Tester[0x30000];
77 logln("Testing UCA extensively\n");
78 RuleBasedCollator coll;
80 coll = (RuleBasedCollator)Collator.getInstance(Locale.ENGLISH);
83 warnln("Error opening collator\n");
88 for (int u = 0; u < 0x30000; u ++) {
89 String comp = UTF16.valueOf(u);
90 int len = comp.length();
91 t[noCases].NFC = Normalizer.normalize(u, Normalizer.NFC);
92 t[noCases].NFD = Normalizer.normalize(u, Normalizer.NFD);
94 if (t[noCases].NFC.length() != t[noCases].NFD.length()
95 || (t[noCases].NFC.compareTo(t[noCases].NFD) != 0)
96 || (len != t[noCases].NFD.length())
97 || (comp.compareTo(t[noCases].NFD) != 0)) {
99 if (len != t[noCases].NFD.length()
100 || (comp.compareTo(t[noCases].NFD) != 0)) {
101 t[noCases].NFC = comp;
104 t[noCases] = new Tester();
108 for (int u = 0; u < noCases; u ++) {
109 if (!coll.equals(t[u].NFC, t[u].NFD)) {
110 errln("Failure: codePoint \\u" + Integer.toHexString(t[u].u)
111 + " fails TestComposeDecompose in the UCA");
112 CollationTest.doTest(this, coll, t[u].NFC, t[u].NFD, 0);
116 logln("Testing locales, number of cases = " + noCases);
117 Locale loc[] = Collator.getAvailableLocales();
118 for (int i = 0; i < loc.length; i ++) {
119 if (hasCollationElements(loc[i])) {
120 logln("Testing locale " + loc[i].getDisplayName());
121 coll = (RuleBasedCollator)Collator.getInstance(loc[i]);
122 coll.setStrength(Collator.IDENTICAL);
124 for (int u = 0; u < noCases; u ++) {
125 if (!coll.equals(t[u].NFC, t[u].NFD)) {
126 errln("Failure: codePoint \\u"
127 + Integer.toHexString(t[u].u)
128 + " fails TestComposeDecompose for locale "
129 + loc[i].getDisplayName());
130 // this tests for the iterators too
131 CollationTest.doTest(this, coll, t[u].NFC, t[u].NFD,
139 public void TestRuleOptions() {
140 // values here are hardcoded and are correct for the current UCA when
141 // the UCA changes, one might be forced to change these values.
144 * These strings contain the last character before [variable top]
145 * and the first and second characters (by primary weights) after it.
146 * See FractionalUCA.txt. For example:
147 [last variable [0C FE, 05, 05]] # U+10A7F OLD SOUTH ARABIAN NUMERIC INDICATOR
148 [variable top = 0C FE]
149 [first regular [0D 0A, 05, 05]] # U+0060 GRAVE ACCENT
151 00B4; [0D 0C, 05, 05]
153 * Note: Starting with UCA 6.0, the [variable top] collation element
154 * is not the weight of any character or string,
155 * which means that LAST_VARIABLE_CHAR_STRING sorts before [last variable].
157 String LAST_VARIABLE_CHAR_STRING = "\\U00010A7F";
158 String FIRST_REGULAR_CHAR_STRING = "\\u0060";
159 String SECOND_REGULAR_CHAR_STRING = "\\u00B4";
162 * This string has to match the character that has the [last regular] weight
163 * which changes with each UCA version.
164 * See the bottom of FractionalUCA.txt which says something like
165 [last regular [7A FE, 05, 05]] # U+1342E EGYPTIAN HIEROGLYPH AA032
167 * Note: Starting with UCA 6.0, the [last regular] collation element
168 * is not the weight of any character or string,
169 * which means that LAST_REGULAR_CHAR_STRING sorts before [last regular].
171 String LAST_REGULAR_CHAR_STRING = "\\U0001342E";
174 // cannot test this anymore, as [last primary ignorable] doesn't
175 // have a code point associated to it anymore
176 // "&[before 3][last primary ignorable]<<<k",
177 // - all befores here amount to zero
178 "&[before 3][first tertiary ignorable]<<<a",
179 "&[before 3][last tertiary ignorable]<<<a",
180 "&[before 3][first secondary ignorable]<<<a",
181 "&[before 3][last secondary ignorable]<<<a",
183 "&[before 3][first primary ignorable]<<<c<<<b &[first primary ignorable]<a",
184 // we don't have a code point that corresponds to the last primary
186 "&[before 3][last primary ignorable]<<<c<<<b &[last primary ignorable]<a",
187 "&[before 3][first variable]<<<c<<<b &[first variable]<a",
188 "&[last variable]<a &[before 3][last variable]<<<c<<<b ",
189 "&[first regular]<a &[before 1][first regular]<b",
190 "&[before 1][last regular]<b &[last regular]<a",
191 "&[before 1][first implicit]<b &[first implicit]<a",
192 "&[before 1][last implicit]<b &[last implicit]<a",
193 "&[last variable]<z&[last primary ignorable]<x&[last secondary ignorable]<<y&[last tertiary ignorable]<<<w&[top]<u",
197 {"\\u0000", "a"}, // you cannot go before first tertiary ignorable
198 {"\\u0000", "a"}, // you cannot go before last tertiary ignorable
199 {"\\u0000", "a"}, // you cannot go before first secondary ignorable
200 {"\\u0000", "a"}, // you cannot go before first secondary ignorable
201 {"c", "b", "\\u0332", "a"},
202 {"\\u0332", "\\u20e3", "c", "b", "a"},
203 {"c", "b", "\\u0009", "a", "\\u000a"},
204 {LAST_VARIABLE_CHAR_STRING, "c", "b", /* [last variable] */ "a", FIRST_REGULAR_CHAR_STRING},
205 {"b", FIRST_REGULAR_CHAR_STRING, "a", SECOND_REGULAR_CHAR_STRING},
206 // The character in the second ordering test string
207 // has to match the character that has the [last regular] weight
208 // which changes with each UCA version.
209 // See the bottom of FractionalUCA.txt which says something like
210 // [last regular [CE 27, 05, 05]] # U+1342E EGYPTIAN HIEROGLYPH AA032
211 {LAST_REGULAR_CHAR_STRING, "b", /* [last regular] */ "a", "\\u4e00"},
212 {"b", "\\u4e00", "a", "\\u4e01"},
213 {"b", "\\U0010FFFD", "a"},
214 {"\ufffb", "w", "y", "\u20e3", "x", LAST_VARIABLE_CHAR_STRING, "z", "u"},
217 for (int i = 0; i< rules.length; i++) {
218 logln(String.format("rules[%d] = \"%s\"", i, rules[i]));
219 genericRulesStarter(rules[i], data[i]);
223 void genericRulesStarter(String rules, String[] s) {
224 genericRulesStarterWithResult(rules, s, -1);
227 void genericRulesStarterWithResult(String rules, String[] s, int result) {
229 RuleBasedCollator coll = null;
231 coll = new RuleBasedCollator(rules);
232 // logln("Rules starter for " + rules);
233 genericOrderingTestWithResult(coll, s, result);
234 } catch (Exception e) {
235 warnln("Unable to open collator with rules " + rules);
239 void genericRulesStarterWithOptionsAndResult(String rules, String[] s, String[] atts, Object[] attVals, int result) {
240 RuleBasedCollator coll = null;
242 coll = new RuleBasedCollator(rules);
243 genericOptionsSetter(coll, atts, attVals);
244 genericOrderingTestWithResult(coll, s, result);
245 } catch (Exception e) {
246 warnln("Unable to open collator with rules " + rules);
249 void genericOrderingTestWithResult(Collator coll, String[] s, int result) {
253 for(int i = 0; i < s.length - 1; i++) {
254 for(int j = i+1; j < s.length; j++) {
255 t1 = Utility.unescape(s[i]);
256 t2 = Utility.unescape(s[j]);
257 // System.out.println(i + " " + j);
258 CollationTest.doTest(this, (RuleBasedCollator)coll, t1, t2,
264 void reportCResult(String source, String target, CollationKey sourceKey, CollationKey targetKey,
265 int compareResult, int keyResult, int incResult, int expectedResult ) {
266 if (expectedResult < -1 || expectedResult > 1) {
267 errln("***** invalid call to reportCResult ****");
270 boolean ok1 = (compareResult == expectedResult);
271 boolean ok2 = (keyResult == expectedResult);
272 boolean ok3 = (incResult == expectedResult);
273 if (ok1 && ok2 && ok3 /* synwee to undo && !isVerbose()*/) {
276 String msg1 = ok1? "Ok: compare(\"" : "FAIL: compare(\"";
277 String msg2 = "\", \"";
278 String msg3 = "\") returned ";
279 String msg4 = "; expected ";
280 String sExpect = new String("");
281 String sResult = new String("");
282 sResult = appendCompareResult(compareResult, sResult);
283 sExpect = appendCompareResult(expectedResult, sExpect);
285 // logln(msg1 + source + msg2 + target + msg3 + sResult);
287 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
289 msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
290 msg2 = "\").compareTo(key(\"";
291 msg3 = "\")) returned ";
292 sResult = appendCompareResult(keyResult, sResult);
294 // logln(msg1 + source + msg2 + target + msg3 + sResult);
296 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
299 errln(msg1 + prettify(sourceKey) + msg2 + prettify(targetKey));
301 msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
303 msg3 = "\") returned ";
304 sResult = appendCompareResult(incResult, sResult);
306 // logln(msg1 + source + msg2 + target + msg3 + sResult);
308 errln(msg1 + source + msg2 + target + msg3 + sResult + msg4 + sExpect);
313 String appendCompareResult(int result, String target) {
314 if (result == -1) { //LESS
316 } else if (result == 0) { //EQUAL
318 } else if (result == 1) { //GREATER
322 target += huh + result;
327 static String prettify(CollationKey sourceKey) {
329 byte[] bytes= sourceKey.toByteArray();
330 StringBuilder target = new StringBuilder("[");
332 for (i = 0; i < bytes.length; i++) {
333 String numStr = Integer.toHexString(bytes[i] & 0xff);
334 if (numStr.length() < 2) {
337 target.append(numStr).append(' ');
340 return target.toString();
343 public void TestBeforePrefixFailure() {
345 "&g <<< a&[before 3]\uff41 <<< x",
346 "&\u30A7=\u30A7=\u3047=\uff6a&\u30A8=\u30A8=\u3048=\uff74&[before 3]\u30a7<<<\u30a9",
347 "&[before 3]\u30a7<<<\u30a9&\u30A7=\u30A7=\u3047=\uff6a&\u30A8=\u30A8=\u3048=\uff74",
351 {"\u30a9", "\u30a7"},
352 {"\u30a9", "\u30a7"},
355 for(int i = 0; i< rules.length; i++) {
356 genericRulesStarter(rules[i], data[i]);
360 public void TestContractionClosure() {
366 { "b", "\u00e4\u00e4", "a\u0308a\u0308", "\u00e4a\u0308", "a\u0308\u00e4" },
367 { "b", "\u00C5", "A\u030A", "\u212B" },
370 for(int i = 0; i< rules.length; i++) {
371 genericRulesStarterWithResult(rules[i], data[i], 0);
375 public void TestPrefixCompose() {
376 String rule1 = "&\u30a7<<<\u30ab|\u30fc=\u30ac|\u30fc";
378 String string = rule1;
380 RuleBasedCollator coll = new RuleBasedCollator(string);
381 logln("rule:" + coll.getRules());
382 } catch (Exception e) {
383 warnln("Error open RuleBasedCollator rule = " + string);
387 public void TestStrCollIdenticalPrefix() {
388 String rule = "&\ud9b0\udc70=\ud9b0\udc71";
393 genericRulesStarterWithResult(rule, test, 0);
396 public void TestPrefix() {
400 "[strength I]&a=\ud900\udc25&z<<<\ud900\udc25|a",
405 {"aa", "az", "\ud900\udc25z", "\ud900\udc25a", "zz"},
408 for(int i = 0; i<rules.length; i++) {
409 genericRulesStarter(rules[i], data[i]);
413 public void TestNewJapanese() {
416 "\u30b7\u30e3\u30fc\u30ec",
417 "\u30b7\u30e3\u30a4",
418 "\u30b7\u30e4\u30a3",
419 "\u30b7\u30e3\u30ec",
420 "\u3061\u3087\u3053",
421 "\u3061\u3088\u3053",
422 "\u30c1\u30e7\u30b3\u30ec\u30fc\u30c8",
423 "\u3066\u30fc\u305f",
424 "\u30c6\u30fc\u30bf",
425 "\u30c6\u30a7\u30bf",
426 "\u3066\u3048\u305f",
427 "\u3067\u30fc\u305f",
428 "\u30c7\u30fc\u30bf",
429 "\u30c7\u30a7\u30bf",
430 "\u3067\u3048\u305f",
431 "\u3066\u30fc\u305f\u30fc",
432 "\u30c6\u30fc\u30bf\u30a1",
433 "\u30c6\u30a7\u30bf\u30fc",
434 "\u3066\u3047\u305f\u3041",
435 "\u3066\u3048\u305f\u30fc",
436 "\u3067\u30fc\u305f\u30fc",
437 "\u30c7\u30fc\u30bf\u30a1",
438 "\u3067\u30a7\u305f\u30a1",
439 "\u30c7\u3047\u30bf\u3041",
440 "\u30c7\u30a8\u30bf\u30a2",
442 "\u3073\u3085\u3042",
443 "\u3074\u3085\u3042",
444 "\u3073\u3085\u3042\u30fc",
445 "\u30d3\u30e5\u30a2\u30fc",
446 "\u3074\u3085\u3042\u30fc",
447 "\u30d4\u30e5\u30a2\u30fc",
448 "\u30d2\u30e5\u30a6",
449 "\u30d2\u30e6\u30a6",
450 "\u30d4\u30e5\u30a6\u30a2",
451 "\u3073\u3085\u30fc\u3042\u30fc",
452 "\u30d3\u30e5\u30fc\u30a2\u30fc",
453 "\u30d3\u30e5\u30a6\u30a2\u30fc",
454 "\u3072\u3085\u3093",
455 "\u3074\u3085\u3093",
456 "\u3075\u30fc\u308a",
457 "\u30d5\u30fc\u30ea",
458 "\u3075\u3045\u308a",
459 "\u3075\u30a5\u308a",
460 "\u3075\u30a5\u30ea",
461 "\u30d5\u30a6\u30ea",
462 "\u3076\u30fc\u308a",
463 "\u30d6\u30fc\u30ea",
464 "\u3076\u3045\u308a",
465 "\u30d6\u30a5\u308a",
466 "\u3077\u3046\u308a",
467 "\u30d7\u30a6\u30ea",
468 "\u3075\u30fc\u308a\u30fc",
469 "\u30d5\u30a5\u30ea\u30fc",
470 "\u3075\u30a5\u308a\u30a3",
471 "\u30d5\u3045\u308a\u3043",
472 "\u30d5\u30a6\u30ea\u30fc",
473 "\u3075\u3046\u308a\u3043",
474 "\u30d6\u30a6\u30ea\u30a4",
475 "\u3077\u30fc\u308a\u30fc",
476 "\u3077\u30a5\u308a\u30a4",
477 "\u3077\u3046\u308a\u30fc",
478 "\u30d7\u30a6\u30ea\u30a4",
495 "\u306f\u309d", // H\u309d
496 "\u30cf\u30fd", // K\u30fd
497 "\u306f\u306f", // HH
498 "\u306f\u30cf", // HK
499 "\u30cf\u30cf", // KK
500 "\u306f\u309e", // H\u309e
501 "\u30cf\u30fe", // K\u30fe
502 "\u306f\u3070", // HH\u309b
503 "\u30cf\u30d0", // KK\u309b
504 "\u306f\u3071", // HH\u309c
505 "\u30cf\u3071", // KH\u309c
506 "\u30cf\u30d1", // KK\u309c
507 "\u3070\u309d", // H\u309b\u309d
508 "\u30d0\u30fd", // K\u309b\u30fd
509 "\u3070\u306f", // H\u309bH
510 "\u30d0\u30cf", // K\u309bK
511 "\u3070\u309e", // H\u309b\u309e
512 "\u30d0\u30fe", // K\u309b\u30fe
513 "\u3070\u3070", // H\u309bH\u309b
514 "\u30d0\u3070", // K\u309bH\u309b
515 "\u30d0\u30d0", // K\u309bK\u309b
516 "\u3070\u3071", // H\u309bH\u309c
517 "\u30d0\u30d1", // K\u309bK\u309c
518 "\u3071\u309d", // H\u309c\u309d
519 "\u30d1\u30fd", // K\u309c\u30fd
520 "\u3071\u306f", // H\u309cH
521 "\u30d1\u30cf", // K\u309cK
522 "\u3071\u3070", // H\u309cH\u309b
523 "\u3071\u30d0", // H\u309cK\u309b
524 "\u30d1\u30d0", // K\u309cK\u309b
525 "\u3071\u3071", // H\u309cH\u309c
526 "\u30d1\u30d1", // K\u309cK\u309c
529 String[] att = { "strength", };
530 Object[] val = { new Integer(Collator.QUATERNARY), };
532 String[] attShifted = { "strength", "AlternateHandling"};
533 Object valShifted[] = { new Integer(Collator.QUATERNARY),
536 genericLocaleStarterWithOptions(Locale.JAPANESE, test1, att, val);
537 genericLocaleStarterWithOptions(Locale.JAPANESE, test2, att, val);
539 genericLocaleStarterWithOptions(Locale.JAPANESE, test1, attShifted,
541 genericLocaleStarterWithOptions(Locale.JAPANESE, test2, attShifted,
545 void genericLocaleStarter(Locale locale, String s[]) {
546 RuleBasedCollator coll = null;
548 coll = (RuleBasedCollator)Collator.getInstance(locale);
550 } catch (Exception e) {
551 warnln("Unable to open collator for locale " + locale);
554 // logln("Locale starter for " + locale);
555 genericOrderingTest(coll, s);
558 void genericLocaleStarterWithOptions(Locale locale, String[] s, String[] attrs, Object[] values) {
559 genericLocaleStarterWithOptionsAndResult(locale, s, attrs, values, -1);
562 private void genericOptionsSetter(RuleBasedCollator coll, String[] attrs, Object[] values) {
563 for(int i = 0; i < attrs.length; i++) {
564 if (attrs[i].equals("strength")) {
565 coll.setStrength(((Integer)values[i]).intValue());
567 else if (attrs[i].equals("decomp")) {
568 coll.setDecomposition(((Integer)values[i]).intValue());
570 else if (attrs[i].equals("AlternateHandling")) {
571 coll.setAlternateHandlingShifted(((Boolean)values[i]
574 else if (attrs[i].equals("NumericCollation")) {
575 coll.setNumericCollation(((Boolean)values[i]).booleanValue());
577 else if (attrs[i].equals("UpperFirst")) {
578 coll.setUpperCaseFirst(((Boolean)values[i]).booleanValue());
580 else if (attrs[i].equals("LowerFirst")) {
581 coll.setLowerCaseFirst(((Boolean)values[i]).booleanValue());
583 else if (attrs[i].equals("CaseLevel")) {
584 coll.setCaseLevel(((Boolean)values[i]).booleanValue());
589 void genericLocaleStarterWithOptionsAndResult(Locale locale, String[] s, String[] attrs, Object[] values, int result) {
590 RuleBasedCollator coll = null;
592 coll = (RuleBasedCollator)Collator.getInstance(locale);
593 } catch (Exception e) {
594 warnln("Unable to open collator for locale " + locale);
597 // logln("Locale starter for " +locale);
599 // logln("Setting attributes");
600 genericOptionsSetter(coll, attrs, values);
602 genericOrderingTestWithResult(coll, s, result);
605 void genericOrderingTest(Collator coll, String[] s) {
606 genericOrderingTestWithResult(coll, s, -1);
609 public void TestNonChars() {
611 "\u0000", /* ignorable */
612 "\uFFFE", /* special merge-sort character with minimum non-ignorable weights */
614 "\\U0001FFFE", "\\U0001FFFF", /* UCA 6.0: noncharacters are treated like unassigned, */
615 "\\U0002FFFE", "\\U0002FFFF", /* not like ignorable. */
616 "\\U0003FFFE", "\\U0003FFFF",
617 "\\U0004FFFE", "\\U0004FFFF",
618 "\\U0005FFFE", "\\U0005FFFF",
619 "\\U0006FFFE", "\\U0006FFFF",
620 "\\U0007FFFE", "\\U0007FFFF",
621 "\\U0008FFFE", "\\U0008FFFF",
622 "\\U0009FFFE", "\\U0009FFFF",
623 "\\U000AFFFE", "\\U000AFFFF",
624 "\\U000BFFFE", "\\U000BFFFF",
625 "\\U000CFFFE", "\\U000CFFFF",
626 "\\U000DFFFE", "\\U000DFFFF",
627 "\\U000EFFFE", "\\U000EFFFF",
628 "\\U000FFFFE", "\\U000FFFFF",
629 "\\U0010FFFE", "\\U0010FFFF",
630 "\uFFFF" /* special character with maximum primary weight */
632 Collator coll = null;
634 coll = Collator.getInstance(new Locale("en", "US"));
635 } catch (Exception e) {
636 warnln("Unable to open collator");
639 // logln("Test non characters");
641 genericOrderingTestWithResult(coll, test, -1);
644 public void TestExtremeCompression() {
645 String[] test = new String[4];
647 for(int i = 0; i<4; i++) {
648 StringBuffer temp = new StringBuffer();
649 for (int j = 0; j < 2047; j++) {
652 temp.append((char)('a' + i));
653 test[i] = temp.toString();
656 genericLocaleStarter(new Locale("en", "US"), test);
660 * Tests surrogate support.
662 public void TestSurrogates() {
663 String test[] = {"z","\ud900\udc25", "\ud805\udc50", "\ud800\udc00y",
664 "\ud800\udc00r", "\ud800\udc00f", "\ud800\udc00",
665 "\ud800\udc00c", "\ud800\udc00b", "\ud800\udc00fa",
666 "\ud800\udc00fb", "\ud800\udc00a", "c", "b"};
668 String rule = "&z < \ud900\udc25 < \ud805\udc50 < \ud800\udc00y "
669 + "< \ud800\udc00r < \ud800\udc00f << \ud800\udc00 "
670 + "< \ud800\udc00fa << \ud800\udc00fb < \ud800\udc00a "
672 genericRulesStarter(rule, test);
675 public void TestBocsuCoverage() {
676 String test = "\u0041\u0441\u4441\\U00044441\u4441\u0441\u0041";
677 Collator coll = Collator.getInstance();
678 coll.setStrength(Collator.IDENTICAL);
679 CollationKey key = coll.getCollationKey(test);
680 logln("source:" + key.getSourceString());
683 public void TestCyrillicTailoring() {
689 genericLocaleStarter(new Locale("en", ""), test);
690 genericRulesStarter("&\u0410 = \u0410", test);
691 genericRulesStarter("&Z < \u0410", test);
692 genericRulesStarter("&\u0410 = \u0410 < \u04d0", test);
693 genericRulesStarter("&Z < \u0410 < \u04d0", test);
694 genericRulesStarter("&\u0410 = \u0410 < \u0410\u0301", test);
695 genericRulesStarter("&Z < \u0410 < \u0410\u0301", test);
698 public void TestSuppressContractions() {
699 String testNoCont2[] = {
704 String testNoCont[] = {
710 genericRulesStarter("[suppressContractions [\u0400-\u047f]]", testNoCont);
711 genericRulesStarter("[suppressContractions [\u0400-\u047f]]", testNoCont2);
714 public void TestCase() {
715 String gRules = "\u0026\u0030\u003C\u0031\u002C\u2460\u003C\u0061\u002C\u0041";
716 String[] testCase = {
717 "1a", "1A", "\u2460a", "\u2460A"
719 int[][] caseTestResults = {
720 { -1, -1, -1, 0, -1, -1, 0, 0, -1 },
721 { 1, -1, -1, 0, -1, -1, 0, 0, 1 },
722 { -1, -1, -1, 0, 1, -1, 0, 0, -1 },
723 { 1, -1, 1, 0, -1, -1, 0, 0, 1 }
726 boolean[][] caseTestAttributes = {
734 Collator myCollation;
736 myCollation = Collator.getInstance(new Locale("en", "US"));
737 } catch (Exception e) {
738 warnln("ERROR: in creation of rule based collator ");
741 // logln("Testing different case settings");
742 myCollation.setStrength(Collator.TERTIARY);
744 for(k = 0; k <4; k++) {
745 if (caseTestAttributes[k][0] == true) {
747 ((RuleBasedCollator)myCollation).setUpperCaseFirst(true);
751 ((RuleBasedCollator)myCollation).setLowerCaseFirst(true);
753 ((RuleBasedCollator)myCollation).setCaseLevel(
754 caseTestAttributes[k][1]);
756 // logln("Case first = " + caseTestAttributes[k][0] + ", Case level = " + caseTestAttributes[k][1]);
757 for (i = 0; i < 3 ; i++) {
758 for(j = i+1; j<4; j++) {
759 CollationTest.doTest(this,
760 (RuleBasedCollator)myCollation,
761 testCase[i], testCase[j],
762 caseTestResults[k][3*i+j-1]);
767 myCollation = new RuleBasedCollator(gRules);
768 } catch (Exception e) {
769 warnln("ERROR: in creation of rule based collator");
772 // logln("Testing different case settings with custom rules");
773 myCollation.setStrength(Collator.TERTIARY);
775 for(k = 0; k<4; k++) {
776 if (caseTestAttributes[k][0] == true) {
777 ((RuleBasedCollator)myCollation).setUpperCaseFirst(true);
780 ((RuleBasedCollator)myCollation).setUpperCaseFirst(false);
782 ((RuleBasedCollator)myCollation).setCaseLevel(
783 caseTestAttributes[k][1]);
784 for (i = 0; i < 3 ; i++) {
785 for(j = i+1; j<4; j++) {
786 CollationTest.doTest(this,
787 (RuleBasedCollator)myCollation,
788 testCase[i], testCase[j],
789 caseTestResults[k][3*i+j-1]);
795 String[] lowerFirst = {
811 String[] upperFirst = {
826 // logln("mixed case test");
827 // logln("lower first, case level off");
828 genericRulesStarter("[casefirst lower]&H<ch<<<Ch<<<CH", lowerFirst);
829 // logln("upper first, case level off");
830 genericRulesStarter("[casefirst upper]&H<ch<<<Ch<<<CH", upperFirst);
831 // logln("lower first, case level on");
832 genericRulesStarter("[casefirst lower][caselevel on]&H<ch<<<Ch<<<CH", lowerFirst);
833 // logln("upper first, case level on");
834 genericRulesStarter("[casefirst upper][caselevel on]&H<ch<<<Ch<<<CH", upperFirst);
838 public void TestIncompleteCnt() {
864 RuleBasedCollator coll = null;
865 String temp = " & Z < ABC < Q < B";
867 coll = new RuleBasedCollator(temp);
868 } catch (Exception e) {
869 warnln("fail to create RuleBasedCollator");
873 int size = cnt1.length;
874 for(int i = 0; i < size-1; i++) {
875 for(int j = i+1; j < size; j++) {
878 CollationTest.doTest(this, coll, t1, t2, -1);
882 temp = " & Z < DAVIS < MARK <DAV";
884 coll = new RuleBasedCollator(temp);
885 } catch (Exception e) {
886 warnln("fail to create RuleBasedCollator");
891 for(int i = 0; i < size-1; i++) {
892 for(int j = i+1; j < size; j++) {
895 CollationTest.doTest(this, coll, t1, t2, -1);
900 public void TestBlackBird() {
912 int[] shiftedTert = {
923 String[] nonignorable = {
936 Collator coll = Collator.getInstance(new Locale("en", "US"));
937 //ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_OFF, &status);
938 //ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &status);
939 ((RuleBasedCollator)coll).setAlternateHandlingShifted(false);
940 size = nonignorable.length;
941 for(i = 0; i < size-1; i++) {
942 for(j = i+1; j < size; j++) {
943 String t1 = nonignorable[i];
944 String t2 = nonignorable[j];
945 CollationTest.doTest(this, (RuleBasedCollator)coll, t1, t2, -1);
948 ((RuleBasedCollator)coll).setAlternateHandlingShifted(true);
949 coll.setStrength(Collator.QUATERNARY);
950 size = shifted.length;
951 for(i = 0; i < size-1; i++) {
952 for(j = i+1; j < size; j++) {
953 String t1 = shifted[i];
954 String t2 = shifted[j];
955 CollationTest.doTest(this, (RuleBasedCollator)coll, t1, t2, -1);
958 coll.setStrength(Collator.TERTIARY);
959 size = shifted.length;
960 for(i = 1; i < size; i++) {
961 String t1 = shifted[i-1];
962 String t2 = shifted[i];
963 CollationTest.doTest(this, (RuleBasedCollator)coll, t1, t2,
968 public void TestFunkyA() {
969 String[] testSourceCases = {
970 "\u0041\u0300\u0301",
971 "\u0041\u0300\u0316",
974 // this would work with forced normalization
978 String[] testTargetCases = {
979 "\u0041\u0301\u0300",
980 "\u0041\u0316\u0300",
982 "\u0041\u0301\u0300",
983 // this would work with forced normalization
984 "\u0041\u0316\u0300",
995 Collator myCollation;
997 myCollation = Collator.getInstance(new Locale("en", "US"));
998 } catch (Exception e) {
999 warnln("ERROR: in creation of rule based collator");
1002 // logln("Testing some A letters, for some reason");
1003 myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
1004 myCollation.setStrength(Collator.TERTIARY);
1005 for (int i = 0; i < 4 ; i++)
1007 CollationTest.doTest(this, (RuleBasedCollator)myCollation,
1008 testSourceCases[i], testTargetCases[i],
1013 public void TestChMove() {
1017 "ca", "cb", "cx", "cy", "CZ",
1018 "c\u030C", "C\u030C",
1021 "ha", "Ha", "harly", "hb", "HB", "hx", "HX", "hy", "HY",
1022 "ch", "cH", "Ch", "CH",
1023 "cha", "charly", "che", "chh", "chch", "chr",
1026 "r\u030C", "R\u030C",
1029 "s\u030C", "S\u030C",
1031 "z\u030C", "Z\u030C"
1033 Collator coll = null;
1035 coll = Collator.getInstance(new Locale("cs", ""));
1036 } catch (Exception e) {
1037 warnln("Cannot create Collator");
1040 int size = chTest.length;
1041 for(int i = 0; i < size-1; i++) {
1042 for(int j = i+1; j < size; j++) {
1043 String t1 = chTest[i];
1044 String t2 = chTest[j];
1045 CollationTest.doTest(this, (RuleBasedCollator)coll, t1, t2, -1);
1050 public void TestImplicitTailoring() {
1051 String rules[] = { "&[before 1]\u4e00 < b < c &[before 1]\u4e00 < d < e",
1052 "&\u4e00 < a <<< A < b <<< B",
1053 "&[before 1]\u4e00 < \u4e01 < \u4e02",
1054 "&[before 1]\u4e01 < \u4e02 < \u4e03",
1056 String cases[][] = {
1057 { "d", "e", "b", "c", "\u4e00"},
1058 { "\u4e00", "a", "A", "b", "B", "\u4e01"},
1059 { "\u4e01", "\u4e02", "\u4e00"},
1060 { "\u4e02", "\u4e03", "\u4e01"},
1065 for(i = 0; i < rules.length; i++) {
1066 genericRulesStarter(rules[i], cases[i]);
1071 public void TestFCDProblem() {
1072 String s1 = "\u0430\u0306\u0325";
1073 String s2 = "\u04D1\u0325";
1074 Collator coll = null;
1076 coll = Collator.getInstance();
1077 } catch (Exception e) {
1078 warnln("Can't create collator");
1082 coll.setDecomposition(Collator.NO_DECOMPOSITION);
1083 CollationTest.doTest(this, (RuleBasedCollator)coll, s1, s2, 0);
1084 coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
1085 CollationTest.doTest(this, (RuleBasedCollator)coll, s1, s2, 0);
1088 public void TestEmptyRule() {
1091 RuleBasedCollator coll = new RuleBasedCollator(rulez);
1092 logln("rule:" + coll.getRules());
1093 } catch (Exception e) {
1094 warnln(e.getMessage());
1098 /* superseded by TestBeforePinyin, since Chinese collation rules have changed */
1100 public void TestJ784() {
1102 "A", "\u0101", "\u00e1", "\u01ce", "\u00e0",
1103 "E", "\u0113", "\u00e9", "\u011b", "\u00e8",
1104 "I", "\u012b", "\u00ed", "\u01d0", "\u00ec",
1105 "O", "\u014d", "\u00f3", "\u01d2", "\u00f2",
1106 "U", "\u016b", "\u00fa", "\u01d4", "\u00f9",
1107 "\u00fc", "\u01d6", "\u01d8", "\u01da", "\u01dc"
1109 genericLocaleStarter(new Locale("zh", ""), data);
1113 public void TestJ815() {
1130 genericLocaleStarter(new Locale("fr", ""), data);
1131 genericRulesStarter("[backwards 2]&A<<\u00e6/e<<<\u00c6/E", data);
1134 public void TestJ3087()
1136 String rule[] = {"&h<H&CH=\u0427",
1139 RuleBasedCollator rbc = null;
1140 CollationElementIterator iter1;
1141 CollationElementIterator iter2;
1142 for (int i = 0; i < rule.length; i ++) {
1144 rbc = new RuleBasedCollator(rule[i]);
1145 } catch (Exception e) {
1146 warnln(e.getMessage());
1149 iter1 = rbc.getCollationElementIterator("CH");
1150 iter2 = rbc.getCollationElementIterator("\u0427");
1151 int ce1 = CollationElementIterator.IGNORABLE;
1152 int ce2 = CollationElementIterator.IGNORABLE;
1153 while (ce1 != CollationElementIterator.NULLORDER
1154 && ce2 != CollationElementIterator.NULLORDER) {
1158 errln("Error generating RuleBasedCollator with the rule "
1160 errln("CH != \\u0427");
1166 public void DontTestJ831() { // Latvian does not use upper first
1173 genericLocaleStarter(new Locale("lv", ""), data);
1176 public void TestBefore() {
1178 "\u0101", "\u00e1", "\u01ce", "\u00e0", "A",
1179 "\u0113", "\u00e9", "\u011b", "\u00e8", "E",
1180 "\u012b", "\u00ed", "\u01d0", "\u00ec", "I",
1181 "\u014d", "\u00f3", "\u01d2", "\u00f2", "O",
1182 "\u016b", "\u00fa", "\u01d4", "\u00f9", "U",
1183 "\u01d6", "\u01d8", "\u01da", "\u01dc", "\u00fc"
1185 genericRulesStarter(
1186 "&[before 1]a<\u0101<\u00e1<\u01ce<\u00e0"
1187 + "&[before 1]e<\u0113<\u00e9<\u011b<\u00e8"
1188 + "&[before 1]i<\u012b<\u00ed<\u01d0<\u00ec"
1189 + "&[before 1]o<\u014d<\u00f3<\u01d2<\u00f2"
1190 + "&[before 1]u<\u016b<\u00fa<\u01d4<\u00f9"
1191 + "&u<\u01d6<\u01d8<\u01da<\u01dc<\u00fc", data);
1194 public void TestRedundantRules() {
1196 //"& a <<< b <<< c << d <<< e& [before 1] e <<< x",
1197 "& b <<< c <<< d << e <<< f& [before 3] f <<< x",
1198 "& a < b <<< c << d <<< e& [before 1] e <<< x",
1199 "& a < b < c < d& [before 1] c < m",
1200 "& a < b <<< c << d <<< e& [before 3] e <<< x",
1201 "& a < b <<< c << d <<< e& [before 2] e <<< x",
1202 "& a < b <<< c << d <<< e <<< f < g& [before 1] g < x",
1203 "& a <<< b << c < d& a < m",
1204 "&a<b<<b\u0301 &z<b",
1207 "& a < b < c < d& r < c",
1208 "& a < b < c < d& r < c",
1209 "& a < b < c < d& c < m",
1210 "& a < b < c < d& a < m"
1213 String[] expectedRules = {
1216 "& a <<< x < b <<< c << d <<< e",
1217 "& a < b < m < c < d",
1218 "& a < b <<< c << d <<< x <<< e",
1219 "& a < b <<< c <<< x << d <<< e",
1220 "& a < b <<< c << d <<< e <<< f < x < g",
1221 "& a <<< b << c < m < d",
1225 "& a < b < d& r < c",
1226 "& a < b < d& r < c",
1227 "& a < b < c < m < d",
1228 "& a < m < b < c < d"
1231 String[][] testdata = {
1234 {"a", "x", "b", "c", "d", "e"},
1235 {"a", "b", "m", "c", "d"},
1236 {"a", "b", "c", "d", "x", "e"},
1237 {"a", "b", "c", "x", "d", "e"},
1238 {"a", "b", "c", "d", "e", "f", "x", "g"},
1239 {"a", "b", "c", "m", "d"},
1240 {"a", "b\u0301", "z", "b"},
1245 {"a", "b", "c", "m", "d"},
1246 {"a", "m", "b", "c", "d"}
1250 for(int i = 0; i<rules.length; i++) {
1251 logln("testing rule " + rules[i] + ", expected to be" + expectedRules[i]);
1254 Collator credundant = new RuleBasedCollator(rlz);
1255 rlz = expectedRules[i];
1256 Collator cresulting = new RuleBasedCollator(rlz);
1257 logln(" credundant Rule:" + ((RuleBasedCollator)credundant).getRules());
1258 logln(" cresulting Rule:" + ((RuleBasedCollator)cresulting).getRules());
1259 } catch (Exception e) {
1260 warnln("Cannot create RuleBasedCollator");
1262 //testAgainstUCA(cresulting, credundant, "expected", TRUE, &status);
1263 // logln("testing using data\n");
1264 genericRulesStarter(rules[i], testdata[i]);
1268 public void TestExpansionSyntax() {
1270 "&AE <<< a << b <<< c &d <<< f",
1271 "&AE <<< a <<< b << c << d < e < f <<< g",
1272 "&AE <<< B <<< C / D <<< F"
1275 String[] expectedRules = {
1276 "&A <<< a / E << b / E <<< c /E &d <<< f",
1277 "&A <<< a / E <<< b / E << c / E << d / E < e < f <<< g",
1278 "&A <<< B / E <<< C / ED <<< F / E"
1281 String[][] testdata = {
1282 {"AE", "a", "b", "c"},
1283 {"AE", "a", "b", "c", "d", "e", "f", "g"},
1284 {"AE", "B", "C"} // / ED <<< F / E"},
1287 for(int i = 0; i<rules.length; i++) {
1288 // logln("testing rule " + rules[i] + ", expected to be " + expectedRules[i]);
1290 String rlz = rules[i];
1291 Collator credundant = new RuleBasedCollator(rlz);
1292 rlz = expectedRules[i];
1293 Collator cresulting = new RuleBasedCollator(rlz);
1294 logln(" credundant Rule:" + ((RuleBasedCollator)credundant).getRules());
1295 logln(" cresulting Rule:" + ((RuleBasedCollator)cresulting).getRules());
1296 } catch (Exception e) {
1297 warnln(e.getMessage());
1299 // testAgainstUCA still doesn't handle expansions correctly, so this is not run
1300 // as a hard error test, but only in information mode
1301 //testAgainstUCA(cresulting, credundant, "expected", FALSE, &status);
1303 // logln("testing using data");
1304 genericRulesStarter(rules[i], testdata[i]);
1308 public void TestHangulTailoring() {
1309 String[] koreanData = {
1310 "\uac00", "\u4f3d", "\u4f73", "\u5047", "\u50f9", "\u52a0", "\u53ef", "\u5475",
1311 "\u54e5", "\u5609", "\u5ac1", "\u5bb6", "\u6687", "\u67b6", "\u67b7", "\u67ef",
1312 "\u6b4c", "\u73c2", "\u75c2", "\u7a3c", "\u82db", "\u8304", "\u8857", "\u8888",
1313 "\u8a36", "\u8cc8", "\u8dcf", "\u8efb", "\u8fe6", "\u99d5",
1314 "\u4EEE", "\u50A2", "\u5496", "\u54FF", "\u5777", "\u5B8A", "\u659D", "\u698E",
1315 "\u6A9F", "\u73C8", "\u7B33", "\u801E", "\u8238", "\u846D", "\u8B0C"
1319 "&\uac00 <<< \u4f3d <<< \u4f73 <<< \u5047 <<< \u50f9 <<< \u52a0 <<< \u53ef <<< \u5475 "
1320 + "<<< \u54e5 <<< \u5609 <<< \u5ac1 <<< \u5bb6 <<< \u6687 <<< \u67b6 <<< \u67b7 <<< \u67ef "
1321 + "<<< \u6b4c <<< \u73c2 <<< \u75c2 <<< \u7a3c <<< \u82db <<< \u8304 <<< \u8857 <<< \u8888 "
1322 + "<<< \u8a36 <<< \u8cc8 <<< \u8dcf <<< \u8efb <<< \u8fe6 <<< \u99d5 "
1323 + "<<< \u4EEE <<< \u50A2 <<< \u5496 <<< \u54FF <<< \u5777 <<< \u5B8A <<< \u659D <<< \u698E "
1324 + "<<< \u6A9F <<< \u73C8 <<< \u7B33 <<< \u801E <<< \u8238 <<< \u846D <<< \u8B0C";
1328 Collator coll = null;
1330 coll = new RuleBasedCollator(rlz);
1331 } catch (Exception e) {
1332 warnln("Unable to open collator with rules" + rules);
1335 // logln("Using start of korean rules\n");
1336 genericOrderingTest(coll, koreanData);
1337 // logln("Setting jamoSpecial to TRUE and testing once more\n");
1339 // can't set jamo in icu4j
1340 // ((UCATableHeader *)coll->image)->jamoSpecial = TRUE; // don't try this at home
1341 // genericOrderingTest(coll, koreanData);
1343 // no such locale in icu4j
1344 // logln("Using ko__LOTUS locale\n");
1345 // genericLocaleStarter(new Locale("ko__LOTUS", ""), koreanData);
1348 public void TestIncrementalNormalize() {
1349 Collator coll = null;
1350 // logln("Test 1 ....");
1352 /* Test 1. Run very long unnormalized strings, to force overflow of*/
1353 /* most buffers along the way.*/
1356 coll = Collator.getInstance(new Locale("en", "US"));
1357 } catch (Exception e) {
1358 warnln("Cannot get default instance!");
1362 char ccMix[] = {0x316, 0x321, 0x300};
1365 StringBuffer strA = new StringBuffer();
1366 StringBuffer strB = new StringBuffer();
1368 coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
1370 for (sLen = 1000; sLen<1001; sLen++) {
1371 strA.delete(0, strA.length());
1373 strB.delete(0, strB.length());
1375 for (i=1; i< sLen; i++) {
1376 strA.append(ccMix[i % 3]);
1377 strB.insert(1, ccMix[i % 3]);
1379 coll.setStrength(Collator.TERTIARY); // Do test with default strength, which runs
1380 CollationTest.doTest(this, (RuleBasedCollator)coll,
1381 strA.toString(), strB.toString(), 0); // optimized functions in the impl
1382 coll.setStrength(Collator.IDENTICAL); // Do again with the slow, general impl.
1383 CollationTest.doTest(this, (RuleBasedCollator)coll,
1384 strA.toString(), strB.toString(), 0);
1387 /* Test 2: Non-normal sequence in a string that extends to the last character*/
1388 /* of the string. Checks a couple of edge cases.*/
1389 // logln("Test 2 ....");
1391 String strA = "AA\u0300\u0316";
1392 String strB = "A\u00c0\u0316";
1393 coll.setStrength(Collator.TERTIARY);
1394 CollationTest.doTest(this, (RuleBasedCollator)coll, strA, strB, 0);
1396 /* Test 3: Non-normal sequence is terminated by a surrogate pair.*/
1397 // logln("Test 3 ....");
1399 String strA = "AA\u0300\u0316\uD800\uDC01";
1400 String strB = "A\u00c0\u0316\uD800\uDC00";
1401 coll.setStrength(Collator.TERTIARY);
1402 CollationTest.doTest(this, (RuleBasedCollator)coll, strA, strB, 1);
1404 /* Test 4: Imbedded nulls do not terminate a string when length is specified.*/
1405 // logln("Test 4 ....");
1407 * not a valid test since string are null-terminated in java{
1408 char strA[] = {0x41, 0x00, 0x42};
1409 char strB[] = {0x41, 0x00, 0x00};
1411 int result = coll.compare(new String(strA), new String(strB));
1413 errln("ERROR 1 in test 4\n");
1416 result = coll.compare(new String(strA, 0, 1), new String(strB, 0, 1));
1418 errln("ERROR 1 in test 4\n");
1421 CollationKey sortKeyA = coll.getCollationKey(new String(strA));
1422 CollationKey sortKeyB = coll.getCollationKey(new String(strB));
1424 int r = sortKeyA.compareTo(sortKeyB);
1426 errln("Error 4 in test 4\n");
1429 coll.setStrength(Collator.IDENTICAL);
1430 sortKeyA = coll.getCollationKey(new String(strA));
1431 sortKeyB = coll.getCollationKey(new String(strB));
1433 r = sortKeyA.compareTo(sortKeyB);
1435 errln("Error 7 in test 4\n");
1438 coll.setStrength(Collator.TERTIARY);
1441 /* Test 5: Null characters in non-normal source strings.*/
1442 // logln("Test 5 ....");
1444 * not a valid test since string are null-terminated in java{
1446 char strA[] = {0x41, 0x41, 0x300, 0x316, 0x00, 0x42,};
1447 char strB[] = {0x41, 0x41, 0x300, 0x316, 0x00, 0x00,};
1450 int result = coll.compare(new String(strA, 0, 6), new String(strB, 0, 6));
1452 errln("ERROR 1 in test 5\n");
1454 result = coll.compare(new String(strA, 0, 4), new String(strB, 0, 4));
1456 errln("ERROR 2 in test 5\n");
1459 CollationKey sortKeyA = coll.getCollationKey(new String(strA));
1460 CollationKey sortKeyB = coll.getCollationKey(new String(strB));
1461 int r = sortKeyA.compareTo(sortKeyB);
1463 errln("Error 4 in test 5\n");
1466 coll.setStrength(Collator.IDENTICAL);
1468 sortKeyA = coll.getCollationKey(new String(strA));
1469 sortKeyB = coll.getCollationKey(new String(strB));
1470 r = sortKeyA.compareTo(sortKeyB);
1472 errln("Error 7 in test 5\n");
1475 coll.setStrength(Collator.TERTIARY);
1478 /* Test 6: Null character as base of a non-normal combining sequence.*/
1479 // logln("Test 6 ....");
1481 * not a valid test since string are null-terminated in java{
1483 char strA[] = {0x41, 0x0, 0x300, 0x316, 0x41, 0x302,};
1484 char strB[] = {0x41, 0x0, 0x302, 0x316, 0x41, 0x300,};
1486 int result = coll.compare(new String(strA, 0, 5), new String(strB, 0, 5));
1488 errln("Error 1 in test 6\n");
1490 result = coll.compare(new String(strA, 0, 1), new String(strB, 0, 1));
1492 errln("Error 2 in test 6\n");
1498 public void TestContraction() {
1499 String[] testrules = {
1501 "&A = A\\u0306/\\u0306",
1504 String[] testdata = {
1505 "AB", "AB", "A\u0306", "ch"
1507 String[] testdata2 = {
1512 String[] testrules3 = {
1513 "&z < xyz &xyzw << B",
1514 "&z < xyz &xyz << B / w",
1515 "&z < ch &achm << B",
1516 "&z < ch &a << B / chm",
1517 "&\ud800\udc00w << B",
1518 "&\ud800\udc00 << B / w",
1519 "&a\ud800\udc00m << B",
1520 "&a << B / \ud800\udc00m",
1523 RuleBasedCollator coll = null;
1524 for (int i = 0; i < testrules.length; i ++) {
1525 CollationElementIterator iter1 = null;
1527 // logln("Rule " + testrules[i] + " for testing\n");
1528 String rule = testrules[i];
1530 coll = new RuleBasedCollator(rule);
1531 } catch (Exception e) {
1532 warnln("Collator creation failed " + testrules[i]);
1536 iter1 = coll.getCollationElementIterator(testdata[i]);
1537 } catch (Exception e) {
1538 errln("Collation iterator creation failed\n");
1542 CollationElementIterator iter2;
1545 iter2 = coll.getCollationElementIterator(String.valueOf(testdata[i].charAt(j)));
1547 }catch (Exception e) {
1548 errln("Collation iterator creation failed\n");
1552 while (ce != CollationElementIterator.NULLORDER) {
1553 if (iter1.next() != ce) {
1554 errln("Collation elements in contraction split does not match\n");
1561 if (iter1.next() != CollationElementIterator.NULLORDER) {
1562 errln("Collation elements not exhausted\n");
1566 String rule = "& a < b < c < ch < d & c = ch / h";
1568 coll = new RuleBasedCollator(rule);
1569 } catch (Exception e) {
1570 errln("cannot create rulebased collator");
1574 if (coll.compare(testdata2[0], testdata2[1]) != -1) {
1575 errln("Expected " + testdata2[0] + " < " + testdata2[1]);
1578 if (coll.compare(testdata2[1], testdata2[2]) != -1) {
1579 errln("Expected " + testdata2[1] + " < " + testdata2[2]);
1582 for (int i = 0; i < testrules3.length; i += 2) {
1583 RuleBasedCollator coll1, coll2;
1584 CollationElementIterator iter1, iter2;
1587 rule = testrules3[i];
1589 coll1 = new RuleBasedCollator(rule);
1590 } catch (Exception e) {
1591 errln("Fail: cannot create rulebased collator, rule:" + rule);
1594 rule = testrules3[i + 1];
1596 coll2 = new RuleBasedCollator(rule);
1597 } catch (Exception e) {
1598 errln("Collator creation failed " + testrules[i]);
1602 iter1 = coll1.getCollationElementIterator(String.valueOf(ch));
1603 iter2 = coll2.getCollationElementIterator(String.valueOf(ch));
1604 } catch (Exception e) {
1605 errln("Collation iterator creation failed\n");
1610 while (ce != CollationElementIterator.NULLORDER) {
1611 if (ce != iter2.next()) {
1612 errln("CEs does not match\n");
1617 if (iter2.next() != CollationElementIterator.NULLORDER) {
1618 errln("CEs not exhausted\n");
1624 public void TestExpansion() {
1625 String[] testrules = {
1626 "&J << K / B & K << M",
1629 String[] testdata = {
1630 "JA", "MA", "KA", "KC", "JC", "MC",
1634 for (int i = 0; i < testrules.length; i++) {
1635 // logln("Rule " + testrules[i] + " for testing\n");
1636 String rule = testrules[i];
1638 coll = new RuleBasedCollator(rule);
1639 } catch (Exception e) {
1640 warnln("Collator creation failed " + testrules[i]);
1644 for (int j = 0; j < 5; j ++) {
1645 CollationTest.doTest(this, (RuleBasedCollator)coll,
1646 testdata[j], testdata[j + 1], -1);
1651 public void TestContractionEndCompare()
1653 String rules = "&b=ch";
1655 String tgt = "bech";
1656 Collator coll = null;
1658 coll = new RuleBasedCollator(rules);
1659 } catch (Exception e) {
1660 warnln("Collator creation failed " + rules);
1663 CollationTest.doTest(this, (RuleBasedCollator)coll, src, tgt, 1);
1666 public void TestLocaleRuleBasedCollators() {
1667 if (getInclusion() < 5) {
1668 // not serious enough to run this
1671 Locale locale[] = Collator.getAvailableLocales();
1672 String prevrule = null;
1673 for (int i = 0; i < locale.length; i ++) {
1674 Locale l = locale[i];
1676 ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,l);
1677 String collkey = rb.getStringWithFallback("collations/default");
1678 ICUResourceBundle elements = rb.getWithFallback("collations/" + collkey);
1679 if (elements == null) {
1684 Object[][] colldata = (Object[][])elements;
1686 if (colldata[0][1] instanceof byte[]){
1687 rule = (String)colldata[1][1];
1690 rule = (String)colldata[0][1];
1693 rule = elements.getString("Sequence");
1695 RuleBasedCollator col1 =
1696 (RuleBasedCollator)Collator.getInstance(l);
1697 if (!rule.equals(col1.getRules())) {
1698 errln("Rules should be the same in the RuleBasedCollator and Locale");
1700 if (rule != null && rule.length() > 0
1701 && !rule.equals(prevrule)) {
1702 RuleBasedCollator col2 = new RuleBasedCollator(rule);
1703 if (!col1.equals(col2)) {
1704 errln("Error creating RuleBasedCollator from " +
1705 "locale rules for " + l.toString());
1709 } catch (Exception e) {
1710 warnln("Error retrieving resource bundle for testing: " + e.toString());
1715 public void TestOptimize() {
1716 /* this is not really a test - just trying out
1717 * whether copying of UCA contents will fail
1718 * Cannot really test, since the functionality
1722 "[optimize [\\uAC00-\\uD7FF]]"
1729 for(i = 0; i<rules.length; i++) {
1730 genericRulesStarter(rules[i], data[i]);
1734 public void TestIdenticalCompare()
1737 RuleBasedCollator coll
1738 = new RuleBasedCollator("& \uD800\uDC00 = \uD800\uDC01");
1739 String strA = "AA\u0300\u0316\uD800\uDC01";
1740 String strB = "A\u00c0\u0316\uD800\uDC00";
1741 coll.setStrength(Collator.IDENTICAL);
1742 CollationTest.doTest(this, coll, strA, strB, 1);
1743 } catch (Exception e) {
1744 warnln(e.getMessage());
1748 public void TestMergeSortKeys()
1750 String cases[] = {"abc", "abcd", "abcde"};
1751 String prefix = "foo";
1752 String suffix = "egg";
1753 CollationKey mergedPrefixKeys[] = new CollationKey[cases.length];
1754 CollationKey mergedSuffixKeys[] = new CollationKey[cases.length];
1756 Collator coll = Collator.getInstance(Locale.ENGLISH);
1757 genericLocaleStarter(Locale.ENGLISH, cases);
1759 int strength = Collator.PRIMARY;
1760 while (strength <= Collator.IDENTICAL) {
1761 coll.setStrength(strength);
1762 CollationKey prefixKey = coll.getCollationKey(prefix);
1763 CollationKey suffixKey = coll.getCollationKey(suffix);
1764 for (int i = 0; i < cases.length; i ++) {
1765 CollationKey key = coll.getCollationKey(cases[i]);
1766 mergedPrefixKeys[i] = prefixKey.merge(key);
1767 mergedSuffixKeys[i] = suffixKey.merge(key);
1768 if (mergedPrefixKeys[i].getSourceString() != null
1769 || mergedSuffixKeys[i].getSourceString() != null) {
1770 errln("Merged source string error: expected null");
1773 if (mergedPrefixKeys[i-1].compareTo(mergedPrefixKeys[i])
1775 errln("Error while comparing prefixed keys @ strength "
1777 errln(prettify(mergedPrefixKeys[i-1]));
1778 errln(prettify(mergedPrefixKeys[i]));
1780 if (mergedSuffixKeys[i-1].compareTo(mergedSuffixKeys[i])
1782 errln("Error while comparing suffixed keys @ strength "
1784 errln(prettify(mergedSuffixKeys[i-1]));
1785 errln(prettify(mergedSuffixKeys[i]));
1789 if (strength == Collator.QUATERNARY) {
1790 strength = Collator.IDENTICAL;
1798 public void TestVariableTop()
1800 // parseNextToken is not released as public so i create my own rules
1801 String rules = "& a < b < c < de < fg & hi = j";
1803 RuleBasedCollator coll = new RuleBasedCollator(rules);
1804 String tokens[] = {"a", "b", "c", "de", "fg", "hi", "j", "ab"};
1805 coll.setAlternateHandlingShifted(true);
1806 for (int i = 0; i < tokens.length; i ++) {
1807 int varTopOriginal = coll.getVariableTop();
1809 int varTop = coll.setVariableTop(tokens[i]);
1811 errln("Token " + tokens[i] + " expected to fail");
1813 if (varTop != coll.getVariableTop()) {
1814 errln("Error setting and getting variable top");
1816 CollationKey key1 = coll.getCollationKey(tokens[i]);
1817 for (int j = 0; j < i; j ++) {
1818 CollationKey key2 = coll.getCollationKey(tokens[j]);
1819 if (key2.compareTo(key1) < 0) {
1820 errln("Setting variable top shouldn't change the comparison sequence");
1822 byte sortorder[] = key2.toByteArray();
1823 if (sortorder.length > 0
1824 && (key2.toByteArray())[0] > 1) {
1825 errln("Primary sort order should be 0");
1828 } catch (Exception e) {
1829 CollationElementIterator iter
1830 = coll.getCollationElementIterator(tokens[i]);
1831 /*int ce =*/ iter.next();
1832 int ce2 = iter.next();
1833 if (ce2 == CollationElementIterator.NULLORDER) {
1834 errln("Token " + tokens[i] + " not expected to fail");
1836 if (coll.getVariableTop() != varTopOriginal) {
1837 errln("When exception is thrown variable top should "
1838 + "not be changed");
1841 coll.setVariableTop(varTopOriginal);
1842 if (varTopOriginal != coll.getVariableTop()) {
1843 errln("Couldn't restore old variable top\n");
1847 // Testing calling with error set
1849 coll.setVariableTop("");
1850 errln("Empty string should throw an IllegalArgumentException");
1851 } catch (IllegalArgumentException e) {
1852 logln("PASS: Empty string failed as expected");
1855 coll.setVariableTop(null);
1856 errln("Null string should throw an IllegalArgumentException");
1857 } catch (IllegalArgumentException e) {
1858 logln("PASS: null string failed as expected");
1860 } catch (Exception e) {
1861 warnln("Error creating RuleBasedCollator");
1865 public void TestUCARules()
1868 // only root locale can have empty tailorings .. not English!
1869 RuleBasedCollator coll
1870 = (RuleBasedCollator)Collator.getInstance(new Locale("","",""));
1872 = coll.getRules(false);
1873 if (!rule.equals("")) {
1874 errln("Empty rule string should have empty rules " + rule);
1876 rule = coll.getRules(true);
1877 if (rule.equals("")) {
1878 errln("UCA rule string should not be empty");
1880 coll = new RuleBasedCollator(rule);
1881 } catch (Exception e) {
1882 warnln(e.getMessage());
1889 public void TestShifted()
1891 RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance();
1892 collator.setStrength(Collator.PRIMARY);
1893 collator.setAlternateHandlingShifted(true);
1894 CollationTest.doTest(this, collator, " a", "a", 0); // works properly
1895 CollationTest.doTest(this, collator, "a", "a ", 0); // inconsistent results
1899 * Test for CollationElementIterator previous and next for the whole set of
1900 * unicode characters with normalization on.
1902 public void TestNumericCollation()
1904 String basicTestStrings[] = {"hello1", "hello2", "hello123456"};
1905 String preZeroTestStrings[] = {"avery1",
1909 String thirtyTwoBitNumericStrings[] = {"avery42949672960",
1912 "avery429496729610"};
1914 String supplementaryDigits[] = {"\uD835\uDFCE", // 0
1915 "\uD835\uDFCF", // 1
1916 "\uD835\uDFD0", // 2
1917 "\uD835\uDFD1", // 3
1918 "\uD835\uDFCF\uD835\uDFCE", // 10
1919 "\uD835\uDFCF\uD835\uDFCF", // 11
1920 "\uD835\uDFCF\uD835\uDFD0", // 12
1921 "\uD835\uDFD0\uD835\uDFCE", // 20
1922 "\uD835\uDFD0\uD835\uDFCF", // 21
1923 "\uD835\uDFD0\uD835\uDFD0" // 22
1926 String foreignDigits[] = {"\u0661",
1940 //Additional tests to cover bug reported in #9476
1941 String lastDigitDifferent[]={"2004","2005",
1944 "100000000005","100000000006"};
1946 // Open our collator.
1947 RuleBasedCollator coll
1948 = (RuleBasedCollator)Collator.getInstance(Locale.ENGLISH);
1949 String att[] = {"NumericCollation"};
1950 Boolean val[] = {Boolean.TRUE};
1951 genericLocaleStarterWithOptions(Locale.ENGLISH, basicTestStrings, att,
1953 genericLocaleStarterWithOptions(Locale.ENGLISH,
1954 thirtyTwoBitNumericStrings, att, val);
1955 genericLocaleStarterWithOptions(Locale.ENGLISH, foreignDigits, att,
1957 genericLocaleStarterWithOptions(Locale.ENGLISH, supplementaryDigits,
1960 // Setting up our collator to do digits.
1961 coll.setNumericCollation(true);
1963 // Testing that prepended zeroes still yield the correct collation
1965 // We expect that every element in our strings array will be equal.
1966 for (int i = 0; i < preZeroTestStrings.length - 1; i ++) {
1967 for (int j = i + 1; j < preZeroTestStrings.length; j ++) {
1968 CollationTest.doTest(this, coll, preZeroTestStrings[i],
1969 preZeroTestStrings[j],0);
1973 //Testing that the behavior reported in #9476 is fixed
1974 //We expect comparisons between adjacent pairs will result in -1
1975 for (int i=0; i < lastDigitDifferent.length -1; i=i+2 ) {
1976 CollationTest.doTest(this, coll, lastDigitDifferent[i], lastDigitDifferent[i+1], -1);
1980 //cover setNumericCollationDefault, getNumericCollation
1981 assertTrue("The Numeric Collation setting is on", coll.getNumericCollation());
1982 coll.setNumericCollationDefault();
1983 logln("After set Numeric to default, the setting is: " + coll.getNumericCollation());
1986 public void Test3249()
1988 String rule = "&x < a &z < a";
1990 RuleBasedCollator coll = new RuleBasedCollator(rule);
1992 logln("Collator did not throw an exception");
1994 } catch (Exception e) {
1995 warnln("Error creating RuleBasedCollator with " + rule + " failed");
1999 public void TestTibetanConformance()
2001 String test[] = {"\u0FB2\u0591\u0F71\u0061", "\u0FB2\u0F71\u0061"};
2003 Collator coll = Collator.getInstance();
2004 coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
2005 if (coll.compare(test[0], test[1]) != 0) {
2006 errln("Tibetan comparison error");
2008 CollationTest.doTest(this, (RuleBasedCollator)coll,
2009 test[0], test[1], 0);
2010 } catch (Exception e) {
2011 warnln("Error creating UCA collator");
2015 public void TestJ3347()
2018 Collator coll = Collator.getInstance(Locale.FRENCH);
2019 ((RuleBasedCollator)coll).setAlternateHandlingShifted(true);
2020 if (coll.compare("6", "!6") != 0) {
2021 errln("Jitterbug 3347 failed");
2023 } catch (Exception e) {
2024 warnln("Error creating UCA collator");
2028 public void TestPinyinProblem()
2030 String test[] = { "\u4E56\u4E56\u7761", "\u4E56\u5B69\u5B50" };
2031 genericLocaleStarter(new Locale("zh", "", "PINYIN"), test);
2034 static final long topByte = 0xFF000000L;
2035 static final long bottomByte = 0xFFL;
2036 static final long fourBytes = 0xFFFFFFFFL;
2038 static final int MAX_INPUT = 0x220001; // 2 * Unicode range + 2
2040 private void show(int i, ImplicitCEGenerator imp) {
2041 if (i >= 0 && i <= MAX_INPUT) {
2042 logln(Utility.hex(i) + "\t" + Utility.hex(imp.getImplicitFromRaw(i) & fourBytes));
2046 private void throwError(String title, int cp, ImplicitCEGenerator imp) {
2047 throw new IllegalArgumentException(title + "\t" + Utility.hex(cp, 6) + "\t" + Utility.hex(imp.getImplicitFromRaw(cp) & fourBytes));
2050 private void throwError(String title, long ce) {
2051 errln(title + "\t" + Utility.hex(ce & fourBytes));
2054 public void TestImplicitGeneration()
2058 ImplicitCEGenerator foo = new ImplicitCEGenerator(0xE0, 0xE4);
2060 //int x = foo.getRawImplicit(0xF810);
2061 foo.getRawFromImplicit(0xE20303E7);
2063 //int gap4 = foo.getGap4();
2064 //logln("Gap4: " + gap4);
2065 //int gap3 = foo.getGap3();
2066 //int minTrail = foo.getMinTrail();
2067 //int maxTrail = foo.getMaxTrail();
2070 for (int i = 0; i <= MAX_INPUT; ++i) {
2071 current = foo.getImplicitFromRaw(i) & fourBytes;
2073 // check that it round-trips AND that all intervening ones are illegal
2074 int roundtrip = foo.getRawFromImplicit((int)current);
2075 if (roundtrip != i) {
2076 throwError("No roundtrip", i, foo);
2079 for (long j = last + 1; j < current; ++j) {
2080 roundtrip = foo.getRawFromImplicit((int)j);
2081 // raise an error if it *doesn't* find an error
2082 if (roundtrip != -1) {
2083 throwError("Fails to recognize illegal", j);
2087 // now do other consistency checks
2088 long lastBottom = last & bottomByte;
2089 long currentBottom = current & bottomByte;
2090 long lastTop = last & topByte;
2091 long currentTop = current & topByte;
2093 // do some consistency checks
2095 long gap = current - last;
2096 if (currentBottom != 0) { // if we are a 4-byte
2097 // gap has to be at least gap4
2098 // and gap from minTrail, maxTrail has to be at least gap4
2099 if (gap <= gap4) foo.throwError("Failed gap4 between", i);
2100 if (currentBottom < minTrail + gap4) foo.throwError("Failed gap4 before", i);
2101 if (currentBottom > maxTrail - gap4) foo.throwError("Failed gap4 after", i);
2102 } else { // we are a three-byte
2103 gap = gap >> 8; // move gap down for comparison.
2104 long current3Bottom = (current >> 8) & bottomByte;
2105 if (gap <= gap3) foo.throwError("Failed gap3 between ", i);
2106 if (current3Bottom < minTrail + gap3) foo.throwError("Failed gap3 before", i);
2107 if (current3Bottom > maxTrail - gap3) foo.throwError("Failed gap3 after", i);
2110 // print out some values for spot-checking
2111 if (lastTop != currentTop || i == 0x10000 || i == 0x110000) {
2117 } else if (lastBottom == 0 && currentBottom != 0) {
2118 logln("+ primary boundary, 4-byte CE's below");
2119 } else if (lastTop != currentTop) {
2120 logln("+ primary boundary");
2128 if(foo.getCodePointFromRaw(foo.getRawFromCodePoint(i)) != i) {
2129 errln("No raw <-> code point roundtrip for "+Utility.hex(i));
2132 show(MAX_INPUT-2, foo);
2133 show(MAX_INPUT-1, foo);
2134 show(MAX_INPUT, foo);
2135 } catch (Exception e) {
2136 e.printStackTrace();
2137 warnln(e.getMessage());
2143 /* supercedes TestJ784 */
2144 public void TestBeforePinyin() {
2146 "&[before 2]A << \u0101 <<< \u0100 << \u00E1 <<< \u00C1 << \u01CE <<< \u01CD << \u00E0 <<< \u00C0" +
2147 "&[before 2]e << \u0113 <<< \u0112 << \u00E9 <<< \u00C9 << \u011B <<< \u011A << \u00E8 <<< \u00C8" +
2148 "&[before 2] i << \u012B <<< \u012A << \u00ED <<< \u00CD << \u01D0 <<< \u01CF << \u00EC <<< \u00CC" +
2149 "&[before 2] o << \u014D <<< \u014C << \u00F3 <<< \u00D3 << \u01D2 <<< \u01D1 << \u00F2 <<< \u00D2" +
2150 "&[before 2]u << \u016B <<< \u016A << \u00FA <<< \u00DA << \u01D4 <<< \u01D3 << \u00F9 <<< \u00D9" +
2151 "&U << \u01D6 <<< \u01D5 << \u01D8 <<< \u01D7 << \u01DA <<< \u01D9 << \u01DC <<< \u01DB << \u00FC";
2196 /* TODO: port builder fixes to before */
2197 genericRulesStarter(rules, test);
2198 genericLocaleStarter(new Locale("zh","",""), test);
2199 genericRulesStarter(rules, test2);
2200 genericLocaleStarter(new Locale("zh","",""), test2);
2203 public void TestUpperFirstQuaternary()
2205 String tests[] = { "B", "b", "Bb", "bB" };
2206 String[] att = { "strength", "UpperFirst" };
2207 Object attVals[] = { new Integer(Collator.QUATERNARY), Boolean.TRUE };
2208 genericLocaleStarterWithOptions(new Locale("root","",""), tests, att, attVals);
2211 public void TestJ4960()
2213 String tests[] = { "\\u00e2T", "aT" };
2214 String att[] = { "strength", "CaseLevel" };
2215 Object attVals[] = { new Integer(Collator.PRIMARY), Boolean.TRUE };
2216 String tests2[] = { "a", "A" };
2217 String rule = "&[first tertiary ignorable]=A=a";
2218 String att2[] = { "CaseLevel" };
2219 Object attVals2[] = { Boolean.TRUE };
2220 // Test whether we correctly ignore primary ignorables on case level when
2221 // we have only primary & case level
2222 genericLocaleStarterWithOptionsAndResult(new Locale("root", ""), tests, att, attVals, 0);
2223 // Test whether ICU4J will make case level for sortkeys that have primary strength
2225 genericLocaleStarterWithOptions(new Locale("root", ""), tests2, att, attVals);
2226 // Test whether completely ignorable letters have case level info (they shouldn't)
2227 genericRulesStarterWithOptionsAndResult(rule, tests2, att2, attVals2, 0);
2230 public void TestJB5298(){
2231 ULocale[] locales = Collator.getAvailableULocales();
2232 logln("Number of collator locales returned : " + locales.length);
2233 // double-check keywords
2234 String[] keywords = Collator.getKeywords();
2235 if (keywords.length != 1 || !keywords[0].equals("collation")) {
2236 throw new IllegalArgumentException("internal collation error");
2239 String[] values = Collator.getKeywordValues("collation");
2240 log("Collator.getKeywordValues returned: ");
2241 for(int i=0; i<values.length;i++){
2242 log(values[i]+", ");
2245 logln("Number of collator values returned : " + values.length);
2247 Set foundValues = new TreeSet(Arrays.asList(values));
2249 for (int i = 0; i < locales.length; ++i) {
2250 for (int j = 0; j < values.length; ++j) {
2251 ULocale tryLocale = values[j].equals("standard")
2252 ? locales[i] : new ULocale(locales[i] + "@collation=" + values[j]);
2253 // only append if not standard
2254 ULocale canon = Collator.getFunctionalEquivalent("collation",tryLocale);
2255 if (!canon.equals(tryLocale)) {
2256 continue; // has a different
2257 }else {// functional equivalent, so skip
2258 logln(tryLocale + " : "+canon+", ");
2260 String can = canon.toString();
2261 int idx = can.indexOf("@collation=");
2262 String val = idx >= 0 ? can.substring(idx+11, can.length()) : "";
2263 if(val.length()>0 && !foundValues.contains(val)){
2264 errln("Unknown collation found "+ can);
2274 String[] test = { "a", "y" };
2275 String rules = "&Ny << Y &[first secondary ignorable] <<< a";
2276 genericRulesStarter(rules, test);
2284 "&a < \u00e2 <<< \u00c2",
2285 "&a < \u1FF3 ", // OMEGA WITH YPOGEGRAMMENI
2286 "&s < \u0161 ", // &s < s with caron
2287 "&z < a\u00EA", // &z < a+e with circumflex
2289 String cases[][] = {
2290 { "\u1EAC", "A\u0323\u0302", "\u1EA0\u0302", "\u00C2\u0323", },
2291 { "\u1FA2", "\u03C9\u0313\u0300\u0345", "\u1FF3\u0313\u0300",
2292 "\u1F60\u0300\u0345", "\u1f62\u0345", "\u1FA0\u0300", },
2293 { "\u1E63\u030C", "s\u0323\u030C", "s\u030C\u0323"},
2294 { "a\u1EC7", // a+ e with dot below and circumflex
2295 "a\u1EB9\u0302", // a + e with dot below + combining circumflex
2296 "a\u00EA\u0323", // a + e with circumflex + combining dot below
2301 for(int i = 0; i < rules.length; i++) {
2303 RuleBasedCollator coll = null;
2305 coll = new RuleBasedCollator(rules[i]);
2306 } catch (Exception e) {
2307 warnln("Unable to open collator with rules " + rules[i]);
2310 logln("Test case["+i+"]:");
2311 CollationKey expectingKey = coll.getCollationKey(cases[i][0]);
2312 for (int j=1; j<cases[i].length; j++) {
2313 CollationKey key = coll.getCollationKey(cases[i][j]);
2314 if ( key.compareTo(expectingKey)!=0) {
2315 errln("Error! Test case["+i+"]:"+"source:" + key.getSourceString());
2316 errln("expecting:"+prettify(expectingKey)+ "got:"+ prettify(key));
2318 logln(" Key:"+ prettify(key));
2323 RuleBasedCollator vi_vi = null;
2325 vi_vi = (RuleBasedCollator)Collator.getInstance(
2326 new Locale("vi", ""));
2328 CollationKey expectingKey = vi_vi.getCollationKey(cases[0][0]);
2329 for (int j=1; j<cases[0].length; j++) {
2330 CollationKey key = vi_vi.getCollationKey(cases[0][j]);
2331 if ( key.compareTo(expectingKey)!=0) {
2332 // TODO (claireho): change the logln to errln after vi.res is up-to-date.
2333 // errln("source:" + key.getSourceString());
2334 // errln("expecting:"+prettify(expectingKey)+ "got:"+ prettify(key));
2335 logln("Error!! in Vietnese sort - source:" + key.getSourceString());
2336 logln("expecting:"+prettify(expectingKey)+ "got:"+ prettify(key));
2338 // logln("source:" + key.getSourceString());
2339 logln(" Key:"+ prettify(key));
2341 } catch (Exception e) {
2342 warnln("Error creating Vietnese collator");
2349 public void Test6179()
2352 "&[last primary ignorable]<< a &[first primary ignorable]<<b ",
2353 "&[last secondary ignorable]<<< a &[first secondary ignorable]<<<b",
2355 // defined in UCA5.1
2356 String firstPrimIgn = "\u0332";
2357 String lastPrimIgn = "\uD800\uDDFD";
2358 String firstVariable = "\u0009";
2359 byte[] secIgnKey = {1,1,4,0};
2364 RuleBasedCollator coll = null;
2366 coll = new RuleBasedCollator(rules[i]);
2367 } catch (Exception e) {
2368 warnln("Unable to open collator with rules " + rules[i]);
2371 logln("Test rule["+i+"]"+rules[i]);
2373 CollationKey keyA = coll.getCollationKey("a");
2374 logln("Key for \"a\":"+ prettify(keyA));
2375 if (keyA.compareTo(coll.getCollationKey(lastPrimIgn))<=0) {
2376 CollationKey key = coll.getCollationKey(lastPrimIgn);
2377 logln("Collation key for 0xD800 0xDDFD: "+prettify(key));
2378 errln("Error! String \"a\" must be greater than \uD800\uDDFD -"+
2379 "[Last Primary Ignorable]");
2381 if (keyA.compareTo(coll.getCollationKey(firstVariable))>=0) {
2382 CollationKey key = coll.getCollationKey(firstVariable);
2383 logln("Collation key for 0x0009: "+prettify(key));
2384 errln("Error! String \"a\" must be less than 0x0009 - [First Variable]");
2386 CollationKey keyB = coll.getCollationKey("b");
2387 logln("Key for \"b\":"+ prettify(keyB));
2388 if (keyB.compareTo(coll.getCollationKey(firstPrimIgn))<=0) {
2389 CollationKey key = coll.getCollationKey(firstPrimIgn);
2390 logln("Collation key for 0x0332: "+prettify(key));
2391 errln("Error! String \"b\" must be greater than 0x0332 -"+
2392 "[First Primary Ignorable]");
2394 if (keyB.compareTo(coll.getCollationKey(firstVariable))>=0) {
2395 CollationKey key = coll.getCollationKey(firstVariable);
2396 logln("Collation key for 0x0009: "+prettify(key));
2397 errln("Error! String \"b\" must be less than 0x0009 - [First Variable]");
2402 RuleBasedCollator coll = null;
2404 coll = new RuleBasedCollator(rules[i]);
2405 } catch (Exception e) {
2406 warnln("Unable to open collator with rules " + rules[i]);
2409 logln("Test rule["+i+"]"+rules[i]);
2411 CollationKey keyA = coll.getCollationKey("a");
2412 logln("Key for \"a\":"+ prettify(keyA));
2413 byte[] keyAInBytes = keyA.toByteArray();
2414 for (int j=0; j<keyAInBytes.length && j<secIgnKey.length; j++) {
2415 if (keyAInBytes[j]!=secIgnKey[j]) {
2416 if ((char)keyAInBytes[j]<=(char)secIgnKey[j]) {
2417 logln("Error! String \"a\" must be greater than [Last Secondary Ignorable]");
2422 if (keyA.compareTo(coll.getCollationKey(firstVariable))>=0) {
2423 errln("Error! String \"a\" must be less than 0x0009 - [First Variable]");
2424 CollationKey key = coll.getCollationKey(firstVariable);
2425 logln("Collation key for 0x0009: "+prettify(key));
2427 CollationKey keyB = coll.getCollationKey("b");
2428 logln("Key for \"b\":"+ prettify(keyB));
2429 byte[] keyBInBytes = keyB.toByteArray();
2430 for (int j=0; j<keyBInBytes.length && j<secIgnKey.length; j++) {
2431 if (keyBInBytes[j]!=secIgnKey[j]) {
2432 if ((char)keyBInBytes[j]<=(char)secIgnKey[j]) {
2433 errln("Error! String \"b\" must be greater than [Last Secondary Ignorable]");
2438 if (keyB.compareTo(coll.getCollationKey(firstVariable))>=0) {
2439 CollationKey key = coll.getCollationKey(firstVariable);
2440 logln("Collation key for 0x0009: "+prettify(key));
2441 errln("Error! String \"b\" must be less than 0x0009 - [First Variable]");
2446 public void TestUCAPrecontext()
2450 "& L\u00B7 << a", // 'a' is an expansion.
2466 RuleBasedCollator en = null;
2470 en = (RuleBasedCollator)Collator.getInstance(
2471 new Locale("en", ""));
2472 for (int j=0; j<cases.length; j++) {
2473 CollationKey key = en.getCollationKey(cases[j]);
2475 CollationKey prevKey = en.getCollationKey(cases[j-1]);
2476 if (key.compareTo(prevKey)<0) {
2477 errln("Error! EN test["+j+"]:source:" + cases[j]+
2478 " is not >= previous test string.");
2482 if ( key.compareTo(expectingKey)!=0) {
2483 errln("Error! Test case["+i+"]:"+"source:" + key.getSourceString());
2484 errln("expecting:"+prettify(expectingKey)+ "got:"+ prettify(key));
2487 logln("String:"+cases[j]+" Key:"+ prettify(key));
2489 } catch (Exception e) {
2490 warnln("Error creating English collator");
2495 RuleBasedCollator ja = null;
2498 ja = (RuleBasedCollator)Collator.getInstance(
2499 new Locale("ja", ""));
2500 for (int j=0; j<cases.length; j++) {
2501 CollationKey key = ja.getCollationKey(cases[j]);
2503 CollationKey prevKey = ja.getCollationKey(cases[j-1]);
2504 if (key.compareTo(prevKey)<0) {
2505 errln("Error! JA test["+j+"]:source:" + cases[j]+
2506 " is not >= previous test string.");
2509 logln("String:"+cases[j]+" Key:"+ prettify(key));
2511 } catch (Exception e) {
2512 warnln("Error creating Japanese collator");
2515 for(int i = 0; i < rules.length; i++) {
2517 RuleBasedCollator coll = null;
2518 logln("Tailoring rule:"+rules[i]);
2520 coll = new RuleBasedCollator(rules[i]);
2521 } catch (Exception e) {
2522 warnln("Unable to open collator with rules " + rules[i]);
2526 for (int j=0; j<cases.length; j++) {
2527 CollationKey key = coll.getCollationKey(cases[j]);
2529 CollationKey prevKey = coll.getCollationKey(cases[j-1]);
2531 if (key.compareTo(prevKey)>0) {
2532 errln("Error! Rule:"+rules[i]+" test["+j+"]:source:"+
2533 cases[j]+" is not <= previous test string.");
2537 if (key.compareTo(prevKey)<0) {
2538 errln("Error! Rule:"+rules[i]+" test["+j+"]:source:"+
2539 cases[j]+" is not >= previous test string.");
2543 logln("String:"+cases[j]+" Key:"+ prettify(key));
2550 * Stores a test case for collation testing.
2552 private class OneTestCase {
2553 /** The first value to compare. **/
2554 public String m_source_;
2556 /** The second value to compare. **/
2557 public String m_target_;
2560 * 0 if the two values sort equal,
2561 * -1 if the first value sorts before the second
2562 * 1 if the first value sorts after the first
2564 public int m_result_;
2566 public OneTestCase(String source, String target, int result) {
2574 * Convenient function to test collation rules.
2576 * @param rules Collation rules in ICU format. All the strings in this
2577 * array represent the same rule, expressed in different forms.
2579 private void doTestCollation(
2580 OneTestCase[] testCases, String[] rules) {
2582 Collator myCollation;
2583 for (String rule : rules) {
2585 myCollation = new RuleBasedCollator(rule);
2586 } catch (Exception e) {
2587 warnln("ERROR: in creation of rule based collator");
2591 myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
2592 myCollation.setStrength(Collator.TERTIARY);
2593 for (OneTestCase testCase : testCases) {
2594 CollationTest.doTest(this, (RuleBasedCollator)myCollation,
2597 testCase.m_result_);
2602 // Test cases to check whether the rules equivalent to
2603 // "&a<b<c<d &b<<k<<l<<m &k<<<x<<<y<<<z &a=1=2=3" are working fine.
2604 private OneTestCase[] m_rangeTestCases_ = {
2605 // Left Right Result
2606 new OneTestCase( "\u0061", "\u0062", -1 ), // "a" < "b"
2607 new OneTestCase( "\u0062", "\u0063", -1 ), // "b" < "c"
2608 new OneTestCase( "\u0061", "\u0063", -1 ), // "a" < "c"
2610 new OneTestCase( "\u0062", "\u006b", -1 ), // "b" << "k"
2611 new OneTestCase( "\u006b", "\u006c", -1 ), // "k" << "l"
2612 new OneTestCase( "\u0062", "\u006c", -1 ), // "b" << "l"
2613 new OneTestCase( "\u0061", "\u006c", -1 ), // "a" << "l"
2614 new OneTestCase( "\u0061", "\u006d", -1 ), // "a" << "m"
2616 new OneTestCase( "\u0079", "\u006d", -1 ), // "y" < "f"
2617 new OneTestCase( "\u0079", "\u0067", -1 ), // "y" < "g"
2618 new OneTestCase( "\u0061", "\u0068", -1 ), // "y" < "h"
2619 new OneTestCase( "\u0061", "\u0065", -1 ), // "g" < "e"
2621 new OneTestCase( "\u0061", "\u0031", 0 ), // "a" == "1"
2622 new OneTestCase( "\u0061", "\u0032", 0 ), // "a" == "2"
2623 new OneTestCase( "\u0061", "\u0033", 0 ), // "a" == "3"
2624 new OneTestCase( "\u0061", "\u0066", -1 ), // "a" < "f",
2625 new OneTestCase( "\u006c\u0061", "\u006b\u0062", -1 ), // "la" < "kb"
2626 new OneTestCase( "\u0061\u0061\u0061", "\u0031\u0032\u0033", 0 ), // "aaa" == "123"
2627 new OneTestCase( "\u0062", "\u007a", -1 ), // "b" < "z"
2628 new OneTestCase( "\u0061\u007a\u0062", "\u0032\u0079\u006d", -1 ), // "azm" < "2yc"
2631 // Test cases to check whether the rules equivalent to
2632 // "&\ufffe<\uffff<\U00010000<\U00010001<\U00010002
2633 // &\U00010000<<\U00020001<<\U00020002<<\U00020002
2634 // &\U00020001=\U0003001=\U0004001=\U0004002
2635 // &\U00040008<\U00030008<\UU00020008"
2636 // are working fine.
2637 private OneTestCase[] m_rangeTestCasesSupplemental_ = {
2638 // Left Right Result
2639 new OneTestCase( "\ufffe", "\uffff", -1 ),
2640 new OneTestCase( "\uffff", "\ud800\udc00", -1 ), // U+FFFF < U+10000
2641 new OneTestCase( "\ud800\udc00", "\ud800\udc01", -1 ), // U+10000 < U+10001
2643 new OneTestCase( "\ufffe", "\ud800\udc01", -1 ), // U+FFFE < U+10001
2644 new OneTestCase( "\ud800\udc01", "\ud800\udc02", -1 ), // U+10001 < U+10002
2645 new OneTestCase( "\ud800\udc00", "\ud840\udc02", -1 ), // U+10000 < U+10002
2646 new OneTestCase( "\ufffe", "\u0d840\udc02", -1 ), // U+FFFF < U+10002
2650 // Test cases in disjoint random code points. To test only the compact syntax.
2651 // Rule: &q<w<e<r &w<<t<<y<<u &t<<<i<<<o<<<p &o=a=s=d
2652 private OneTestCase[] m_qwertCollationTestCases_ = {
2653 new OneTestCase("q", "w" , -1),
2654 new OneTestCase("w", "e" , -1),
2656 new OneTestCase("y", "u" , -1),
2657 new OneTestCase("q", "u" , -1),
2659 new OneTestCase("t", "i" , -1),
2660 new OneTestCase("o", "p" , -1),
2662 new OneTestCase("y", "e" , -1),
2663 new OneTestCase("i", "u" , -1),
2665 new OneTestCase("quest", "were" , -1),
2666 new OneTestCase("quack", "quest", -1)
2669 // Tests the compact list with ASCII codepoints.
2670 public void TestSameStrengthList() {
2671 String[] rules = new String[] {
2673 "&a<b<c<d &b<<k<<l<<m &k<<<x<<<y<<<z &y<f<g<h<e &a=1=2=3",
2676 "&a<*bcd &b<<*klm &k<<<*xyz &y<*fghe &a=*123",
2678 // Lists with quoted characters
2679 "&'\u0061'<*bcd &b<<*klm &k<<<*xyz &y<*f'\u0067\u0068'e &a=*123",
2681 doTestCollation(m_rangeTestCases_, rules);
2684 public void TestSameStrengthListQuoted() {
2685 String[] rules = new String[] {
2686 "&'\u0061'<*bcd &b<<*klm &k<<<*xyz &y<*f'\u0067\u0068'e &a=1=2=3",
2687 "&'\u0061'<*b'\u0063'd &b<<*klm &k<<<*xyz &'\u0079'<*fgh'\u0065' " +
2688 "&a=*'\u0031\u0032\u0033'",
2690 "&'\u0061'<*'\u0062'c'\u0064' &b<<*klm &k<<<*xyz &y<*fghe " +
2691 "&a=*'\u0031\u0032\u0033'",
2693 doTestCollation(m_rangeTestCases_, rules);
2696 // Tests the compact list with ASCII codepoints in non-codepoint order.
2697 public void TestSameStrengthListQwerty() {
2698 String[] rules = new String[] {
2699 "&q<w<e<r &w<<t<<y<<u &t<<<i<<<o<<<p &o=a=s=d", // Normal
2700 "&q<*wer &w<<*tyu &t<<<*iop &o=*asd", // Lists
2703 doTestCollation(m_qwertCollationTestCases_, rules);
2706 // Tests the compact list with supplemental codepoints.
2707 public void TestSameStrengthListWithSupplementalCharacters() {
2708 String[] rules = new String[] {
2709 // ** Rule without compact list syntax **
2710 // \ufffe < \uffff < \U00010000 < \U00010001 < \U00010002
2711 "&'\ufffe'<'\uffff'<'\ud800\udc00'<'\ud800\udc01'<'\ud800\udc02' " +
2712 // \U00010000 << \U00020001 << \U00020002 \U00020002
2713 "&'\ud800\udc00'<<'\ud840\udc01'<<'\ud840\udc02'<<'\ud840\udc02' " +
2714 // \U00020001 = \U0003001 = \U0004001 = \U0004002
2715 "&'\ud840\udc01'='\ud880\udc01'='\ud8c0\udc01'='\ud8c0\udc02'" +
2716 // \U00040008 < \U00030008 < \U00020008
2717 "&'\ud8c0\udc08'<'\ud880\udc08'<'\ud840\udc08'",
2719 // ** Rule with compact list syntax **
2720 // \ufffe <* \uffff\U00010000 \U00010001
2721 "&'\ufffe'<*'\uffff\ud800\udc00\ud800\udc01\ud800\udc02' " +
2722 // \U00010000 <<* \U00020001 \U00020002
2723 "&'\ud800\udc00'<<*'\ud840\udc01\ud840\udc02\ud840\udc03' " +
2724 // \U00020001 =* \U0003001 \U0003002 \U0003003 \U0004001
2725 "&'\ud840\udc01'=*'\ud880\udc01\ud880\udc02\ud880\udc03\ud8c0\udc01' " +
2726 // \U00040008 <* \U00030008 \U00030009 \U0003000a \U00020008
2727 "&'\ud8c0\udc08'<*'\ud880\udc08\ud880\udc09\ud880\udc0a\ud840\udc08'",
2730 doTestCollation(m_rangeTestCasesSupplemental_, rules);
2734 // Tests the compact range syntax with ASCII codepoints.
2735 public void TestSameStrengthListRanges() {
2736 String[] rules = new String[] {
2738 "&a<*b-d &b<<*k-m &k<<<*x-z &y<*f-he &a=*1-3",
2740 // Ranges with quoted characters
2741 "&'\u0061'<*'\u0062'-'\u0064' &b<<*klm &k<<<*xyz " +
2742 "&'\u0079'<*'\u0066'-'\u0068e' &a=*123",
2743 "&'\u0061'<*'\u0062'-'\u0064' " +
2744 "&b<<*'\u006B'-m &k<<<*x-'\u007a' " +
2745 "&'\u0079'<*'\u0066'-h'\u0065' &a=*'\u0031\u0032\u0033'",
2748 doTestCollation(m_rangeTestCases_, rules);
2751 // Tests the compact range syntax with supplemental codepoints.
2752 public void TestSameStrengthListRangesWithSupplementalCharacters() {
2753 String[] rules = new String[] {
2754 // \ufffe <* \uffff\U00010000 \U00010001
2755 "&'\ufffe'<*'\uffff'-'\ud800\udc02' " +
2756 // \U00010000 <<* \U00020001 - \U00020003
2757 "&'\ud800\udc00'<<*'\ud840\udc01'-'\ud840\udc03' " +
2758 // \U00020001 =* \U0003001 \U0004001
2759 "&'\ud840\udc01'=*'\ud880\udc01'-'\ud880\udc03\ud8c0\udc01' " +
2760 // \U00040008 <* \U00030008 \U00020008
2761 "&'\ud8c0\udc08'<*'\ud880\udc08'-'\ud880\udc0a\ud840\udc08'",
2763 doTestCollation(m_rangeTestCasesSupplemental_, rules);
2766 // Tests the compact range syntax with special characters used as syntax characters in rules.
2767 public void TestSpecialCharacters() {
2768 String rules[] = new String[] {
2770 "&';'<'+'<','<'-'<'&'<'*'",
2778 "&'\u003b'<'\u002b'<'\u002c'<'\u002d'<'\u0026'<'\u002a'",
2780 "&'\u003b'<*'\u002b\u002c\u002d\u0026\u002a'",
2781 "&'\u003b'<*'\u002b\u002c\u002d\u0026\u002a'",
2782 "&'\u003b'<*'\u002b'-'\u002d\u0026\u002a'",
2783 "&'\u003b'<*'\u002b'-'\u002d\u0026\u002a'",
2785 OneTestCase[] testCases = new OneTestCase[] {
2786 new OneTestCase("\u003b", "\u002b", -1), // ; < +
2787 new OneTestCase("\u002b", "\u002c", -1), // + < ,
2788 new OneTestCase("\u002c", "\u002d", -1), // , < -
2789 new OneTestCase("\u002d", "\u0026", -1), // - < &
2791 doTestCollation(testCases, rules);
2794 public void TestInvalidListsAndRanges() {
2795 String[] invalidRules = new String[] {
2796 // Range not in starred expression
2797 "&'\ufffe'<'\uffff'-'\ud800\udc02'",
2799 // Range without start
2802 // Range without end
2805 // More than one hyphen
2808 // Range in the wrong order
2811 for (String rule : invalidRules) {
2813 Collator myCollation = new RuleBasedCollator(rule);
2814 warnln("ERROR: Creation of collator didn't fail for " + rule + " when it should.");
2815 CollationTest.doTest(this, (RuleBasedCollator)myCollation,
2820 } catch (Exception e) {
2823 throw new IllegalArgumentException("ERROR: Invalid collator with rule " + rule + " worked fine.");
2827 // This is the same example above with ' and space added.
2828 // They work a little different than expected. Desired rules are commented out.
2829 public void TestQuoteAndSpace() {
2830 String rules[] = new String[] {
2831 // These are working as expected.
2832 "&';'<'+'<','<'-'<'&'<''<'*'<' '",
2834 // List. Desired rule is
2835 // "&';'<*'+,-&''* '",
2836 // but it doesn't work. Instead, '' should be outside quotes as below.
2837 "&';'<*'+,-&''''* '",
2839 // Range. Similar issues here as well. The following are working.
2840 //"&';'<*'+'-'-&''* '",
2841 //"&';'<*'+'-'-&'\\u0027'* '",
2842 "&';'<*'+'-'-&''''* '",
2843 //"&';'<*'+'-'-&'\\u0027'* '",
2845 // The following rules are not working.
2846 // "&';'<'+'<','<'-'<'&'<\\u0027<'*'<' '",
2847 //"&'\u003b'<'\u002b'<'\u002c'<'\u002d'<'\u0026'<'\u0027'<\u002a'<'\u0020'",
2848 //"&'\u003b'<'\u002b'<'\u002c'<'\u002d'<'\u0026'<\\u0027<\u002a'<'\u0020'",
2851 OneTestCase[] testCases = new OneTestCase[] {
2852 new OneTestCase("\u003b", "\u002b", -1), // ; < ,
2853 new OneTestCase("\u002b", "\u002c", -1), // ; < ,
2854 new OneTestCase("\u002c", "\u002d", -1), // , < -
2855 new OneTestCase("\u002d", "\u0026", -1), // - < &
2856 new OneTestCase("\u0026", "\u0027", -1), // & < '
2857 new OneTestCase("\u0027", "\u002a", -1), // ' < *
2858 // new OneTestCase("\u002a", "\u0020", -1), // * < <space>
2860 doTestCollation(testCases, rules);
2864 * Tests the method public boolean equals(Object target) in CollationKey
2866 public void TestCollationKeyEquals() {
2867 CollationKey ck = new CollationKey("", (byte[]) null);
2869 // Tests when "if (!(target instanceof CollationKey))" is true
2870 if (ck.equals(new Object())) {
2871 errln("CollationKey.equals() was not suppose to return false "
2872 + "since it is comparing to a non Collation Key object.");
2874 if (ck.equals("")) {
2875 errln("CollationKey.equals() was not suppose to return false "
2876 + "since it is comparing to a non Collation Key object.");
2879 errln("CollationKey.equals() was not suppose to return false "
2880 + "since it is comparing to a non Collation Key object.");
2882 if (ck.equals(0.0)) {
2883 errln("CollationKey.equals() was not suppose to return false "
2884 + "since it is comparing to a non Collation Key object.");
2887 // Tests when "if (target == null)" is true
2888 if (ck.equals((CollationKey) null)) {
2889 errln("CollationKey.equals() was not suppose to return false "
2890 + "since it is comparing to a null Collation Key object.");
2895 * Tests the method public int hashCode() in CollationKey
2897 public void TestCollationKeyHashCode() {
2898 CollationKey ck = new CollationKey("", (byte[]) null);
2900 // Tests when "if (m_key_ == null)" is true
2901 if (ck.hashCode() != 1) {
2902 errln("CollationKey.hashCode() was suppose to return 1 "
2903 + "when m_key is null due a null parameter in the " + "constructor.");
2908 * Tests the method public CollationKey getBound(int boundType, int noOfLevels)
2910 public void TestGetBound() {
2911 CollationKey ck = new CollationKey("", (byte[]) null);
2913 // Tests when "if (noOfLevels > Collator.PRIMARY)" is false
2914 // Tests when "default: " is true for "switch (boundType)"
2916 ck.getBound(BoundMode.COUNT, -1);
2917 errln("CollationKey.getBound(int,int) was suppose to return an "
2918 + "exception for an invalid boundType value.");
2919 } catch (Exception e) {
2922 // Tests when "if (noOfLevels > 0)"
2924 CollationKey ck1 = new CollationKey("", b);
2927 errln("CollationKey.getBound(int,int) was suppose to return an "
2928 + "exception a value of noOfLevels that exceeds expected.");
2929 } catch (Exception e) {
2934 * Tests the method public CollationKey merge(CollationKey source)
2936 public void TestMerge() {
2938 CollationKey ck = new CollationKey("", b);
2940 // Tests when "if (source == null || source.getLength() == 0)" is true
2943 errln("Collationkey.merge(CollationKey) was suppose to return " + "an exception for a null parameter.");
2944 } catch (Exception e) {
2948 errln("Collationkey.merge(CollationKey) was suppose to return " + "an exception for a null parameter.");
2949 } catch (Exception e) {
2953 /* Test the method public int compareTo(RawCollationKey rhs) */
2954 public void TestRawCollationKeyCompareTo(){
2955 RawCollationKey rck = new RawCollationKey();
2956 byte[] b = {(byte) 10, (byte) 20};
2957 RawCollationKey rck100 = new RawCollationKey(b, 2);
2959 if(rck.compareTo(rck) != 0){
2960 errln("RawCollatonKey.compareTo(RawCollationKey) was suppose to return 0 " +
2961 "for two idential RawCollationKey objects.");
2964 if(rck.compareTo(rck100) == 0){
2965 errln("RawCollatonKey.compareTo(RawCollationKey) was not suppose to return 0 " +
2966 "for two different RawCollationKey objects.");
2970 /* Track7223: CollationElementIterator does not return correct order for Hungarian */
2971 public void TestHungarianTailoring(){
2972 String rules = new String("&DZ<dzs<<<Dzs<<<DZS" +
2979 "&O<\u00f6<<<\u00d6<<\u0151<<<\u0150" +
2980 "&U<\u00fc<<<\u00dc<<\u0171<<<\u0171" +
2993 RuleBasedCollator coll;
2995 String str1 = "ggy";
2996 String str2 = "GGY";
2997 coll = new RuleBasedCollator(rules);
2998 if (coll.compare("ggy", "GGY") >= 0) {
2999 errln("TestHungarianTailoring.compare(" + str1 + ","+ str2 +
3000 ") was suppose to return -1 ");
3002 CollationKey sortKey1 = coll.getCollationKey(str1);
3003 CollationKey sortKey2 = coll.getCollationKey(str2);
3004 if (sortKey1.compareTo(sortKey2) >= 0) {
3005 errln("TestHungarianTailoring getCollationKey(\"" + str1 +"\") was suppose "+
3006 "less than getCollationKey(\""+ str2 + "\").");
3007 errln(" getCollationKey(\"ggy\"):" + prettify(sortKey1) +
3008 " getCollationKey(\"GGY\"):" + prettify(sortKey2));
3011 CollationElementIterator iter1 = coll.getCollationElementIterator(str1);
3012 CollationElementIterator iter2 = coll.getCollationElementIterator(str2);
3014 while((ce1 = iter1.next()) != CollationElementIterator.NULLORDER &&
3015 (ce2 = iter2.next()) != CollationElementIterator.NULLORDER) {
3017 errln("TestHungarianTailoring.CollationElementIterator(" + str1 +
3018 ","+ str2 + ") was suppose to return -1 ");
3021 } catch (Exception e) {
3022 e.printStackTrace();
3026 public void TestImport(){
3028 RuleBasedCollator vicoll = (RuleBasedCollator)Collator.getInstance(new ULocale("vi"));
3029 RuleBasedCollator escoll = (RuleBasedCollator)Collator.getInstance(new ULocale("es"));
3030 RuleBasedCollator viescoll = new RuleBasedCollator(vicoll.getRules() + escoll.getRules());
3031 RuleBasedCollator importviescoll = new RuleBasedCollator("[import vi][import es]");
3033 UnicodeSet tailoredSet = viescoll.getTailoredSet();
3034 UnicodeSet importTailoredSet = importviescoll.getTailoredSet();
3036 if(!tailoredSet.equals(importTailoredSet)){
3037 warnln("Tailored set not equal");
3040 for (UnicodeSetIterator it = new UnicodeSetIterator(tailoredSet); it.next();) {
3041 String t = it.getString();
3042 CollationKey sk1 = viescoll.getCollationKey(t);
3043 CollationKey sk2 = importviescoll.getCollationKey(t);
3044 if(!sk1.equals(sk2)){
3045 warnln("Collation key's not equal for " + t);
3049 }catch(Exception e){
3050 warnln("ERROR: in creation of rule based collator");
3054 public void TestImportWithType(){
3056 RuleBasedCollator vicoll = (RuleBasedCollator)Collator.getInstance(new ULocale("vi"));
3057 RuleBasedCollator decoll = (RuleBasedCollator)Collator.getInstance(ULocale.forLanguageTag("de-u-co-phonebk"));
3058 RuleBasedCollator videcoll = new RuleBasedCollator(vicoll.getRules() + decoll.getRules());
3059 RuleBasedCollator importvidecoll = new RuleBasedCollator("[import vi][import de-u-co-phonebk]");
3061 UnicodeSet tailoredSet = videcoll.getTailoredSet();
3062 UnicodeSet importTailoredSet = importvidecoll.getTailoredSet();
3064 if(!tailoredSet.equals(importTailoredSet)){
3065 warnln("Tailored set not equal");
3068 for (UnicodeSetIterator it = new UnicodeSetIterator(tailoredSet); it.next();) {
3069 String t = it.getString();
3070 CollationKey sk1 = videcoll.getCollationKey(t);
3071 CollationKey sk2 = importvidecoll.getCollationKey(t);
3072 if(!sk1.equals(sk2)){
3073 warnln("Collation key's not equal for " + t);
3077 }catch(Exception e){
3078 warnln("ERROR: in creation of rule based collator");
3083 * This test ensures that characters placed before a character in a different script have the same lead byte
3084 * in their collation key before and after script reordering.
3086 public void TestBeforeRuleWithScriptReordering() throws Exception
3088 /* build collator */
3089 String rules = "&[before 1]\u03b1 < \u0e01";
3090 int[] reorderCodes = {UScript.GREEK};
3093 Collator myCollation = new RuleBasedCollator(rules);
3094 myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
3095 myCollation.setStrength(Collator.TERTIARY);
3097 String base = "\u03b1"; /* base */
3098 String before = "\u0e01"; /* ko kai */
3100 /* check collation results - before rule applied but not script reordering */
3101 result = myCollation.compare(base, before);
3102 if (!(result > 0)) {
3103 errln("Collation result not correct before script reordering.");
3106 /* check the lead byte of the collation keys before script reordering */
3107 CollationKey baseKey = myCollation.getCollationKey(base);
3108 CollationKey beforeKey = myCollation.getCollationKey(before);
3109 byte[] baseKeyBytes = baseKey.toByteArray();
3110 byte[] beforeKeyBytes = beforeKey.toByteArray();
3111 if (baseKeyBytes[0] != beforeKeyBytes[0]) {
3112 errln("Different lead byte for sort keys using before rule and before script reordering. base character lead byte = "
3113 + baseKeyBytes[0] + ", before character lead byte = " + beforeKeyBytes[0]);
3116 /* reorder the scripts */
3117 myCollation.setReorderCodes(reorderCodes);
3119 /* check collation results - before rule applied and after script reordering */
3120 result = myCollation.compare(base, before);
3121 if (!(result > 0)) {
3122 errln("Collation result not correct after script reordering.");
3125 /* check the lead byte of the collation keys after script reordering */
3126 baseKey = myCollation.getCollationKey(base);
3127 beforeKey = myCollation.getCollationKey(before);
3128 baseKeyBytes = baseKey.toByteArray();
3129 beforeKeyBytes = beforeKey.toByteArray();
3130 if (baseKeyBytes[0] != beforeKeyBytes[0]) {
3131 errln("Different lead byte for sort keys using before rule and before script reordering. base character lead byte = "
3132 + baseKeyBytes[0] + ", before character lead byte = " + beforeKeyBytes[0]);
3137 * Test that in a primary-compressed sort key all bytes except the first one are unchanged under script reordering.
3139 public void TestNonLeadBytesDuringCollationReordering() throws Exception
3141 Collator myCollation;
3144 int[] reorderCodes = {UScript.GREEK};
3145 String testString = "\u03b1\u03b2\u03b3";
3147 /* build collator tertiary */
3148 myCollation = new RuleBasedCollator("");
3149 myCollation.setStrength(Collator.TERTIARY);
3150 baseKey = myCollation.getCollationKey(testString).toByteArray();
3152 myCollation.setReorderCodes(reorderCodes);
3153 reorderKey = myCollation.getCollationKey(testString).toByteArray();
3155 if (baseKey.length != reorderKey.length) {
3156 errln("Key lengths not the same during reordering.\n");
3159 for (int i = 1; i < baseKey.length; i++) {
3160 if (baseKey[i] != reorderKey[i]) {
3161 errln("Collation key bytes not the same at position " + i);
3165 /* build collator tertiary */
3166 myCollation = new RuleBasedCollator("");
3167 myCollation.setStrength(Collator.QUATERNARY);
3168 baseKey = myCollation.getCollationKey(testString).toByteArray();
3170 myCollation.setReorderCodes(reorderCodes);
3171 reorderKey = myCollation.getCollationKey(testString).toByteArray();
3173 if (baseKey.length != reorderKey.length) {
3174 errln("Key lengths not the same during reordering.\n");
3177 for (int i = 1; i < baseKey.length; i++) {
3178 if (baseKey[i] != reorderKey[i]) {
3179 errln("Collation key bytes not the same at position " + i);
3185 * Test reordering API.
3187 public void TestReorderingAPI() throws Exception
3189 Collator myCollation;
3190 int[] reorderCodes = {UScript.GREEK, UScript.HAN, ReorderCodes.PUNCTUATION};
3191 int[] duplicateReorderCodes = {UScript.CUNEIFORM, UScript.GREEK, ReorderCodes.CURRENCY, UScript.EGYPTIAN_HIEROGLYPHS};
3192 int[] reorderCodesStartingWithDefault = {ReorderCodes.DEFAULT, UScript.GREEK, UScript.HAN, ReorderCodes.PUNCTUATION};
3193 int[] retrievedReorderCodes;
3194 String greekString = "\u03b1";
3195 String punctuationString = "\u203e";
3197 /* build collator tertiary */
3198 myCollation = new RuleBasedCollator("");
3199 myCollation.setStrength(Collator.TERTIARY);
3201 /* set the reorderding */
3202 myCollation.setReorderCodes(reorderCodes);
3204 retrievedReorderCodes = myCollation.getReorderCodes();
3205 if (!Arrays.equals(reorderCodes, retrievedReorderCodes)) {
3206 errln("ERROR: retrieved reorder codes do not match set reorder codes.");
3208 if (!(myCollation.compare(greekString, punctuationString) < 0)) {
3209 errln("ERROR: collation result should have been less.");
3212 /* clear the reordering */
3213 myCollation.setReorderCodes(null);
3214 retrievedReorderCodes = myCollation.getReorderCodes();
3215 if (retrievedReorderCodes.length != 0) {
3216 errln("ERROR: retrieved reorder codes was not null.");
3219 if (!(myCollation.compare(greekString, punctuationString) > 0)) {
3220 errln("ERROR: collation result should have been greater.");
3223 // do it again with an empty but non-null array
3225 /* set the reorderding */
3226 myCollation.setReorderCodes(reorderCodes);
3228 retrievedReorderCodes = myCollation.getReorderCodes();
3229 if (!Arrays.equals(reorderCodes, retrievedReorderCodes)) {
3230 errln("ERROR: retrieved reorder codes do not match set reorder codes.");
3232 if (!(myCollation.compare(greekString, punctuationString) < 0)) {
3233 errln("ERROR: collation result should have been less.");
3236 /* clear the reordering */
3237 myCollation.setReorderCodes(new int[]{});
3238 retrievedReorderCodes = myCollation.getReorderCodes();
3239 if (retrievedReorderCodes.length != 0) {
3240 errln("ERROR: retrieved reorder codes was not null.");
3243 if (!(myCollation.compare(greekString, punctuationString) > 0)) {
3244 errln("ERROR: collation result should have been greater.");
3247 boolean gotException = false;
3248 /* set duplicates in the reorder codes */
3250 myCollation.setReorderCodes(duplicateReorderCodes);
3251 } catch (IllegalArgumentException e) {
3252 // expect exception on illegal arguments
3253 gotException = true;
3255 if (!gotException) {
3256 errln("ERROR: exception was not thrown for illegal reorder codes argument.");
3259 /* set duplicate reorder codes */
3260 gotException = false;
3262 myCollation.setReorderCodes(reorderCodesStartingWithDefault);
3263 } catch (IllegalArgumentException e) {
3264 gotException = true;
3266 if (!gotException) {
3267 errln("ERROR: reorder codes following a 'default' code should have thrown an exception but did not.");
3272 * Test reordering API.
3274 public void TestReorderingAPIWithRuleCreatedCollator() throws Exception
3276 Collator myCollation;
3277 String rules = "[reorder Hani Grek]";
3278 int[] rulesReorderCodes = {UScript.HAN, UScript.GREEK};
3279 int[] reorderCodes = {UScript.GREEK, UScript.HAN, ReorderCodes.PUNCTUATION};
3280 int[] retrievedReorderCodes;
3283 /* build collator tertiary */
3284 myCollation = new RuleBasedCollator(rules);
3285 myCollation.setStrength(Collator.TERTIARY);
3287 retrievedReorderCodes = myCollation.getReorderCodes();
3288 if (!Arrays.equals(rulesReorderCodes, retrievedReorderCodes)) {
3289 errln("ERROR: retrieved reorder codes do not match set reorder codes.");
3292 /* clear the reordering */
3293 myCollation.setReorderCodes(null);
3294 retrievedReorderCodes = myCollation.getReorderCodes();
3295 if (retrievedReorderCodes.length != 0) {
3296 errln("ERROR: retrieved reorder codes was not null.");
3299 /* set the reorderding */
3300 myCollation.setReorderCodes(reorderCodes);
3302 retrievedReorderCodes = myCollation.getReorderCodes();
3303 if (!Arrays.equals(reorderCodes, retrievedReorderCodes)) {
3304 errln("ERROR: retrieved reorder codes do not match set reorder codes.");
3307 /* reset the reordering */
3308 myCollation.setReorderCodes(ReorderCodes.DEFAULT);
3309 retrievedReorderCodes = myCollation.getReorderCodes();
3310 if (!Arrays.equals(rulesReorderCodes, retrievedReorderCodes)) {
3311 errln("ERROR: retrieved reorder codes do not match set reorder codes.");
3315 public void TestSameLeadBytScriptReorder(){
3316 String[] testSourceCases = {
3317 "\ud800\udf31", // Gothic
3318 "\ud801\udc50", // Shavian
3321 String[] testTargetCases = {
3322 "\u0100", // Latin Extended-A
3323 "\u2c74", // Latin Extended-C
3331 Collator myCollation;
3332 String rules = "[reorder Goth Latn]";
3334 myCollation = new RuleBasedCollator(rules);
3335 } catch (Exception e) {
3336 warnln("ERROR: in creation of rule based collator");
3339 myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
3340 myCollation.setStrength(Collator.TERTIARY);
3341 for (int i = 0; i < testSourceCases.length ; i++)
3343 CollationTest.doTest(this, (RuleBasedCollator)myCollation,
3344 testSourceCases[i], testTargetCases[i],
3348 // ensure that the non-reordered and reordered collation is the same
3349 Collator nonReorderdCollator = RuleBasedCollator.getInstance();
3350 int nonReorderedResults = nonReorderdCollator.compare(testSourceCases[0], testSourceCases[1]);
3351 CollationTest.doTest(this, (RuleBasedCollator)myCollation,
3352 testSourceCases[0], testSourceCases[1], nonReorderedResults);
3355 public void TestEquivalentReorderingScripts() {
3356 int[] equivalentScriptsResult = {
3357 UScript.BOPOMOFO, //Bopo
3358 UScript.LISU, //Lisu
3359 UScript.LYCIAN, //Lyci
3360 UScript.CARIAN, //Cari
3361 UScript.LYDIAN, //Lydi
3363 UScript.OLD_ITALIC, //Ital
3364 UScript.GOTHIC, //Goth
3365 UScript.DESERET, //Dsrt
3366 UScript.SHAVIAN, //Shaw
3367 UScript.OSMANYA, //Osma
3368 UScript.LINEAR_B, //Linb
3369 UScript.CYPRIOT, //Cprt
3370 UScript.OLD_SOUTH_ARABIAN, //Sarb
3371 UScript.AVESTAN, //Avst
3372 UScript.IMPERIAL_ARAMAIC, //Armi
3373 UScript.INSCRIPTIONAL_PARTHIAN, //Prti
3374 UScript.INSCRIPTIONAL_PAHLAVI, //Phli
3375 UScript.UGARITIC, //Ugar
3376 UScript.OLD_PERSIAN, //Xpeo
3377 UScript.CUNEIFORM, //Xsux
3378 UScript.EGYPTIAN_HIEROGLYPHS, //Egyp
3379 UScript.PHONETIC_POLLARD, //Plrd
3380 UScript.SORA_SOMPENG, //Sora
3381 UScript.MEROITIC_CURSIVE, //Merc
3382 UScript.MEROITIC_HIEROGLYPHS //Mero
3384 Arrays.sort(equivalentScriptsResult);
3386 int[] equivalentScripts = RuleBasedCollator.getEquivalentReorderCodes(UScript.GOTHIC);
3387 Arrays.sort(equivalentScripts);
3388 boolean equal = Arrays.equals(equivalentScripts, equivalentScriptsResult);
3389 assertTrue("Script Equivalents for Reordering", equal);
3391 StringBuilder s = new StringBuilder(" {");
3392 for (int code : equivalentScripts) {
3393 s.append(" " + UCharacter.getPropertyValueName(UProperty.SCRIPT, code, UProperty.NameChoice.SHORT));
3395 s.append(" } vs. {");
3396 for (int code : equivalentScriptsResult) {
3397 s.append(" " + UCharacter.getPropertyValueName(UProperty.SCRIPT, code, UProperty.NameChoice.SHORT));
3400 errln(s.toString());
3403 equivalentScripts = RuleBasedCollator.getEquivalentReorderCodes(UScript.SHAVIAN);
3404 Arrays.sort(equivalentScripts);
3405 assertTrue("Script Equivalents for Reordering", Arrays.equals(equivalentScripts, equivalentScriptsResult));
3408 public void TestGreekFirstReorderCloning() {
3409 String[] testSourceCases = {
3417 String[] testTargetCases = {
3433 Collator originalCollation;
3434 Collator myCollation;
3435 String rules = "[reorder Grek]";
3437 originalCollation = new RuleBasedCollator(rules);
3438 } catch (Exception e) {
3439 warnln("ERROR: in creation of rule based collator");
3443 myCollation = (Collator) originalCollation.clone();
3444 } catch (Exception e) {
3445 warnln("ERROR: in creation of rule based collator");
3448 myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
3449 myCollation.setStrength(Collator.TERTIARY);
3450 for (int i = 0; i < testSourceCases.length ; i++)
3452 CollationTest.doTest(this, (RuleBasedCollator)myCollation,
3453 testSourceCases[i], testTargetCases[i],
3459 * Utility function to test one collation reordering test case.
3460 * @param testcases Array of test cases.
3461 * @param n_testcases Size of the array testcases.
3462 * @param str_rules Array of rules. These rules should be specifying the same rule in different formats.
3463 * @param n_rules Size of the array str_rules.
3465 private void doTestOneReorderingAPITestCase(OneTestCase testCases[], int reorderTokens[])
3467 Collator myCollation = Collator.getInstance(ULocale.ENGLISH);
3468 myCollation.setReorderCodes(reorderTokens);
3470 for (OneTestCase testCase : testCases) {
3471 CollationTest.doTest(this, (RuleBasedCollator)myCollation,
3474 testCase.m_result_);
3478 public void TestGreekFirstReorder()
3480 String[] strRules = {
3488 OneTestCase[] privateUseCharacterStrings = {
3489 new OneTestCase("\u0391", "\u0391", 0),
3490 new OneTestCase("\u0041", "\u0391", 1),
3491 new OneTestCase("\u03B1\u0041", "\u03B1\u0391", 1),
3492 new OneTestCase("\u0060", "\u0391", -1),
3493 new OneTestCase("\u0391", "\ue2dc", -1),
3494 new OneTestCase("\u0391", "\u0060", 1),
3497 /* Test rules creation */
3498 doTestCollation(privateUseCharacterStrings, strRules);
3500 /* Test collation reordering API */
3501 doTestOneReorderingAPITestCase(privateUseCharacterStrings, apiRules);
3504 public void TestGreekLastReorder()
3506 String[] strRules = {
3507 "[reorder Zzzz Grek]"
3511 UScript.UNKNOWN, UScript.GREEK
3514 OneTestCase[] privateUseCharacterStrings = {
3515 new OneTestCase("\u0391", "\u0391", 0),
3516 new OneTestCase("\u0041", "\u0391", -1),
3517 new OneTestCase("\u03B1\u0041", "\u03B1\u0391", -1),
3518 new OneTestCase("\u0060", "\u0391", -1),
3519 new OneTestCase("\u0391", "\ue2dc", 1),
3522 /* Test rules creation */
3523 doTestCollation(privateUseCharacterStrings, strRules);
3525 /* Test collation reordering API */
3526 doTestOneReorderingAPITestCase(privateUseCharacterStrings, apiRules);
3529 public void TestNonScriptReorder()
3531 String[] strRules = {
3532 "[reorder Grek Symbol DIGIT Latn Punct space Zzzz cURRENCy]"
3536 UScript.GREEK, ReorderCodes.SYMBOL, ReorderCodes.DIGIT, UScript.LATIN,
3537 ReorderCodes.PUNCTUATION, ReorderCodes.SPACE, UScript.UNKNOWN,
3538 ReorderCodes.CURRENCY
3541 OneTestCase[] privateUseCharacterStrings = {
3542 new OneTestCase("\u0391", "\u0041", -1),
3543 new OneTestCase("\u0041", "\u0391", 1),
3544 new OneTestCase("\u0060", "\u0041", -1),
3545 new OneTestCase("\u0060", "\u0391", 1),
3546 new OneTestCase("\u0024", "\u0041", 1),
3549 /* Test rules creation */
3550 doTestCollation(privateUseCharacterStrings, strRules);
3552 /* Test collation reordering API */
3553 doTestOneReorderingAPITestCase(privateUseCharacterStrings, apiRules);
3556 public void TestHaniReorder()
3558 String[] strRules = {
3565 OneTestCase[] privateUseCharacterStrings = {
3566 new OneTestCase("\u4e00", "\u0041", -1),
3567 new OneTestCase("\u4e00", "\u0060", 1),
3568 new OneTestCase("\uD86D\uDF40", "\u0041", -1),
3569 new OneTestCase("\uD86D\uDF40", "\u0060", 1),
3570 new OneTestCase("\u4e00", "\uD86D\uDF40", -1),
3571 new OneTestCase("\ufa27", "\u0041", -1),
3572 new OneTestCase("\uD869\uDF00", "\u0041", -1),
3575 /* Test rules creation */
3576 doTestCollation(privateUseCharacterStrings, strRules);
3578 /* Test collation reordering API */
3579 doTestOneReorderingAPITestCase(privateUseCharacterStrings, apiRules);
3582 public void TestHaniReorderWithOtherRules()
3584 String[] strRules = {
3585 "[reorder Hani] &b<a"
3588 OneTestCase[] privateUseCharacterStrings = {
3589 new OneTestCase("\u4e00", "\u0041", -1),
3590 new OneTestCase("\u4e00", "\u0060", 1),
3591 new OneTestCase("\uD86D\uDF40", "\u0041", -1),
3592 new OneTestCase("\uD86D\uDF40", "\u0060", 1),
3593 new OneTestCase("\u4e00", "\uD86D\uDF40", -1),
3594 new OneTestCase("\ufa27", "\u0041", -1),
3595 new OneTestCase("\uD869\uDF00", "\u0041", -1),
3596 new OneTestCase("b", "a", -1),
3599 /* Test rules creation */
3600 doTestCollation(privateUseCharacterStrings, strRules);
3603 public void TestMultipleReorder()
3605 String[] strRules = {
3606 "[reorder Grek Zzzz DIGIT Latn Hani]"
3610 UScript.GREEK, UScript.UNKNOWN, ReorderCodes.DIGIT, UScript.LATIN, UScript.HAN
3613 OneTestCase[] collationTestCases = {
3614 new OneTestCase("\u0391", "\u0041", -1),
3615 new OneTestCase("\u0031", "\u0041", -1),
3616 new OneTestCase("u0041", "\u4e00", -1),
3619 /* Test rules creation */
3620 doTestCollation(collationTestCases, strRules);
3622 /* Test collation reordering API */
3623 doTestOneReorderingAPITestCase(collationTestCases, apiRules);
3626 public void TestFrozeness()
3628 Collator myCollation = Collator.getInstance(ULocale.CANADA);
3629 boolean exceptionCaught = false;
3631 myCollation.freeze();
3632 assertTrue("Collator not frozen.", myCollation.isFrozen());
3635 myCollation.setStrength(Collator.SECONDARY);
3636 } catch (UnsupportedOperationException e) {
3638 exceptionCaught = true;
3640 assertTrue("Frozen collator allowed change.", exceptionCaught);
3641 exceptionCaught = false;
3644 myCollation.setReorderCodes(ReorderCodes.DEFAULT);
3645 } catch (UnsupportedOperationException e) {
3647 exceptionCaught = true;
3649 assertTrue("Frozen collator allowed change.", exceptionCaught);
3650 exceptionCaught = false;
3653 myCollation.setVariableTop(12);
3654 } catch (UnsupportedOperationException e) {
3656 exceptionCaught = true;
3658 assertTrue("Frozen collator allowed change.", exceptionCaught);
3659 exceptionCaught = false;
3661 Collator myClone = null;
3663 myClone = (Collator) myCollation.clone();
3664 } catch (CloneNotSupportedException e) {
3665 // should not happen - clone is implemented in Collator
3666 errln("ERROR: unable to clone collator.");
3668 assertTrue("Clone not frozen as expected.", myClone.isFrozen());
3670 myClone = myClone.cloneAsThawed();
3671 assertFalse("Clone not thawed as expected.", myClone.isFrozen());
3674 // Test case for Ticket#9409
3675 // Unknown collation type should be ignored, without printing stack trace
3676 public void TestUnknownCollationKeyword() {
3677 Collator coll1 = Collator.getInstance(new ULocale("en_US@collation=bogus"));
3678 Collator coll2 = Collator.getInstance(new ULocale("en_US"));
3679 assertEquals("Unknown collation keyword 'bogus' should be ignored", coll1, coll2);