mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-5426 Reduce the VM size on Windows by two thirds of a megabyte,
and make it easier to update UCA rules. X-SVN-Rev: 20465
This commit is contained in:
parent
932759f00a
commit
b0d276726b
1 changed files with 157 additions and 160 deletions
|
@ -1,6 +1,6 @@
|
|||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 2002-2005, International Business Machines Corporation and
|
||||
* Copyright (c) 2002-2006, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
|
@ -24,29 +24,29 @@ rbUCA(NULL),
|
|||
testFile(NULL),
|
||||
status(U_ZERO_ERROR)
|
||||
{
|
||||
UCA = ucol_open("root", &status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("ERROR - UCAConformanceTest: Unable to open UCA collator!");
|
||||
}
|
||||
UCA = ucol_open("root", &status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("ERROR - UCAConformanceTest: Unable to open UCA collator!");
|
||||
}
|
||||
|
||||
const char *srcDir = IntlTest::getSourceTestData(status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("ERROR: could not open test data %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
uprv_strcpy(testDataPath, srcDir);
|
||||
uprv_strcat(testDataPath, "CollationTest_");
|
||||
const char *srcDir = IntlTest::getSourceTestData(status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("ERROR: could not open test data %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
uprv_strcpy(testDataPath, srcDir);
|
||||
uprv_strcat(testDataPath, "CollationTest_");
|
||||
}
|
||||
|
||||
UCAConformanceTest::~UCAConformanceTest()
|
||||
{
|
||||
ucol_close(UCA);
|
||||
if(rbUCA) {
|
||||
ucol_close(rbUCA);
|
||||
}
|
||||
if(testFile) {
|
||||
fclose(testFile);
|
||||
}
|
||||
ucol_close(UCA);
|
||||
if(rbUCA) {
|
||||
ucol_close(rbUCA);
|
||||
}
|
||||
if(testFile) {
|
||||
fclose(testFile);
|
||||
}
|
||||
}
|
||||
|
||||
void UCAConformanceTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par */)
|
||||
|
@ -65,27 +65,24 @@ void UCAConformanceTest::runIndexedTest( int32_t index, UBool exec, const char*
|
|||
}
|
||||
}
|
||||
|
||||
static const int BUFFER_SIZE_ = 330000;
|
||||
static UChar buffer[BUFFER_SIZE_];
|
||||
|
||||
void UCAConformanceTest::initRbUCA()
|
||||
{
|
||||
if(!rbUCA) {
|
||||
UParseError parseError;
|
||||
UChar *ucarules = buffer;
|
||||
int32_t size = ucol_getRulesEx(UCA, UCOL_FULL_RULES, ucarules,
|
||||
BUFFER_SIZE_);
|
||||
if (size > BUFFER_SIZE_) {
|
||||
if(!rbUCA) {
|
||||
UParseError parseError;
|
||||
UChar *ucarules;
|
||||
// preflight rules
|
||||
int32_t size = ucol_getRulesEx(UCA, UCOL_FULL_RULES, NULL, 0);
|
||||
ucarules = (UChar *)malloc(size * sizeof(UChar));
|
||||
|
||||
size = ucol_getRulesEx(UCA, UCOL_FULL_RULES, ucarules, size);
|
||||
rbUCA = ucol_openRules(ucarules, size, UCOL_DEFAULT, UCOL_TERTIARY,
|
||||
&parseError, &status);
|
||||
free(ucarules);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failure creating UCA rule-based collator: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
}
|
||||
rbUCA = ucol_openRules(ucarules, size, UCOL_DEFAULT, UCOL_TERTIARY,
|
||||
&parseError, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failure creating UCA rule-based collator: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UCAConformanceTest::setCollNonIgnorable(UCollator *coll)
|
||||
|
@ -99,170 +96,170 @@ void UCAConformanceTest::setCollNonIgnorable(UCollator *coll)
|
|||
|
||||
void UCAConformanceTest::setCollShifted(UCollator *coll)
|
||||
{
|
||||
ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
|
||||
ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_OFF, &status);
|
||||
ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_OFF, &status);
|
||||
ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_QUATERNARY, &status);
|
||||
ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
|
||||
ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
|
||||
ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_OFF, &status);
|
||||
ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_OFF, &status);
|
||||
ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_QUATERNARY, &status);
|
||||
ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
|
||||
}
|
||||
|
||||
void UCAConformanceTest::openTestFile(const char *type)
|
||||
{
|
||||
const char *ext = ".txt";
|
||||
if(testFile) {
|
||||
fclose(testFile);
|
||||
}
|
||||
char buffer[1024];
|
||||
uprv_strcpy(buffer, testDataPath);
|
||||
uprv_strcat(buffer, type);
|
||||
int32_t bufLen = (int32_t)uprv_strlen(buffer);
|
||||
const char *ext = ".txt";
|
||||
if(testFile) {
|
||||
fclose(testFile);
|
||||
}
|
||||
char buffer[1024];
|
||||
uprv_strcpy(buffer, testDataPath);
|
||||
uprv_strcat(buffer, type);
|
||||
int32_t bufLen = (int32_t)uprv_strlen(buffer);
|
||||
|
||||
// we try to open 3 files:
|
||||
// path/CollationTest_type.txt
|
||||
// path/CollationTest_type_SHORT.txt
|
||||
// path/CollationTest_type_STUB.txt
|
||||
// we are going to test with the first one that we manage to open.
|
||||
// we try to open 3 files:
|
||||
// path/CollationTest_type.txt
|
||||
// path/CollationTest_type_SHORT.txt
|
||||
// path/CollationTest_type_STUB.txt
|
||||
// we are going to test with the first one that we manage to open.
|
||||
|
||||
uprv_strcpy(buffer+bufLen, ext);
|
||||
uprv_strcpy(buffer+bufLen, ext);
|
||||
|
||||
testFile = fopen(buffer, "rb");
|
||||
|
||||
if(testFile == 0) {
|
||||
uprv_strcpy(buffer+bufLen, "_SHORT");
|
||||
uprv_strcat(buffer, ext);
|
||||
testFile = fopen(buffer, "rb");
|
||||
|
||||
if(testFile == 0) {
|
||||
uprv_strcpy(buffer+bufLen, "_STUB");
|
||||
uprv_strcat(buffer, ext);
|
||||
testFile = fopen(buffer, "rb");
|
||||
uprv_strcpy(buffer+bufLen, "_SHORT");
|
||||
uprv_strcat(buffer, ext);
|
||||
testFile = fopen(buffer, "rb");
|
||||
|
||||
if (testFile == 0) {
|
||||
*(buffer+bufLen) = 0;
|
||||
errln("ERROR: could not open any of the conformance test files, tried opening base %s\n", buffer);
|
||||
return;
|
||||
} else {
|
||||
infoln(
|
||||
"INFO: Working with the stub file.\n"
|
||||
"If you need the full conformance test, please\n"
|
||||
"download the appropriate data files from:\n"
|
||||
"http://dev.icu-project.org/cgi-bin/viewcvs.cgi/unicodetools/com/ibm/text/data/");
|
||||
}
|
||||
if(testFile == 0) {
|
||||
uprv_strcpy(buffer+bufLen, "_STUB");
|
||||
uprv_strcat(buffer, ext);
|
||||
testFile = fopen(buffer, "rb");
|
||||
|
||||
if (testFile == 0) {
|
||||
*(buffer+bufLen) = 0;
|
||||
errln("ERROR: could not open any of the conformance test files, tried opening base %s\n", buffer);
|
||||
return;
|
||||
} else {
|
||||
infoln(
|
||||
"INFO: Working with the stub file.\n"
|
||||
"If you need the full conformance test, please\n"
|
||||
"download the appropriate data files from:\n"
|
||||
"http://dev.icu-project.org/cgi-bin/viewcvs.cgi/unicodetools/com/ibm/text/data/");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UCAConformanceTest::testConformance(UCollator *coll)
|
||||
{
|
||||
if(testFile == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t line = 0;
|
||||
|
||||
UChar b1[1024], b2[1024];
|
||||
char lineB[1024];
|
||||
UChar *buffer = b1, *oldB = NULL;
|
||||
uint8_t sk1[1024], sk2[1024];
|
||||
uint8_t *oldSk = NULL, *newSk = sk1;
|
||||
int32_t resLen = 0, oldLen = 0;
|
||||
int32_t buflen = 0, oldBlen = 0;
|
||||
uint32_t first = 0;
|
||||
uint32_t offset = 0;
|
||||
UnicodeString oldS, newS;
|
||||
|
||||
|
||||
while (fgets(lineB, 1024, testFile) != NULL) {
|
||||
offset = 0;
|
||||
|
||||
line++;
|
||||
if(*lineB == 0 || strlen(lineB) < 3 || lineB[0] == '#') {
|
||||
continue;
|
||||
if(testFile == 0) {
|
||||
return;
|
||||
}
|
||||
offset = u_parseString(lineB, buffer, 1024, &first, &status);
|
||||
buflen = offset;
|
||||
buffer[offset++] = 0;
|
||||
|
||||
resLen = ucol_getSortKey(coll, buffer, buflen, newSk, 1024);
|
||||
int32_t line = 0;
|
||||
|
||||
int32_t res = 0, cmpres = 0, cmpres2 = 0;
|
||||
UChar b1[1024], b2[1024];
|
||||
char lineB[1024];
|
||||
UChar *buffer = b1, *oldB = NULL;
|
||||
uint8_t sk1[1024], sk2[1024];
|
||||
uint8_t *oldSk = NULL, *newSk = sk1;
|
||||
int32_t resLen = 0, oldLen = 0;
|
||||
int32_t buflen = 0, oldBlen = 0;
|
||||
uint32_t first = 0;
|
||||
uint32_t offset = 0;
|
||||
UnicodeString oldS, newS;
|
||||
|
||||
if(oldSk != NULL) {
|
||||
res = strcmp((char *)oldSk, (char *)newSk);
|
||||
cmpres = ucol_strcoll(coll, oldB, oldBlen, buffer, buflen);
|
||||
cmpres2 = ucol_strcoll(coll, buffer, buflen, oldB, oldBlen);
|
||||
|
||||
if(cmpres != -cmpres2) {
|
||||
errln("Compare result not symmetrical on line %i", line);
|
||||
}
|
||||
while (fgets(lineB, 1024, testFile) != NULL) {
|
||||
offset = 0;
|
||||
|
||||
if(((res&0x80000000) != (cmpres&0x80000000)) || (res == 0 && cmpres != 0) || (res != 0 && cmpres == 0)) {
|
||||
errln("Difference between ucol_strcoll and sortkey compare on line %i", line);
|
||||
logln("Data line %s", lineB);
|
||||
}
|
||||
|
||||
if(res > 0) {
|
||||
errln("Line %i is not greater or equal than previous line", line);
|
||||
logln("Data line %s", lineB);
|
||||
prettify(CollationKey(oldSk, oldLen), oldS);
|
||||
prettify(CollationKey(newSk, resLen), newS);
|
||||
logln("Keys: "+oldS+" and "+newS);
|
||||
} else if(res == 0) { /* equal */
|
||||
res = u_strcmpCodePointOrder(oldB, buffer);
|
||||
if (res == 0) {
|
||||
errln("Probable error in test file on line %i (comparing identical strings)", line);
|
||||
logln("Data line %s", lineB);
|
||||
} else if (res > 0) {
|
||||
errln("Sortkeys are identical, but code point comapare gives >0 on line %i", line);
|
||||
logln("Data line %s", lineB);
|
||||
line++;
|
||||
if(*lineB == 0 || strlen(lineB) < 3 || lineB[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
offset = u_parseString(lineB, buffer, 1024, &first, &status);
|
||||
buflen = offset;
|
||||
buffer[offset++] = 0;
|
||||
|
||||
resLen = ucol_getSortKey(coll, buffer, buflen, newSk, 1024);
|
||||
|
||||
int32_t res = 0, cmpres = 0, cmpres2 = 0;
|
||||
|
||||
if(oldSk != NULL) {
|
||||
res = strcmp((char *)oldSk, (char *)newSk);
|
||||
cmpres = ucol_strcoll(coll, oldB, oldBlen, buffer, buflen);
|
||||
cmpres2 = ucol_strcoll(coll, buffer, buflen, oldB, oldBlen);
|
||||
|
||||
if(cmpres != -cmpres2) {
|
||||
errln("Compare result not symmetrical on line %i", line);
|
||||
}
|
||||
|
||||
if(((res&0x80000000) != (cmpres&0x80000000)) || (res == 0 && cmpres != 0) || (res != 0 && cmpres == 0)) {
|
||||
errln("Difference between ucol_strcoll and sortkey compare on line %i", line);
|
||||
logln("Data line %s", lineB);
|
||||
}
|
||||
|
||||
if(res > 0) {
|
||||
errln("Line %i is not greater or equal than previous line", line);
|
||||
logln("Data line %s", lineB);
|
||||
prettify(CollationKey(oldSk, oldLen), oldS);
|
||||
prettify(CollationKey(newSk, resLen), newS);
|
||||
logln("Keys: "+oldS+" and "+newS);
|
||||
} else if(res == 0) { /* equal */
|
||||
res = u_strcmpCodePointOrder(oldB, buffer);
|
||||
if (res == 0) {
|
||||
errln("Probable error in test file on line %i (comparing identical strings)", line);
|
||||
logln("Data line %s", lineB);
|
||||
} else if (res > 0) {
|
||||
errln("Sortkeys are identical, but code point comapare gives >0 on line %i", line);
|
||||
logln("Data line %s", lineB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oldSk = newSk;
|
||||
oldLen = resLen;
|
||||
|
||||
newSk = (newSk == sk1)?sk2:sk1;
|
||||
oldB = buffer;
|
||||
oldBlen = buflen;
|
||||
buffer = (buffer == b1)?b2:b1;
|
||||
}
|
||||
|
||||
oldSk = newSk;
|
||||
oldLen = resLen;
|
||||
|
||||
newSk = (newSk == sk1)?sk2:sk1;
|
||||
oldB = buffer;
|
||||
oldBlen = buflen;
|
||||
buffer = (buffer == b1)?b2:b1;
|
||||
}
|
||||
}
|
||||
|
||||
void UCAConformanceTest::TestTableNonIgnorable(/* par */) {
|
||||
setCollNonIgnorable(UCA);
|
||||
openTestFile("NON_IGNORABLE");
|
||||
testConformance(UCA);
|
||||
setCollNonIgnorable(UCA);
|
||||
openTestFile("NON_IGNORABLE");
|
||||
testConformance(UCA);
|
||||
}
|
||||
|
||||
void UCAConformanceTest::TestTableShifted(/* par */) {
|
||||
setCollShifted(UCA);
|
||||
openTestFile("SHIFTED");
|
||||
testConformance(UCA);
|
||||
setCollShifted(UCA);
|
||||
openTestFile("SHIFTED");
|
||||
testConformance(UCA);
|
||||
}
|
||||
|
||||
void UCAConformanceTest::TestRulesNonIgnorable(/* par */) {
|
||||
initRbUCA();
|
||||
initRbUCA();
|
||||
|
||||
if(U_SUCCESS(status)) {
|
||||
setCollNonIgnorable(rbUCA);
|
||||
openTestFile("NON_IGNORABLE");
|
||||
testConformance(rbUCA);
|
||||
}
|
||||
if(U_SUCCESS(status)) {
|
||||
setCollNonIgnorable(rbUCA);
|
||||
openTestFile("NON_IGNORABLE");
|
||||
testConformance(rbUCA);
|
||||
}
|
||||
}
|
||||
|
||||
void UCAConformanceTest::TestRulesShifted(/* par */) {
|
||||
logln("This test is currently disabled, as it is impossible to "
|
||||
"wholly represent fractional UCA using tailoring rules.");
|
||||
return;
|
||||
logln("This test is currently disabled, as it is impossible to "
|
||||
"wholly represent fractional UCA using tailoring rules.");
|
||||
return;
|
||||
|
||||
initRbUCA();
|
||||
initRbUCA();
|
||||
|
||||
if(U_SUCCESS(status)) {
|
||||
setCollShifted(rbUCA);
|
||||
openTestFile("SHIFTED");
|
||||
testConformance(rbUCA);
|
||||
}
|
||||
if(U_SUCCESS(status)) {
|
||||
setCollShifted(rbUCA);
|
||||
openTestFile("SHIFTED");
|
||||
testConformance(rbUCA);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_COLLATION */
|
||||
|
|
Loading…
Add table
Reference in a new issue