2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
|
|
|
* Copyright (c) 1997-1999, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#ifndef _COLL
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/coll.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _TBLCOLL
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/tblcoll.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _UNISTR
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/unistr.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SORTKEY
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/sortkey.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _G7COLL
|
|
|
|
#include "g7coll.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const Locale G7CollationTest::locales[8] = {
|
|
|
|
Locale("en", "US", ""),
|
|
|
|
Locale("en", "GB", ""),
|
|
|
|
Locale("en", "CA", ""),
|
|
|
|
Locale("fr", "FR", ""),
|
|
|
|
Locale("fr", "CA", ""),
|
|
|
|
Locale("de", "DE", ""),
|
|
|
|
Locale("it", "IT", ""),
|
|
|
|
Locale("ja", "JP", "")
|
|
|
|
};
|
|
|
|
|
|
|
|
const UChar G7CollationTest::testCases[][G7CollationTest::MAX_TOKEN_LEN] = {
|
2000-03-22 23:17:42 +00:00
|
|
|
{ 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x2d, 0x62, 0x69, 0x72, 0x64, 0x73, 0}, // 0
|
|
|
|
{ 0x50, 0x61, 0x74, 0}, // 1
|
|
|
|
{ 0x70, 0x00E9, 0x63, 0x68, 0x00E9, 0}, // 2
|
|
|
|
{ 0x70, 0x00EA, 0x63, 0x68, 0x65, 0}, // 3
|
|
|
|
{ 0x70, 0x00E9, 0x63, 0x68, 0x65, 0x72, 0}, // 4
|
|
|
|
{ 0x70, 0x00EA, 0x63, 0x68, 0x65, 0x72, 0}, // 5
|
|
|
|
{ 0x54, 0x6f, 0x64, 0}, // 6
|
|
|
|
{ 0x54, 0x00F6, 0x6e, 0x65, 0}, // 7
|
|
|
|
{ 0x54, 0x6f, 0x66, 0x75, 0}, // 8
|
|
|
|
{ 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x62, 0x69, 0x72, 0x64, 0x73, 0}, // 9
|
|
|
|
{ 0x54, 0x6f, 0x6e, 0}, // 10
|
|
|
|
{ 0x50, 0x41, 0x54, 0}, // 11
|
|
|
|
{ 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x62, 0x69, 0x72, 0x64, 0}, // 12
|
|
|
|
{ 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x2d, 0x62, 0x69, 0x72, 0x64, 0}, // 13
|
|
|
|
{ 0x70, 0x61, 0x74, 0}, // 14
|
1999-08-16 21:50:52 +00:00
|
|
|
// Additional tests
|
2000-03-22 23:17:42 +00:00
|
|
|
{ 0x63, 0x7a, 0x61, 0x72, 0 }, // 15
|
|
|
|
{ 0x63, 0x68, 0x75, 0x72, 0x6f, 0 }, // 16
|
|
|
|
{ 0x63, 0x61, 0x74, 0 }, // 17
|
|
|
|
{ 0x64, 0x61, 0x72, 0x6e, 0 }, // 18
|
|
|
|
{ 0x3f, 0 }, // 19
|
|
|
|
{ 0x71, 0x75, 0x69, 0x63, 0x6b, 0 }, // 20
|
|
|
|
{ 0x23, 0 }, // 21
|
|
|
|
{ 0x26, 0 }, // 22
|
|
|
|
{ 0x61, 0x61, 0x72, 0x64, 0x76, 0x61, 0x72, 0x6b, 0}, // 23
|
|
|
|
{ 0x61, 0x2d, 0x72, 0x64, 0x76, 0x61, 0x72, 0x6b, 0}, // 24
|
|
|
|
{ 0x61, 0x62, 0x62, 0x6f, 0x74, 0}, // 25
|
|
|
|
{ 0x63, 0x6f, 0x6f, 0x70, 0}, // 26
|
|
|
|
{ 0x63, 0x6f, 0x2d, 0x70, 0}, // 27
|
|
|
|
{ 0x63, 0x6f, 0x70, 0}, // 28
|
|
|
|
{ 0x7a, 0x65, 0x62, 0x72, 0x61, 0} // 29
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const int32_t G7CollationTest::results[G7CollationTest::TESTLOCALES][G7CollationTest::TOTALTESTSET] = {
|
|
|
|
{ 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
|
|
|
|
{ 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
|
|
|
|
{ 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
|
|
|
|
{ 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
|
|
|
|
{ 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 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void G7CollationTest::doTest( Collator* myCollation, UnicodeString source, UnicodeString target, Collator::EComparisonResult result)
|
|
|
|
{
|
|
|
|
Collator::EComparisonResult compareResult = myCollation->compare(source, target);
|
|
|
|
CollationKey sortKey1, sortKey2;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode key1status = U_ZERO_ERROR, key2status = U_ZERO_ERROR; //nos
|
1999-08-16 21:50:52 +00:00
|
|
|
myCollation->getCollationKey(source, /*nos*/ sortKey1, key1status );
|
|
|
|
myCollation->getCollationKey(target, /*nos*/ sortKey2, key2status );
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(key1status) || U_FAILURE(key2status)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("SortKey generation Failed.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Collator::EComparisonResult keyResult = sortKey1.compareTo(sortKey2);
|
|
|
|
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
|
|
|
|
}
|
|
|
|
|
|
|
|
void G7CollationTest::TestG7Locales( char* par )
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
Collator *myCollation= 0;
|
|
|
|
UnicodeString dispName;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
RuleBasedCollator* tblColl1 = 0;
|
|
|
|
|
|
|
|
myCollation = Collator::createInstance(locales[i], status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UnicodeString msg;
|
|
|
|
|
|
|
|
msg += "Locale ";
|
|
|
|
msg += locales[i].getDisplayName(dispName);
|
|
|
|
msg += "creation failed.";
|
|
|
|
|
|
|
|
errln(msg);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const UnicodeString& defRules = ((RuleBasedCollator*)myCollation)->getRules();
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
tblColl1 = new RuleBasedCollator(((RuleBasedCollator*)myCollation)->getRules(), status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UnicodeString msg, name;
|
|
|
|
|
|
|
|
msg += "Recreate ";
|
|
|
|
msg += locales[i].getDisplayName(name);
|
|
|
|
msg += "collation failed.";
|
|
|
|
|
|
|
|
errln(msg);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString msg;
|
|
|
|
|
|
|
|
msg += "Locale ";
|
|
|
|
msg += locales[i].getDisplayName(dispName);
|
|
|
|
msg += "tests start :";
|
|
|
|
logln(msg);
|
|
|
|
|
|
|
|
int32_t j = 0, n = 0;
|
|
|
|
for (j = 0; j < FIXEDTESTSET; j++)
|
|
|
|
{
|
|
|
|
for (n = j+1; n < FIXEDTESTSET; n++)
|
|
|
|
{
|
|
|
|
doTest(tblColl1, testCases[results[i][j]], testCases[results[i][n]], Collator::LESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete myCollation;
|
|
|
|
delete tblColl1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void G7CollationTest::TestDemo1( char* par )
|
|
|
|
{
|
|
|
|
logln("Demo Test 1 : Create a new table collation with rules \"& Z < p, P\"");
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
Collator *col = Collator::createInstance(status);
|
|
|
|
const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules();
|
|
|
|
UnicodeString newRules(" & Z < p, P");
|
|
|
|
newRules.insert(0, baseRules);
|
|
|
|
RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln( "Demo Test 1 Table Collation object creation failed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t j = 0, n = 0;
|
|
|
|
for (j = 0; j < FIXEDTESTSET; j++)
|
|
|
|
{
|
|
|
|
for (n = j+1; n < FIXEDTESTSET; n++)
|
|
|
|
{
|
|
|
|
doTest(myCollation, testCases[results[8][j]], testCases[results[8][n]], Collator::LESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete myCollation;
|
|
|
|
delete col;
|
|
|
|
}
|
|
|
|
|
|
|
|
void G7CollationTest::TestDemo2( char* par )
|
|
|
|
{
|
|
|
|
logln("Demo Test 2 : Create a new table collation with rules \"& C < ch , cH, Ch, CH\"");
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
Collator *col = Collator::createInstance(status);
|
|
|
|
const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules();
|
|
|
|
UnicodeString newRules("& C < ch , cH, Ch, CH");
|
|
|
|
newRules.insert(0, baseRules);
|
|
|
|
RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Demo Test 2 Table Collation object creation failed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t j = 0;
|
|
|
|
for (j; j < TOTALTESTSET; j++)
|
|
|
|
{
|
|
|
|
for (int32_t n = j+1; n < TOTALTESTSET; n++)
|
|
|
|
{
|
|
|
|
doTest(myCollation, testCases[results[9][j]], testCases[results[9][n]], Collator::LESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete myCollation;
|
|
|
|
delete col;
|
|
|
|
}
|
|
|
|
|
|
|
|
void G7CollationTest::TestDemo3( char* par )
|
|
|
|
{
|
|
|
|
logln("Demo Test 3 : Create a new table collation with rules \"& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'\"");
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
Collator *col = Collator::createInstance(status);
|
|
|
|
const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules();
|
|
|
|
UnicodeString newRules = "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'";
|
|
|
|
newRules.insert(0, baseRules);
|
|
|
|
RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln("Demo Test 3 Table Collation object creation failed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t j = 0;
|
|
|
|
for (j = 0; j < TOTALTESTSET; j++)
|
|
|
|
{
|
|
|
|
for (int32_t n = j+1; n < TOTALTESTSET; n++)
|
|
|
|
{
|
|
|
|
doTest(myCollation, testCases[results[10][j]], testCases[results[10][n]], Collator::LESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete myCollation;
|
|
|
|
delete col;
|
|
|
|
}
|
|
|
|
|
|
|
|
void G7CollationTest::TestDemo4( char* par )
|
|
|
|
{
|
|
|
|
logln("Demo Test 4 : Create a new table collation with rules \" & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' \"");
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
Collator *col = Collator::createInstance(status);
|
|
|
|
const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules();
|
|
|
|
UnicodeString newRules = " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' ";
|
|
|
|
newRules.insert(0, baseRules);
|
|
|
|
RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
errln( "Demo Test 4 Table Collation object creation failed." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t j;
|
|
|
|
for (j = 0; j < TOTALTESTSET; j++)
|
|
|
|
{
|
|
|
|
for (int32_t n = j+1; n < TOTALTESTSET; n++)
|
|
|
|
{
|
|
|
|
doTest(myCollation, testCases[results[11][j]], testCases[results[11][n]], Collator::LESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete myCollation;
|
|
|
|
delete col;
|
|
|
|
}
|
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
void G7CollationTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (exec) logln("TestSuite G7CollationTest: ");
|
|
|
|
switch (index) {
|
|
|
|
case 0: name = "TestG7Locales"; if (exec) TestG7Locales( par ); break;
|
|
|
|
case 1: name = "TestDemo1"; if (exec) TestDemo1( par ); break;
|
|
|
|
case 2: name = "TestDemo2"; if (exec) TestDemo2( par ); break;
|
|
|
|
case 3: name = "TestDemo3"; if (exec) TestDemo3( par ); break;
|
|
|
|
case 4: name = "TestDemo4"; if (exec) TestDemo4( par ); break;
|
|
|
|
default: name = ""; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|