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 _FRCOLL
|
|
|
|
#include "frcoll.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CollationFrenchTest::CollationFrenchTest()
|
|
|
|
: myCollation(0)
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
myCollation = Collator::createInstance(Locale::FRANCE, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
CollationFrenchTest::~CollationFrenchTest()
|
|
|
|
{
|
|
|
|
delete myCollation;
|
|
|
|
}
|
|
|
|
|
|
|
|
const UChar CollationFrenchTest::testSourceCases[][CollationFrenchTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x61, 0x62, 0x63, 0},
|
|
|
|
{0x43, 0x4f, 0x54, 0x45, 0},
|
|
|
|
{0x63, 0x6f, 0x2d, 0x6f, 0x70, 0},
|
|
|
|
{0x70, 0x00EA, 0x63, 0x68, 0x65, 0},
|
|
|
|
{0x70, 0x00EA, 0x63, 0x68, 0x65, 0x72, 0},
|
|
|
|
{0x70, 0x00E9, 0x63, 0x68, 0x65, 0x72, 0},
|
|
|
|
{0x70, 0x00E9, 0x63, 0x68, 0x65, 0x72, 0},
|
|
|
|
{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0},
|
1999-08-16 21:50:52 +00:00
|
|
|
{0x01f1, 0},
|
|
|
|
{0xfb00, 0},
|
|
|
|
{0x01fa, 0},
|
|
|
|
{0x0101, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
const UChar CollationFrenchTest::testTargetCases[][CollationFrenchTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x41, 0x42, 0x43, 0},
|
|
|
|
{0x63, 0x00f4, 0x74, 0x65, 0},
|
|
|
|
{0x43, 0x4f, 0x4f, 0x50, 0},
|
|
|
|
{0x70, 0x00E9, 0x63, 0x68, 0x00E9, 0},
|
|
|
|
{0x70, 0x00E9, 0x63, 0x68, 0x00E9, 0},
|
|
|
|
{0x70, 0x00EA, 0x63, 0x68, 0x65, 0},
|
|
|
|
{0x70, 0x00EA, 0x63, 0x68, 0x65, 0x72, 0},
|
|
|
|
{0x68, 0x65, 0x6c, 0x6c, 0x4f, 0},
|
1999-08-16 21:50:52 +00:00
|
|
|
{0x01ee, 0},
|
|
|
|
{0x25ca, 0},
|
|
|
|
{0x00e0, 0},
|
|
|
|
{0x01df, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
const Collator::EComparisonResult CollationFrenchTest::results[] =
|
|
|
|
{
|
|
|
|
Collator::LESS,
|
|
|
|
Collator::LESS,
|
|
|
|
Collator::GREATER,
|
|
|
|
Collator::LESS,
|
|
|
|
Collator::GREATER,
|
|
|
|
Collator::GREATER,
|
|
|
|
Collator::LESS,
|
|
|
|
Collator::GREATER,
|
|
|
|
Collator::GREATER,
|
|
|
|
Collator::GREATER,
|
|
|
|
Collator::GREATER,
|
|
|
|
Collator::GREATER
|
|
|
|
};
|
|
|
|
|
|
|
|
// 0x0300 is grave, 0x0301 is acute
|
|
|
|
// the order of elements in this array must be different than the order in CollationEnglishTest
|
|
|
|
const UChar CollationFrenchTest::testAcute[][CollationFrenchTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x65, 0x65, 0},
|
|
|
|
{0x65, 0x0301, 0x65, 0},
|
|
|
|
{0x65, 0x0301, 0x0300, 0x65, 0},
|
|
|
|
{0x65, 0x0300, 0x65, 0},
|
|
|
|
{0x65, 0x0300, 0x0301, 0x65, 0},
|
|
|
|
{0x65, 0x65, 0x0301, 0},
|
|
|
|
{0x65, 0x0301, 0x65, 0x0301, 0},
|
|
|
|
{0x65, 0x0301, 0x0300, 0x65, 0x0301, 0},
|
|
|
|
{0x65, 0x0300, 0x65, 0x0301, 0},
|
|
|
|
{0x65, 0x0300, 0x0301, 0x65, 0x0301, 0},
|
|
|
|
{0x65, 0x65, 0x0301, 0x0300, 0},
|
|
|
|
{0x65, 0x0301, 0x65, 0x0301, 0x0300, 0},
|
|
|
|
{0x65, 0x0301, 0x0300, 0x65, 0x0301, 0x0300, 0},
|
|
|
|
{0x65, 0x0300, 0x65, 0x0301, 0x0300, 0},
|
|
|
|
{0x65, 0x0300, 0x0301, 0x65, 0x0301, 0x0300, 0},
|
|
|
|
{0x65, 0x65, 0x0300, 0},
|
|
|
|
{0x65, 0x0301, 0x65, 0x0300, 0},
|
|
|
|
{0x65, 0x0301, 0x0300, 0x65, 0x0300, 0},
|
|
|
|
{0x65, 0x0300, 0x65, 0x0300, 0},
|
|
|
|
{0x65, 0x0300, 0x0301, 0x65, 0x0300, 0},
|
|
|
|
{0x65, 0x65, 0x0300, 0x0301, 0},
|
|
|
|
{0x65, 0x0301, 0x65, 0x0300, 0x0301, 0},
|
|
|
|
{0x65, 0x0301, 0x0300, 0x65, 0x0300, 0x0301, 0},
|
|
|
|
{0x65, 0x0300, 0x65, 0x0300, 0x0301, 0},
|
|
|
|
{0x65, 0x0300, 0x0301, 0x65, 0x0300, 0x0301, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const UChar CollationFrenchTest::testBugs[][CollationFrenchTest::MAX_TOKEN_LEN] =
|
|
|
|
{
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x61, 0},
|
|
|
|
{0x41, 0},
|
|
|
|
{0x65, 0},
|
|
|
|
{0x45, 0},
|
1999-08-16 21:50:52 +00:00
|
|
|
{0x00e9, 0},
|
|
|
|
{0x00e8, 0},
|
|
|
|
{0x00ea, 0},
|
|
|
|
{0x00eb, 0},
|
2000-03-22 23:17:42 +00:00
|
|
|
{0x65, 0x61, 0},
|
|
|
|
{0x78, 0}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void CollationFrenchTest::doTest( 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 );
|
|
|
|
}
|
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationFrenchTest::TestTertiary(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
int32_t i = 0;
|
|
|
|
myCollation->setStrength(Collator::TERTIARY);
|
|
|
|
for (i = 0; i < 12 ; i++)
|
|
|
|
{
|
|
|
|
doTest(testSourceCases[i], testTargetCases[i], results[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationFrenchTest::TestSecondary(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
//test acute and grave ordering
|
|
|
|
int32_t i = 0;
|
|
|
|
int32_t j;
|
|
|
|
Collator::EComparisonResult expected;
|
|
|
|
const int32_t testAcuteSize = sizeof(testAcute) / sizeof(testAcute[0]);
|
|
|
|
for (i = 0; i < testAcuteSize; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < testAcuteSize; j++)
|
|
|
|
{
|
2000-08-14 21:42:36 +00:00
|
|
|
if (i < j)
|
|
|
|
expected = Collator::LESS;
|
|
|
|
else if (i == j)
|
|
|
|
expected = Collator::EQUAL;
|
|
|
|
else // (i > j)
|
|
|
|
expected = Collator::GREATER;
|
1999-08-16 21:50:52 +00:00
|
|
|
doTest(testAcute[i], testAcute[j], expected );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationFrenchTest::TestExtra(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
int32_t i, j;
|
|
|
|
myCollation->setStrength(Collator::TERTIARY);
|
|
|
|
for (i = 0; i < 9 ; i++)
|
|
|
|
{
|
|
|
|
for (j = i + 1; j < 10; j += 1)
|
|
|
|
{
|
|
|
|
doTest(testBugs[i], testBugs[j], Collator::LESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void CollationFrenchTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (exec) logln("TestSuite CollationFrenchTest: ");
|
|
|
|
switch (index) {
|
2000-08-23 19:11:16 +00:00
|
|
|
case 0: name = "TestSecondary"; if (exec) TestSecondary(/* par */); break;
|
|
|
|
case 1: name = "TestTertiary"; if (exec) TestTertiary(/* par */); break;
|
|
|
|
case 2: name = "TestExtra"; if (exec) TestExtra(/* par */); break;
|
1999-08-16 21:50:52 +00:00
|
|
|
default: name = ""; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|