#include <stdlib.h>
#include "unicode/utypes.h"
#if !UCONFIG_NO_COLLATION
#include "unicode/ucol.h"
#include "unicode/uloc.h"
#include "cintltst.h"
#include "ccolltst.h"
#include "callcoll.h"
#include "cfrtst.h"
#include "unicode/ustring.h"
#include "string.h"
static UCollator *myCollation;
const static UChar testSourceCases[][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 static UChar testTargetCases[][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 static UCollationResult results[] =
{
UCOL_LESS,
UCOL_LESS,
UCOL_LESS,
UCOL_LESS,
UCOL_GREATER,
UCOL_GREATER,
UCOL_LESS,
UCOL_GREATER,
UCOL_LESS,
UCOL_GREATER,
UCOL_LESS,
UCOL_LESS
};
const static UChar testAcute[][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 static UChar testBugs[][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 addFrenchCollTest(TestNode** root)
{
addTest(root, &TestSecondary, "tscoll/cfrtst/TestSecondary");
addTest(root, &TestTertiary, "tscoll/cfrtst/TestTertiary");
addTest(root, &TestExtra, "tscoll/cfrtst/TestExtra");
}
static void TestTertiary( )
{
int32_t i;
UErrorCode status = U_ZERO_ERROR;
myCollation = ucol_open("fr_FR", &status);
if(U_FAILURE(status) || !myCollation){
log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
return;
}
ucol_setAttribute(myCollation, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
if(U_FAILURE(status)){
log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
return;
}
log_verbose("Testing French Collation with Tertiary strength\n");
ucol_setStrength(myCollation, UCOL_QUATERNARY);
for (i = 0; i < 12 ; i++)
{
doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
}
ucol_close(myCollation);
}
static void TestSecondary()
{
int32_t i,j, testAcuteSize;
UCollationResult expected=UCOL_EQUAL;
UErrorCode status = U_ZERO_ERROR;
myCollation = ucol_open("fr_FR", &status);
if(U_FAILURE(status)){
log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
return;
}
ucol_setAttribute(myCollation, UCOL_STRENGTH, UCOL_SECONDARY, &status);
if(U_FAILURE(status)){
log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
return;
}
log_verbose("Testing French Collation with Secondary strength\n");
testAcuteSize = sizeof(testAcute) / sizeof(testAcute[0]);
for (i = 0; i < testAcuteSize; i++)
{
for (j = 0; j < testAcuteSize; j++)
{
if (i < j) expected = UCOL_LESS;
if (i == j) expected = UCOL_EQUAL;
if (i > j) expected = UCOL_GREATER;
doTest(myCollation, testAcute[i], testAcute[j], expected );
}
}
ucol_close(myCollation);
}
static void TestExtra()
{
int32_t i, j;
UErrorCode status = U_ZERO_ERROR;
myCollation = ucol_open("fr_FR", &status);
if(U_FAILURE(status)){
log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
return;
}
log_verbose("Testing French Collation extra with secondary strength\n");
ucol_setStrength(myCollation, UCOL_TERTIARY);
for (i = 0; i < 9 ; i++)
{
for (j = i + 1; j < 10; j += 1)
{
doTest(myCollation, testBugs[i], testBugs[j], UCOL_LESS);
}
}
ucol_close(myCollation);
}
#endif