2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
2008-09-26 21:25:04 +00:00
|
|
|
* COPYRIGHT:
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (c) 1997-2016, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
2000-01-15 02:00:06 +00:00
|
|
|
********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_COLLATION
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/coll.h"
|
2014-02-25 21:21:49 +00:00
|
|
|
#include "unicode/localpointer.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/tblcoll.h"
|
|
|
|
#include "unicode/unistr.h"
|
|
|
|
#include "unicode/sortkey.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "regcoll.h"
|
2000-12-12 19:40:58 +00:00
|
|
|
#include "sfwdchit.h"
|
2009-10-14 21:45:30 +00:00
|
|
|
#include "testutil.h"
|
2009-10-20 16:48:17 +00:00
|
|
|
#include "cmemory.h"
|
2000-12-12 19:40:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
CollationRegressionTest::CollationRegressionTest()
|
|
|
|
{
|
2001-03-27 02:52:12 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
2002-08-21 00:16:30 +00:00
|
|
|
en_us = (RuleBasedCollator *)Collator::createInstance(Locale::getUS(), status);
|
2003-06-06 04:54:34 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
delete en_us;
|
|
|
|
en_us = 0;
|
2009-06-12 19:34:21 +00:00
|
|
|
errcheckln(status, "Collator creation failed with %s", u_errorName(status));
|
2003-06-06 04:54:34 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CollationRegressionTest::~CollationRegressionTest()
|
|
|
|
{
|
|
|
|
delete en_us;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// @bug 4048446
|
|
|
|
//
|
|
|
|
// CollationElementIterator.reset() doesn't work
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4048446(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-27 02:52:12 +00:00
|
|
|
const UnicodeString test1 = "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?";
|
|
|
|
const UnicodeString test2 = "Xf_ile What subset of all possible test cases has the lowest probability of detecting the least errors?";
|
1999-08-16 21:50:52 +00:00
|
|
|
CollationElementIterator *i1 = en_us->createCollationElementIterator(test1);
|
|
|
|
CollationElementIterator *i2 = en_us->createCollationElementIterator(test1);
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if (i1 == NULL|| i2 == NULL)
|
|
|
|
{
|
|
|
|
errln("Could not create CollationElementIterator's");
|
|
|
|
delete i1;
|
|
|
|
delete i2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (i1->next(status) != CollationElementIterator::NULLORDER)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("error calling next()");
|
|
|
|
|
|
|
|
delete i1;
|
|
|
|
delete i2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i1->reset();
|
|
|
|
|
|
|
|
assertEqual(*i1, *i2);
|
|
|
|
|
|
|
|
delete i1;
|
|
|
|
delete i2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4051866
|
|
|
|
//
|
|
|
|
// Collator -> rules -> Collator round-trip broken for expanding characters
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4051866(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UnicodeString rules;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
rules += "&n < o ";
|
1999-08-16 21:50:52 +00:00
|
|
|
rules += "& oe ,o";
|
|
|
|
rules += (UChar)0x3080;
|
|
|
|
rules += "& oe ,";
|
|
|
|
rules += (UChar)0x1530;
|
|
|
|
rules += " ,O";
|
|
|
|
rules += "& OE ,O";
|
|
|
|
rules += (UChar)0x3080;
|
|
|
|
rules += "& OE ,";
|
|
|
|
rules += (UChar)0x1520;
|
|
|
|
rules += "< p ,P";
|
|
|
|
|
|
|
|
// Build a collator containing expanding characters
|
2014-11-20 00:27:17 +00:00
|
|
|
LocalPointer<RuleBasedCollator> c1(new RuleBasedCollator(rules, status), status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln("RuleBasedCollator(rule string) failed - %s", u_errorName(status));
|
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// Build another using the rules from the first
|
2014-11-20 00:27:17 +00:00
|
|
|
LocalPointer<RuleBasedCollator> c2(new RuleBasedCollator(c1->getRules(), status), status);
|
2014-02-25 21:21:49 +00:00
|
|
|
if (U_FAILURE(status)) {
|
2014-11-20 00:27:17 +00:00
|
|
|
errln("RuleBasedCollator(rule string from other RBC) failed - %s", u_errorName(status));
|
2014-02-25 21:21:49 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// Make sure they're the same
|
|
|
|
if (!(c1->getRules() == c2->getRules()))
|
|
|
|
{
|
|
|
|
errln("Rules are not equal");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4053636
|
|
|
|
//
|
|
|
|
// Collator thinks "black-bird" == "black"
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4053636(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (en_us->equals("black_bird", "black"))
|
|
|
|
{
|
|
|
|
errln("black-bird == black");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4054238
|
|
|
|
//
|
|
|
|
// CollationElementIterator will not work correctly if the associated
|
|
|
|
// Collator object's mode is changed
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4054238(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-27 02:52:12 +00:00
|
|
|
const UChar chars3[] = {0x61, 0x00FC, 0x62, 0x65, 0x63, 0x6b, 0x20, 0x47, 0x72, 0x00F6, 0x00DF, 0x65, 0x20, 0x4c, 0x00FC, 0x62, 0x63, 0x6b, 0};
|
|
|
|
const UnicodeString test3(chars3);
|
1999-08-16 21:50:52 +00:00
|
|
|
RuleBasedCollator *c = (RuleBasedCollator *) en_us->clone();
|
|
|
|
|
|
|
|
// NOTE: The Java code uses en_us to create the CollationElementIterators
|
|
|
|
// but I'm pretty sure that's wrong, so I've changed this to use c.
|
2002-08-21 19:09:33 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
c->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
CollationElementIterator *i1 = c->createCollationElementIterator(test3);
|
|
|
|
delete i1;
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4054734
|
|
|
|
//
|
|
|
|
// Collator::IDENTICAL documented but not implemented
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4054734(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Here's the original Java:
|
|
|
|
|
|
|
|
String[] decomp = {
|
|
|
|
"\u0001", "<", "\u0002",
|
|
|
|
"\u0001", "=", "\u0001",
|
|
|
|
"A\u0001", ">", "~\u0002", // Ensure A and ~ are not compared bitwise
|
|
|
|
"\u00C0", "=", "A\u0300" // Decomp should make these equal
|
|
|
|
};
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
String[] nodecomp = {
|
|
|
|
"\u00C0", ">", "A\u0300" // A-grave vs. A combining-grave
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const UChar decomp[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x0001, 0}, {0x3c, 0}, {0x0002, 0},
|
|
|
|
{0x0001, 0}, {0x3d, 0}, {0x0001, 0},
|
|
|
|
{0x41, 0x0001, 0}, {0x3e, 0}, {0x7e, 0x0002, 0},
|
|
|
|
{0x00c0, 0}, {0x3d, 0}, {0x41, 0x0300, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2002-08-21 19:09:33 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
RuleBasedCollator *c = (RuleBasedCollator *) en_us->clone();
|
|
|
|
|
|
|
|
c->setStrength(Collator::IDENTICAL);
|
|
|
|
|
2002-08-21 19:09:33 +00:00
|
|
|
c->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, decomp, UPRV_LENGTHOF(decomp));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4054736
|
|
|
|
//
|
|
|
|
// Full Decomposition mode not implemented
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4054736(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2002-08-21 19:09:33 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
RuleBasedCollator *c = (RuleBasedCollator *) en_us->clone();
|
|
|
|
|
2001-03-15 02:53:05 +00:00
|
|
|
c->setStrength(Collator::SECONDARY);
|
2002-08-21 19:09:33 +00:00
|
|
|
c->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
static const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0xFB4F, 0}, {0x3d, 0}, {0x05D0, 0x05DC} // Alef-Lamed vs. Alef, Lamed
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, tests, UPRV_LENGTHOF(tests));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4058613
|
|
|
|
//
|
2008-09-26 21:25:04 +00:00
|
|
|
// Collator::createInstance() causes an ArrayIndexOutofBoundsException for Korean
|
1999-08-16 21:50:52 +00:00
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4058613(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
// Creating a default collator doesn't work when Korean is the default
|
|
|
|
// locale
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
Locale oldDefault = Locale::getDefault();
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2002-03-26 23:18:57 +00:00
|
|
|
Locale::setDefault(Locale::getKorean(), status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Could not set default locale to Locale::KOREAN");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Collator *c = NULL;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2001-03-21 22:13:30 +00:00
|
|
|
c = Collator::createInstance("en_US", status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Could not create a Korean collator");
|
|
|
|
Locale::setDefault(oldDefault, status);
|
|
|
|
delete c;
|
|
|
|
return;
|
|
|
|
}
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// Since the fix to this bug was to turn off decomposition for Korean collators,
|
|
|
|
// ensure that's what we got
|
2002-08-21 19:09:33 +00:00
|
|
|
if (c->getAttribute(UCOL_NORMALIZATION_MODE, status) != UCOL_OFF)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Decomposition is not set to NO_DECOMPOSITION for Korean collator");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete c;
|
|
|
|
|
|
|
|
Locale::setDefault(oldDefault, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4059820
|
|
|
|
//
|
|
|
|
// RuleBasedCollator.getRules does not return the exact pattern as input
|
|
|
|
// for expanding character sequences
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4059820(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
RuleBasedCollator *c = NULL;
|
2014-02-25 21:21:49 +00:00
|
|
|
UnicodeString rules = "&9 < a < b , c/a < d < z";
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
c = new RuleBasedCollator(rules, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Failure building a collator.");
|
|
|
|
delete c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( c->getRules().indexOf("c/a") == -1)
|
|
|
|
{
|
|
|
|
errln("returned rules do not contain 'c/a'");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4060154
|
|
|
|
//
|
|
|
|
// MergeCollation::fixEntry broken for "& H < \u0131, \u0130, i, I"
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4060154(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString rules;
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
rules += "&f < g, G < h, H < i, I < j, J";
|
1999-08-16 21:50:52 +00:00
|
|
|
rules += " & H < ";
|
|
|
|
rules += (UChar)0x0131;
|
|
|
|
rules += ", ";
|
|
|
|
rules += (UChar)0x0130;
|
|
|
|
rules += ", i, I";
|
|
|
|
|
|
|
|
RuleBasedCollator *c = NULL;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
c = new RuleBasedCollator(rules, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("failure building collator.");
|
|
|
|
delete c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-21 19:09:33 +00:00
|
|
|
c->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
String[] tertiary = {
|
|
|
|
"A", "<", "B",
|
|
|
|
"H", "<", "\u0131",
|
|
|
|
"H", "<", "I",
|
|
|
|
"\u0131", "<", "\u0130",
|
|
|
|
"\u0130", "<", "i",
|
|
|
|
"\u0130", ">", "H",
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const UChar tertiary[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x41, 0}, {0x3c, 0}, {0x42, 0},
|
|
|
|
{0x48, 0}, {0x3c, 0}, {0x0131, 0},
|
|
|
|
{0x48, 0}, {0x3c, 0}, {0x49, 0},
|
|
|
|
{0x0131, 0}, {0x3c, 0}, {0x0130, 0},
|
|
|
|
{0x0130, 0}, {0x3c, 0}, {0x69, 0},
|
|
|
|
{0x0130, 0}, {0x3e, 0}, {0x48, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
c->setStrength(Collator::TERTIARY);
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, tertiary, UPRV_LENGTHOF(tertiary));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
String[] secondary = {
|
|
|
|
"H", "<", "I",
|
|
|
|
"\u0131", "=", "\u0130",
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
static const UChar secondary[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x48, 0}, {0x3c, 0}, {0x49, 0},
|
|
|
|
{0x0131, 0}, {0x3d, 0}, {0x0130, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
c->setStrength(Collator::PRIMARY);
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, secondary, UPRV_LENGTHOF(secondary));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
2004-12-30 07:25:51 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// @bug 4062418
|
|
|
|
//
|
|
|
|
// Secondary/Tertiary comparison incorrect in French Secondary
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4062418(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
RuleBasedCollator *c = NULL;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2010-10-19 03:31:50 +00:00
|
|
|
c = (RuleBasedCollator *) Collator::createInstance(Locale::getCanadaFrench(), status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2010-10-19 03:31:50 +00:00
|
|
|
errln("Failed to create collator for Locale::getCanadaFrench()");
|
1999-08-16 21:50:52 +00:00
|
|
|
delete c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->setStrength(Collator::SECONDARY);
|
|
|
|
|
|
|
|
/*
|
|
|
|
String[] tests = {
|
|
|
|
"p\u00eache", "<", "p\u00e9ch\u00e9", // Comparing accents from end, p\u00e9ch\u00e9 is greater
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
static const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x70, 0x00EA, 0x63, 0x68, 0x65, 0}, {0x3c, 0}, {0x70, 0x00E9, 0x63, 0x68, 0x00E9, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, tests, UPRV_LENGTHOF(tests));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4065540
|
|
|
|
//
|
|
|
|
// Collator::compare() method broken if either string contains spaces
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4065540(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (en_us->compare("abcd e", "abcd f") == 0)
|
|
|
|
{
|
|
|
|
errln("'abcd e' == 'abcd f'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4066189
|
|
|
|
//
|
|
|
|
// Unicode characters need to be recursively decomposed to get the
|
|
|
|
// correct result. For example,
|
|
|
|
// u1EB1 -> \u0103 + \u0300 -> a + \u0306 + \u0300.
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4066189(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
static const UChar chars1[] = {0x1EB1, 0};
|
2000-03-22 23:17:42 +00:00
|
|
|
static const UChar chars2[] = {0x61, 0x0306, 0x0300, 0};
|
1999-08-16 21:50:52 +00:00
|
|
|
const UnicodeString test1(chars1);
|
|
|
|
const UnicodeString test2(chars2);
|
2002-08-21 19:09:33 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// NOTE: The java code used en_us to create the
|
|
|
|
// CollationElementIterator's. I'm pretty sure that
|
|
|
|
// was wrong, so I've change the code to use c1 and c2
|
|
|
|
RuleBasedCollator *c1 = (RuleBasedCollator *) en_us->clone();
|
2002-08-21 19:09:33 +00:00
|
|
|
c1->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
CollationElementIterator *i1 = c1->createCollationElementIterator(test1);
|
|
|
|
|
|
|
|
RuleBasedCollator *c2 = (RuleBasedCollator *) en_us->clone();
|
2002-08-21 19:09:33 +00:00
|
|
|
c2->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_OFF, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
CollationElementIterator *i2 = c2->createCollationElementIterator(test2);
|
|
|
|
|
|
|
|
assertEqual(*i1, *i2);
|
|
|
|
|
|
|
|
delete i2;
|
|
|
|
delete c2;
|
|
|
|
delete i1;
|
|
|
|
delete c1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4066696
|
|
|
|
//
|
|
|
|
// French secondary collation checking at the end of compare iteration fails
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4066696(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
RuleBasedCollator *c = NULL;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2010-10-19 03:31:50 +00:00
|
|
|
c = (RuleBasedCollator *)Collator::createInstance(Locale::getCanadaFrench(), status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2010-10-19 03:31:50 +00:00
|
|
|
errln("Failure creating collator for Locale::getCanadaFrench()");
|
1999-08-16 21:50:52 +00:00
|
|
|
delete c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->setStrength(Collator::SECONDARY);
|
|
|
|
|
|
|
|
/*
|
|
|
|
String[] tests = {
|
|
|
|
"\u00e0", "<", "\u01fa", // a-grave < A-ring-acute
|
|
|
|
};
|
2000-12-05 01:05:46 +00:00
|
|
|
|
|
|
|
should be:
|
|
|
|
|
|
|
|
String[] tests = {
|
|
|
|
"\u00e0", ">", "\u01fa", // a-grave < A-ring-acute
|
|
|
|
};
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-12-05 01:05:46 +00:00
|
|
|
{0x00E0, 0}, {0x3e, 0}, {0x01FA, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, tests, UPRV_LENGTHOF(tests));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4076676
|
|
|
|
//
|
|
|
|
// Bad canonicalization of same-class combining characters
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4076676(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
// These combining characters are all in the same class, so they should not
|
|
|
|
// be reordered, and they should compare as unequal.
|
2000-03-22 23:17:42 +00:00
|
|
|
static const UChar s1[] = {0x41, 0x0301, 0x0302, 0x0300, 0};
|
|
|
|
static const UChar s2[] = {0x41, 0x0302, 0x0300, 0x0301, 0};
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
RuleBasedCollator *c = (RuleBasedCollator *) en_us->clone();
|
|
|
|
c->setStrength(Collator::TERTIARY);
|
|
|
|
|
|
|
|
if (c->compare(s1,s2) == 0)
|
|
|
|
{
|
|
|
|
errln("Same-class combining chars were reordered");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4079231
|
|
|
|
//
|
|
|
|
// RuleBasedCollator::operator==(NULL) throws NullPointerException
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4079231(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
// I don't think there's any way to write this test
|
|
|
|
// in C++. The following is equivalent to the Java,
|
|
|
|
// but doesn't compile 'cause NULL can't be converted
|
|
|
|
// to Collator&
|
|
|
|
//
|
|
|
|
// if (en_us->operator==(NULL))
|
|
|
|
// {
|
|
|
|
// errln("en_us->operator==(NULL) returned TRUE");
|
|
|
|
// }
|
|
|
|
|
|
|
|
/*
|
|
|
|
try {
|
|
|
|
if (en_us->equals(null)) {
|
|
|
|
errln("en_us->equals(null) returned true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
errln("en_us->equals(null) threw " + e.toString());
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4078588
|
|
|
|
//
|
|
|
|
// RuleBasedCollator breaks on "< a < bb" rule
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4078588(/* char *par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2014-02-25 21:21:49 +00:00
|
|
|
RuleBasedCollator *rbc = new RuleBasedCollator("&9 < a < bb", status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (rbc == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Failed to create RuleBasedCollator.");
|
|
|
|
delete rbc;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-19 13:21:51 +00:00
|
|
|
Collator::EComparisonResult result = rbc->compare("a","bb");
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-03-19 13:21:51 +00:00
|
|
|
if (result != Collator::LESS)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-26 23:27:49 +00:00
|
|
|
errln((UnicodeString)"Compare(a,bb) returned " + (int)result
|
|
|
|
+ (UnicodeString)"; expected -1");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete rbc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4081866
|
|
|
|
//
|
|
|
|
// Combining characters in different classes not reordered properly.
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4081866(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
// These combining characters are all in different classes,
|
|
|
|
// so they should be reordered and the strings should compare as equal.
|
2000-03-22 23:17:42 +00:00
|
|
|
static const UChar s1[] = {0x41, 0x0300, 0x0316, 0x0327, 0x0315, 0};
|
|
|
|
static const UChar s2[] = {0x41, 0x0327, 0x0316, 0x0315, 0x0300, 0};
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-08-21 19:09:33 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
RuleBasedCollator *c = (RuleBasedCollator *) en_us->clone();
|
|
|
|
c->setStrength(Collator::TERTIARY);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// 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
|
2002-08-21 19:09:33 +00:00
|
|
|
c->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if (c->compare(s1,s2) != 0)
|
|
|
|
{
|
|
|
|
errln("Combining chars were not reordered");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4087241
|
|
|
|
//
|
|
|
|
// string comparison errors in Scandinavian collators
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4087241(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
Locale da_DK("da", "DK");
|
|
|
|
RuleBasedCollator *c = NULL;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
c = (RuleBasedCollator *) Collator::createInstance(da_DK, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Failed to create collator for da_DK locale");
|
|
|
|
delete c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->setStrength(Collator::SECONDARY);
|
|
|
|
|
|
|
|
static const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x7a, 0}, {0x3c, 0}, {0x00E6, 0}, // z < ae
|
2014-02-25 21:21:49 +00:00
|
|
|
{0x61, 0x0308, 0}, {0x3c, 0}, {0x61, 0x030A, 0}, // a-umlaut < a-ring
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x59, 0}, {0x3c, 0}, {0x75, 0x0308, 0}, // Y < u-umlaut
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, tests, UPRV_LENGTHOF(tests));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4087243
|
|
|
|
//
|
|
|
|
// CollationKey takes ignorable strings into account when it shouldn't
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4087243(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
RuleBasedCollator *c = (RuleBasedCollator *) en_us->clone();
|
|
|
|
c->setStrength(Collator::TERTIARY);
|
|
|
|
|
|
|
|
static const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x31, 0x32, 0x33, 0}, {0x3d, 0}, {0x31, 0x32, 0x33, 0x0001, 0} // 1 2 3 = 1 2 3 ctrl-A
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, tests, UPRV_LENGTHOF(tests));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4092260
|
|
|
|
//
|
|
|
|
// Mu/micro conflict
|
|
|
|
// Micro symbol and greek lowercase letter Mu should sort identically
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4092260(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
Locale el("el", "");
|
|
|
|
Collator *c = NULL;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
c = Collator::createInstance(el, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Failed to create collator for el locale.");
|
|
|
|
delete c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-13 00:05:42 +00:00
|
|
|
// These now have tertiary differences in UCA
|
|
|
|
c->setAttribute(UCOL_STRENGTH, UCOL_SECONDARY, status);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
static const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x00B5, 0}, {0x3d, 0}, {0x03BC, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, tests, UPRV_LENGTHOF(tests));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4095316
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4095316(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
Locale el_GR("el", "GR");
|
|
|
|
Collator *c = Collator::createInstance(el_GR, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Failed to create collator for el_GR locale");
|
|
|
|
delete c;
|
|
|
|
return;
|
|
|
|
}
|
2001-04-13 00:05:42 +00:00
|
|
|
// These now have tertiary differences in UCA
|
|
|
|
//c->setStrength(Collator::TERTIARY);
|
|
|
|
c->setAttribute(UCOL_STRENGTH, UCOL_SECONDARY, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
static const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x03D4, 0}, {0x3d, 0}, {0x03AB, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, tests, UPRV_LENGTHOF(tests));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4101940
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4101940(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
RuleBasedCollator *c = NULL;
|
2014-02-25 21:21:49 +00:00
|
|
|
UnicodeString rules = "&9 < a < b";
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString nothing = "";
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
c = new RuleBasedCollator(rules, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Failed to create RuleBasedCollator");
|
|
|
|
delete c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CollationElementIterator *i = c->createCollationElementIterator(nothing);
|
|
|
|
i->reset();
|
|
|
|
|
|
|
|
if (i->next(status) != CollationElementIterator::NULLORDER)
|
|
|
|
{
|
|
|
|
errln("next did not return NULLORDER");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete i;
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4103436
|
|
|
|
//
|
|
|
|
// Collator::compare not handling spaces properly
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4103436(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
RuleBasedCollator *c = (RuleBasedCollator *) en_us->clone();
|
|
|
|
c->setStrength(Collator::TERTIARY);
|
|
|
|
|
|
|
|
static const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x66, 0x69, 0x6c, 0x65, 0}, {0x3c, 0}, {0x66, 0x69, 0x6c, 0x65, 0x20, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0},
|
|
|
|
{0x66, 0x69, 0x6c, 0x65, 0}, {0x3c, 0}, {0x66, 0x69, 0x6c, 0x65, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, tests, UPRV_LENGTHOF(tests));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4114076
|
|
|
|
//
|
|
|
|
// Collation not Unicode conformant with Hangul syllables
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4114076(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2002-08-21 19:09:33 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
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
|
|
|
|
//
|
|
|
|
static const UChar test1[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0xd4db, 0}, {0x3d, 0}, {0x1111, 0x1171, 0x11b6, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2002-08-21 19:09:33 +00:00
|
|
|
c->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, test1, UPRV_LENGTHOF(test1));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-12 22:02:37 +00:00
|
|
|
// From UTR #15:
|
|
|
|
// *In earlier versions of Unicode, jamo characters like ksf
|
2008-09-26 21:25:04 +00:00
|
|
|
// had compatibility mappings to kf + sf. These mappings were
|
2000-07-12 22:02:37 +00:00
|
|
|
// removed in Unicode 2.1.9 to ensure that Hangul syllables are maintained.)
|
|
|
|
// That is, the following test is obsolete as of 2.1.9
|
|
|
|
|
|
|
|
//obsolete- // With Full decomposition, it should go all the way down to
|
|
|
|
//obsolete- // conjoining Jamo characters.
|
|
|
|
//obsolete- //
|
|
|
|
//obsolete- static const UChar test2[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
//obsolete- {
|
|
|
|
//obsolete- {0xd4db, 0}, {0x3d, 0}, {0x1111, 0x116e, 0x1175, 0x11af, 0x11c2, 0}
|
|
|
|
//obsolete- };
|
|
|
|
//obsolete-
|
|
|
|
//obsolete- c->setDecomposition(Normalizer::DECOMP_COMPAT);
|
2016-02-23 10:40:09 +00:00
|
|
|
//obsolete- compareArray(*c, test2, UPRV_LENGTHOF(test2));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// @bug 4124632
|
|
|
|
//
|
|
|
|
// Collator::getCollationKey was hanging on certain character sequences
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4124632(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
Collator *coll = NULL;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2002-08-21 00:16:30 +00:00
|
|
|
coll = Collator::createInstance(Locale::getJapan(), status);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (coll == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Failed to create collator for Locale::JAPAN");
|
|
|
|
delete coll;
|
2008-01-21 17:35:02 +00:00
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-03-22 23:17:42 +00:00
|
|
|
static const UChar test[] = {0x41, 0x0308, 0x62, 0x63, 0};
|
1999-08-16 21:50:52 +00:00
|
|
|
CollationKey key;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
coll->getCollationKey(test, key, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (key.isBogus() || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("CollationKey creation failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete coll;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4132736
|
|
|
|
//
|
|
|
|
// sort order of french words with multiple accents has errors
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4132736(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
Collator *c = NULL;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2010-10-19 03:31:50 +00:00
|
|
|
c = Collator::createInstance(Locale::getCanadaFrench(), status);
|
2001-03-15 02:53:05 +00:00
|
|
|
c->setStrength(Collator::TERTIARY);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2010-10-19 03:31:50 +00:00
|
|
|
errln("Failed to create a collator for Locale::getCanadaFrench()");
|
1999-08-16 21:50:52 +00:00
|
|
|
delete c;
|
2008-01-21 17:35:02 +00:00
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const UChar test1[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x65, 0x0300, 0x65, 0x0301, 0}, {0x3c, 0}, {0x65, 0x0301, 0x65, 0x0300, 0},
|
2000-12-05 01:05:46 +00:00
|
|
|
{0x65, 0x0300, 0x0301, 0}, {0x3c, 0}, {0x65, 0x0301, 0x0300, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, test1, UPRV_LENGTHOF(test1));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4133509
|
|
|
|
//
|
|
|
|
// The sorting using java.text.CollationKey is not in the exact order
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4133509(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
static const UChar test1[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0}, {0x3c, 0}, {0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x72, 0x45, 0x72, 0x72, 0x6f, 0x72, 0},
|
|
|
|
{0x47, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0}, {0x3c, 0}, {0x47, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0},
|
|
|
|
{0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0}, {0x3c, 0}, {0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*en_us, test1, UPRV_LENGTHOF(test1));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4114077
|
|
|
|
//
|
2008-09-26 21:25:04 +00:00
|
|
|
// Collation with decomposition off doesn't work for Europe
|
1999-08-16 21:50:52 +00:00
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4114077(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
// Ensure that we get the same results with decomposition off
|
|
|
|
// as we do with it on....
|
2008-09-26 21:25:04 +00:00
|
|
|
|
2002-08-21 19:09:33 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
RuleBasedCollator *c = (RuleBasedCollator *) en_us->clone();
|
|
|
|
c->setStrength(Collator::TERTIARY);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
static const UChar test1[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x00C0, 0}, {0x3d, 0}, {0x41, 0x0300, 0}, // Should be equivalent
|
|
|
|
{0x70, 0x00ea, 0x63, 0x68, 0x65, 0}, {0x3e, 0}, {0x70, 0x00e9, 0x63, 0x68, 0x00e9, 0},
|
|
|
|
{0x0204, 0}, {0x3d, 0}, {0x45, 0x030F, 0},
|
|
|
|
{0x01fa, 0}, {0x3d, 0}, {0x41, 0x030a, 0x0301, 0}, // a-ring-acute -> a-ring, acute
|
1999-08-16 21:50:52 +00:00
|
|
|
// -> a, ring, acute
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x41, 0x0300, 0x0316, 0}, {0x3c, 0}, {0x41, 0x0316, 0x0300, 0} // No reordering --> unequal
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2002-08-21 19:09:33 +00:00
|
|
|
c->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_OFF, status);
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, test1, UPRV_LENGTHOF(test1));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
static const UChar test2[][CollationRegressionTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x41, 0x0300, 0x0316, 0}, {0x3d, 0}, {0x41, 0x0316, 0x0300, 0} // Reordering --> equal
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2002-08-21 19:09:33 +00:00
|
|
|
c->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
|
2016-02-23 10:40:09 +00:00
|
|
|
compareArray(*c, test2, UPRV_LENGTHOF(test2));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4141640
|
|
|
|
//
|
2008-09-26 21:25:04 +00:00
|
|
|
// Support for Swedish gone in 1.1.6 (Can't create Swedish collator)
|
1999-08-16 21:50:52 +00:00
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4141640(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t i, localeCount;
|
|
|
|
const Locale *locales = Locale::getAvailableLocales(localeCount);
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
for (i = 0; i < localeCount; i += 1)
|
|
|
|
{
|
|
|
|
Collator *c = NULL;
|
2002-04-02 02:55:31 +00:00
|
|
|
|
|
|
|
status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
c = Collator::createInstance(locales[i], status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UnicodeString msg, localeName;
|
|
|
|
|
|
|
|
msg += "Could not create collator for locale ";
|
2000-04-15 21:28:17 +00:00
|
|
|
msg += locales[i].getName();
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
errln(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4139572
|
|
|
|
//
|
2008-09-26 21:25:04 +00:00
|
|
|
// getCollationKey throws exception for spanish text
|
1999-08-16 21:50:52 +00:00
|
|
|
// Cannot reproduce this bug on 1.2, however it DOES fail on 1.1.6
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4139572(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// Code pasted straight from the bug report
|
|
|
|
// (and then translated to C++ ;-)
|
|
|
|
//
|
|
|
|
// create spanish locale and collator
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
Locale l("es", "es");
|
|
|
|
Collator *col = NULL;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
col = Collator::createInstance(l, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (col == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Failed to create a collator for es_es locale.");
|
|
|
|
delete col;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CollationKey key;
|
|
|
|
|
|
|
|
// this spanish phrase kills it!
|
|
|
|
col->getCollationKey("Nombre De Objeto", key, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (key.isBogus() || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Error creating CollationKey for \"Nombre De Ojbeto\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete col;
|
|
|
|
}
|
1999-11-23 22:47:47 +00:00
|
|
|
/* HSYS : RuleBasedCollator::compare() performance enhancements
|
|
|
|
compare() does not create CollationElementIterator() anymore.*/
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
class My4146160Collator : public RuleBasedCollator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
My4146160Collator(RuleBasedCollator &rbc, UErrorCode &status);
|
|
|
|
~My4146160Collator();
|
|
|
|
|
|
|
|
CollationElementIterator *createCollationElementIterator(const UnicodeString &text) const;
|
|
|
|
|
|
|
|
CollationElementIterator *createCollationElementIterator(const CharacterIterator &text) const;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
static int32_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
int32_t My4146160Collator::count = 0;
|
|
|
|
|
|
|
|
My4146160Collator::My4146160Collator(RuleBasedCollator &rbc, UErrorCode &status)
|
|
|
|
: RuleBasedCollator(rbc.getRules(), status)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
My4146160Collator::~My4146160Collator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CollationElementIterator *My4146160Collator::createCollationElementIterator(const UnicodeString &text) const
|
|
|
|
{
|
|
|
|
count += 1;
|
|
|
|
return RuleBasedCollator::createCollationElementIterator(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
CollationElementIterator *My4146160Collator::createCollationElementIterator(const CharacterIterator &text) const
|
|
|
|
{
|
|
|
|
count += 1;
|
|
|
|
return RuleBasedCollator::createCollationElementIterator(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @bug 4146160
|
|
|
|
//
|
|
|
|
// RuleBasedCollator doesn't use createCollationElementIterator internally
|
|
|
|
//
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::Test4146160(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-11-23 22:47:47 +00:00
|
|
|
#if 0
|
1999-08-16 21:50:52 +00:00
|
|
|
//
|
|
|
|
// Use a custom collator class whose createCollationElementIterator
|
|
|
|
// methods increment a count....
|
|
|
|
//
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
CollationKey key;
|
|
|
|
|
|
|
|
My4146160Collator::count = 0;
|
|
|
|
My4146160Collator *mc = NULL;
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
mc = new My4146160Collator(*en_us, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (mc == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Failed to create a My4146160Collator.");
|
|
|
|
delete mc;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mc->getCollationKey("1", key, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (key.isBogus() || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Failure to get a CollationKey from a My4146160Collator.");
|
|
|
|
delete mc;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (My4146160Collator::count < 1)
|
|
|
|
{
|
|
|
|
errln("My4146160Collator::createCollationElementIterator not called for getCollationKey");
|
|
|
|
}
|
|
|
|
|
|
|
|
My4146160Collator::count = 0;
|
|
|
|
mc->compare("1", "2");
|
|
|
|
|
|
|
|
if (My4146160Collator::count < 1)
|
|
|
|
{
|
|
|
|
errln("My4146160Collator::createtCollationElementIterator not called for compare");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete mc;
|
1999-11-23 22:47:47 +00:00
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2009-10-14 21:45:30 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
void CollationRegressionTest::Test4179216() {
|
|
|
|
// you can position a CollationElementIterator in the middle of
|
|
|
|
// a contracting character sequence, yielding a bogus collation
|
|
|
|
// element
|
|
|
|
IcuTestErrorCode errorCode(*this, "Test4179216");
|
|
|
|
RuleBasedCollator coll(en_us->getRules() + " & C < ch , cH , Ch , CH < cat < crunchy", errorCode);
|
|
|
|
UnicodeString testText = "church church catcatcher runcrunchynchy";
|
|
|
|
CollationElementIterator *iter = coll.createCollationElementIterator(testText);
|
|
|
|
|
|
|
|
// test that the "ch" combination works properly
|
|
|
|
iter->setOffset(4, errorCode);
|
|
|
|
int32_t elt4 = CollationElementIterator::primaryOrder(iter->next(errorCode));
|
|
|
|
|
|
|
|
iter->reset();
|
|
|
|
int32_t elt0 = CollationElementIterator::primaryOrder(iter->next(errorCode));
|
|
|
|
|
|
|
|
iter->setOffset(5, errorCode);
|
|
|
|
int32_t elt5 = CollationElementIterator::primaryOrder(iter->next(errorCode));
|
|
|
|
|
|
|
|
// Compares and prints only 16-bit primary weights.
|
|
|
|
if (elt4 != elt0 || elt5 != elt0) {
|
|
|
|
errln("The collation elements at positions 0 (0x%04x), "
|
|
|
|
"4 (0x%04x), and 5 (0x%04x) don't match.",
|
|
|
|
elt0, elt4, elt5);
|
|
|
|
}
|
|
|
|
|
|
|
|
// test that the "cat" combination works properly
|
|
|
|
iter->setOffset(14, errorCode);
|
|
|
|
int32_t elt14 = CollationElementIterator::primaryOrder(iter->next(errorCode));
|
|
|
|
|
|
|
|
iter->setOffset(15, errorCode);
|
|
|
|
int32_t elt15 = CollationElementIterator::primaryOrder(iter->next(errorCode));
|
|
|
|
|
|
|
|
iter->setOffset(16, errorCode);
|
|
|
|
int32_t elt16 = CollationElementIterator::primaryOrder(iter->next(errorCode));
|
|
|
|
|
|
|
|
iter->setOffset(17, errorCode);
|
|
|
|
int32_t elt17 = CollationElementIterator::primaryOrder(iter->next(errorCode));
|
|
|
|
|
|
|
|
iter->setOffset(18, errorCode);
|
|
|
|
int32_t elt18 = CollationElementIterator::primaryOrder(iter->next(errorCode));
|
|
|
|
|
|
|
|
iter->setOffset(19, errorCode);
|
|
|
|
int32_t elt19 = CollationElementIterator::primaryOrder(iter->next(errorCode));
|
|
|
|
|
|
|
|
// Compares and prints only 16-bit primary weights.
|
|
|
|
if (elt14 != elt15 || elt14 != elt16 || elt14 != elt17
|
|
|
|
|| elt14 != elt18 || elt14 != elt19) {
|
|
|
|
errln("\"cat\" elements don't match: elt14 = 0x%04x, "
|
|
|
|
"elt15 = 0x%04x, elt16 = 0x%04x, elt17 = 0x%04x, "
|
|
|
|
"elt18 = 0x%04x, elt19 = 0x%04x",
|
|
|
|
elt14, elt15, elt16, elt17, elt18, 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();
|
|
|
|
|
|
|
|
int32_t elt = iter->next(errorCode);
|
|
|
|
int32_t count = 0;
|
|
|
|
while (elt != CollationElementIterator::NULLORDER) {
|
|
|
|
++count;
|
|
|
|
elt = iter->next(errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalArray<UnicodeString> nextElements(new UnicodeString[count]);
|
|
|
|
LocalArray<UnicodeString> setOffsetElements(new UnicodeString[count]);
|
|
|
|
int32_t lastPos = 0;
|
|
|
|
|
|
|
|
iter->reset();
|
|
|
|
elt = iter->next(errorCode);
|
|
|
|
count = 0;
|
|
|
|
while (elt != CollationElementIterator::NULLORDER) {
|
|
|
|
nextElements[count++] = testText.tempSubStringBetween(lastPos, iter->getOffset());
|
|
|
|
lastPos = iter->getOffset();
|
|
|
|
elt = iter->next(errorCode);
|
|
|
|
}
|
|
|
|
int32_t nextElementsLength = count;
|
|
|
|
count = 0;
|
|
|
|
for (int32_t i = 0; i < testText.length(); ) {
|
|
|
|
iter->setOffset(i, errorCode);
|
|
|
|
lastPos = iter->getOffset();
|
|
|
|
elt = iter->next(errorCode);
|
|
|
|
setOffsetElements[count++] = testText.tempSubStringBetween(lastPos, iter->getOffset());
|
|
|
|
i = iter->getOffset();
|
|
|
|
}
|
|
|
|
for (int32_t i = 0; i < nextElementsLength; i++) {
|
|
|
|
if (nextElements[i] == setOffsetElements[i]) {
|
|
|
|
logln(nextElements[i]);
|
|
|
|
} else {
|
|
|
|
errln(UnicodeString("Error: next() yielded ") + nextElements[i] +
|
|
|
|
", but setOffset() yielded " + setOffsetElements[i]);
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 23:20:31 +00:00
|
|
|
delete iter;
|
2014-02-25 21:21:49 +00:00
|
|
|
}
|
|
|
|
|
2009-10-14 21:45:30 +00:00
|
|
|
// Ticket 7189
|
|
|
|
//
|
|
|
|
// nextSortKeyPart incorrect for EO_S1 collation
|
2010-05-25 22:17:12 +00:00
|
|
|
static int32_t calcKeyIncremental(UCollator *coll, const UChar* text, int32_t len, uint8_t *keyBuf, int32_t /*keyBufLen*/, UErrorCode& status) {
|
2009-10-20 16:48:17 +00:00
|
|
|
UCharIterator uiter;
|
|
|
|
uint32_t state[2] = { 0, 0 };
|
|
|
|
int32_t keyLen;
|
|
|
|
int32_t count = 8;
|
|
|
|
|
|
|
|
uiter_setString(&uiter, text, len);
|
|
|
|
keyLen = 0;
|
|
|
|
while (TRUE) {
|
|
|
|
int32_t keyPartLen = ucol_nextSortKeyPart(coll, &uiter, state, &keyBuf[keyLen], count, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (keyPartLen == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
keyLen += keyPartLen;
|
|
|
|
}
|
|
|
|
return keyLen;
|
2009-10-14 21:45:30 +00:00
|
|
|
}
|
|
|
|
|
2009-10-20 16:48:17 +00:00
|
|
|
void CollationRegressionTest::TestT7189() {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UCollator *coll;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
static const UChar text1[][CollationRegressionTest::MAX_TOKEN_LEN] = {
|
|
|
|
// "Achter De Hoven"
|
|
|
|
{ 0x41, 0x63, 0x68, 0x74, 0x65, 0x72, 0x20, 0x44, 0x65, 0x20, 0x48, 0x6F, 0x76, 0x65, 0x6E, 0x00 },
|
|
|
|
// "ABC"
|
|
|
|
{ 0x41, 0x42, 0x43, 0x00 },
|
|
|
|
// "HELLO world!"
|
2009-10-20 16:51:02 +00:00
|
|
|
{ 0x48, 0x45, 0x4C, 0x4C, 0x4F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x00 }
|
2009-10-20 16:48:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const UChar text2[][CollationRegressionTest::MAX_TOKEN_LEN] = {
|
|
|
|
// "Achter de Hoven"
|
|
|
|
{ 0x41, 0x63, 0x68, 0x74, 0x65, 0x72, 0x20, 0x64, 0x65, 0x20, 0x48, 0x6F, 0x76, 0x65, 0x6E, 0x00 },
|
|
|
|
// "abc"
|
|
|
|
{ 0x61, 0x62, 0x63, 0x00 },
|
|
|
|
// "hello world!"
|
|
|
|
{ 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x00 }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Open the collator
|
|
|
|
coll = ucol_openFromShortString("EO_S1", FALSE, NULL, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln("Failed to create a collator for short string EO_S1");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-26 11:21:55 +00:00
|
|
|
for (i = 0; i < UPRV_LENGTHOF(text1); i++) {
|
2009-10-20 16:48:17 +00:00
|
|
|
uint8_t key1[100], key2[100];
|
|
|
|
int32_t len1, len2;
|
|
|
|
|
|
|
|
len1 = calcKeyIncremental(coll, text1[i], -1, key1, sizeof(key1), status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln(UnicodeString("Failed to get a partial collation key for ") + text1[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
len2 = calcKeyIncremental(coll, text2[i], -1, key2, sizeof(key2), status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln(UnicodeString("Failed to get a partial collation key for ") + text2[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len1 == len2 && uprv_memcmp(key1, key2, len1) == 0) {
|
|
|
|
errln(UnicodeString("Failed: Identical key\n") + " text1: " + text1[i] + "\n" + " text2: " + text2[i] + "\n" + " key : " + TestUtility::hex(key1, len1));
|
|
|
|
} else {
|
|
|
|
logln(UnicodeString("Keys produced -\n") + " text1: " + text1[i] + "\n" + " key1 : " + TestUtility::hex(key1, len1) + "\n" + " text2: " + text2[i] + "\n" + " key2 : "
|
|
|
|
+ TestUtility::hex(key2, len2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ucol_close(coll);
|
2009-10-14 21:45:30 +00:00
|
|
|
}
|
|
|
|
|
2011-06-20 17:18:46 +00:00
|
|
|
void CollationRegressionTest::TestCaseFirstCompression() {
|
|
|
|
RuleBasedCollator *col = (RuleBasedCollator *) en_us->clone();
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
// default
|
|
|
|
caseFirstCompressionSub(col, "default");
|
|
|
|
|
|
|
|
// Upper first
|
|
|
|
col->setAttribute(UCOL_CASE_FIRST, UCOL_UPPER_FIRST, status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln("Failed to set UCOL_UPPER_FIRST");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
caseFirstCompressionSub(col, "upper first");
|
|
|
|
|
|
|
|
// Lower first
|
|
|
|
col->setAttribute(UCOL_CASE_FIRST, UCOL_LOWER_FIRST, status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln("Failed to set UCOL_LOWER_FIRST");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
caseFirstCompressionSub(col, "lower first");
|
|
|
|
|
|
|
|
delete col;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollationRegressionTest::caseFirstCompressionSub(Collator *col, UnicodeString opt) {
|
|
|
|
const int32_t maxLength = 50;
|
|
|
|
|
|
|
|
UChar str1[maxLength];
|
|
|
|
UChar str2[maxLength];
|
|
|
|
|
|
|
|
CollationKey key1, key2;
|
|
|
|
|
|
|
|
for (int32_t len = 1; len <= maxLength; len++) {
|
|
|
|
int32_t i = 0;
|
|
|
|
for (; i < len - 1; i++) {
|
|
|
|
str1[i] = str2[i] = (UChar)0x61; // 'a'
|
|
|
|
}
|
|
|
|
str1[i] = (UChar)0x41; // 'A'
|
|
|
|
str2[i] = (UChar)0x61; // 'a'
|
|
|
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
col->getCollationKey(str1, len, key1, status);
|
|
|
|
col->getCollationKey(str2, len, key2, status);
|
|
|
|
|
|
|
|
UCollationResult cmpKey = key1.compareTo(key2, status);
|
|
|
|
UCollationResult cmpCol = col->compare(str1, len, str2, len, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln("Error in caseFirstCompressionSub");
|
|
|
|
} else if (cmpKey != cmpCol) {
|
|
|
|
errln((UnicodeString)"Inconsistent comparison(" + opt
|
|
|
|
+ "): str1=" + UnicodeString(str1, len) + ", str2=" + UnicodeString(str2, len)
|
|
|
|
+ ", cmpKey=" + cmpKey + ", cmpCol=" + cmpCol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 22:52:07 +00:00
|
|
|
void CollationRegressionTest::TestTrailingComment() {
|
|
|
|
// ICU ticket #8070:
|
|
|
|
// Check that the rule parser handles a comment without terminating end-of-line.
|
|
|
|
IcuTestErrorCode errorCode(*this, "TestTrailingComment");
|
|
|
|
RuleBasedCollator coll(UNICODE_STRING_SIMPLE("&c<b#comment1\n<a#comment2"), errorCode);
|
|
|
|
UnicodeString a((UChar)0x61), b((UChar)0x62), c((UChar)0x63);
|
|
|
|
assertTrue("c<b", coll.compare(c, b) < 0);
|
|
|
|
assertTrue("b<a", coll.compare(b, a) < 0);
|
|
|
|
}
|
2011-06-20 17:18:46 +00:00
|
|
|
|
2014-02-28 20:15:58 +00:00
|
|
|
void CollationRegressionTest::TestBeforeWithTooStrongAfter() {
|
|
|
|
// ICU ticket #9959:
|
|
|
|
// Forbid rules with a before-reset followed by a stronger relation.
|
|
|
|
IcuTestErrorCode errorCode(*this, "TestBeforeWithTooStrongAfter");
|
|
|
|
RuleBasedCollator before2(UNICODE_STRING_SIMPLE("&[before 2]x<<q<p"), errorCode);
|
|
|
|
if(errorCode.isSuccess()) {
|
|
|
|
errln("should forbid before-2-reset followed by primary relation");
|
|
|
|
} else {
|
|
|
|
errorCode.reset();
|
|
|
|
}
|
|
|
|
RuleBasedCollator before3(UNICODE_STRING_SIMPLE("&[before 3]x<<<q<<s<p"), errorCode);
|
|
|
|
if(errorCode.isSuccess()) {
|
|
|
|
errln("should forbid before-3-reset followed by primary or secondary relation");
|
|
|
|
} else {
|
|
|
|
errorCode.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void CollationRegressionTest::compareArray(Collator &c,
|
|
|
|
const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN],
|
|
|
|
int32_t testCount)
|
|
|
|
{
|
|
|
|
int32_t i;
|
2003-03-19 13:21:51 +00:00
|
|
|
Collator::EComparisonResult expectedResult = Collator::EQUAL;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
for (i = 0; i < testCount; i += 3)
|
|
|
|
{
|
|
|
|
UnicodeString source(tests[i]);
|
|
|
|
UnicodeString comparison(tests[i + 1]);
|
|
|
|
UnicodeString target(tests[i + 2]);
|
|
|
|
|
|
|
|
if (comparison == "<")
|
|
|
|
{
|
2003-03-19 13:21:51 +00:00
|
|
|
expectedResult = Collator::LESS;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
else if (comparison == ">")
|
|
|
|
{
|
2003-03-19 13:21:51 +00:00
|
|
|
expectedResult = Collator::GREATER;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
else if (comparison == "=")
|
|
|
|
{
|
2003-03-19 13:21:51 +00:00
|
|
|
expectedResult = Collator::EQUAL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UnicodeString bogus1("Bogus comparison string \"");
|
|
|
|
UnicodeString bogus2("\"");
|
|
|
|
errln(bogus1 + comparison + bogus2);
|
|
|
|
}
|
|
|
|
|
2003-03-19 13:21:51 +00:00
|
|
|
Collator::EComparisonResult compareResult = c.compare(source, target);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
CollationKey sourceKey, targetKey;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
c.getCollationKey(source, sourceKey, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Couldn't get collationKey for source");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
c.getCollationKey(target, targetKey, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Couldn't get collationKey for target");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-03-19 13:21:51 +00:00
|
|
|
Collator::EComparisonResult keyResult = sourceKey.compareTo(targetKey);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-06-19 21:16:48 +00:00
|
|
|
reportCResult( source, target, sourceKey, targetKey, compareResult, keyResult, compareResult, expectedResult );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollationRegressionTest::assertEqual(CollationElementIterator &i1, CollationElementIterator &i2)
|
|
|
|
{
|
|
|
|
int32_t c1, c2, count = 0;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c1 = i1.next(status);
|
|
|
|
c2 = i2.next(status);
|
|
|
|
|
|
|
|
if (c1 != c2)
|
|
|
|
{
|
|
|
|
UnicodeString msg, msg1(" ");
|
2008-09-26 21:25:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
msg += msg1 + count;
|
|
|
|
msg += ": strength(0x";
|
|
|
|
appendHex(c1, 8, msg);
|
|
|
|
msg += ") != strength(0x";
|
|
|
|
appendHex(c2, 8, msg);
|
|
|
|
msg += ")";
|
|
|
|
|
|
|
|
errln(msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
while (c1 != CollationElementIterator::NULLORDER);
|
|
|
|
}
|
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationRegressionTest::runIndexedTest(int32_t index, UBool exec, const char* &name, char* /* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (exec)
|
|
|
|
{
|
|
|
|
logln("Collation Regression Tests: ");
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
if(en_us == NULL) {
|
|
|
|
dataerrln("Class collator not instantiated");
|
|
|
|
name = "";
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2014-02-25 21:21:49 +00:00
|
|
|
TESTCASE_AUTO_BEGIN;
|
|
|
|
TESTCASE_AUTO(Test4048446);
|
|
|
|
TESTCASE_AUTO(Test4051866);
|
|
|
|
TESTCASE_AUTO(Test4053636);
|
|
|
|
TESTCASE_AUTO(Test4054238);
|
|
|
|
TESTCASE_AUTO(Test4054734);
|
|
|
|
TESTCASE_AUTO(Test4054736);
|
|
|
|
TESTCASE_AUTO(Test4058613);
|
|
|
|
TESTCASE_AUTO(Test4059820);
|
|
|
|
TESTCASE_AUTO(Test4060154);
|
|
|
|
TESTCASE_AUTO(Test4062418);
|
|
|
|
TESTCASE_AUTO(Test4065540);
|
|
|
|
TESTCASE_AUTO(Test4066189);
|
|
|
|
TESTCASE_AUTO(Test4066696);
|
|
|
|
TESTCASE_AUTO(Test4076676);
|
|
|
|
TESTCASE_AUTO(Test4078588);
|
|
|
|
TESTCASE_AUTO(Test4079231);
|
|
|
|
TESTCASE_AUTO(Test4081866);
|
|
|
|
TESTCASE_AUTO(Test4087241);
|
|
|
|
TESTCASE_AUTO(Test4087243);
|
|
|
|
TESTCASE_AUTO(Test4092260);
|
|
|
|
TESTCASE_AUTO(Test4095316);
|
|
|
|
TESTCASE_AUTO(Test4101940);
|
|
|
|
TESTCASE_AUTO(Test4103436);
|
|
|
|
TESTCASE_AUTO(Test4114076);
|
|
|
|
TESTCASE_AUTO(Test4114077);
|
|
|
|
TESTCASE_AUTO(Test4124632);
|
|
|
|
TESTCASE_AUTO(Test4132736);
|
|
|
|
TESTCASE_AUTO(Test4133509);
|
|
|
|
TESTCASE_AUTO(Test4139572);
|
|
|
|
TESTCASE_AUTO(Test4141640);
|
|
|
|
TESTCASE_AUTO(Test4146160);
|
|
|
|
TESTCASE_AUTO(Test4179216);
|
|
|
|
TESTCASE_AUTO(TestT7189);
|
|
|
|
TESTCASE_AUTO(TestCaseFirstCompression);
|
2014-02-27 22:52:07 +00:00
|
|
|
TESTCASE_AUTO(TestTrailingComment);
|
2014-02-28 20:15:58 +00:00
|
|
|
TESTCASE_AUTO(TestBeforeWithTooStrongAfter);
|
2014-02-25 21:21:49 +00:00
|
|
|
TESTCASE_AUTO_END;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_COLLATION */
|