#include "unicode/utypes.h"
#if !UCONFIG_NO_COLLATION
#include "unicode/coll.h"
#include "unicode/tblcoll.h"
#include "unicode/unistr.h"
#include "unicode/sortkey.h"
#include "frcoll.h"
#include "sfwdchit.h"
CollationFrenchTest::CollationFrenchTest()
: myCollation(0)
{
UErrorCode status = U_ZERO_ERROR;
myCollation = Collator::createInstance(Locale::getFrance(), status);
if(!myCollation || U_FAILURE(status)) {
errln(__FILE__ "failed to create! err " + UnicodeString(u_errorName(status)));
delete myCollation;
myCollation = NULL;
}
}
CollationFrenchTest::~CollationFrenchTest()
{
delete myCollation;
}
const UChar CollationFrenchTest::testSourceCases[][CollationFrenchTest::MAX_TOKEN_LEN] =
{
{0x0061, 0x0062, 0x0063, 0x0000},
{0x0043, 0x004f, 0x0054, 0x0045, 0x0000},
{0x0063, 0x006f, 0x002d, 0x006f, 0x0070, 0x0000},
{0x0070, 0x00EA, 0x0063, 0x0068, 0x0065, 0x0000},
{0x0070, 0x00EA, 0x0063, 0x0068, 0x0065, 0x0072, 0x0000},
{0x0070, 0x00E9, 0x0063, 0x0068, 0x0065, 0x0072, 0x0000},
{0x0070, 0x00E9, 0x0063, 0x0068, 0x0065, 0x0072, 0x0000},
{0x0048, 0x0065, 0x006c, 0x006c, 0x006f, 0x0000},
{0x01f1, 0x0000},
{0xfb00, 0x0000},
{0x01fa, 0x0000},
{0x0101, 0x0000}
};
const UChar CollationFrenchTest::testTargetCases[][CollationFrenchTest::MAX_TOKEN_LEN] =
{
{0x0041, 0x0042, 0x0043, 0x0000},
{0x0063, 0x00f4, 0x0074, 0x0065, 0x0000},
{0x0043, 0x004f, 0x004f, 0x0050, 0x0000},
{0x0070, 0x00E9, 0x0063, 0x0068, 0x00E9, 0x0000},
{0x0070, 0x00E9, 0x0063, 0x0068, 0x00E9, 0x0000},
{0x0070, 0x00EA, 0x0063, 0x0068, 0x0065, 0x0000},
{0x0070, 0x00EA, 0x0063, 0x0068, 0x0065, 0x0072, 0x0000},
{0x0068, 0x0065, 0x006c, 0x006c, 0x004f, 0x0000},
{0x01ee, 0x0000},
{0x25ca, 0x0000},
{0x00e0, 0x0000},
{0x01df, 0x0000}
};
const Collator::EComparisonResult CollationFrenchTest::results[] =
{
Collator::LESS,
Collator::LESS,
Collator::LESS,
Collator::LESS,
Collator::GREATER,
Collator::GREATER,
Collator::LESS,
Collator::GREATER,
Collator::LESS,
Collator::GREATER,
Collator::LESS,
Collator::LESS
};
const UChar CollationFrenchTest::testAcute[][CollationFrenchTest::MAX_TOKEN_LEN] =
{
{0x0065, 0x0065, 0x0000},
{0x0065, 0x0301, 0x0065, 0x0000},
{0x0065, 0x0300, 0x0301, 0x0065, 0x0000},
{0x0065, 0x0300, 0x0065, 0x0000},
{0x0065, 0x0301, 0x0300, 0x0065, 0x0000},
{0x0065, 0x0065, 0x0301, 0x0000},
{0x0065, 0x0301, 0x0065, 0x0301, 0x0000},
{0x0065, 0x0300, 0x0301, 0x0065, 0x0301, 0x0000},
{0x0065, 0x0300, 0x0065, 0x0301, 0x0000},
{0x0065, 0x0301, 0x0300, 0x0065, 0x0301, 0x0000},
{0x0065, 0x0065, 0x0300, 0x0301, 0x0000},
{0x0065, 0x0301, 0x0065, 0x0300, 0x0301, 0x0000},
{0x0065, 0x0300, 0x0301, 0x0065, 0x0300, 0x0301, 0x0000},
{0x0065, 0x0300, 0x0065, 0x0300, 0x0301, 0x0000},
{0x0065, 0x0301, 0x0300, 0x0065, 0x0300, 0x0301, 0x0000},
{0x0065, 0x0065, 0x0300, 0x0000},
{0x0065, 0x0301, 0x0065, 0x0300, 0x0000},
{0x0065, 0x0300, 0x0301, 0x0065, 0x0300, 0x0000},
{0x0065, 0x0300, 0x0065, 0x0300, 0x0000},
{0x0065, 0x0301, 0x0300, 0x0065, 0x0300, 0x0000},
{0x0065, 0x0065, 0x0301, 0x0300, 0x0000},
{0x0065, 0x0301, 0x0065, 0x0301, 0x0300, 0x0000},
{0x0065, 0x0300, 0x0301, 0x0065, 0x0301, 0x0300, 0x0000},
{0x0065, 0x0300, 0x0065, 0x0301, 0x0300, 0x0000},
{0x0065, 0x0301, 0x0300, 0x0065, 0x0301, 0x0300, 0x0000}
};
const UChar CollationFrenchTest::testBugs[][CollationFrenchTest::MAX_TOKEN_LEN] =
{
{0x0061, 0x000},
{0x0041, 0x000},
{0x0065, 0x000},
{0x0045, 0x000},
{0x00e9, 0x000},
{0x00e8, 0x000},
{0x00ea, 0x000},
{0x00eb, 0x000},
{0x0065, 0x0061, 0x000},
{0x0078, 0x000}
};
void CollationFrenchTest::TestTertiary()
{
int32_t i = 0;
UErrorCode status = U_ZERO_ERROR;
myCollation->setStrength(Collator::TERTIARY);
myCollation->setAttribute(UCOL_FRENCH_COLLATION, UCOL_ON, status);
myCollation->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status);
if (U_FAILURE(status)) {
errln("Error setting attribute in French collator");
}
else
{
for (i = 0; i < 12 ; i++)
{
doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
}
}
}
void CollationFrenchTest::TestSecondary()
{
int32_t i = 0;
int32_t j;
Collator::EComparisonResult expected;
UErrorCode status = U_ZERO_ERROR;
myCollation->setStrength(Collator::SECONDARY);
if (U_FAILURE(status))
errln("Error setting attribute in French collator");
else
{
const int32_t testAcuteSize = (int32_t)(sizeof(testAcute) / sizeof(testAcute[0]));
for (i = 0; i < testAcuteSize; i++)
{
for (j = 0; j < testAcuteSize; j++)
{
if (i < j)
expected = Collator::LESS;
else if (i == j)
expected = Collator::EQUAL;
else expected = Collator::GREATER;
doTest(myCollation, testAcute[i], testAcute[j], expected );
}
}
}
}
void CollationFrenchTest::TestExtra()
{
int32_t i, j;
myCollation->setStrength(Collator::TERTIARY);
for (i = 0; i < 9 ; i++)
{
for (j = i + 1; j < 10; j += 1)
{
doTest(myCollation, testBugs[i], testBugs[j], Collator::LESS);
}
}
}
void CollationFrenchTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* )
{
if (exec) logln("TestSuite CollationFrenchTest: ");
if((!myCollation) && exec) {
errln(__FILE__ " cannot test - failed to create collator.");
name = "some test";
return;
}
switch (index) {
case 0: name = "TestSecondary"; if (exec) TestSecondary(); break;
case 1: name = "TestTertiary"; if (exec) TestTertiary(); break;
case 2: name = "TestExtra"; if (exec) TestExtra(); break;
default: name = ""; break;
}
}
#endif