undefect. CWE-407 — 63 sites patched across 27 ecosystems

Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
This commit is contained in:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,325 @@
/*
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
/*
* @test
* @library /java/text/testlib
* @summary test Collation API
* @modules jdk.localedata
* @run junit APITest
*/
import java.util.Locale;
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.text.CollationKey;
import java.text.CollationElementIterator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
public class APITest {
final void doAssert(boolean condition, String message)
{
if (!condition) {
fail("ERROR: " + message);
}
}
@Test
public final void TestProperty( )
{
Collator col = null;
try {
col = Collator.getInstance(Locale.ROOT);
System.out.println("The property tests begin : ");
System.out.println("Test ctors : ");
doAssert(col.compare("ab", "abc") < 0, "ab < abc comparison failed");
doAssert(col.compare("ab", "AB") < 0, "ab < AB comparison failed");
doAssert(col.compare("black-bird", "blackbird") > 0, "black-bird > blackbird comparison failed");
doAssert(col.compare("black bird", "black-bird") < 0, "black bird < black-bird comparison failed");
doAssert(col.compare("Hello", "hello") > 0, "Hello > hello comparison failed");
System.out.println("Test ctors ends.");
System.out.println("testing Collator.getStrength() method ...");
doAssert(col.getStrength() == Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
System.out.println("testing Collator.setStrength() method ...");
col.setStrength(Collator.SECONDARY);
doAssert(col.getStrength() != Collator.TERTIARY, "collation object's strength is secondary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() == Collator.SECONDARY, "collation object has the wrong strength");
System.out.println("testing Collator.setDecomposition() method ...");
col.setDecomposition(Collator.NO_DECOMPOSITION);
doAssert(col.getDecomposition() != Collator.FULL_DECOMPOSITION, "collation object's strength is secondary difference");
doAssert(col.getDecomposition() != Collator.CANONICAL_DECOMPOSITION, "collation object's strength is primary difference");
doAssert(col.getDecomposition() == Collator.NO_DECOMPOSITION, "collation object has the wrong strength");
} catch (Exception foo) {
fail("Error : " + foo.getMessage()
+ "\n Default Collator creation failed.");
}
System.out.println("Default collation property test ended.");
System.out.println("Collator.getRules() testing ...");
doAssert(((RuleBasedCollator)col).getRules().length() != 0, "getRules() result incorrect" );
System.out.println("getRules tests end.");
try {
col = Collator.getInstance(Locale.FRENCH);
col.setStrength(Collator.PRIMARY);
System.out.println("testing Collator.getStrength() method again ...");
doAssert(col.getStrength() != Collator.TERTIARY, "collation object has the wrong strength");
doAssert(col.getStrength() == Collator.PRIMARY, "collation object's strength is not primary difference");
System.out.println("testing French Collator.setStrength() method ...");
col.setStrength(Collator.TERTIARY);
doAssert(col.getStrength() == Collator.TERTIARY, "collation object's strength is not tertiary difference");
doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
doAssert(col.getStrength() != Collator.SECONDARY, "collation object's strength is secondary difference");
} catch (Exception bar) {
fail("Error : " + bar.getMessage()
+ "\n Creating French collation failed.");
}
System.out.println("Create junk collation: ");
Locale abcd = Locale.of("ab", "CD");
Collator junk = null;
try {
junk = Collator.getInstance(abcd);
} catch (Exception err) {
fail("Error : " + err.getMessage()
+ "\n Junk collation creation failed, should at least return the collator for the base bundle.");
}
try {
col = Collator.getInstance(Locale.ROOT);
doAssert(col.equals(junk), "The base bundle's collation should be returned.");
} catch (Exception exc) {
fail("Error : " + exc.getMessage()
+ "\n Default collation comparison, caching not working.");
}
System.out.println("Collator property test ended.");
}
@Test
public final void TestHashCode( )
{
System.out.println("hashCode tests begin.");
Collator col1 = null;
try {
col1 = Collator.getInstance(Locale.ROOT);
} catch (Exception foo) {
fail("Error : " + foo.getMessage()
+ "\n Default collation creation failed.");
}
Collator col2 = null;
Locale dk = Locale.of("da", "DK");
try {
col2 = Collator.getInstance(dk);
} catch (Exception bar) {
fail("Error : " + bar.getMessage()
+ "\n Danish collation creation failed.");
return;
}
Collator col3 = null;
try {
col3 = Collator.getInstance(Locale.ROOT);
} catch (Exception err) {
fail("Error : " + err.getMessage()
+ "\n 2nd default collation creation failed.");
}
System.out.println("Collator.hashCode() testing ...");
if (col1 != null) {
doAssert(col1.hashCode() != col2.hashCode(), "Hash test1 result incorrect");
if (col3 != null) {
doAssert(col1.hashCode() == col3.hashCode(), "Hash result not equal");
}
}
System.out.println("hashCode tests end.");
}
//----------------------------------------------------------------------------
// ctor -- Tests the constructor methods
//
@Test
public final void TestCollationKey( )
{
System.out.println("testing CollationKey begins...");
Collator col = null;
try {
col = Collator.getInstance(Locale.ROOT);
} catch (Exception foo) {
fail("Error : " + foo.getMessage()
+ "\n Default collation creation failed.");
}
if (col == null) {
return;
}
String test1 = "Abcda", test2 = "abcda";
System.out.println("Use tertiary comparison level testing ....");
CollationKey sortk1 = col.getCollationKey(test1);
CollationKey sortk2 = col.getCollationKey(test2);
doAssert(sortk1.compareTo(sortk2) > 0,
"Result should be \"Abcda\" >>> \"abcda\"");
CollationKey sortk3 = sortk2;
CollationKey sortkNew = sortk1;
doAssert(sortk1 != sortk2, "The sort keys should be different");
doAssert(sortk1.hashCode() != sortk2.hashCode(), "sort key hashCode() failed");
doAssert(sortk2.compareTo(sortk3) == 0, "The sort keys should be the same");
doAssert(sortk1 == sortkNew, "The sort keys assignment failed");
doAssert(sortk1.hashCode() == sortkNew.hashCode(), "sort key hashCode() failed");
doAssert(sortkNew != sortk3, "The sort keys should be different");
doAssert(sortk1.compareTo(sortk3) > 0, "Result should be \"Abcda\" >>> \"abcda\"");
doAssert(sortk2.compareTo(sortk3) == 0, "Result should be \"abcda\" == \"abcda\"");
long cnt1, cnt2;
byte byteArray1[] = sortk1.toByteArray();
byte byteArray2[] = sortk2.toByteArray();
doAssert(byteArray1 != null && byteArray2 != null, "CollationKey.toByteArray failed.");
System.out.println("testing sortkey ends...");
}
//----------------------------------------------------------------------------
// ctor -- Tests the constructor methods
//
@Test
public final void TestElemIter( )
{
System.out.println("testing sortkey begins...");
Collator col = null;
try {
col = Collator.getInstance();
} catch (Exception foo) {
fail("Error : " + foo.getMessage()
+ "\n Default collation creation failed.");
}
RuleBasedCollator rbCol;
if (col instanceof RuleBasedCollator) {
rbCol = (RuleBasedCollator) col;
} else {
return;
}
String testString1 = "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?";
String testString2 = "Xf ile What subset of all possible test cases has the lowest probability of detecting the least errors?";
System.out.println("Constructors and comparison testing....");
CollationElementIterator iterator1 = rbCol.getCollationElementIterator(testString1);
CollationElementIterator iterator2 = rbCol.getCollationElementIterator(testString1);
CollationElementIterator iterator3 = rbCol.getCollationElementIterator(testString2);
int order1, order2, order3;
order1 = iterator1.next();
order2 = iterator2.next();
doAssert(order1 == order2, "The order result should be the same");
order3 = iterator3.next();
doAssert(CollationElementIterator.primaryOrder(order1)
== CollationElementIterator.primaryOrder(order3),
"The primary orders should be the same");
doAssert(CollationElementIterator.secondaryOrder(order1)
== CollationElementIterator.secondaryOrder(order3),
"The secondary orders should be the same");
doAssert(CollationElementIterator.tertiaryOrder(order1)
== CollationElementIterator.tertiaryOrder(order3),
"The tertiary orders should be the same");
order1 = iterator1.next();
order3 = iterator3.next();
doAssert(CollationElementIterator.primaryOrder(order1)
== CollationElementIterator.primaryOrder(order3),
"The primary orders should be identical");
doAssert(CollationElementIterator.tertiaryOrder(order1)
!= CollationElementIterator.tertiaryOrder(order3),
"The tertiary orders should be different");
order1 = iterator1.next();
order3 = iterator3.next();
doAssert(CollationElementIterator.secondaryOrder(order1)
!= CollationElementIterator.secondaryOrder(order3),
"The secondary orders should be different");
doAssert(order1 != CollationElementIterator.NULLORDER,
"Unexpected end of iterator reached");
iterator1.reset();
iterator2.reset();
iterator3.reset();
order1 = iterator1.next();
order2 = iterator2.next();
doAssert(order1 == order2, "The order result should be the same");
order3 = iterator3.next();
doAssert(CollationElementIterator.primaryOrder(order1)
== CollationElementIterator.primaryOrder(order3),
"The orders should be the same");
doAssert(CollationElementIterator.secondaryOrder(order1)
== CollationElementIterator.secondaryOrder(order3),
"The orders should be the same");
doAssert(CollationElementIterator.tertiaryOrder(order1)
== CollationElementIterator.tertiaryOrder(order3),
"The orders should be the same");
order1 = iterator1.next();
order2 = iterator2.next();
order3 = iterator3.next();
doAssert(CollationElementIterator.primaryOrder(order1)
== CollationElementIterator.primaryOrder(order3),
"The primary orders should be identical");
doAssert(CollationElementIterator.tertiaryOrder(order1)
!= CollationElementIterator.tertiaryOrder(order3),
"The tertiary orders should be different");
order1 = iterator1.next();
order3 = iterator3.next();
doAssert(CollationElementIterator.secondaryOrder(order1)
!= CollationElementIterator.secondaryOrder(order3),
"The secondary orders should be different");
doAssert(order1 != CollationElementIterator.NULLORDER, "Unexpected end of iterator reached");
System.out.println("testing CollationElementIterator ends...");
}
@Test
public final void TestGetAll()
{
Locale[] list = Collator.getAvailableLocales();
for (int i = 0; i < list.length; ++i) {
System.out.println("Locale name: ");
System.out.println(list[i].toString());
System.out.println(" , the display name is : ");
System.out.println(list[i].getDisplayName());
}
}
}

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 5047314
* @summary verify that compare() and getCollationKey() don't go into an infinite loop for unfinished Thai/Lao text.
* @run main/timeout=60 Bug5047314
*/
import java.text.Collator;
import java.util.Locale;
public class Bug5047314 {
private static Collator colLao = Collator.getInstance(Locale.of("lo"));
private static Collator colThai = Collator.getInstance(Locale.of("th"));
private static String[] textLao = {
"\u0ec0", "\u0ec1", "\u0ec2", "\u0ec3", "\u0ec4"
};
private static String[] textThai = {
"\u0e40", "\u0e41", "\u0e42", "\u0e43", "\u0e44"
};
public static void main(String[] args) {
testLao1();
testLao2();
testThai1();
testThai2();
}
private static void testLao1() {
System.out.print("Test(Lao 1) .... ");
for (int i = 0; i < textLao.length; i++) {
colLao.compare(textLao[i], textLao[i]);
}
System.out.println("Passed.");
}
private static void testLao2() {
System.out.print("Test(Lao 2) .... ");
for (int i = 0; i < textLao.length; i++) {
colLao.compare(textLao[i], textLao[i]);
}
System.out.println("Passed.");
}
private static void testThai1() {
System.out.print("Test(Thai 1) .... ");
for (int i = 0; i < textThai.length; i++) {
colThai.compare(textThai[i], textThai[i]);
}
System.out.println("Passed.");
}
private static void testThai2() {
System.out.print("Test(Thai 2) .... ");
for (int i = 0; i < textThai.length; i++) {
colThai.getCollationKey(textThai[i]);
}
System.out.println("Passed.");
}
}

View file

@ -0,0 +1,196 @@
/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6271411
* @summary Confirm that three JCK testcases for CollationElementIterator pass.
* @run junit Bug6271411
*/
import java.text.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
/*
* Based on JCK-runtime-15/tests/api/java_text/CollationElementIterator/ColltnElmtIterTests.java.
*/
public class Bug6271411 {
/*
* Rule for RuleBasedCollator
*/
static final String rule = "< c, C < d; D";
/*
* Textdata
*/
static final String[] values = {
"", "c", "cH522Yd", "Hi, high school", "abcchCHidD"
};
/*
* Confirm that setOffset() throws IllegalArgumentException
* (not IndexOutOfBoundsException) if the given offset is invalid.
* Use CollationElementIterator.setText(String).
*/
@Test
public void Test_CollationElementIterator0007() throws Exception {
int[] offsets = {
Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -10000, -2, -1,
100, 101, // These two are customized for every test data later.
12345, Integer.MAX_VALUE - 1, Integer.MAX_VALUE
};
boolean err = false;
RuleBasedCollator rbc = new RuleBasedCollator(rule);
CollationElementIterator iterator = rbc.getCollationElementIterator("");
for (int i = 0; i < values.length; i++) {
String source = values[i];
iterator.setText(source);
int len = source.length();
offsets[5] = len + 1;
offsets[6] = len + 2;
for (int j = 0; j < offsets.length; j++) {
try {
iterator.setOffset(offsets[j]);
System.out.println("IllegalArgumentException should be thrown for setOffset(" +
offsets[j] + ") for <" + source + ">.");
err = true;
}
catch (IllegalArgumentException e) {
}
}
}
if (err) {
fail("CollationElementIterator.setOffset() didn't throw an expected IllegalArguemntException.");
}
}
/*
* Confirm that setText() doesn't throw an exception and setOffset() throws
* IllegalArgumentException if the given offset is invalid.
* Use CollationElementIterator.setText(CharacterIterator).
*/
@Test
public void Test_CollationElementIterator0010() throws Exception {
String prefix = "xyz abc";
String suffix = "1234567890";
int begin = prefix.length();
int[] offsets = {
Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -10000,
-2, -1, 0, 1, begin - 2, begin - 1, 9, 10, 11, 12, 13, 14,
15, 12345, Integer.MAX_VALUE - 1, Integer.MAX_VALUE
};
boolean err = false;
RuleBasedCollator rbc = new RuleBasedCollator(rule);
CollationElementIterator iterator = rbc.getCollationElementIterator("");
for (int i = 0; i < values.length; i++) {
String str = prefix + values[i] + suffix;
int len = str.length();
int end = len - suffix.length();
CharacterIterator source =
new StringCharacterIterator(str, begin, end, begin);
iterator.setText(source);
offsets[9] = end + 1;
offsets[10] = end + 2;
offsets[11] = (end + len) / 2;
offsets[12] = len - 1;
offsets[13] = len;
offsets[14] = len + 1;
offsets[15] = len + 2;
for (int j = 0; j < offsets.length; j++) {
try {
iterator.setOffset(offsets[j]);
System.out.println("IllegalArgumentException should be thrown for setOffset(" +
offsets[j] + ") for <" + str + ">.");
err = true;
}
catch (IllegalArgumentException e) {
}
}
}
if (err) {
fail("CollationElementIterator.setOffset() didn't throw an expected IllegalArguemntException.");
}
}
/*
* Confirm that setText() doesn't throw an exception and setOffset() sets
* an offset as expected.
* Use CollationElementIterator.setText(CharacterIterator).
*/
@Test
public void Test_CollationElementIterator0011() throws Exception {
String prefix = "xyz abc";
String suffix = "1234567890";
int begin = prefix.length();
int[] offsets = { begin, begin + 1, 2, 3, 4 };
RuleBasedCollator rbc = new RuleBasedCollator(rule);
CollationElementIterator iterator = rbc.getCollationElementIterator("");
for (int i = 0; i < values.length; i++) {
String str = prefix + values[i] + suffix;
int len = str.length();
int end = len - suffix.length();
CharacterIterator source =
new StringCharacterIterator(str, begin, end, begin);
iterator.setText(source);
offsets[2] = (end + len) / 2;
offsets[3] = len - 1;
offsets[4] = len;
for (int j = 0; j < offsets.length; j++) {
int offset = offsets[j];
if (offset < begin || offset > end) {
break;
}
iterator.setOffset(offset);
int newOffset = iterator.getOffset();
if (newOffset != offset) {
throw new RuntimeException("setOffset() didn't set a correct offset. Got: " +
newOffset + " Expected: " + offset + " for <" + str + ">.");
}
}
}
}
}

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6970930
* @summary verify that compare() throws NPE instead of IAE when an argument is null.
*/
import java.text.*;
public class Bug6970930 {
private static boolean err = false;
public static void main(String[] args) {
// Check if compare() throws NPE.
test1(null, null);
test1("\"foo\"", null);
test1(null, "\"bar\"");
if (err) {
throw new RuntimeException("Failed.");
} else {
System.out.println("Passed.");
}
}
private static void test1(String s1, String s2) {
RuleBasedCollator col = null;
try {
col = new RuleBasedCollator("< a < b");
}
catch (ParseException e) {
err = true;
System.err.println(e);
}
try {
col.compare("foo", "bar"); // This line is necessary to reproduce the bug.
col.compare(s1, s2);
err = true;
System.err.println("No exception was thrown for compare(" +
s1 + ", " + s2 + ").");
}
catch (NullPointerException e) {
System.out.println("NPE was thrown as expected for compare(" +
s1 + ", " + s2 + ").");
}
catch (Exception e) {
err = true;
System.err.println("Unexpected exception was thrown for compare(" +
s1 + ", " + s2 + "): " + e);
}
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7200119
* @summary verify that getAvailableLocales() contains Locale.US
*/
import java.text.*;
import java.util.*;
public class Bug7200119 {
public static void main(String[] args) {
List<Locale> avail = Arrays.asList(Collator.getAvailableLocales());
if (!avail.contains(Locale.US)) {
throw new RuntimeException("Failed.");
}
}
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4106263
* @summary Tests on the bug 4106263 - CollationKey became non-final extendable class.
* The implementation of CollationKey is moved to the new private class,
* RuleBasedCollationKey. This test basically tests on the two features:
* 1. Existing code using CollationKey works (backward compatiblility)
* 2. CollationKey can be extended by its subclass.
* @modules jdk.localedata
*/
public class CollationKeyTest {
public static void main(String[] args) {
CollationKeyTestImpl ck = new CollationKeyTestImpl("Testing the CollationKey");
ck.run();
}
}

View file

@ -0,0 +1,243 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
*
* A part of tests on the bug 4106263. CollationKey became non-final extendable class.
* The implementation of CollationKey is moved to the new private class,
* RuleBasedCollationKey. This test basically tests on the two features:
* 1. Existing code using CollationKey works (backward compatiblility)
* 2. CollationKey can be extended by its subclass.
*/
import java.util.Locale;
import java.text.Collator;
import java.text.CollationKey;
import java.io.*;
import java.text.*;
public class CollationKeyTestImpl extends CollationKey {
private static String[] sourceData_ja = {
"\u3042\u3044\u3046\u3048\u3048",
"\u3041\u3043\u3045\u3047\u3049",
"\u3052\u3054\u3056\u3058\u3058",
"\u3051\u3053\u3055\u3057\u3059",
"\u3062\u3064\u3066\u3068\u3068",
"\u3061\u3063\u3065\u3067\u3069",
"\u3072\u3074\u3075\u3078\u3078",
"\u3071\u3073\u3075\u3077\u3079",
"\u3082\u3084\u3085\u3088\u3088",
"\u3081\u3083\u3085\u3087\u3089",
"\u30a2\u30a4\u30a6\u30a8\u30aa",
"\u30a1\u30a3\u30a5\u30a7\u30a9",
"\u30c2\u30c4\u30c6\u30c8\u30ca",
"\u30c1\u30c3\u30c5\u30c7\u30c9",
"\u30b2\u30b4\u30b6\u30b8\u30ba",
"\u30b1\u30b3\u30b5\u30b7\u30b9",
"\u30d2\u30d4\u30d6\u30d8\u30da",
"\u30d1\u30d3\u30d5\u30d7\u30d9",
"\u30e2\u30e4\u30e6\u30e8\u30ea",
"\u30e1\u30e3\u30e5\u30e7\u30e9"
};
private static final String[] targetData_ja = {
"\u3042\u3044\u3046\u3048\u3048",
"\u3041\u3043\u3045\u3047\u3049",
"\u30a2\u30a4\u30a6\u30a8\u30aa",
"\u30a1\u30a3\u30a5\u30a7\u30a9",
"\u3052\u3054\u3056\u3058\u3058",
"\u3051\u3053\u3055\u3057\u3059",
"\u30b1\u30b3\u30b5\u30b7\u30b9",
"\u30b2\u30b4\u30b6\u30b8\u30ba",
"\u3061\u3063\u3065\u3067\u3069",
"\u30c1\u30c3\u30c5\u30c7\u30c9",
"\u3062\u3064\u3066\u3068\u3068",
"\u30c2\u30c4\u30c6\u30c8\u30ca",
"\u3071\u3073\u3075\u3077\u3079",
"\u30d1\u30d3\u30d5\u30d7\u30d9",
"\u3072\u3074\u3075\u3078\u3078",
"\u30d2\u30d4\u30d6\u30d8\u30da",
"\u3081\u3083\u3085\u3087\u3089",
"\u30e1\u30e3\u30e5\u30e7\u30e9",
"\u3082\u3084\u3085\u3088\u3088",
"\u30e2\u30e4\u30e6\u30e8\u30ea"
};
public void run() {
/** debug: printout the test data
for (int i=0; i<sourceData_ja.length; i++){
System.out.println(i+": "+sourceData_ja[i]);
}
**/
/*
* 1. Test the backward compatibility
* note: targetData_ja.length is equal to sourceData_ja.length
*/
Collator myCollator = Collator.getInstance(Locale.JAPAN);
CollationKey[] keys = new CollationKey[sourceData_ja.length];
CollationKey[] target_keys = new CollationKey[targetData_ja.length];
for (int i=0; i<sourceData_ja.length; i++){
keys[i] = myCollator.getCollationKey(sourceData_ja[i]);
target_keys[i] = myCollator.getCollationKey(targetData_ja[i]); //used later
}
/* Sort the string using CollationKey */
InsertionSort(keys);
/** debug: printout the result after sort
System.out.println("--- After Sorting ---");
for (int i=0; i<sourceData_ja.length; i++){
System.out.println(i+" :"+keys[i].getSourceString());
}
**/
/*
* Compare the result using equals method and getSourceString method.
*/
boolean pass = true;
for (int i=0; i<sourceData_ja.length; i++){
/* Comparing using String.equals: in order to use getStringSource() */
if (! targetData_ja[i].equals(keys[i].getSourceString())){
throw new RuntimeException("FAILED: CollationKeyTest backward compatibility "
+"while comparing" +targetData_ja[i]+" vs "
+keys[i].getSourceString());
}
/* Comparing using CollaionKey.equals: in order to use equals() */
if (! target_keys[i].equals(keys[i])){
throw new RuntimeException("FAILED: CollationKeyTest backward compatibility."
+" Using CollationKey.equals " +targetData_ja[i]
+" vs " +keys[i].getSourceString());
}
/* Comparing using CollaionKey.hashCode(): in order to use hashCode() */
if (target_keys[i].hashCode() != keys[i].hashCode()){
throw new RuntimeException("FAILED: CollationKeyTest backward compatibility."
+" Using CollationKey.hashCode " +targetData_ja[i]
+" vs " +keys[i].getSourceString());
}
/* Comparing using CollaionKey.toByteArray(): in order to use toByteArray() */
byte[] target_bytes = target_keys[i].toByteArray();
byte[] source_bytes = keys[i].toByteArray();
for (int j=0; j<target_bytes.length; j++){
Byte targetByte = new Byte(target_bytes[j]);
Byte sourceByte = new Byte(source_bytes[j]);
if (targetByte.compareTo(sourceByte)!=0){
throw new RuntimeException("FAILED: CollationKeyTest backward "
+"compatibility. Using Byte.compareTo from CollationKey.toByteArray "
+targetData_ja[i]
+" vs " +keys[i].getSourceString());
}
}
}
testSubclassMethods();
testConstructor();
}
/*
* Sort the array of CollationKey using compareTo method in insertion sort.
*/
private void InsertionSort(CollationKey[] keys){
int f, i;
CollationKey tmp;
for (f=1; f < keys.length; f++){
if(keys[f].compareTo( keys[f-1]) > 0){
continue;
}
tmp = keys[f];
i = f-1;
while ( (i>=0) && (keys[i].compareTo(tmp) > 0) ) {
keys[i+1] = keys[i];
i--;
}
keys[i+1]=tmp;
}
}
/*
* From here is the bogus methods to test the subclass of
* the CollationKey class.
*/
public CollationKeyTestImpl(String str){
super (str);
// debug: System.out.println("CollationKeyTest extends CollationKey class: "+str);
}
/* abstract method: needs to be implemented */
public byte[] toByteArray(){
String foo= "Hello";
return foo.getBytes();
}
/* abstract method: needs to be implemented */
public int compareTo(CollationKey target){
return 0;
}
public boolean equals(Object target){
return true;
}
public String getSourceString(){
return "CollationKeyTestImpl";
}
/*
* This method tests the collection of bugus methods from the extended
* subclass of CollationKey class.
*/
private void testSubclassMethods() {
CollationKeyTestImpl clt1 = new CollationKeyTestImpl("testSubclassMethods-1");
CollationKeyTestImpl clt2 = new CollationKeyTestImpl("testSubclassMethods-2");
// extended method, equals always returns true
if (!clt1.equals(clt2)){
throw new RuntimeException("Failed: equals(CollationKeySubClass)");
}
// extended method, compareTo always returns 0
if (clt1.compareTo(clt2)!=0){
throw new RuntimeException("Failed: compareTo(CollationKeySubClass)");
}
// overriding extended method, getSourceString always returns "CollationKeyTestImpl"
if (! clt1.getSourceString().equals("CollationKeyTestImpl")){
throw new RuntimeException("Failed: CollationKey subclass overriding getSourceString()");
}
// extended method, toByteArray always returns bytes from "Hello"
String str2 = new String( clt2.toByteArray());
if (! clt2.equals("Hello")){
throw new RuntimeException("Failed: CollationKey subclass toByteArray()");
}
}
/*
* This method tests CollationKey constructor with null source string.
* It should throw NPE.
*/
private void testConstructor() {
boolean npe=false;
try{
CollationKeyTestImpl cltNull = new CollationKeyTestImpl(null);
} catch (NullPointerException npException){
npe=true;
// debug: System.out.println("--- NPE is thrown with NULL arguement: PASS ---");
}
if(!npe){
throw new RuntimeException("Failed: CollationKey Constructor with null source"+
" didn't throw NPE!");
}
}
}

View file

@ -0,0 +1,86 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 4114080 4150807
* @summary Test currency collation. For bug 4114080, make sure the collation
* of the euro sign behaves properly. For bug 4150807, make sure the collation
* order of ALL the current symbols is correct. This means they sort
* in English alphabetical order of their English names. This test can be
* easily extended to do simple spot checking. See other collation tests for
* more sophisticated testing.
*/
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Locale;
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.text.CollationKey;
/* Author: Alan Liu
* (C) Copyright IBM Corp. 1998 - All Rights Reserved
*/
public class CurrencyCollate {
static Collator myCollation = Collator.getInstance(Locale.US);
public static void main(String[] args) {
String[] DATA = {
"\u20AC", ">", "$", // euro > dollar
"\u20AC", "<", "\u00A3", // euro < pound
// additional tests for general currency sort order (bug #4150807)
"\u00a4", "<", "\u0e3f", // generic currency < baht
"\u0e3f", "<", "\u00a2", // baht < cent
"\u00a2", "<", "\u20a1", // cent < colon
"\u20a1", "<", "\u20a2", // colon < cruzeiro
"\u20a2", "<", "\u0024", // cruzeiro < dollar
"\u0024", "<", "\u20ab", // dollar < dong
"\u20ab", "<", "\u20a3", // dong < franc
"\u20a3", "<", "\u20a4", // franc < lira
"\u20a4", "<", "\u20a5", // lira < mill
"\u20a5", "<", "\u20a6", // mill < naira
"\u20a6", "<", "\u20a7", // naira < peseta
"\u20a7", "<", "\u00a3", // peseta < pound
"\u00a3", "<", "\u20a8", // pound < rupee
"\u20a8", "<", "\u20aa", // rupee < shekel
"\u20aa", "<", "\u20a9", // shekel < won
"\u20a9", "<", "\u00a5" // won < yen
};
for (int i=0; i<DATA.length; i+=3) {
int expected = DATA[i+1].equals(">") ? 1 : (DATA[i+1].equals("<") ? -1 : 0);
int actual = myCollation.compare(DATA[i], DATA[i+2]);
if (actual != expected) {
throw new RuntimeException("Collation of " +
DATA[i] + " vs. " +
DATA[i+2] + " yields " + actual +
"; expected " + expected);
}
}
System.out.println("Ok");
}
}
//eof

View file

@ -0,0 +1,219 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4930708 4174436 5008498
* @library /java/text/testlib
* @summary test Danish Collation
* @modules jdk.localedata
* @run junit DanishTest
*/
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
import java.util.Locale;
import java.text.Collator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
// Quick dummy program for printing out test results
public class DanishTest {
/*
* Data for TestPrimary()
*/
private static final String[] primarySourceData = {
"Lvi",
"L\u00E4vi",
"L\u00FCbeck",
"ANDR\u00C9",
"ANDRE",
"ANNONCERER"
};
private static final String[] primaryTargetData = {
"Lwi",
"L\u00F6wi",
"Lybeck",
"ANDR\u00E9",
"ANDR\u00C9",
"ANN\u00D3NCERER"
};
private static final int[] primaryResults = {
-1, -1, 0, 0, 0, 0
};
/*
* Data for TestTertiary()
*/
private static final String[] tertiarySourceData = {
"Luc",
"luck",
"L\u00FCbeck",
"L\u00E4vi",
"L\u00F6ww"
};
private static final String[] tertiaryTargetData = {
"luck",
"L\u00FCbeck",
"lybeck",
"L\u00F6we",
"mast"
};
private static final int[] tertiaryResults = {
-1, -1, 1, -1, -1
};
/*
* Data for TestExtra()
*/
private static final String[] testData = {
"A/S",
"ANDRE",
"ANDR\u00C9", // E-acute
"ANDR\u00C8", // E-grave
"ANDR\u00E9", // e-acute
"ANDR\u00EA", // e-circ
"Andre",
"Andr\u00E9", // e-acute
"\u00C1NDRE", // A-acute
"\u00C0NDRE", // A-grave
"andre",
"\u00E1ndre", // a-acute
"\u00E0ndre", // a-grave
"ANDREAS",
"ANNONCERER",
"ANN\u00D3NCERER", // O-acute
"annoncerer",
"ann\u00F3ncerer", // o-acute
"AS",
"A\u00e6RO", // ae-ligature
"CA",
"\u00C7A", // C-cedilla
"CB",
"\u00C7C", // C-cedilla
"D.S.B.",
"DA",
"DB",
"\u00D0ORA", // capital eth
"DSB",
"\u00D0SB", // capital eth
"DSC",
"EKSTRA_ARBEJDE",
"EKSTRABUD",
"H\u00D8ST", // could the 0x00D8 be 0x2205?
"HAAG",
"H\u00C5NDBOG", // A-ring
"HAANDV\u00C6RKSBANKEN", // AE-ligature
"INTERNETFORBINDELSE",
"Internetforbindelse",
"\u00CDNTERNETFORBINDELSE", // I-acute
"internetforbindelse",
"\u00EDnternetforbindelse", // i-acute
"Karl",
"karl",
"NIELSEN",
"NIELS J\u00D8RGEN", // O-slash
"NIELS-J\u00D8RGEN", // O-slash
"OERVAL",
"\u0152RVAL", // OE-ligature
"\u0153RVAL", // oe-ligature
"R\u00C9E, A", // E-acute
"REE, B",
"R\u00C9E, L", // E-acute
"REE, V",
"SCHYTT, B",
"SCHYTT, H",
"SCH\u00DCTT, H", // U-diaeresis
"SCHYTT, L",
"SCH\u00DCTT, M", // U-diaeresis
"SS",
"ss",
"\u00DF", // sharp S
"SSA",
"\u00DFA", // sharp S
"STOREK\u00C6R", // AE-ligature
"STORE VILDMOSE",
"STORMLY",
"STORM PETERSEN",
"THORVALD",
"THORVARDUR",
"\u00DEORVAR\u0110UR", // capital thorn, capital d-stroke(like eth) (sami)
"THYGESEN",
"VESTERG\u00C5RD, A",
"VESTERGAARD, A",
"VESTERG\u00C5RD, B", // 50
"Westmalle",
"YALLE",
"Yderligere",
"\u00DDderligere", // Y-acute
"\u00DCderligere", // U-diaeresis
"\u00FDderligere", // y-acute
"\u00FCderligere", // u-diaeresis
"U\u0308ruk-hai",
"ZORO",
"\u00C6BLE", // AE-ligature
"\u00E6BLE", // ae-ligature
"\u00C4BLE", // A-diaeresis
"\u00E4BLE", // a-diaeresis
"\u00D8BERG", // O-stroke
"\u00F8BERG", // o-stroke
"\u00D6BERG", // O-diaeresis
"\u00F6BERG" // o-diaeresis
};
@Test
public void TestPrimary() {
TestUtils.doCollatorTest(myCollation, Collator.PRIMARY,
primarySourceData, primaryTargetData, primaryResults);
}
@Test
public void TestTertiary() {
TestUtils.doCollatorTest(myCollation, Collator.TERTIARY,
tertiarySourceData, tertiaryTargetData, tertiaryResults);
for (int i = 0; i < testData.length-1; i++) {
for (int j = i+1; j < testData.length; j++) {
TestUtils.doCollatorTest(myCollation, testData[i], testData[j], -1);
}
}
}
private final Collator myCollation = Collator.getInstance(Locale.of("da"));
}

View file

@ -0,0 +1,425 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test Dummy Collation
* @run junit DummyTest
*/
import java.text.Collator;
import java.text.RuleBasedCollator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
public class DummyTest {
private static final String DEFAULTRULES =
"='\u200B'=\u200C=\u200D=\u200E=\u200F"
// Control Characters
+ "=\u0000 =\u0001 =\u0002 =\u0003 =\u0004" //null, .. eot
+ "=\u0005 =\u0006 =\u0007 =\u0008 ='\u0009'" //enq, ...
+ "='\u000b' =\u000e" //vt,, so
+ "=\u000f ='\u0010' =\u0011 =\u0012 =\u0013" //si, dle, dc1, dc2, dc3
+ "=\u0014 =\u0015 =\u0016 =\u0017 =\u0018" //dc4, nak, syn, etb, can
+ "=\u0019 =\u001a =\u001b =\u001c =\u001d" //em, sub, esc, fs, gs
+ "=\u001e =\u001f =\u007f" //rs, us, del
//....then the C1 Latin 1 reserved control codes
+ "=\u0080 =\u0081 =\u0082 =\u0083 =\u0084 =\u0085"
+ "=\u0086 =\u0087 =\u0088 =\u0089 =\u008a =\u008b"
+ "=\u008c =\u008d =\u008e =\u008f =\u0090 =\u0091"
+ "=\u0092 =\u0093 =\u0094 =\u0095 =\u0096 =\u0097"
+ "=\u0098 =\u0099 =\u009a =\u009b =\u009c =\u009d"
+ "=\u009e =\u009f"
// IGNORE except for secondary, tertiary difference
// Spaces
+ ";'\u0020';'\u00A0'" // spaces
+ ";'\u2000';'\u2001';'\u2002';'\u2003';'\u2004'" // spaces
+ ";'\u2005';'\u2006';'\u2007';'\u2008';'\u2009'" // spaces
+ ";'\u200A';'\u3000';'\uFEFF'" // spaces
+ ";'\r' ;'\t' ;'\n';'\f';'\u000b'" // whitespace
// Non-spacing accents
+ ";\u0301" // non-spacing acute accent
+ ";\u0300" // non-spacing grave accent
+ ";\u0306" // non-spacing breve accent
+ ";\u0302" // non-spacing circumflex accent
+ ";\u030c" // non-spacing caron/hacek accent
+ ";\u030a" // non-spacing ring above accent
+ ";\u030d" // non-spacing vertical line above
+ ";\u0308" // non-spacing diaeresis accent
+ ";\u030b" // non-spacing double acute accent
+ ";\u0303" // non-spacing tilde accent
+ ";\u0307" // non-spacing dot above/overdot accent
+ ";\u0304" // non-spacing macron accent
+ ";\u0337" // non-spacing short slash overlay (overstruck diacritic)
+ ";\u0327" // non-spacing cedilla accent
+ ";\u0328" // non-spacing ogonek accent
+ ";\u0323" // non-spacing dot-below/underdot accent
+ ";\u0332" // non-spacing underscore/underline accent
// with the rest of the general diacritical marks in binary order
+ ";\u0305" // non-spacing overscore/overline
+ ";\u0309" // non-spacing hook above
+ ";\u030e" // non-spacing double vertical line above
+ ";\u030f" // non-spacing double grave
+ ";\u0310" // non-spacing chandrabindu
+ ";\u0311" // non-spacing inverted breve
+ ";\u0312" // non-spacing turned comma above/cedilla above
+ ";\u0313" // non-spacing comma above
+ ";\u0314" // non-spacing reversed comma above
+ ";\u0315" // non-spacing comma above right
+ ";\u0316" // non-spacing grave below
+ ";\u0317" // non-spacing acute below
+ ";\u0318" // non-spacing left tack below
+ ";\u0319" // non-spacing tack below
+ ";\u031a" // non-spacing left angle above
+ ";\u031b" // non-spacing horn
+ ";\u031c" // non-spacing left half ring below
+ ";\u031d" // non-spacing up tack below
+ ";\u031e" // non-spacing down tack below
+ ";\u031f" // non-spacing plus sign below
+ ";\u0320" // non-spacing minus sign below
+ ";\u0321" // non-spacing palatalized hook below
+ ";\u0322" // non-spacing retroflex hook below
+ ";\u0324" // non-spacing double dot below
+ ";\u0325" // non-spacing ring below
+ ";\u0326" // non-spacing comma below
+ ";\u0329" // non-spacing vertical line below
+ ";\u032a" // non-spacing bridge below
+ ";\u032b" // non-spacing inverted double arch below
+ ";\u032c" // non-spacing hacek below
+ ";\u032d" // non-spacing circumflex below
+ ";\u032e" // non-spacing breve below
+ ";\u032f" // non-spacing inverted breve below
+ ";\u0330" // non-spacing tilde below
+ ";\u0331" // non-spacing macron below
+ ";\u0333" // non-spacing double underscore
+ ";\u0334" // non-spacing tilde overlay
+ ";\u0335" // non-spacing short bar overlay
+ ";\u0336" // non-spacing long bar overlay
+ ";\u0338" // non-spacing long slash overlay
+ ";\u0339" // non-spacing right half ring below
+ ";\u033a" // non-spacing inverted bridge below
+ ";\u033b" // non-spacing square below
+ ";\u033c" // non-spacing seagull below
+ ";\u033d" // non-spacing x above
+ ";\u033e" // non-spacing vertical tilde
+ ";\u033f" // non-spacing double overscore
+ ";\u0340" // non-spacing grave tone mark
+ ";\u0341" // non-spacing acute tone mark
+ ";\u0342;\u0343;\u0344;\u0345;\u0360;\u0361" // newer
+ ";\u0483;\u0484;\u0485;\u0486" // Cyrillic accents
+ ";\u20D0;\u20D1;\u20D2" // symbol accents
+ ";\u20D3;\u20D4;\u20D5" // symbol accents
+ ";\u20D6;\u20D7;\u20D8" // symbol accents
+ ";\u20D9;\u20DA;\u20DB" // symbol accents
+ ";\u20DC;\u20DD;\u20DE" // symbol accents
+ ";\u20DF;\u20E0;\u20E1" // symbol accents
+ ",'\u002D';\u00AD" // dashes
+ ";\u2010;\u2011;\u2012" // dashes
+ ";\u2013;\u2014;\u2015" // dashes
+ ";\u2212" // dashes
// other punctuation
+ "<'\u005f'" // underline/underscore (spacing)
+ "<\u00af" // overline or macron (spacing)
// + "<\u00ad" // syllable hyphen (SHY) or soft hyphen
+ "<'\u002c'" // comma (spacing)
+ "<'\u003b'" // semicolon
+ "<'\u003a'" // colon
+ "<'\u0021'" // exclamation point
+ "<\u00a1" // inverted exclamation point
+ "<'\u003f'" // question mark
+ "<\u00bf" // inverted question mark
+ "<'\u002f'" // slash
+ "<'\u002e'" // period/full stop
+ "<\u00b4" // acute accent (spacing)
+ "<'\u0060'" // grave accent (spacing)
+ "<'\u005e'" // circumflex accent (spacing)
+ "<\u00a8" // diaresis/umlaut accent (spacing)
+ "<'\u007e'" // tilde accent (spacing)
+ "<\u00b7" // middle dot (spacing)
+ "<\u00b8" // cedilla accent (spacing)
+ "<'\u0027'" // apostrophe
+ "<'\"'" // quotation marks
+ "<\u00ab" // left angle quotes
+ "<\u00bb" // right angle quotes
+ "<'\u0028'" // left parenthesis
+ "<'\u0029'" // right parenthesis
+ "<'\u005b'" // left bracket
+ "<'\u005d'" // right bracket
+ "<'\u007b'" // left brace
+ "<'\u007d'" // right brace
+ "<\u00a7" // section symbol
+ "<\u00b6" // paragraph symbol
+ "<\u00a9" // copyright symbol
+ "<\u00ae" // registered trademark symbol
+ "<'\u0040'" // at sign
+ "<\u00a4" // international currency symbol
+ "<\u00a2" // cent sign
+ "<'\u0024'" // dollar sign
+ "<\u00a3" // pound-sterling sign
+ "<\u00a5" // yen sign
+ "<'\u002a'" // asterisk
+ "<'\\u005c'" // backslash
+ "<'\u0026'" // ampersand
+ "<'\u0023'" // number sign
+ "<'\u0025'" // percent sign
+ "<'\u002b'" // plus sign
// + "<\u002d" // hyphen or minus sign
+ "<\u00b1" // plus-or-minus sign
+ "<\u00f7" // divide sign
+ "<\u00d7" // multiply sign
+ "<'\u003c'" // less-than sign
+ "<'\u003d'" // equal sign
+ "<'\u003e'" // greater-than sign
+ "<\u00ac" // end of line symbol/logical NOT symbol
+ "<'\u007c'" // vertical line/logical OR symbol
+ "<\u00a6" // broken vertical line
+ "<\u00b0" // degree symbol
+ "<\u00b5" // micro symbol
// NUMERICS
+ "<0<1<2<3<4<5<6<7<8<9"
+ "<\u00bc<\u00bd<\u00be" // 1/4,1/2,3/4 fractions
// NON-IGNORABLES
+ "<a,A"
+ "<b,B"
+ "<c,C"
+ "<d,D"
+ "<\u00F0,\u00D0" // eth
+ "<e,E"
+ "<f,F"
+ "<g,G"
+ "<h,H"
+ "<i,I"
+ "<j,J"
+ "<k,K"
+ "<l,L"
+ "<m,M"
+ "<n,N"
+ "<o,O"
+ "<p,P"
+ "<q,Q"
+ "<r,R"
+ "<s, S & SS,\u00DF" // s-zet
+ "<t,T"
+ "&th, \u00FE & TH, \u00DE" // thorn
+ "<u,U"
+ "<v,V"
+ "<w,W"
+ "<x,X"
+ "<y,Y"
+ "<z,Z"
+ "&AE,\u00C6" // ae & AE ligature
+ "&AE,\u00E6"
+ "&OE,\u0152" // oe & OE ligature
+ "&OE,\u0153";
/*
* Data for TestPrimary()
*/
private static final String[] primarySourceData = {
"p\u00EAche",
"abc",
"abc",
"abc",
"abc",
"abc",
"a\u00E6c",
"acHc",
"black"
};
private static final String[] primaryTargetData = {
"p\u00E9ch\u00E9",
"abc",
"aBC",
"abch",
"abd",
"\u00E4bc",
"a\u00C6c",
"aCHc",
"black-bird"
};
private static final int[] primaryResults = {
0, 0, 0, -1, -1, 0, 0, 0, -1
};
/*
* Data for TestSecondary()
*/
private static final String[] secondarySourceData = {
"four",
"five",
"1",
"abc",
"abc",
"abcH",
"abc",
"acHc"
};
private static final String[] secondaryTargetData = {
"4",
"5",
"one",
"abc",
"aBc",
"abch",
"abd",
"aCHc"
};
private static final int[] secondaryResults = {
0, 0, 0, 0, 0, 0, -1, 0
};
/*
* Data for TestTertiary()
*/
private static final String[] tertiarySourceData = {
"ab'c",
"co-op",
"ab",
"ampersad",
"all",
"four",
"five",
"1",
"1",
"1",
"2",
"2",
"Hello",
"a<b",
"a<b",
"acc",
"acHc"
};
private static final String[] tertiaryTargetData = {
"abc",
"COOP",
"abc",
"&",
"&",
"4",
"5",
"one",
"nne",
"pne",
"two",
"uwo",
"hellO",
"a<=b",
"abc",
"aCHc",
"aCHc"
};
private static final int[] tertiaryResults = {
-1, 1, -1, -1, -1, -1, -1, 1, 1, -1,
1, -1, 1, 1, -1, -1, -1
};
private static final String[] testData = {
"a",
"A",
"\u00e4",
"\u00c4",
"ae",
"aE",
"Ae",
"AE",
"\u00e6",
"\u00c6",
"b",
"c",
"z"
};
@Test
public void TestPrimary() {
TestUtils.doCollatorTest(getCollator(), Collator.PRIMARY,
primarySourceData, primaryTargetData, primaryResults);
}
@Test
public void TestSecondary() {
TestUtils.doCollatorTest(getCollator(), Collator.SECONDARY,
secondarySourceData, secondaryTargetData, secondaryResults);
}
@Test
public void TestTertiary() {
Collator col = getCollator();
TestUtils.doCollatorTest(col, Collator.TERTIARY,
tertiarySourceData, tertiaryTargetData, tertiaryResults);
for (int i = 0; i < testData.length-1; i++) {
for (int j = i+1; j < testData.length; j++) {
TestUtils.doCollatorTest(col, testData[i], testData[j], -1);
}
}
}
private RuleBasedCollator myCollation = null;
private Collator getCollator() {
if (myCollation == null) {
try {
myCollation = new RuleBasedCollator
(DEFAULTRULES + "& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ");
} catch (Exception foo) {
fail("Collator creation failed.");
myCollation = (RuleBasedCollator)Collator.getInstance();
}
}
return myCollation;
}
}

View file

@ -0,0 +1,230 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test English Collation
* @run junit EnglishTest
*/
import java.util.Locale;
import java.text.Collator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
public class EnglishTest {
/*
* Data for TestPrimary()
*/
private static final String[] primarySourceData = {
"p\u00EAche",
"abc",
"abc",
"abc",
"a\u00E6c"
};
private static final String[] primaryTargetData = {
"p\u00E9ch\u00E9",
"aBC",
"abd",
"\u00E4bc",
"a\u00C6c"
};
private static final int[] primaryResults = {
0, 0, -1, 0, 0,
};
/*
* Data for TestSecondary()
*/
private static final String[] secondarySourceData = {
"abc",
"abc",
"a\u00E6c",
"abc",
"abc",
"p\u00e9ch\u00e9"
};
private static final String[] secondaryTargetData = {
"aBd",
"\u00E4bc",
"a\u00C6c",
"aBd",
"\u00E4bc",
"p\u00eache"
};
private static final int[] secondaryResults = {
-1, -1, 0, -1, -1, -1
};
/*
* Data for TestTertiary() {
*/
private static final String[] tertiarySourceData = {
"ab",
"black-bird",
"black bird",
"black-bird",
"Hello",
"ABC",
"abc",
"blackbird",
"black-bird",
"black-bird",
"p\u00EAche",
"p\u00E9ch\u00E9",
"\u00C4B\u0308C\u0308",
"a\u0308bc",
"p\u00E9cher",
"roles",
"abc",
"A",
"A",
"ab",
"tcompareplain",
"ab",
"a#b",
"a#b",
"abc",
"Abcda",
"abcda",
"abcda",
"\u00E6bcda",
"\u00E4bcda",
"abc",
"abc",
"abc",
"abc",
"abc",
"acHc",
"a\u0308bc",
"thi\u0302s"
};
private static final String[] tertiaryTargetData = {
"abc",
"blackbird",
"black-bird",
"black",
"hello",
"ABC",
"ABC",
"blackbirds",
"blackbirds",
"blackbird",
"p\u00E9ch\u00E9",
"p\u00E9cher",
"\u00C4B\u0308C\u0308",
"A\u0308bc",
"p\u00E9che",
"ro\u0302le",
"A\u00E1cd",
"A\u00E1cd",
"abc",
"abc",
"TComparePlain",
"aBc",
"a#B",
"a&b",
"a#c",
"abcda",
"\u00C4bcda",
"\u00E4bcda",
"\u00C4bcda",
"\u00C4bcda",
"ab#c",
"abc",
"ab=c",
"abd",
"\u00E4bc",
"aCHc",
"\u00E4bc",
"th\u00EEs"
};
private static final int[] tertiaryResults = {
-1, 1, -1, 1, 1, 0, -1, -1, -1, 1,
1, -1, 0, -1, 1, 1, 1, -1, -1, -1,
-1, -1, -1, 1, 1, 1, -1, -1, 1, -1,
1, 0, 1, -1, -1, -1, 0, 0
};
private static final String testData[] = {
"a",
"A",
"e",
"E",
"\u00e9",
"\u00e8",
"\u00ea",
"\u00eb",
"ea",
"x"
};
@Test
public void TestPrimary() {
TestUtils.doCollatorTest(myCollation, Collator.PRIMARY,
primarySourceData, primaryTargetData, primaryResults);
}
@Test
public void TestSecondary() {
TestUtils.doCollatorTest(myCollation, Collator.SECONDARY,
secondarySourceData, secondaryTargetData, secondaryResults);
}
@Test
public void TestTertiary() {
TestUtils.doCollatorTest(myCollation, Collator.TERTIARY,
tertiarySourceData, tertiaryTargetData, tertiaryResults);
for (int i = 0; i < testData.length-1; i++) {
for (int j = i+1; j < testData.length; j++) {
TestUtils.doCollatorTest(myCollation, testData[i], testData[j], -1);
}
}
}
private final Collator myCollation = Collator.getInstance(Locale.ENGLISH);
}

View file

@ -0,0 +1,102 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test Finnish Collation
* @modules jdk.localedata
* @run junit FinnishTest
*/
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
import java.util.Locale;
import java.text.Collator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
// Quick dummy program for printing out test results
public class FinnishTest {
/*
* Data for TestPrimary()
*/
private static final String[] primarySourceData = {
"L\u00E5vi",
"wat"
};
private static final String[] primaryTargetData = {
"L\u00E4we",
"vat"
};
private static final int[] primaryResults = {
-1, 0
};
/*
* Data for TestTertiary()
*/
private static final String tertiarySourceData[] = {
"wat",
"vat",
"a\u00FCbeck"
};
private static final String tertiaryTargetData[] = {
"vat",
"way",
"axbeck"
};
private static final int[] tertiaryResults = {
1, -1, 1
};
@Test
public void TestPrimary() {
TestUtils.doCollatorTest(myCollation, Collator.PRIMARY,
primarySourceData, primaryTargetData, primaryResults);
}
@Test
public void TestTertiary() {
TestUtils.doCollatorTest(myCollation, Collator.TERTIARY,
tertiarySourceData, tertiaryTargetData, tertiaryResults);
}
private final Collator myCollation = Collator.getInstance(Locale.of("fi", "FI"));
}

View file

@ -0,0 +1,103 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test French Collation
* @modules jdk.localedata
* @run junit FrenchTest
*/
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
import java.util.Locale;
import java.text.Collator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
// Quick dummy program for printing out test results
public class FrenchTest {
private static final String[] tertiarySourceData = {
"abc",
"COTE",
"p\u00EAche",
"p\u00EAcher",
"p\u00E9cher",
"p\u00E9cher",
"Hello"
};
private static final String[] tertiaryTargetData = {
"ABC",
"c\u00f4te",
"p\u00E9ch\u00E9",
"p\u00E9ch\u00E9",
"p\u00EAche",
"p\u00EAcher",
"hellO"
};
private static final int[] tertiaryResults = {
-1, -1, -1, 1, 1, -1, 1
};
private static final String[] testData = {
"a",
"A",
"e",
"E",
"\u00e9",
"\u00e8",
"\u00ea",
"\u00eb",
"ea",
"x"
};
@Test
public void TestTertiary() {
TestUtils.doCollatorTest(myCollation, Collator.TERTIARY,
tertiarySourceData, tertiaryTargetData, tertiaryResults);
for (int i = 0; i < testData.length-1; i++) {
for (int j = i+1; j < testData.length; j++) {
TestUtils.doCollatorTest(myCollation, testData[i], testData[j], -1);
}
}
}
private final Collator myCollation = Collator.getInstance(Locale.FRANCE);
}

View file

@ -0,0 +1,301 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test G7 Collation
* @modules jdk.localedata
* @run junit G7Test
*/
/*
*
*
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
* (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved
*
* Portions copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
*
* The original version of this source code and documentation is copyrighted
* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
* materials are provided under terms of a License Agreement between Taligent
* and Sun. This technology is protected by multiple US and International
* patents. This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
*/
/**
* G7 Test cases
*
* @author Helena Shih
*/
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.Locale;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
// G7 test program for printing out test results
public class G7Test {
private static final String testCases[] = {
"black-birds", // 0
"Pat", // 1
"p\u00E9ch\u00E9", // 2
"p\u00EAche", // 3
"p\u00E9cher", // 4
"p\u00EAcher", // 5
"Tod", // 6
"T\u00F6ne", // 7
"Tofu", // 8
"blackbirds", // 9
"Ton", // 10
"PAT", // 11
"blackbird", // 12
"black-bird", // 13
"pat", // 14
// Additional tests
"czar", // 15
"churo", // 16
"cat", // 17
"darn", // 18
"?", // 19
"quick", // 20
"#", // 21
"&", // 22
"aardvark", // 23
"a-rdvark", // 24
"abbot", // 25
"coop", // 26
"co-p", // 27
"cop", // 28
"zebra" // 29
};
// loop to TOTALTESTSET
private static final int[][] G7Results = {
{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,
5, 6, 8, 10, 7, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // en_US
{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,
5, 6, 8, 10, 7, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // en_GB
{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,
5, 6, 8, 10, 7, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // en_CA
{ 12, 13, 9, 0, 14, 1, 11, 3, 2, 4,
5, 6, 8, 10, 7, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // fr_FR
{ 12, 13, 9, 0, 14, 1, 11, 3, 2, 4,
5, 6, 8, 10, 7, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // fr_CA
{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,
5, 6, 8, 10, 7, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // de_DE
{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,
5, 6, 8, 10, 7, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // it_IT
{ 12, 13, 9, 0, 14, 1, 11, 2, 3, 4,
5, 6, 8, 10, 7, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, // ja_JP
};
// new table collation with rules "& Z < p, P"
// loop to FIXEDTESTSET
private static final int[] Test1Results = {
12, 13, 9, 0, 6, 8, 10, 7, 14, 1,
11, 2, 3, 4, 5, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31
};
// new table collation with rules "& C < ch , cH, Ch, CH "
// loop to TOTALTESTSET
private static final int[] Test2Results = {
19, 22, 21, 23, 25, 24, 12, 13, 9, 0,
17, 26, 28, 27, 15, 16, 18, 14, 1, 11,
2, 3, 4, 5, 20, 6, 8, 10, 7, 29
};
// new table collation with rules
// "& Question-mark ; ? & Hash-mark ; # & Ampersand ; '&' "
// loop to TOTALTESTSET
private static final int[] Test3Results = {
23, 25, 22, 24, 12, 13, 9, 0, 17, 16,
26, 28, 27, 15, 18, 21, 14, 1, 11, 2,
3, 4, 5, 19, 20, 6, 8, 10, 7, 29
};
// analogous to Japanese rules
// " & aa ; a- & ee ; e- & ii ; i- & oo ; o- & uu ; u- "
// loop to TOTALTESTSET
private static final int[] Test4Results = {
19, 22, 21, 23, 24, 25, 12, 13, 9, 0,
17, 16, 26, 27, 28, 15, 18, 14, 1, 11,
2, 3, 4, 5, 20, 6, 8, 10, 7, 29
};
@Test
public void TestG7Data() {
for (int i = 0; i < locales.length; i++) {
Collator myCollation= null;
RuleBasedCollator tblColl1 = null;
try {
myCollation = Collator.getInstance(locales[i]);
tblColl1 = new RuleBasedCollator(((RuleBasedCollator)myCollation).getRules());
} catch (Exception foo) {
fail("Exception: " + foo.getMessage() +
" Locale : " + locales[i].getDisplayName() +
" getRules failed\n");
continue;
}
for (int j = 0; j < FIXEDTESTSET; j++) {
for (int n = j+1; n < FIXEDTESTSET; n++) {
TestUtils.doCollatorTest(tblColl1, testCases[G7Results[i][j]],
testCases[G7Results[i][n]], -1);
}
}
myCollation = null;
}
}
/*
* Demo Test 1 : Create a new table collation with rules "& Z < p, P"
*/
@Test
public void TestDemoTest1() {
int j = 0;
final Collator myCollation = Collator.getInstance(Locale.US);
final String defRules = ((RuleBasedCollator)myCollation).getRules();
RuleBasedCollator tblColl = null;
String newRules = defRules + " & Z < p, P";
try {
tblColl = new RuleBasedCollator(newRules);
for (j = 0; j < FIXEDTESTSET; j++) {
for (int n = j+1; n < FIXEDTESTSET; n++) {
TestUtils.doCollatorTest(tblColl, testCases[Test1Results[j]],
testCases[Test1Results[n]], -1);
}
}
tblColl = null;
} catch (Exception foo) {
fail("Exception: " + foo.getMessage() +
"\nDemo Test 1 Table Collation object creation failed.");
}
}
/*
* Demo Test 2 : Create a new table collation with rules
* "& C < ch , cH, Ch, CH"
*/
@Test
public void TestDemoTest2() {
final Collator myCollation = Collator.getInstance(Locale.US);
final String defRules = ((RuleBasedCollator)myCollation).getRules();
String newRules = defRules + "& C < ch , cH, Ch, CH";
try {
RuleBasedCollator tblColl = new RuleBasedCollator(newRules);
for (int j = 0; j < TOTALTESTSET; j++) {
for (int n = j+1; n < TOTALTESTSET; n++) {
TestUtils.doCollatorTest(tblColl, testCases[Test2Results[j]],
testCases[Test2Results[n]], -1);
}
}
} catch (Exception foo) {
fail("Exception: " + foo.getMessage() +
"\nDemo Test 2 Table Collation object creation failed.\n");
}
}
/*
* Demo Test 3 : Create a new table collation with rules
* "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'"
*/
@Test
public void TestDemoTest3() {
final Collator myCollation = Collator.getInstance(Locale.US);
final String defRules = ((RuleBasedCollator)myCollation).getRules();
RuleBasedCollator tblColl = null;
String newRules = defRules + "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&";
try {
tblColl = new RuleBasedCollator(newRules);
for (int j = 0; j < TOTALTESTSET; j++) {
for (int n = j+1; n < TOTALTESTSET; n++) {
TestUtils.doCollatorTest(tblColl, testCases[Test3Results[j]],
testCases[Test3Results[n]], -1);
}
}
} catch (Exception foo) {
fail("Exception: " + foo.getMessage() +
"\nDemo Test 3 Table Collation object creation failed.");
}
}
/*
* Demo Test 4 : Create a new table collation with rules
* " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' "
*/
@Test
public void TestDemoTest4() {
final Collator myCollation = Collator.getInstance(Locale.US);
final String defRules = ((RuleBasedCollator)myCollation).getRules();
RuleBasedCollator tblColl = null;
String newRules = defRules + " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' ";
try {
tblColl = new RuleBasedCollator(newRules);
for (int j = 0; j < TOTALTESTSET; j++) {
for (int n = j+1; n < TOTALTESTSET; n++) {
TestUtils.doCollatorTest(tblColl, testCases[Test4Results[j]],
testCases[Test4Results[n]], -1);
}
}
} catch (Exception foo) {
fail("Exception: " + foo.getMessage() +
"\nDemo Test 4 Table Collation object creation failed.");
}
tblColl = null;
}
private static final int FIXEDTESTSET = 15;
private static final int TOTALTESTSET = 30;
private static final Locale locales[] = {
Locale.US,
Locale.UK,
Locale.CANADA,
Locale.FRANCE,
Locale.CANADA_FRENCH,
Locale.GERMANY,
Locale.JAPAN,
Locale.ITALY
};
}

View file

@ -0,0 +1,114 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test German Collation
* @run junit GermanTest
*/
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
import java.util.Locale;
import java.text.Collator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
// Quick dummy program for printing out test results
public class GermanTest {
/*
* Shared data for TestPrimary() and TestTertiary()
*/
private static final String testSourceData[] = {
"Gr\u00F6\u00DFe",
"abc",
"T\u00F6ne",
"T\u00F6ne",
"T\u00F6ne",
"a\u0308bc",
"\u00E4bc",
"\u00E4bc",
"Stra\u00DFe",
"efg",
"\u00E4bc",
"Stra\u00DFe"
};
private static final String testTargetData[] = {
"Grossist",
"a\u0308bc",
"Ton",
"Tod",
"Tofu",
"A\u0308bc",
"a\u0308bc",
"aebc",
"Strasse",
"efg",
"aebc",
"Strasse"
};
/*
* Data for TestPrimary()
*/
private static final int[] primaryResults = {
-1, 0, 1, 1, 1, 0, 0, -1, 0, 0,
-1, 0
};
/*
* Data for TestTertiary()
*/
private static final int[] tertiaryResults = {
-1, -1, 1, 1, 1, -1, 0, -1, 1, 0,
-1, 1
};
@Test
public void TestPrimary() {
TestUtils.doCollatorTest(myCollation, Collator.PRIMARY,
testSourceData, testTargetData, primaryResults);
}
@Test
public void TestTertiary() {
TestUtils.doCollatorTest(myCollation, Collator.TERTIARY,
testSourceData, testTargetData, tertiaryResults);
}
private final Collator myCollation = Collator.getInstance(Locale.GERMAN);
}

View file

@ -0,0 +1,297 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4062985 4108758 4108762 4157299
* @library /java/text/testlib
* @summary Test CollationElementIterator, particularly the new methods in 1.2
* @run junit IteratorTest
*/
/*
* (C) Copyright IBM Corp. 1998 - All Rights Reserved
*
* The original version of this source code and documentation is copyrighted
* and owned by IBM, Inc. These materials are provided under terms of a
* License Agreement between IBM and Sun. This technology is protected by
* multiple US and International patents. This notice and attribution to IBM
* may not be removed.
*/
import java.util.Locale;
import java.text.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
public class IteratorTest {
// TODO:
// - Test previous() with contracting character sequences, which don't work
// at the moment.
// - Test edge cases on setOffset(), e.g. offset > length, etc.
//
/**
* Test for CollationElementIterator.previous()
*
* @bug 4108758 - Make sure it works with contracting characters
*
*/
@Test
public void TestPrevious() throws ParseException {
// A basic test to see if it's working at all
backAndForth(en_us.getCollationElementIterator(test1));
// Test with a contracting character sequence
RuleBasedCollator c1 = new RuleBasedCollator(
"< a,A < b,B < c,C, d,D < z,Z < ch,cH,Ch,CH" );
backAndForth(c1.getCollationElementIterator("abchdcba"));
// Test with an expanding character sequence
RuleBasedCollator c2 = new RuleBasedCollator(
"< a < b < c/abd < d" );
backAndForth(c2.getCollationElementIterator("abcd"));
// Now try both
RuleBasedCollator c3 = new RuleBasedCollator(
"< a < b < c/aba < d < z < ch" );
backAndForth(c3.getCollationElementIterator("abcdbchdc"));
}
/**
* Test for getOffset() and setOffset()
*/
@Test
public void TestOffset() {
CollationElementIterator iter = en_us.getCollationElementIterator(test1);
// Run all the way through the iterator, then get the offset
int orders[] = getOrders(iter);
int offset = iter.getOffset();
if (offset != test1.length()) {
System.out.println("offset at end != length: "
+ offset + " vs " + test1.length());
}
// Now set the offset back to the beginning and see if it works
iter.setOffset(0);
TestUtils.compareCollationElementIters(iter, en_us.getCollationElementIterator(test1));
// TODO: try iterating halfway through a messy string.
}
/**
* Test for setText()
*/
@Test
public void TestSetText() {
CollationElementIterator iter1 = en_us.getCollationElementIterator(test1);
CollationElementIterator iter2 = en_us.getCollationElementIterator(test2);
// Run through the second iterator just to exercise it
int c = iter2.next();
int i = 0;
while ( ++i < 10 && c != CollationElementIterator.NULLORDER) {
c = iter2.next();
}
// Now set it to point to the same string as the first iterator
iter2.setText(test1);
TestUtils.compareCollationElementIters(iter1, iter2);
}
/** @bug 4108762
* Test for getMaxExpansion()
*/
@Test
public void TestMaxExpansion() throws ParseException {
// Try a simple one first:
// The only expansion ends with 'e' and has length 2
String[][] test1 = {
{ "< a & ae = \u00e4 < b < e", "" },
{ "a", "1" },
{ "b", "1" },
{ "e", "2" },
};
verifyExpansion(test1);
// Now a more complicated one:
// "a1" --> "ae"
// "z" --> "aeef"
//
String[][] test2 = {
{ "< a & ae = a1 & aeef = z < b < e < f", "" },
{ "a", "1" },
{ "b", "1" },
{ "e", "2" },
{ "f", "4" },
};
verifyExpansion(test2);
}
/*
* @bug 4157299
*/
@Test
public void TestClearBuffers() throws ParseException {
RuleBasedCollator c = new RuleBasedCollator("< a < b < c & ab = d");
CollationElementIterator i = c.getCollationElementIterator("abcd");
int e0 = i.next(); // save the first collation element
i.setOffset(3); // go to the expanding character
i.next(); // but only use up half of it
i.setOffset(0); // go back to the beginning
int e = i.next(); // and get this one again
if (e != e0) {
fail("got " + Integer.toString(e, 16) + ", expected " +
Integer.toString(e0, 16));
}
}
//------------------------------------------------------------------------
// Internal utilities
//
private void backAndForth(CollationElementIterator iter) {
// Run through the iterator forwards and stick it into an array
int [] orders = getOrders(iter);
// Now go through it backwards and make sure we get the same values
int index = orders.length;
int o;
while ((o = iter.previous()) != CollationElementIterator.NULLORDER) {
if (o != orders[--index]) {
fail("Mismatch at index " + index + ": "
+ orders[index] + " vs " + o);
break;
}
}
if (index != 0) {
fail("Didn't get back to beginning - index is " + index);
iter.reset();
fail("next: ");
while ((o = iter.next()) != NULLORDER) {
fail( Integer.toHexString(o) + " ");
}
fail("");
fail("prev: ");
while ((o = iter.previous()) != NULLORDER) {
fail( Integer.toHexString(o) + " ");
}
fail("");
}
}
/**
* Verify that getMaxExpansion works on a given set of collation rules
*
* The first row of the "tests" array contains the collation rules
* at index 0, and the string at index 1 is ignored.
*
* Subsequent rows of the array contain a character and a number, both
* represented as strings. The character's collation order is determined,
* and getMaxExpansion is called for that character. If its value is
* not equal to the specified number, an error results.
*/
private void verifyExpansion(String[][] tests) throws ParseException
{
RuleBasedCollator coll = new RuleBasedCollator(tests[0][0]);
CollationElementIterator iter = coll.getCollationElementIterator("");
for (int i = 1; i < tests.length; i++) {
// First get the collation key that the test string expands to
iter.setText(tests[i][0]);
int order = iter.next();
if (order == NULLORDER || iter.next() != NULLORDER) {
iter.reset();
fail("verifyExpansion: '" + tests[i][0] +
"' has multiple orders:" + orderString(iter));
}
int expansion = iter.getMaxExpansion(order);
int expect = new Integer(tests[i][1]).intValue();
if (expansion != expect) {
fail("expansion for '" + tests[i][0] + "' is wrong: " +
"expected " + expect + ", got " + expansion);
}
}
}
/**
* Return an integer array containing all of the collation orders
* returned by calls to next on the specified iterator
*/
private int[] getOrders(CollationElementIterator iter)
{
int maxSize = 100;
int size = 0;
int[] orders = new int[maxSize];
int order;
while ((order = iter.next()) != NULLORDER) {
if (size == maxSize) {
maxSize *= 2;
int[] temp = new int[maxSize];
System.arraycopy(orders, 0, temp, 0, size);
orders = temp;
}
orders[size++] = order;
}
if (orders.length > size) {
int[] temp = new int[size];
System.arraycopy(orders, 0, temp, 0, size);
orders = temp;
}
return orders;
};
/**
* Return a string containing all of the collation orders
* returned by calls to next on the specified iterator
*/
private String orderString(CollationElementIterator iter) {
StringBuffer buf = new StringBuffer();
int order;
while ((order = iter.next()) != NULLORDER) {
buf.append( Integer.toHexString(order) + " ");
}
return buf.toString();
}
static final private int NULLORDER = CollationElementIterator.NULLORDER;
RuleBasedCollator en_us = (RuleBasedCollator)Collator.getInstance(Locale.US);
String test1 = "What subset of all possible test cases?";
String test2 = "has the highest probability of detecting";
}

View file

@ -0,0 +1,325 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test 1.1 02/09/11
* @bug 4176141 4655819
* @summary Regression tests for Japanese Collation
* @modules jdk.localedata
*/
import java.text.*;
import java.util.*;
public class JapaneseTest {
// NOTE:
// Golden data in this test case is locale data dependent and
// may need to be changed if the Japanese locale collation rules
// are changed.
/*
* | NO_DECOMP(default) | CANONICAL_DECOMP | FULL_DECOMP
* -------------------+--------------------+------------------+-------------
* PRIMARY | s1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)
* SECONDARY | s1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)
* TERTIARY(default) | S1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)
*/
static final int[][] results1 = {
{ -1, -1, -1},
{ -1, -1, -1},
{ -1, -1, -1},
};
static final String[][] compData1 = {
/*
* Data to verify '<' relationship in LocaleElements_ja.java
*/
{"\u3084", "\u30E6",
"Hiragana \"YA\"(0x3084) <---> Katakana \"YU\"(0x30E6)"},
{"\u30E6", "\u3088",
"Katakana \"YU\"(0x30E6) <---> Hiragana \"YO\"(0x3088)"},
{"\u00B1", "\u2260",
"Plus-Minus Sign(0x00B1) <---> Not Equal To(0x2260)"},
{"\u3011", "\u2260",
"Right Black Lenticular Bracket(0x3011) <---> Not Equal To(0x2260)"},
{"\u2260", "\u2103",
"Not Equal To(0x2260) <---> Degree Celsius(0x2103)"},
{"\u2260", "\u2606",
"Not Equal To(0x2260) <---> White Star(0x2606)"},
{"\u30FD", "\u309E",
"Katakana Iteration Mark(0x30FD) <---> Hiragana Voiced Iteration Mark(0x309E)"},
{"\u3059\u309D", "\u3059\u309E",
"Hiragana \"SU\"(0x3059)Hiragana Iteration Mark(0x309D) <---> Hiragana \"SU\"(0x3059)Hiragana Voiced Iteration Mark(0x309E)"},
{"\u821E", "\u798F",
"CJK Unified Ideograph(0x821E) <---> CJK Unified Ideograph(0x798F)"},
/*
* Data to verify normalization
*/
{"\u2260", "\u225F",
"Not Equal To(0x2260) <---> Questioned Equal To(0x225F)"},
{"\u226E", "\u2260",
"Not Less-than(0x226E) <---> Not Equal To(0x2260)"},
{"\u226E", "\u226D",
"Not Less-than(0x226E) <---> Not Equivalent To(0x226D)"},
};
/*
* | NO_DECOMP(default) | CANONICAL_DECOMP | FULL_DECOMP
* -------------------+--------------------+------------------+-------------
* PRIMARY | s1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)
* SECONDARY | s1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)
* TERTIARY(default) | S1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)
*/
static final int[][] results2 = {
{ 0, 0, 0},
{ -1, -1, -1},
{ -1, -1, -1},
};
static final String[][] compData2 = {
/*
* Data to verify ';' relationship in LocaleElements_ja.java
*/
{"\u3099", "\u309A",
"Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Combining Katakana-Hiragana Semi-voiced Sound Mark(0x309A)"},
{"\u3053\u3046\u3068\u3046", "\u3053\u3046\u3068\u3099\u3046",
"Hiragana \"KOUTOU\"(0x3053 0x3046 0x3068 0x3046) <---> Hiragana \"KOUTO\"(0x3053 0x3046 0x3068)Combining Katakana-Hiragana Voiced Sound Mark(0X3099)\"U\"(0x3046)"},
{"\u3053\u3046\u3068\u3046", "\u3053\u3046\u3069\u3046",
"Hiragana \"KOUTOU\"(0x3053 0x3046 0x3068 0x3046) <---> Hiragana \"KOUDOU\"(0x3053 0x3046 0x3069 0x3046)"},
{"\u3053\u3046\u3069\u3046", "\u3054\u3046\u3068\u3046",
"Hiragana \"KOUTOU\"(0x3053 0x3046 0x3069 0x3046) <---> Hiragana \"GOUTOU\"(0x3054 0x3046 0x3068 0x3046)"},
{"\u3054\u3046\u3068\u3046", "\u3054\u3046\u3069\u3046",
"Hiragana \"GOUTOU\"(0x3054 0x3046 0x3068 0x3046) <---> Hiragana \"GOUDOU\"(0x3054 0x3046 0x3069 0x3046)"},
};
/*
* | NO_DECOMP(default) | CANONICAL_DECOMP | FULL_DECOMP
* -------------------+--------------------+------------------+-------------
* PRIMARY | s1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)
* SECONDARY | s1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)
* TERTIARY(default) | S1 < s2 (-1) | s1 < s2 (-1) | s1 < s2 (-1)
*/
static final int[][] results3 = {
{ 0, 0, 0},
{ 0, 0, 0},
{ -1, -1, -1},
};
static final String[][] compData3 = {
/*
* Data to verify ',' relationship in LocaleElements_ja.java
*/
{"\u3042", "\u3041",
"Hiragana \"A\"(0x3042) <---> Hiragana \"a\"(0x3041)"},
{"\u3041", "\u30A2",
"Hiragana \"a\"(0x3041) <---> Katakana \"A\"(0x30A2)"},
{"\u30A2", "\u30A1",
"Katakana \"A\"(0x30A2) <---> Katakana \"a\"(0x30A1)"},
{"\u3094", "\u30F4",
"Hiragana \"VU\"(0x3094) <---> Katakana \"VU\"(0x30F4)"},
{"\u3094", "\u30A6\u3099",
"Hiragana \"VU\"(0x3094) <---> Katakana \"U\"(0x30A6)Combining Katakana-Hiragana Voiced Sound Mark(0x3099)"},
{"\u3046\u3099", "\u30F4",
"Hiragana \"U\"(0x3046)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VU\"(0x30F4)"},
{"\u3046\u3099", "\u30A6\u3099",
"Hiragana \"U\"(0x3046)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"U\"(0x30A6)Combining Katakana-Hiragana Voiced Sound Mark(0x3099)"},
{"\u30AB\u30A2", "\u30AB\u30FC",
"Katakana \"KAA\"(0x30AB 0x30A2) <---> Katakana \"KA-\"(0x30AB 0x30FC)"},
{"\u30CB\u30A1\u30A2", "\u30CB\u30A1\u30FC",
"Katakana \"NyaA\"(0x30CB 0x30A1 0x30A2) <---> Katakana \"Nya-\"(0x30CB 0x30A1 0x30FC)"},
{"\u30B3\u30AA\u30D2\u30A4", "\u30B3\u30FC\u30D2\u30FC",
"Katakana \"KOOHII\"(0x30B3 0x30AA 0x30D2 0x30A4) <---> Katakana \"KO-HI-\"(0x30B3 0x30FC 0x30D2 0x30FC)"},
{"\u308A\u3088\u3046", "\u308A\u3087\u3046",
"Hiragana \"RIYOU\"(0x308A 0x3088 0x3046) <---> Hiragana \"Ryou\"(0x308A 0x3087 0x3046)"},
{"\u3081\u3064\u304D", "\u3081\u3063\u304D",
"Hiragana \"METSUKI\"(0x3081 0x3064 0x304D) <---> Hiragana \"MEKKI\"(0x3081 0x3063 0x304D)"},
{"\u3075\u3042\u3093", "\u30D5\u30A1\u30F3",
"Hiragana \"FUAN\"(0x3075 0x3042 0x3093) <---> Katakana \"FUaN\"(0x30D5 0x30A1 0x30F3)"},
{"\u3075\u3041\u3093", "\u30D5\u30A2\u30F3",
"Hiragana \"FUaN\"(0x3075 0x3041 0x3093) <---> Katakana \"FUAN\"(0x30D5 0x30A2 0x30F3)"},
{"\u30D5\u30A2\u30F3", "\u30D5\u30A1\u30F3",
"Katakana \"FUAN\"(0x30D5 0x30A2 0x30F3) <---> Katakana \"FUaN\"(0x30D5 0x30A1 0x30F3)"},
};
/*
* | NO_DECOMP(default) | CANONICAL_DECOMP | FULL_DECOMP
* -------------------+--------------------+------------------+-------------
* PRIMARY | s1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)
* SECONDARY | s1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)
* TERTIARY(default) | S1 = s2 (0) | s1 = s2 (0) | s1 = s2 (0)
*/
static final int[][] results4 = {
{ 0, 0, 0},
{ 0, 0, 0},
{ 0, 0, 0},
};
static final String[][] compData4 = {
/*
* Data to verify Japanese normalization
*/
{"\u309E", "\u309D\u3099",
"Hiragana Voiced Iteration Mark(0x309E) <---> Hiragana Iteration Mark(0x309D)Combining Katakana-Hiragana Voiced Sound Mark(0x3099)"},
{"\u30FE", "\u30FD\u3099",
"Katakana Voiced Iteration Mark(0x30FE) <---> Katakana iteration mark(0x30FD)Combining Katakana-Hiragana Voiced Sound Mark(0x3099)"},
{"\u306F\u3099", "\u3070",
"Hiragana \"HA\"(0x306F)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Hiragana \"BA\"(0x3070)"},
{"\u306F\u309A", "\u3071",
"Hiragana \"HA\"(0x306F)Combining Katakana-Hiragana Semi-voiced Sound Mark(0x309A) <---> Hiragana \"PA\"(0x3071)"},
{"\u30EF\u3099", "\u30F7",
"Katakana \"WA\"(0x306F)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VA\"(0x30F7)"},
{"\u30F0\u3099", "\u30F8",
"Katakana \"WI\"(0x30F0)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VI\"(0x30F8)"},
{"\u30F1\u3099", "\u30F9",
"Katakana \"WE\"(0x30F1)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VE\"(0x30F9)"},
{"\u30F2\u3099", "\u30FA",
"Katakana \"WO\"(0x30F2)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VO\"(0x30FA)"},
{"\u3046\u3099", "\u3094",
"Hiragana \"U\"(0x3046)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Hiragana \"VU\"(0x3094)"},
{"\u30A6\u3099", "\u30F4",
"Katakana \"U\"(0x30A6)Combining Katakana-Hiragana Voiced Sound Mark(0x3099) <---> Katakana \"VU\"(0x30F4)"},
// verify normalization
{"\u2260", "\u003D\u0338",
"Not Equal To(0x2260) <---> Equal(0x003D)Combining Long Solidus Overlay(0x0338)"},
{"\u2262", "\u2261\u0338",
"Not Identical To(0x2262) <---> Identical To(0x2261)Combining Long Solidus Overlay(0x0338)"},
{"\u226E", "\u003C\u0338",
"Not Less-than(0x226E) <---> Less-than Sign(0x003C)Combining Long Solidus Overlay(0x0338)"},
// Verify a character which has been added since Unicode 2.1.X.
{"\u798F", "\uFA1B",
"CJK Unified Ideograph \"FUKU\"(0x798F) <---> CJK Compatibility Ideograph \"FUKU\"(0xFA1B)"},
};
/*
* | NO_DECOMP(default) | CANONICAL_DECOMP | FULL_DECOMP
* -------------------+--------------------+------------------+-------------
* PRIMARY | s1 > s2 (1) | s1 = s2 (0) | s1 = s2 (0)
* SECONDARY | s1 > s2 (1) | s1 = s2 (0) | s1 = s2 (0)
* TERTIARY(default) | S1 > s2 (1) | s1 = s2 (0) | s1 = s2 (0)
*/
static final int[][] results5 = {
{ 1, 0, 0},
{ 1, 0, 0},
{ 1, 0, 0},
};
static final String[][] compData5 = {
/*
* Data to verify normalization
*/
{"\u226D", "\u224D\u0338",
"Not Equivalent To(0x226D) <---> Equivalent To(0x224D)Combining Long Solidus Overlay(0x0338)"},
};
static final int[][] results6 = {
{ 1, -1, -1},
{ 1, -1, -1},
{ 1, -1, -1},
};
static final String[][] compData6 = {
/*
* Data to verify normalization
*/
{"\u226D", "\u226C",
"Not Equivalent To(0x226D) <---> Between(0x226C)"},
{"\u226D", "\u225F",
"Not Equivalent To(0x226D) <---> Questioned Equal To(0x225F)"},
};
/*
* The following data isn't used at the moment because iteration marks
* aren't supported now.
*/
static final String[][] compData0 = {
{"\u307F\u307F", "\u307F\u309D",
"Hiragana \"MIMI\"(0x307F 0x307F) <---> Hiragana \"MI\"(0x307F)Hiragana Iteration Mark(0x309D)"},
{"\u3044\u3059\u305A", "\u3044\u3059\u309E",
"Hiragana \"ISUZU\"(0x3044 0x3059 0x305A) <---> Hiragana \"ISU\"(0x3044 0x3059)Hiragana Voiced Iteration Mark(0x309E)"},
{"\u30DF\u30DF", "\u30DF\u30FD",
"Katakana \"MIMI\"(0x30DF 0x30DF) <---> Katakana \"MI\"(0x30DF)Katakana Iteration Mark(0x30FD)"},
{"\u30A4\u30B9\u30BA", "\u30A4\u30B9\u30FE",
"Katakana \"ISUZU\"(0x30A4 0x30B9 0x30BA) <---> Katakana \"ISU\"(0x30A4 0x30B9)Katakana Voiced Iteration Mark(0x30FE)"},
};
static final String[] decomp_name = {
"NO_DECOMP", "CANONICAL_DECOMP", "FULL_DECOMP"
};
static final String[] strength_name = {
"PRIMARY", "SECONDARY", "TERTIARY"
};
Collator col = Collator.getInstance(Locale.JAPAN);
int result = 0;
public static void main(String[] args) throws Exception {
new JapaneseTest().run();
}
public void run() {
// Use all available localse on the initial testing....
// Locale[] locales = Locale.getAvailableLocales();
Locale[] locales = { Locale.getDefault() };
for (int l = 0; l < locales.length; l++) {
Locale.setDefault(locales[l]);
for (int decomp = 0; decomp < 3; decomp++) {// See decomp_name.
col.setDecomposition(decomp);
for (int strength = 0; strength < 3; strength++) {// See strength_name.
// System.err.println("\n" + locales[l] + ": " + strength_name[strength] + " --- " + decomp_name[decomp]);
col.setStrength(strength);
doCompare(compData1, results1[strength][decomp], strength, decomp);
doCompare(compData2, results2[strength][decomp], strength, decomp);
doCompare(compData3, results3[strength][decomp], strength, decomp);
doCompare(compData4, results4[strength][decomp], strength, decomp);
doCompare(compData5, results5[strength][decomp], strength, decomp);
doCompare(compData6, results6[strength][decomp], strength, decomp);
}
}
}
/* Check result */
if (result !=0) {
throw new RuntimeException("Unexpected results on Japanese collation.");
}
}
void doCompare(String[][] s, int expectedValue, int strength, int decomp) {
int value;
for (int i=0; i < s.length; i++) {
if ((value = col.compare(s[i][0], s[i][1])) != expectedValue) {
result++;
System.err.println(strength_name[strength] +
": compare() returned unexpected value.(" +
value + ") on " + decomp_name[decomp] +
" Expected(" + expectedValue +
") for " + s[i][2]);
}
}
}
}

View file

@ -0,0 +1,143 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test 1.1 02/09/12
* @bug 4176141 4655819
* @summary Regression tests for Korean Collation
* @modules jdk.localedata
*/
import java.text.*;
import java.util.*;
public class KoreanTest {
// NOTE:
// Golden data in this test case is locale data dependent and
// may need to be changed if the Korean locale collation rules
// are changed.
// And, CollationDecomp has been set to 0(NO_DECOMPOSITION) in
// LocaleElements_ko.java.
// This is very important to consider what is correct behavior in
// Korean Collator. Sometimes different from other locales.
/*
* TERTIARY(default): s1 < s2, SECONDARY: s1 < s2, PRIMARY: s1 < s2
*/
static final String[][] compData1 = {
/*
* Data to verify '<' relationship in LocaleElements_ja.java
*/
{"\uACE0\uC591\uC774", "\u732B",
"Hangul \"Cat\"(0xACE0 0xC591 0xC774) <---> Chinese Kanji \"Cat\"(0x732B)"},
{"\u30FB", "\u2025",
"Katakana middle dot(0x30FB) <---> Two dot leader(0x2025)"},
{"\u00B1", "\u2260",
"Plus-Minus Sign(0x00B1) <---> Not Equal To(0x2260)"},
{"\u3011", "\u2260",
"Right Black Lenticular Bracket(0x3011) <---> Not Equal To(0x2260)"},
{"\u2260", "\u2103",
"Not Equal To(0x2260) <---> Degree Celsius(0x2103)"},
{"\u2260", "\u2606",
"Not Equal To(0x2260) <---> White Star(0x2606)"},
// Unlike other locales' Collator, compare() returns -1 because of
// NO_DECOMPOSITION.
/* above "assumption" is no longer true, now we do normalize ("decomposition")
for the pattern in ko locale, but exclude those hangul syllables, so the
test case below need to be excluded from tiger/1.5
{"\u003D\u0338", "\u2260",
"Equal(0x003D)Combining Long Solidus Overlay(0x0338) <---> Not Equal To(0x2260)"},
*/
};
/*
* TERTIARY(default): s1 = s2, SECONDARY: s1 = s2, PRIMARY: s1 = s2
*/
static final String[][] compData2 = {
// Verify a character which has been added since Unicode 2.1.X.
{"\u798F", "\uFA1B",
"CJK Unified Ideograph \"FUKU\"(0x798F) <---> CJK Compatibility Ideograph \"FUKU\"(0xFA1B)"},
};
Collator col = Collator.getInstance(Locale.KOREA);
int result = 0;
public static void main(String[] args) throws Exception {
new KoreanTest().run();
}
public void run() {
//
// Test for TERTIARY(default)
//
doCompare(compData1);
doEquals(compData2);
//
// Test for SECONDARY
//
col.setStrength(Collator.SECONDARY);
doCompare(compData1);
doEquals(compData2);
//
// Test for PRIMARY
//
col.setStrength(Collator.PRIMARY);
doCompare(compData1);
doEquals(compData2);
if (result !=0) {
throw new RuntimeException("Unexpected results on Korean collation.");
}
}
/* compare() should return -1 for each combination. */
void doCompare(String[][] s) {
int value;
for (int i=0; i < s.length; i++) {
if ((value = col.compare(s[i][0], s[i][1])) > -1) {
result++;
System.err.println("TERTIARY: The first string should be less than the second string: " +
s[i][2] + " compare() returned " + value + ".");
}
}
}
/* equals() should return true for each combination. */
void doEquals(String[][] s) {
for (int i=0; i < s.length; i++) {
if (!col.equals(s[i][0], s[i][1])) {
result++;
System.err.println("TERTIARY: The first string should be equals to the second string: " +
s[i][2] + " compare() returned " +
col.compare(s[i][0], s[i][1] + "."));
}
}
}
}

View file

@ -0,0 +1,152 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test Collation, Monkey style
* @run junit MonkeyTest
*/
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
import java.io.IOException;
import java.util.Random;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Locale;
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.text.CollationKey;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
public class MonkeyTest
{
public void report(String s, String t, int result, int revResult)
{
if (result == -1)
{
if (revResult != 1)
fail(" --> Test Failed");
}
else if (result == 1)
{
if (revResult != -1)
fail(" --> Test Failed");
}
else if (result == 0)
{
if (revResult != 0)
fail(" --> Test Failed");
}
}
@Test
public void TestCollationKey()
{
String source = "-abcdefghijklmnopqrstuvwxyz#&^$@";
Random r = new Random(3);
int s = checkValue(r.nextInt() % source.length());
int t = checkValue(r.nextInt() % source.length());
int slen = checkValue((r.nextInt() - source.length()) % source.length());
int tlen = checkValue((r.nextInt() - source.length()) % source.length());
String subs = source.substring((s > slen ? slen : s), (s >= slen ? s : slen));
String subt = source.substring((t > tlen ? tlen : t), (t >= tlen ? t : tlen));
myCollator.setStrength(Collator.TERTIARY);
CollationKey CollationKey1 = myCollator.getCollationKey(subs);
CollationKey CollationKey2 = myCollator.getCollationKey(subt);
int result = CollationKey1.compareTo(CollationKey2); // Tertiary
int revResult = CollationKey2.compareTo(CollationKey1); // Tertiary
report(("CollationKey(" + subs + ")"), ("CollationKey(" + subt + ")"), result, revResult);
myCollator.setStrength(Collator.SECONDARY);
CollationKey1 = myCollator.getCollationKey(subs);
CollationKey2 = myCollator.getCollationKey(subt);
result = CollationKey1.compareTo(CollationKey2); // Secondary
revResult = CollationKey2.compareTo(CollationKey1); // Secondary
report(("CollationKey(" + subs + ")") , ("CollationKey(" + subt + ")"), result, revResult);
myCollator.setStrength(Collator.PRIMARY);
CollationKey1 = myCollator.getCollationKey(subs);
CollationKey2 = myCollator.getCollationKey(subt);
result = CollationKey1.compareTo(CollationKey2); // Primary
revResult = CollationKey2.compareTo(CollationKey1); // Primary
report(("CollationKey(" + subs + ")"), ("CollationKey(" + subt + ")"), result, revResult);
String addOne = subs + "\uE000";
CollationKey1 = myCollator.getCollationKey(subs);
CollationKey2 = myCollator.getCollationKey(addOne);
result = CollationKey1.compareTo(CollationKey2);
if (result != -1)
fail("CollationKey(" + subs + ")" + ".LT." + "CollationKey(" + addOne + ") Failed.");
result = CollationKey2.compareTo(CollationKey1);
if (result != 1)
fail("CollationKey(" + addOne + ")" + ".GT." + "CollationKey(" + subs + ") Failed.");
}
private static int checkValue(int value)
{
value *= (value > 0) ? 1 : -1;
return value;
}
@Test
public void TestCompare()
{
String source = "-abcdefghijklmnopqrstuvwxyz#&^$@";
Random r = new Random(3);
int s = checkValue(r.nextInt() % source.length());
int t = checkValue(r.nextInt() % source.length());
int slen = checkValue((r.nextInt() - source.length()) % source.length());
int tlen = checkValue((r.nextInt() - source.length()) % source.length());
String subs = source.substring((s > slen ? slen : s), (s >= slen ? s : slen));
String subt = source.substring((t > tlen ? tlen : t), (t >= tlen ? t : tlen));
myCollator.setStrength(Collator.TERTIARY);
int result = myCollator.compare(subs, subt); // Tertiary
int revResult = myCollator.compare(subt, subs); // Tertiary
report(subs, subt, result, revResult);
myCollator.setStrength(Collator.SECONDARY);
result = myCollator.compare(subs, subt); // Secondary
revResult = myCollator.compare(subt, subs); // Secondary
report(subs, subt, result, revResult);
myCollator.setStrength(Collator.PRIMARY);
result = myCollator.compare(subs, subt); // Primary
revResult = myCollator.compare(subt, subs); // Primary
report(subs, subt, result, revResult);
String addOne = subs + "\uE000";
result = myCollator.compare(subs, addOne);
if (result != -1)
fail("Test : " + subs + " .LT. " + addOne + " Failed.");
result = myCollator.compare(addOne, subs);
if (result != 1)
fail("Test : " + addOne + " .GE. " + subs + " Failed.");
}
private static Collator myCollator = Collator.getInstance();
}

View file

@ -0,0 +1,978 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 4048446 4051866 4053636 4054238 4054734 4054736 4058613 4059820 4060154
* 4062418 4065540 4066189 4066696 4076676 4078588 4079231 4081866 4087241
* 4087243 4092260 4095316 4101940 4103436 4114076 4114077 4124632 4132736
* 4133509 4139572 4141640 4179126 4179686 4244884 4663220
* @library /java/text/testlib
* @summary Regression tests for Collation and associated classes
* @modules jdk.localedata
* @run junit Regression
*/
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
import java.text.*;
import java.util.Locale;
import java.util.Vector;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
public class Regression {
// CollationElementIterator.reset() doesn't work
//
@Test
public void Test4048446() {
CollationElementIterator i1 = en_us.getCollationElementIterator(test1);
CollationElementIterator i2 = en_us.getCollationElementIterator(test1);
while ( i1.next() != CollationElementIterator.NULLORDER ) {
}
i1.reset();
TestUtils.compareCollationElementIters(i1, i2);
}
// Collator -> rules -> Collator round-trip broken for expanding characters
//
@Test
public void Test4051866() throws ParseException {
// Build a collator containing expanding characters
RuleBasedCollator c1 = new RuleBasedCollator("< o "
+"& oe ,o\u3080"
+"& oe ,\u1530 ,O"
+"& OE ,O\u3080"
+"& OE ,\u1520"
+"< p ,P");
// Build another using the rules from the first
RuleBasedCollator c2 = new RuleBasedCollator(c1.getRules());
// Make sure they're the same
if (!c1.getRules().equals(c2.getRules())) {
fail("Rules are not equal");
}
}
// Collator thinks "black-bird" == "black"
//
@Test
public void Test4053636() {
if (en_us.equals("black-bird","black")) {
fail("black-bird == black");
}
}
// CollationElementIterator will not work correctly if the associated
// Collator object's mode is changed
//
@Test
public void Test4054238() {
RuleBasedCollator c = (RuleBasedCollator) en_us.clone();
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
CollationElementIterator i1 = en_us.getCollationElementIterator(test3);
c.setDecomposition(Collator.NO_DECOMPOSITION);
CollationElementIterator i2 = en_us.getCollationElementIterator(test3);
// At this point, BOTH iterators should use NO_DECOMPOSITION, since the
// collator itself is in that mode
TestUtils.compareCollationElementIters(i1, i2);
}
// Collator.IDENTICAL documented but not implemented
//
@Test
public void Test4054734() {
RuleBasedCollator c = (RuleBasedCollator) en_us.clone();
try {
c.setStrength(Collator.IDENTICAL);
}
catch (Exception e) {
fail("Caught " + e.toString() + " setting Collator.IDENTICAL");
}
String[] decomp = {
"\u0001", "<", "\u0002",
"\u0001", "=", "\u0001",
"A\u0001", ">", "~\u0002", // Ensure A and ~ are not compared bitwise
"\u00C0", "=", "A\u0300" // Decomp should make these equal
};
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
compareArray(c, decomp);
String[] nodecomp = {
"\u00C0", ">", "A\u0300" // A-grave vs. A combining-grave
};
c.setDecomposition(Collator.NO_DECOMPOSITION);
compareArray(c, nodecomp);
}
// Full Decomposition mode not implemented
//
@Test
public void Test4054736() {
RuleBasedCollator c = (RuleBasedCollator) en_us.clone();
c.setDecomposition(Collator.FULL_DECOMPOSITION);
String[] tests = {
"\uFB4f", "=", "\u05D0\u05DC", // Alef-Lamed vs. Alef, Lamed
};
compareArray(c, tests);
}
// Collator.getInstance() causes an ArrayIndexOutofBoundsException for Korean
//
@Test
public void Test4058613() {
// Creating a default collator doesn't work when Korean is the default
// locale
Locale oldDefault = Locale.getDefault();
Locale.setDefault( Locale.KOREAN );
try {
Collator c = Collator.getInstance();
// Since the fix to this bug was to turn of decomposition for Korean collators,
// ensure that's what we got
if (c.getDecomposition() != Collator.NO_DECOMPOSITION) {
fail("Decomposition is not set to NO_DECOMPOSITION");
}
}
finally {
Locale.setDefault(oldDefault);
}
}
// RuleBasedCollator.getRules does not return the exact pattern as input
// for expanding character sequences
//
@Test
public void Test4059820() {
RuleBasedCollator c = null;
try {
c = new RuleBasedCollator("< a < b , c/a < d < z");
} catch (ParseException e) {
fail("Exception building collator: " + e.toString());
return;
}
if ( c.getRules().indexOf("c/a") == -1) {
fail("returned rules do not contain 'c/a'");
}
}
// MergeCollation::fixEntry broken for "& H < \u0131, \u0130, i, I"
//
@Test
public void Test4060154() {
RuleBasedCollator c = null;
try {
c = new RuleBasedCollator("< g, G < h, H < i, I < j, J"
+ " & H < \u0131, \u0130, i, I" );
} catch (ParseException e) {
fail("Exception building collator: " + e.toString());
return;
}
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
String[] tertiary = {
"A", "<", "B",
"H", "<", "\u0131",
"H", "<", "I",
"\u0131", "<", "\u0130",
"\u0130", "<", "i",
"\u0130", ">", "H",
};
c.setStrength(Collator.TERTIARY);
compareArray(c, tertiary);
String[] secondary = {
"H", "<", "I",
"\u0131", "=", "\u0130",
};
c.setStrength(Collator.PRIMARY);
compareArray(c, secondary);
};
// Secondary/Tertiary comparison incorrect in French Secondary
//
@Test
public void Test4062418() throws ParseException {
RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.FRANCE);
c.setStrength(Collator.SECONDARY);
String[] tests = {
"p\u00eache", "<", "p\u00e9ch\u00e9", // Comparing accents from end, p\u00e9ch\u00e9 is greater
};
compareArray(c, tests);
}
// Collator.compare() method broken if either string contains spaces
//
@Test
public void Test4065540() {
if (en_us.compare("abcd e", "abcd f") == 0) {
fail("'abcd e' == 'abcd f'");
}
}
// Unicode characters need to be recursively decomposed to get the
// correct result. For example,
// u1EB1 -> \u0103 + \u0300 -> a + \u0306 + \u0300.
//
@Test
public void Test4066189() {
String test1 = "\u1EB1";
String test2 = "a\u0306\u0300";
RuleBasedCollator c1 = (RuleBasedCollator) en_us.clone();
c1.setDecomposition(Collator.FULL_DECOMPOSITION);
CollationElementIterator i1 = en_us.getCollationElementIterator(test1);
RuleBasedCollator c2 = (RuleBasedCollator) en_us.clone();
c2.setDecomposition(Collator.NO_DECOMPOSITION);
CollationElementIterator i2 = en_us.getCollationElementIterator(test2);
TestUtils.compareCollationElementIters(i1, i2);
}
// French secondary collation checking at the end of compare iteration fails
//
@Test
public void Test4066696() {
RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.FRANCE);
c.setStrength(Collator.SECONDARY);
String[] tests = {
"\u00e0", "<", "\u01fa", // a-grave < A-ring-acute
};
compareArray(c, tests);
}
// Bad canonicalization of same-class combining characters
//
@Test
public void Test4076676() {
// These combining characters are all in the same class, so they should not
// be reordered, and they should compare as unequal.
String s1 = "A\u0301\u0302\u0300";
String s2 = "A\u0302\u0300\u0301";
RuleBasedCollator c = (RuleBasedCollator) en_us.clone();
c.setStrength(Collator.TERTIARY);
if (c.compare(s1,s2) == 0) {
fail("Same-class combining chars were reordered");
}
}
// RuleBasedCollator.equals(null) throws NullPointerException
//
@Test
public void Test4079231() {
try {
if (en_us.equals(null)) {
fail("en_us.equals(null) returned true");
}
}
catch (Exception e) {
fail("en_us.equals(null) threw " + e.toString());
}
}
// RuleBasedCollator breaks on "< a < bb" rule
//
@Test
public void Test4078588() throws ParseException {
RuleBasedCollator rbc=new RuleBasedCollator("< a < bb");
int result = rbc.compare("a","bb");
if (result != -1) {
fail("Compare(a,bb) returned " + result + "; expected -1");
}
}
// Combining characters in different classes not reordered properly.
//
@Test
public void Test4081866() throws ParseException {
// These combining characters are all in different classes,
// so they should be reordered and the strings should compare as equal.
String s1 = "A\u0300\u0316\u0327\u0315";
String s2 = "A\u0327\u0316\u0315\u0300";
RuleBasedCollator c = (RuleBasedCollator) en_us.clone();
c.setStrength(Collator.TERTIARY);
// Now that the default collators are set to NO_DECOMPOSITION
// (as a result of fixing bug 4114077), we must set it explicitly
// when we're testing reordering behavior. -- lwerner, 5/5/98
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
if (c.compare(s1,s2) != 0) {
fail("Combining chars were not reordered");
}
}
// string comparison errors in Scandinavian collators
//
@Test
public void Test4087241() {
RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(
Locale.of("da", "DK"));
c.setStrength(Collator.SECONDARY);
String[] tests = {
"\u007a", "<", "\u00e6", // z < ae
"a\u0308", "<", "a\u030a", // a-unlaut < a-ring
"Y", "<", "u\u0308", // Y < u-umlaut
};
compareArray(c, tests);
}
// CollationKey takes ignorable strings into account when it shouldn't
//
@Test
public void Test4087243() {
RuleBasedCollator c = (RuleBasedCollator) en_us.clone();
c.setStrength(Collator.TERTIARY);
String[] tests = {
"123", "=", "123\u0001", // 1 2 3 = 1 2 3 ctrl-A
};
compareArray(c, tests);
}
// Mu/micro conflict
// Micro symbol and greek lowercase letter Mu should sort identically
//
@Test
public void Test4092260() {
Collator c = Collator.getInstance(Locale.of("el"));
// will only be equal when FULL_DECOMPOSITION is used
c.setDecomposition(Collator.FULL_DECOMPOSITION);
String[] tests = {
"\u00B5", "=", "\u03BC",
};
compareArray(c, tests);
}
void Test4095316() {
Collator c = Collator.getInstance(Locale.of("el", "GR"));
c.setStrength(Collator.TERTIARY);
// javadocs for RuleBasedCollator clearly specify that characters containing compatability
// chars MUST use FULL_DECOMPOSITION to get accurate comparisons.
c.setDecomposition(Collator.FULL_DECOMPOSITION);
String[] tests = {
"\u03D4", "=", "\u03AB",
};
compareArray(c, tests);
}
@Test
public void Test4101940() {
try {
RuleBasedCollator c = new RuleBasedCollator("< a < b");
CollationElementIterator i = c.getCollationElementIterator("");
i.reset();
if (i.next() != i.NULLORDER) {
fail("next did not return NULLORDER");
}
}
catch (Exception e) {
fail("Caught " + e );
}
}
// Collator.compare not handling spaces properly
//
@Test
public void Test4103436() {
RuleBasedCollator c = (RuleBasedCollator) en_us.clone();
c.setStrength(Collator.TERTIARY);
String[] tests = {
"file", "<", "file access",
"file", "<", "fileaccess",
};
compareArray(c, tests);
}
// Collation not Unicode conformant with Hangul syllables
//
@Test
public void Test4114076() {
RuleBasedCollator c = (RuleBasedCollator) en_us.clone();
c.setStrength(Collator.TERTIARY);
//
// With Canonical decomposition, Hangul syllables should get decomposed
// into Jamo, but Jamo characters should not be decomposed into
// conjoining Jamo
//
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
String[] test1 = {
"\ud4db", "=", "\u1111\u1171\u11b6",
};
compareArray(c, test1);
// Full decomposition result should be the same as canonical decomposition
// for all hangul.
c.setDecomposition(Collator.FULL_DECOMPOSITION);
compareArray(c, test1);
}
// Collator.getCollationKey was hanging on certain character sequences
//
@Test
public void Test4124632() throws Exception {
Collator coll = Collator.getInstance(Locale.JAPAN);
try {
coll.getCollationKey("A\u0308bc");
} catch (OutOfMemoryError e) {
fail("Ran out of memory -- probably an infinite loop");
}
}
// sort order of french words with multiple accents has errors
//
@Test
public void Test4132736() {
Collator c = Collator.getInstance(Locale.FRANCE);
String[] test1 = {
"e\u0300e\u0301", "<", "e\u0301e\u0300",
"e\u0300\u0301", ">", "e\u0301\u0300",
};
compareArray(c, test1);
}
// The sorting using java.text.CollationKey is not in the exact order
//
@Test
public void Test4133509() {
String[] test1 = {
"Exception", "<", "ExceptionInInitializerError",
"Graphics", "<", "GraphicsEnvironment",
"String", "<", "StringBuffer",
};
compareArray(en_us, test1);
}
// Collation with decomposition off doesn't work for Europe
//
@Test
public void Test4114077() {
// Ensure that we get the same results with decomposition off
// as we do with it on....
RuleBasedCollator c = (RuleBasedCollator) en_us.clone();
c.setStrength(Collator.TERTIARY);
String[] test1 = {
"\u00C0", "=", "A\u0300", // Should be equivalent
"p\u00eache", ">", "p\u00e9ch\u00e9",
"\u0204", "=", "E\u030F",
"\u01fa", "=", "A\u030a\u0301", // a-ring-acute -> a-ring, acute
// -> a, ring, acute
"A\u0300\u0316", "<", "A\u0316\u0300", // No reordering --> unequal
};
c.setDecomposition(Collator.NO_DECOMPOSITION);
compareArray(c, test1);
String[] test2 = {
"A\u0300\u0316", "=", "A\u0316\u0300", // Reordering --> equal
};
c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
compareArray(c, test2);
}
// Support for Swedish gone in 1.1.6 (Can't create Swedish collator)
//
@Test
public void Test4141640() {
//
// Rather than just creating a Swedish collator, we might as well
// try to instantiate one for every locale available on the system
// in order to prevent this sort of bug from cropping up in the future
//
Locale[] locales = Collator.getAvailableLocales();
for (int i = 0; i < locales.length; i++) {
try {
Collator c = Collator.getInstance(locales[i]);
} catch (Exception e) {
fail("Caught " + e + " creating collator for " + locales[i]);
}
}
}
// getCollationKey throws exception for spanish text
// Cannot reproduce this bug on 1.2, however it DOES fail on 1.1.6
//
@Test
public void Test4139572() {
//
// Code pasted straight from the bug report
//
// create spanish locale and collator
Locale l = Locale.of("es", "es");
Collator col = Collator.getInstance(l);
// this spanish phrase kills it!
col.getCollationKey("Nombre De Objeto");
}
// RuleBasedCollator doesn't use getCollationElementIterator internally
//
@Test
public void Test4146160() throws ParseException {
//
// Use a custom collator class whose getCollationElementIterator
// methods increment a count....
//
My4146160Collator.count = 0;
new My4146160Collator().getCollationKey("1");
if (My4146160Collator.count < 1) {
fail("getCollationElementIterator not called");
}
My4146160Collator.count = 0;
new My4146160Collator().compare("1", "2");
if (My4146160Collator.count < 1) {
fail("getCollationElementIterator not called");
}
}
static class My4146160Collator extends RuleBasedCollator {
public My4146160Collator() throws ParseException {
super(Regression.en_us.getRules());
}
public CollationElementIterator getCollationElementIterator(
String text) {
count++;
return super.getCollationElementIterator(text);
}
public CollationElementIterator getCollationElementIterator(
CharacterIterator text) {
count++;
return super.getCollationElementIterator(text);
}
public static int count = 0;
};
// CollationElementIterator.previous broken for expanding char sequences
//
@Test
public void Test4179686() throws ParseException {
// Create a collator with a few expanding character sequences in it....
RuleBasedCollator coll = new RuleBasedCollator(en_us.getRules()
+ " & ae ; \u00e4 & AE ; \u00c4"
+ " & oe ; \u00f6 & OE ; \u00d6"
+ " & ue ; \u00fc & UE ; \u00dc");
String text = "T\u00f6ne"; // o-umlaut
CollationElementIterator iter = coll.getCollationElementIterator(text);
Vector elements = new Vector();
int elem;
// Iterate forward and collect all of the elements into a Vector
while ((elem = iter.next()) != iter.NULLORDER) {
elements.addElement(new Integer(elem));
}
// Now iterate backward and make sure they're the same
int index = elements.size() - 1;
while ((elem = iter.previous()) != iter.NULLORDER) {
int expect = ((Integer)elements.elementAt(index)).intValue();
if (elem != expect) {
fail("Mismatch at index " + index
+ ": got " + Integer.toString(elem,16)
+ ", expected " + Integer.toString(expect,16));
}
index--;
}
}
@Test
public void Test4244884() throws ParseException {
RuleBasedCollator coll = (RuleBasedCollator)Collator.getInstance(Locale.US);
coll = new RuleBasedCollator(coll.getRules()
+ " & C < ch , cH , Ch , CH < cat < crunchy");
String[] testStrings = new String[] {
"car",
"cave",
"clamp",
"cramp",
"czar",
"church",
"catalogue",
"crunchy",
"dog"
};
for (int i = 1; i < testStrings.length; i++) {
if (coll.compare(testStrings[i - 1], testStrings[i]) >= 0) {
fail("error: \"" + testStrings[i - 1]
+ "\" is greater than or equal to \"" + testStrings[i]
+ "\".");
}
}
}
@Test
public void Test4179216() throws ParseException {
// you can position a CollationElementIterator in the middle of
// a contracting character sequence, yielding a bogus collation
// element
RuleBasedCollator coll = (RuleBasedCollator)Collator.getInstance(Locale.US);
coll = new RuleBasedCollator(coll.getRules()
+ " & C < ch , cH , Ch , CH < cat < crunchy");
String testText = "church church catcatcher runcrunchynchy";
CollationElementIterator iter = coll.getCollationElementIterator(
testText);
// test that the "ch" combination works properly
iter.setOffset(4);
int elt4 = CollationElementIterator.primaryOrder(iter.next());
iter.reset();
int elt0 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(5);
int elt5 = CollationElementIterator.primaryOrder(iter.next());
if (elt4 != elt0 || elt5 != elt0)
fail("The collation elements at positions 0 (" + elt0 + "), 4 ("
+ elt4 + "), and 5 (" + elt5 + ") don't match.");
// test that the "cat" combination works properly
iter.setOffset(14);
int elt14 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(15);
int elt15 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(16);
int elt16 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(17);
int elt17 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(18);
int elt18 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(19);
int elt19 = CollationElementIterator.primaryOrder(iter.next());
if (elt14 != elt15 || elt14 != elt16 || elt14 != elt17
|| elt14 != elt18 || elt14 != elt19)
fail("\"cat\" elements don't match: elt14 = " + elt14 + ", elt15 = "
+ elt15 + ", elt16 = " + elt16 + ", elt17 = " + elt17
+ ", elt18 = " + elt18 + ", elt19 = " + elt19);
// now generate a complete list of the collation elements,
// first using next() and then using setOffset(), and
// make sure both interfaces return the same set of elements
iter.reset();
int elt = iter.next();
int count = 0;
while (elt != CollationElementIterator.NULLORDER) {
++count;
elt = iter.next();
}
String[] nextElements = new String[count];
String[] setOffsetElements = new String[count];
int lastPos = 0;
iter.reset();
elt = iter.next();
count = 0;
while (elt != CollationElementIterator.NULLORDER) {
nextElements[count++] = testText.substring(lastPos, iter.getOffset());
lastPos = iter.getOffset();
elt = iter.next();
}
count = 0;
for (int i = 0; i < testText.length(); ) {
iter.setOffset(i);
lastPos = iter.getOffset();
elt = iter.next();
setOffsetElements[count++] = testText.substring(lastPos, iter.getOffset());
i = iter.getOffset();
}
for (int i = 0; i < nextElements.length; i++) {
if (nextElements[i].equals(setOffsetElements[i])) {
System.out.println(nextElements[i]);
} else {
fail("Error: next() yielded " + nextElements[i] + ", but setOffset() yielded "
+ setOffsetElements[i]);
}
}
}
@Test
public void Test4216006() throws Exception {
// rule parser barfs on "<\u00e0=a\u0300", and on other cases
// where the same token (after normalization) appears twice in a row
boolean caughtException = false;
try {
RuleBasedCollator dummy = new RuleBasedCollator("\u00e0<a\u0300");
}
catch (ParseException e) {
caughtException = true;
}
if (!caughtException) {
throw new Exception("\"a<a\" collation sequence didn't cause parse error!");
}
RuleBasedCollator collator = new RuleBasedCollator("<\u00e0=a\u0300");
collator.setDecomposition(Collator.FULL_DECOMPOSITION);
collator.setStrength(Collator.IDENTICAL);
String[] tests = {
"a\u0300", "=", "\u00e0",
"\u00e0", "=", "a\u0300"
};
compareArray(collator, tests);
}
@Test
public void Test4171974() {
// test French accent ordering more thoroughly
String[] frenchList = {
"\u0075\u0075", // u u
"\u00fc\u0075", // u-umlaut u
"\u01d6\u0075", // u-umlaut-macron u
"\u016b\u0075", // u-macron u
"\u1e7b\u0075", // u-macron-umlaut u
"\u0075\u00fc", // u u-umlaut
"\u00fc\u00fc", // u-umlaut u-umlaut
"\u01d6\u00fc", // u-umlaut-macron u-umlaut
"\u016b\u00fc", // u-macron u-umlaut
"\u1e7b\u00fc", // u-macron-umlaut u-umlaut
"\u0075\u01d6", // u u-umlaut-macron
"\u00fc\u01d6", // u-umlaut u-umlaut-macron
"\u01d6\u01d6", // u-umlaut-macron u-umlaut-macron
"\u016b\u01d6", // u-macron u-umlaut-macron
"\u1e7b\u01d6", // u-macron-umlaut u-umlaut-macron
"\u0075\u016b", // u u-macron
"\u00fc\u016b", // u-umlaut u-macron
"\u01d6\u016b", // u-umlaut-macron u-macron
"\u016b\u016b", // u-macron u-macron
"\u1e7b\u016b", // u-macron-umlaut u-macron
"\u0075\u1e7b", // u u-macron-umlaut
"\u00fc\u1e7b", // u-umlaut u-macron-umlaut
"\u01d6\u1e7b", // u-umlaut-macron u-macron-umlaut
"\u016b\u1e7b", // u-macron u-macron-umlaut
"\u1e7b\u1e7b" // u-macron-umlaut u-macron-umlaut
};
Collator french = Collator.getInstance(Locale.FRENCH);
System.out.println("Testing French order...");
checkListOrder(frenchList, french);
System.out.println("Testing French order without decomposition...");
french.setDecomposition(Collator.NO_DECOMPOSITION);
checkListOrder(frenchList, french);
String[] englishList = {
"\u0075\u0075", // u u
"\u0075\u00fc", // u u-umlaut
"\u0075\u01d6", // u u-umlaut-macron
"\u0075\u016b", // u u-macron
"\u0075\u1e7b", // u u-macron-umlaut
"\u00fc\u0075", // u-umlaut u
"\u00fc\u00fc", // u-umlaut u-umlaut
"\u00fc\u01d6", // u-umlaut u-umlaut-macron
"\u00fc\u016b", // u-umlaut u-macron
"\u00fc\u1e7b", // u-umlaut u-macron-umlaut
"\u01d6\u0075", // u-umlaut-macron u
"\u01d6\u00fc", // u-umlaut-macron u-umlaut
"\u01d6\u01d6", // u-umlaut-macron u-umlaut-macron
"\u01d6\u016b", // u-umlaut-macron u-macron
"\u01d6\u1e7b", // u-umlaut-macron u-macron-umlaut
"\u016b\u0075", // u-macron u
"\u016b\u00fc", // u-macron u-umlaut
"\u016b\u01d6", // u-macron u-umlaut-macron
"\u016b\u016b", // u-macron u-macron
"\u016b\u1e7b", // u-macron u-macron-umlaut
"\u1e7b\u0075", // u-macron-umlaut u
"\u1e7b\u00fc", // u-macron-umlaut u-umlaut
"\u1e7b\u01d6", // u-macron-umlaut u-umlaut-macron
"\u1e7b\u016b", // u-macron-umlaut u-macron
"\u1e7b\u1e7b" // u-macron-umlaut u-macron-umlaut
};
Collator english = Collator.getInstance(Locale.ENGLISH);
System.out.println("Testing English order...");
checkListOrder(englishList, english);
System.out.println("Testing English order without decomposition...");
english.setDecomposition(Collator.NO_DECOMPOSITION);
checkListOrder(englishList, english);
}
private void checkListOrder(String[] sortedList, Collator c) {
// this function uses the specified Collator to make sure the
// passed-in list is already sorted into ascending order
for (int i = 0; i < sortedList.length - 1; i++) {
if (c.compare(sortedList[i], sortedList[i + 1]) >= 0) {
fail("List out of order at element #" + i + ": "
+ TestUtils.prettify(sortedList[i]) + " >= "
+ TestUtils.prettify(sortedList[i + 1]));
}
}
}
// CollationElementIterator set doesn't work propertly with next/prev
@Test
public void Test4663220() {
RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(Locale.US);
CharacterIterator stringIter = new StringCharacterIterator("fox");
CollationElementIterator iter = collator.getCollationElementIterator(stringIter);
int[] elements_next = new int[3];
System.out.println("calling next:");
for (int i = 0; i < 3; ++i) {
System.out.println("[" + i + "] " + (elements_next[i] = iter.next()));
}
int[] elements_fwd = new int[3];
System.out.println("calling set/next:");
for (int i = 0; i < 3; ++i) {
iter.setOffset(i);
System.out.println("[" + i + "] " + (elements_fwd[i] = iter.next()));
}
for (int i = 0; i < 3; ++i) {
if (elements_next[i] != elements_fwd[i]) {
fail("mismatch at position " + i +
": " + elements_next[i] +
" != " + elements_fwd[i]);
}
}
}
//------------------------------------------------------------------------
// Internal utilities
//
private void compareArray(Collator c, String[] tests) {
for (int i = 0; i < tests.length; i += 3) {
int expect = 0;
if (tests[i+1].equals("<")) {
expect = -1;
} else if (tests[i+1].equals(">")) {
expect = 1;
} else if (tests[i+1].equals("=")) {
expect = 0;
} else {
expect = Integer.decode(tests[i+1]).intValue();
}
int result = c.compare(tests[i], tests[i+2]);
if (sign(result) != sign(expect))
{
fail( i/3 + ": compare(" + TestUtils.prettify(tests[i])
+ " , " + TestUtils.prettify(tests[i+2])
+ ") got " + result + "; expected " + expect);
}
else
{
// Collator.compare worked OK; now try the collation keys
CollationKey k1 = c.getCollationKey(tests[i]);
CollationKey k2 = c.getCollationKey(tests[i+2]);
result = k1.compareTo(k2);
if (sign(result) != sign(expect)) {
fail( i/3 + ": key(" + TestUtils.prettify(tests[i])
+ ").compareTo(key(" + TestUtils.prettify(tests[i+2])
+ ")) got " + result + "; expected " + expect);
fail(" " + TestUtils.prettifyCKey(k1) + " vs. " + TestUtils.prettifyCKey(k2));
}
}
}
}
private static final int sign(int i) {
if (i < 0) return -1;
if (i > 0) return 1;
return 0;
}
static RuleBasedCollator en_us = (RuleBasedCollator)Collator.getInstance(Locale.US);
String test1 = "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?";
String test2 = "Xf ile What subset of all possible test cases has the lowest probability of detecting the least errors?";
String test3 = "a\u00FCbeck Gr\u00F6\u00DFe L\u00FCbeck";
}

View file

@ -0,0 +1,238 @@
/*
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4406815 8222969 8266784
* @summary RuleBasedCollatorTest uses very limited but selected test data
* to test basic functionalities provided by RuleBasedCollator.
* @run junit/othervm RuleBasedCollatorTest
*/
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.text.CollationElementIterator;
import java.text.CollationKey;
import java.text.Collator;
import java.text.ParseException;
import java.text.RuleBasedCollator;
import java.util.Arrays;
import java.util.Locale;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class RuleBasedCollatorTest {
private static RuleBasedCollator USC;
private static String US_RULES;
@BeforeAll
void setup() {
Collator c = Collator.getInstance(Locale.US);
assumeFalse(!(c instanceof RuleBasedCollator), "skip tests.");
USC = (RuleBasedCollator) c;
US_RULES = USC.getRules();
}
Object[][] rulesData() {
//Basic Tailor
String BASIC_TAILOR_RULES = "< b=c<\u00e6;A,a";
String[] BASIC_TAILOR_DATA = {"\u00e6", "b", "a", "c", "A"};
String[] BASIC_TAILOR_EXPECTED = {"b", "c", "\u00e6", "A", "a"};
//Contraction
String CONTRACTION_RULES = US_RULES + "& b < ch ,cH, Ch, CH < c ";
String[] CONTRACTION_DATA = {"b", "c", "ch", "CH", "Ch", "cH"};
String[] CONTRACTION_EXPECTED = {"b", "ch", "cH", "Ch", "CH", "c"};
//Expansion
String EXPANSION_RULES = US_RULES + "& ae = \u00e4 < b";
String[] EXPANSION_DATA = {"ad", "af", "\u00e4"};
String[] EXPANSION_EXPECTED = {"ad", "\u00e4", "af"};
//Punctuation
String PUNCTUATION_RULES = US_RULES + "< ' ' < '-'";
String[] PUNCTUATION_DATA = {"b-w", "b-W", "B-w", "B-W", "bW", "bw",
"Bw", "BW", "b w", "b W", "B w", "B W"};
String[] PUNCTUATION_EXPECTED = {"bw", "bW", "Bw", "BW", "b w", "b W",
"B w", "B W", "b-w", "b-W", "B-w", "B-W"};
return new Object[][] {
{BASIC_TAILOR_RULES, BASIC_TAILOR_DATA, BASIC_TAILOR_EXPECTED},
{CONTRACTION_RULES, CONTRACTION_DATA, CONTRACTION_EXPECTED},
{EXPANSION_RULES, EXPANSION_DATA, EXPANSION_EXPECTED},
{PUNCTUATION_RULES, PUNCTUATION_DATA, PUNCTUATION_EXPECTED}
};
}
@ParameterizedTest
@MethodSource("rulesData")
void testRules(String rules, String[] testData, String[] expected)
throws ParseException {
Arrays.sort(testData, new RuleBasedCollator(rules));
assertArrayEquals(expected, testData);
}
Object[][] FrenchSecondarySort() {
return new Object[][] {
{ "\u0061\u00e1\u0061", "\u00e1\u0061\u0061", 1 },
//{"\u0061\u00e1", "\u00e1\u0041", 1}, //JDK-4406815
//{"\u00e1\u0041", "\u0061\u00e1", -1}, //JDK-4406815
{"\u1ea0a", "\u1ea2A", -1}, //case ignore
{ "\u1ea0b", "\u1ea2A", 1 }, //primary overwrite
{ "\u1e15", "\u1e1d", -1 }, //ignore sec diacritic
{ "a", "\u1ea1", -1 } };
}
@ParameterizedTest
@MethodSource("FrenchSecondarySort")
void testFrenchSecondarySort(String sData, String tData,
int expected) throws ParseException {
String french_rule = "@";
String rules = US_RULES + french_rule;
RuleBasedCollator rc = new RuleBasedCollator(rules);
int result = rc.compare(sData, tData);
assertEquals(expected, result);
}
Object[][] ThaiLaoVowelConsonantSwapping() {
return new Object[][] {{"\u0e44\u0e01", "\u0e40\u0e2e", -1},//swap
{"\u0e2e\u0e40", "\u0e01\u0e44", 1},//no swap
{"\u0e44\u0061", "\u0e40\u0081", 1}//no swap
};
}
@ParameterizedTest
@MethodSource("ThaiLaoVowelConsonantSwapping")
void testThaiLaoVowelConsonantSwapping(String sData, String tData,
int expected) throws ParseException {
String thai_rule = "& Z < \u0e01 < \u0e2e <\u0e40 < \u0e44!";
String rules = US_RULES + thai_rule;
RuleBasedCollator rc = new RuleBasedCollator(rules);
int result = rc.compare(sData, tData);
assertEquals(expected, result);
}
@Test
void testIgnorableCharacter() throws ParseException {
String rule = "=f<a<c";
RuleBasedCollator rc = new RuleBasedCollator(rule);
CollationElementIterator iter = rc.getCollationElementIterator("f");
int element = iter.next();
int primary = iter.primaryOrder(element);
assertEquals(0, primary);
}
Object[][] Normalization() {
return new Object[][] {
//micro sign has no canonical decomp mapping
// 0:NO_Decomposition;
// 1:CANONICAL_Decomposition;
// 2:FULL_Decomposition
{"\u00b5", "\u03BC", 0, -1},
{"\u00b5", "\u03BC", 1, -1},
{"\u00b5", "\u03BC", 2, 0}
};
}
@ParameterizedTest
@MethodSource("Normalization")
void testNormalization(String sData, String tData, int decomp,
int result) {
RuleBasedCollator rc = (RuleBasedCollator)USC.clone();
rc.setDecomposition(decomp);
assertEquals(result, rc.compare(sData, tData));
}
@Test
void testEquality() throws ParseException {
String rule1 = "<a=b";
RuleBasedCollator rc1= new RuleBasedCollator(rule1);
//test equals()
assertTrue(rc1.equals(new RuleBasedCollator(rule1)));
//test semantic equality
String[] array1 = {"b", "c", "a"};
String[] array2 = Arrays.copyOf(array1, array1.length);
String[] expected = {"b", "a", "c"};
String rule2 = "<b=a";
RuleBasedCollator rc2= new RuleBasedCollator(rule2);
Arrays.sort(array1, rc1);
Arrays.sort(array2, rc2);
assertArrayEquals(array2, array1);
assertArrayEquals(expected, array1);
}
@Test
void testBasicParsingOrder() throws ParseException {
String rule1 = "< a < b & a < c";
String rule2 = "< a < c & a < b";
String rule3 = "< a < b < c";
String s = "abc";
RuleBasedCollator c1 = new RuleBasedCollator(rule1);
RuleBasedCollator c2 = new RuleBasedCollator(rule2);
RuleBasedCollator c3 = new RuleBasedCollator(rule3);
CollationKey k1 = c1.getCollationKey(s);
CollationKey k2 = c2.getCollationKey(s);
CollationKey k3 = c3.getCollationKey(s);
//rule1 should not equals to rule2
assertNotEquals(0, k1.compareTo(k2));
//rule2 should equals to rule3
assertEquals(0, k2.compareTo(k3));
}
Object[][] ParseData() {
return new Object[][] {
{""},
{"a < b"},
{"< a-b < c"},
{"< ,a"},
{"< a < b & c < d"}
};
}
@ParameterizedTest
@MethodSource("ParseData")
void testParseException(String rule) {
assertThrows(ParseException.class, () -> new RuleBasedCollator(rule));
}
@Test
void testNullParseException() {
assertThrows(NullPointerException.class, () -> new RuleBasedCollator(null));
}
}

View file

@ -0,0 +1,109 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test Spanish Collation
* @run junit SpanishTest
*/
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
import java.util.Locale;
import java.text.Collator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
// Quick dummy program for printing out test results
public class SpanishTest {
/*
* TestPrimary()
*/
private static final String[] primarySourceData = {
"alias",
"acHc",
"acc",
"Hello"
};
private static final String[] primaryTargetData = {
"allias",
"aCHc",
"aCHc",
"hellO"
};
private static final int[] primaryResults = {
-1, 0, -1, 0
};
/*
* TestTertiary()
*/
private static final String[] tertiarySourceData = {
"alias",
"Elliot",
"Hello",
"acHc",
"acc"
};
private static final String[] tertiaryTargetData = {
"allias",
"Emiot",
"hellO",
"aCHc",
"aCHc"
};
private static final int[] tertiaryResults = {
-1, -1, 1, -1, -1
};
@Test
public void TestPrimary() {
TestUtils.doCollatorTest(myCollation, Collator.PRIMARY,
primarySourceData, primaryTargetData, primaryResults);
}
@Test
public void TestTertiary() {
TestUtils.doCollatorTest(myCollation, Collator.TERTIARY,
tertiarySourceData, tertiaryTargetData, tertiaryResults);
}
private final Collator myCollation = Collator.getInstance(Locale.of("es", "ES"));
}

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test Supplementary Character Collation
* @run junit SurrogatesTest
*/
import java.text.Collator;
import java.text.RuleBasedCollator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
// Quick dummy program for printing out test results
public class SurrogatesTest {
/*
* Data for TestPrimary()
*/
private static final String[] primarySourceData = {
"A\ud800\udc04BCD"
};
private static final String[] primaryTargetData = {
"A\ud800\udc05BCD"
};
private static final int[] primaryResults = {
0
};
/*
* Data for TestTertiary()
*/
private static final String[] tertiarySourceData = {
"ABCD",
"ABCD",
"A\ud800\udc00CD",
"WXYZ",
"WXYZ",
"AFEM",
"FGM",
"BB",
"BB"
};
private static final String[] tertiaryTargetData = {
"A\ud800\udc00CD",
"AB\ud800\udc00D",
"A\ud800\udc01CD",
"W\ud800\udc0aYZ",
"W\ud800\udc0bYZ",
"A\ud800\udc08M",
"\ud800\udc08M",
"\ud800\udc04\ud800\udc02",
"\ud800\udc04\ud800\udc05"
};
private static final int[] tertiaryResults = {
-1, 1, 1, 1, -1, -1, -1, -1, 1
};
@Test
public void TestPrimary() {
TestUtils.doCollatorTest(myCollation, Collator.PRIMARY,
primarySourceData, primaryTargetData, primaryResults);
}
@Test
public void TestTertiary() {
TestUtils.doCollatorTest(myCollation, Collator.TERTIARY,
tertiarySourceData, tertiaryTargetData, tertiaryResults);
}
private Collator getCollator() {
RuleBasedCollator base = (RuleBasedCollator)Collator.getInstance();
String rule = base.getRules();
try {
return new RuleBasedCollator(rule
+ "&B < \ud800\udc01 < \ud800\udc00"
+ ", \ud800\udc02, \ud800\udc03"
+ "; \ud800\udc04, \ud800\udc05"
+ "< \ud800\udc06 < \ud800\udc07"
+ "&FE < \ud800\udc08"
+ "&PE, \ud800\udc09"
+ "&Z < \ud800\udc0a < \ud800\udc0b < \ud800\udc0c"
+ "&\ud800\udc0a < x, X"
+ "&A < \ud800\udc04\ud800\udc05");
} catch (Exception e) {
fail("Failed to create new RulebasedCollator object");
return null;
}
}
private Collator myCollation = getCollator();
}

View file

@ -0,0 +1,100 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 4401726
* @author John O'Conner
* @library /java/text/testlib
* @summary Regression tests for Collation and associated classes
* @run junit Test4401726
*/
import java.text.*;
import java.util.Locale;
import java.util.Vector;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
public class Test4401726 {
@Test
public void TestSetOffSet() {
int[] expected = {0, -1, 65536};
int[] actual = new int[expected.length];
try {
String rule = "< a, A < d; D";
RuleBasedCollator rbc = new RuleBasedCollator(rule);
String str = "aD";
CollationElementIterator iterator =
rbc.getCollationElementIterator(str);
iterator.setOffset(0);
actual[0] = iterator.getOffset();
actual[1] = iterator.previous();
iterator.setOffset(0);
actual[2] = iterator.next();
if (compareArray(expected, actual) == false) {
fail("Failed.");
}
str = "a";
iterator = rbc.getCollationElementIterator(str);
iterator.setOffset(0);
actual[0] = iterator.getOffset();
actual[1] = iterator.previous();
iterator.setOffset(0);
actual[2] = iterator.next();
if (compareArray(expected, actual) == false) {
fail("Failed.");
}
} catch (ParseException e) {
fail("Unexpected ParseException: " + e);
}
}
boolean compareArray(int[] expected, int[] actual) {
boolean retVal = false;
if (expected.length == actual.length) {
int errors = 0;
for(int x=0; x< expected.length; ++x) {
if (expected[x] != actual[x]) {
++errors;
}
}
if (errors == 0) retVal = true;
}
return retVal;
}
}

View file

@ -0,0 +1,159 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test Thai Collation
* @modules jdk.localedata
* @run junit ThaiTest
*/
/*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
*
* This software is the proprietary information of Oracle.
* Use is subject to license terms.
*
*/
import java.util.Locale;
import java.text.Collator;
import java.text.RuleBasedCollator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
public class ThaiTest {
/*
* Data for TestPrimary()
*/
private static final String[] primarySourceData = {
"\u0e01\u0e01",
"\u0e07\u0e42\u0e01\u0e49",
"\u0e10\u0e34\u0e19",
"\u0e16\u0e32\u0e21\u0e23\u0e23\u0e04\u0e40\u0e17\u0e28\u0e19\u0e32",
"\u0e23\u0e21\u0e18\u0e23\u0e23\u0e21\u0e4c\u0e1b\u0e23\u0e30\u0e01\u0e31\u0e19\u0e20\u0e31\u0e22",
"\u0e23\u0e23\u0e21\u0e2a\u0e34\u0e17\u0e18\u0e34\u0e4c\u0e40\u0e04\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e2b\u0e21\u0e32\u0e22\u0e41\u0e25\u0e30\u0e22\u0e35\u0e48\u0e2b\u0e49\u0e2d\u0e01\u0e32\u0e23\u0e04\u0e49\u0e32\u0e02\u0e32\u0e22",
"\u0e23\u0e23\u0e25\u0e38\u0e19\u0e34\u0e15\u0e34\u0e20\u0e32\u0e27\u0e30",
"\u0e01\u0e25\u0e37\u0e2d\u0e41\u0e01\u0e07",
"\u0e21\u0e17\u0e34\u0e25\u0e41\u0e2d\u0e25\u0e01\u0e2d\u0e2e\u0e2d\u0e25\u0e4c",
"\u0e40\u0e2d\u0e35\u0e48\u0e22\u0e21\u0e2d\u0e48\u0e2d\u0e07",
"\u0e2a\u0e14\u0e32\u0e1b\u0e31\u0e15\u0e15\u0e34\u0e1c\u0e25",
"\u0e2d\u0e19\u0e01\u0e23\u0e23\u0e21\u0e2a\u0e34\u0e17\u0e18\u0e34\u0e4c",
"\u0e21\u0e49\u0e40\u0e17\u0e49\u0e32\u0e22\u0e32\u0e22\u0e21\u0e48\u0e2d\u0e21",
"\u0e2a\u0e49\u0e25\u0e30\u0e21\u0e32\u0e19",
"\u0e2a\u0e49\u0e28\u0e36\u0e01",
"\u0e2a\u0e49\u0e2d\u0e31\u0e48\u0e27",
"\u0e2a\u0e49\u0e40\u0e14\u0e37\u0e2d\u0e19",
"\u0e2a\u0e49\u0e40\u0e25\u0e37\u0e48\u0e2d\u0e19",
"\u0e2a\u0e49\u0e41\u0e02\u0e27\u0e19",
"\u0e2a\u0e49\u0e41\u0e2b\u0e49\u0e07",
"\u0e2a\u0e49\u0e44\u0e01\u0e48",
"\u0e2b",
"\u0e2b\u0e0b\u0e2d\u0e07",
"\u0e2b\u0e19",
"\u0e2b\u0e1b\u0e25\u0e32\u0e23\u0e49\u0e32",
"\u0e2b\u0e21",
"\u0e2b\u0e21\u0e17\u0e2d\u0e07",
"\u0e2b\u0e21\u0e2a\u0e31\u0e1a\u0e1b\u0e30\u0e23\u0e14",
"\u0e2b\u0e21\u0e49",
"\u0e2b\u0e23\u0e13\u0e22\u0e4c",
"\u0e2b\u0e25",
"\u0e2b\u0e25\u0e19\u0e49\u0e33",
"\u0e2b\u0e25\u0e48",
"\u0e2b\u0e25\u0e48\u0e16\u0e19\u0e19",
"\u0e2b\u0e25\u0e48\u0e17\u0e27\u0e35\u0e1b",
"\u0e2b\u0e25\u0e48\u0e17\u0e32\u0e07",
"\u0e2b\u0e25\u0e48\u0e23\u0e27\u0e1a",
"\u0e2b\u0e49",
"\u0e2d",
"\u0e2d\u0e49",
"\u0e2e\u0e42\u0e25",
"\u0e2e\u0e44\u0e1f",
"\u0e2e\u0e49"
};
private static final String[] primaryTargetData = {
"\u0e01\u0e01",
"\u0e07\u0e42\u0e01\u0e49",
"\u0e10\u0e34\u0e19",
"\u0e16\u0e32\u0e21\u0e23\u0e23\u0e04\u0e40\u0e17\u0e28\u0e19\u0e32",
"\u0e23\u0e21\u0e18\u0e23\u0e23\u0e21\u0e4c\u0e1b\u0e23\u0e30\u0e01\u0e31\u0e19\u0e20\u0e31\u0e22",
"\u0e23\u0e23\u0e21\u0e2a\u0e34\u0e17\u0e18\u0e34\u0e4c\u0e40\u0e04\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e2b\u0e21\u0e32\u0e22\u0e41\u0e25\u0e30\u0e22\u0e35\u0e48\u0e2b\u0e49\u0e2d\u0e01\u0e32\u0e23\u0e04\u0e49\u0e32\u0e02\u0e32\u0e22",
"\u0e23\u0e23\u0e25\u0e38\u0e19\u0e34\u0e15\u0e34\u0e20\u0e32\u0e27\u0e30",
"\u0e01\u0e25\u0e37\u0e2d\u0e41\u0e01\u0e07",
"\u0e21\u0e17\u0e34\u0e25\u0e41\u0e2d\u0e25\u0e01\u0e2d\u0e2e\u0e2d\u0e25\u0e4c",
"\u0e40\u0e2d\u0e35\u0e48\u0e22\u0e21\u0e2d\u0e48\u0e2d\u0e07",
"\u0e2a\u0e14\u0e32\u0e1b\u0e31\u0e15\u0e15\u0e34\u0e1c\u0e25",
"\u0e2d\u0e19\u0e01\u0e23\u0e23\u0e21\u0e2a\u0e34\u0e17\u0e18\u0e34\u0e4c",
"\u0e21\u0e49\u0e40\u0e17\u0e49\u0e32\u0e22\u0e32\u0e22\u0e21\u0e48\u0e2d\u0e21",
"\u0e2a\u0e49\u0e25\u0e30\u0e21\u0e32\u0e19",
"\u0e2a\u0e49\u0e28\u0e36\u0e01",
"\u0e2a\u0e49\u0e2d\u0e31\u0e48\u0e27",
"\u0e2a\u0e49\u0e40\u0e14\u0e37\u0e2d\u0e19",
"\u0e2a\u0e49\u0e40\u0e25\u0e37\u0e48\u0e2d\u0e19",
"\u0e2a\u0e49\u0e41\u0e02\u0e27\u0e19",
"\u0e2a\u0e49\u0e41\u0e2b\u0e49\u0e07",
"\u0e2a\u0e49\u0e44\u0e01\u0e48",
"\u0e2b",
"\u0e2b\u0e0b\u0e2d\u0e07",
"\u0e2b\u0e19",
"\u0e2b\u0e1b\u0e25\u0e32\u0e23\u0e49\u0e32",
"\u0e2b\u0e21",
"\u0e2b\u0e21\u0e17\u0e2d\u0e07",
"\u0e2b\u0e21\u0e2a\u0e31\u0e1a\u0e1b\u0e30\u0e23\u0e14",
"\u0e2b\u0e21\u0e49",
"\u0e2b\u0e23\u0e13\u0e22\u0e4c",
"\u0e2b\u0e25",
"\u0e2b\u0e25\u0e19\u0e49\u0e33",
"\u0e2b\u0e25\u0e48",
"\u0e2b\u0e25\u0e48\u0e16\u0e19\u0e19",
"\u0e2b\u0e25\u0e48\u0e17\u0e27\u0e35\u0e1b",
"\u0e2b\u0e25\u0e48\u0e17\u0e32\u0e07",
"\u0e2b\u0e25\u0e48\u0e23\u0e27\u0e1a",
"\u0e2b\u0e49",
"\u0e2d",
"\u0e2d\u0e49",
"\u0e2e\u0e42\u0e25",
"\u0e2e\u0e44\u0e1f",
"\u0e2e\u0e49"
};
private static final int[] primaryResults = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0
};
@Test
public void TestPrimary() {
TestUtils.doCollatorTest(myCollation, Collator.PRIMARY,
primarySourceData, primaryTargetData, primaryResults);
}
private final Collator myCollation = Collator.getInstance(Locale.of("th"));
}

View file

@ -0,0 +1,122 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @library /java/text/testlib
* @summary test Turkish Collation
* @modules jdk.localedata
* @run junit TurkishTest
*/
/*
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
(C) Copyright IBM Corp. 1996 - All Rights Reserved
The original version of this source code and documentation is copyrighted and
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
provided under terms of a License Agreement between Taligent and Sun. This
technology is protected by multiple US and International patents. This notice and
attribution to Taligent may not be removed.
Taligent is a registered trademark of Taligent, Inc.
*/
import java.util.Locale;
import java.text.Collator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
// Quick dummy program for printing out test results
public class TurkishTest {
/*
* Data for TestPrimary()
*/
private static final String[] primarySourceData = {
"\u00FCoid",
"vo\u0131d",
"idea",
"Idea",
"\u0130dea"
};
private static final String[] primaryTargetData = {
"void",
"void",
"Idea",
"\u0130dea",
"\u0131dea"
};
private static final int[] primaryResults = {
-1, -1, 1, -1, 1
};
/*
* Data for TestTertiary()
*/
private static final String[] tertiarySourceData = {
"s\u0327",
"v\u00E4t",
"old",
"\u00FCoid",
"h\u011Ealt",
"stres\u015E",
"vo\u0131d",
"idea",
"idea",
"\u0131dea"
};
private static final String tertiaryTargetData[] = {
"u\u0308",
"vbt",
"\u00D6ay",
"void",
"halt",
"\u015Etre\u015Es",
"void",
"Idea",
"\u0130dea",
"Idea"
};
private static final int[] tertiaryResults = {
-1, -1, -1, -1, 1, -1, -1, 1, -1, -1
};
@Test
public void TestPrimary() {
TestUtils.doCollatorTest(myCollation, Collator.PRIMARY,
primarySourceData, primaryTargetData, primaryResults);
}
@Test
public void TestTertiary() {
TestUtils.doCollatorTest(myCollation, Collator.TERTIARY,
tertiarySourceData, tertiaryTargetData, tertiaryResults);
}
private final Collator myCollation = Collator.getInstance(Locale.of("tr", "TR"));
}

View file

@ -0,0 +1,368 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4932968 5015215
* @library /java/text/testlib
* @summary test Vietnamese Collation
* @modules jdk.localedata
* @run junit VietnameseTest
*/
/*
*******************************************************************************
* (C) Copyright IBM Corp. 1996-2003 - All Rights Reserved *
* *
* The original version of this source code and documentation is copyrighted *
* and owned by IBM, These materials are provided under terms of a License *
* Agreement between IBM and Sun. This technology is protected by multiple *
* US and International patents. This notice and attribution to IBM may not *
* to removed. *
*******************************************************************************
*/
import java.util.Locale;
import java.text.Collator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
// Quick dummy program for printing out test results
public class VietnameseTest {
private final static String testPS[] = {
"a",
"a",
"\u00c2",
"Cz",
"d",
"e",
"e",
"\u1ec7",
"gz",
"i",
"kz",
"nz",
"nh",
"o",
"o",
"\u01a0",
"pz",
"tz",
"tr",
"u",
"u",
"y"
};
private final static String testPT[] = {
"\u00e0",
"\u0102",
"\u0102",
"Ch",
"\u0110",
"\u0111",
"\u1eb9",
"\u1eb9",
"gi",
"\u0128",
"kh",
"ng",
"ng",
"\u00f2",
"\u00f4",
"\u00f4",
"ph",
"th",
"th",
"\u1ee5",
"\u01b0",
"\u1ef4"
};
private final static int testPR[] = {
0,
-1,
1,
1,
-1,
1,
0,
1,
1,
0,
1,
1,
1,
0,
-1,
1,
1,
1,
1,
0,
-1,
0
};
private final static String testT[] = {
"a",
"A",
"\u00e0",
"\u00c0",
"\u1ea3",
"\u1ea2",
"\u00e3",
"\u00c3",
"\u00e1",
"\u00c1",
"\u1ea1",
"\u1ea0",
"\u0103",
"\u0102",
"\u1eb1",
"\u1eb0",
"\u1eb3",
"\u1eb2",
"\u1eb5",
"\u1eb4",
"\u1eaf",
"\u1eae",
"\u1eb7",
"\u1eb6",
"\u00e2",
"\u00c2",
"\u1ea7",
"\u1ea6",
"\u1ea9",
"\u1ea8",
"\u1eab",
"\u1eaa",
"\u1ea5",
"\u1ea4",
"\u1ead",
"\u1eac",
"b",
"B",
"c",
"C",
"ch",
"Ch",
"CH",
"d",
"D",
"\u0111",
"\u0110",
"e",
"E",
"\u00e8",
"\u00c8",
"\u1ebb",
"\u1eba",
"\u1ebd",
"\u1ebc",
"\u00e9",
"\u00c9",
"\u1eb9",
"\u1eb8",
"\u00ea",
"\u00ca",
"\u1ec1",
"\u1ec0",
"\u1ec3",
"\u1ec2",
"\u1ec5",
"\u1ec4",
"\u1ebf",
"\u1ebe",
"\u1ec7",
"\u1ec6",
"f",
"F",
"g",
"G",
"gi",
"Gi",
"GI",
"gz",
"h",
"H",
"i",
"I",
"\u00ec",
"\u00cc",
"\u1ec9",
"\u1ec8",
"\u0129",
"\u0128",
"\u00ed",
"\u00cd",
"\u1ecb",
"\u1eca",
"j",
"J",
"k",
"K",
"kh",
"Kh",
"KH",
"kz",
"l",
"L",
"m",
"M",
"n",
"N",
"ng",
"Ng",
"NG",
"ngz",
"nh",
"Nh",
"NH",
"nz",
"o",
"O",
"\u00f2",
"\u00d2",
"\u1ecf",
"\u1ece",
"\u00f5",
"\u00d5",
"\u00f3",
"\u00d3",
"\u1ecd",
"\u1ecc",
"\u00f4",
"\u00d4",
"\u1ed3",
"\u1ed2",
"\u1ed5",
"\u1ed4",
"\u1ed7",
"\u1ed6",
"\u1ed1",
"\u1ed0",
"\u1ed9",
"\u1ed8",
"\u01a1",
"\u01a0",
"\u1edd",
"\u1edc",
"\u1edf",
"\u1ede",
"\u1ee1",
"\u1ee0",
"\u1edb",
"\u1eda",
"\u1ee3",
"\u1ee2",
"p",
"P",
"ph",
"Ph",
"PH",
"pz",
"q",
"Q",
"r",
"R",
"s",
"S",
"t",
"T",
"th",
"Th",
"TH",
"thz",
"tr",
"Tr",
"TR",
"tz",
"u",
"U",
"\u00f9",
"\u00d9",
"\u1ee7",
"\u1ee6",
"\u0169",
"\u0168",
"\u00fa",
"\u00da",
"\u1ee5",
"\u1ee4",
"\u01b0",
"\u01af",
"\u1eeb",
"\u1eea",
"\u1eed",
"\u1eec",
"\u1eef",
"\u1eee",
"\u1ee9",
"\u1ee8",
"\u1ef1",
"\u1ef0",
"v",
"V",
"w",
"W",
"x",
"X",
"y",
"Y",
"\u1ef3",
"\u1ef2",
"\u1ef7",
"\u1ef6",
"\u1ef9",
"\u1ef8",
"\u00fd",
"\u00dd",
"\u1ef5",
"\u1ef4",
"z",
"Z"
};
@Test
public void TestPrimary() {
TestUtils.doCollatorTest(myCollation, Collator.PRIMARY, testPS, testPT, testPR);
}
@Test
public void TestTertiary() {
int testLength = testT.length;
myCollation.setStrength(Collator.TERTIARY);
for (int i = 0; i < testLength - 1; i++) {
for (int j = i+1; j < testLength; j++) {
TestUtils.doCollatorTest(myCollation, testT[i], testT[j], -1);
}
}
}
private final Collator myCollation = Collator.getInstance(Locale.of("vi", "VN"));
}