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
|
|
|
*
|
|
|
|
* File CESTST.C
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
* Name Description
|
1999-10-18 22:48:32 +00:00
|
|
|
* Madhu Katragadda Ported for C API
|
2000-08-14 23:35:57 +00:00
|
|
|
*********************************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* CollationSpanishTest is a third level test class. This tests the locale
|
|
|
|
* specific primary, secondary and tertiary rules. For example, the ignorable
|
|
|
|
* character '-' in string "black-bird". The en_US locale uses the default
|
|
|
|
* collation rules as its sorting sequence.
|
|
|
|
*/
|
|
|
|
|
2000-08-28 21:43:03 +00:00
|
|
|
#include <stdlib.h>
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/ucol.h"
|
|
|
|
#include "unicode/uloc.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cintltst.h"
|
|
|
|
#include "cestst.h"
|
|
|
|
#include "ccolltst.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "string.h"
|
1999-12-22 22:57:04 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
static UCollator *myCollation;
|
|
|
|
const static UChar testSourceCases[][MAX_TOKEN_LEN] = {
|
|
|
|
{0x0062/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
|
|
|
|
{0x0045/*'E'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000},
|
|
|
|
{0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
|
|
|
|
{0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
|
|
|
|
{0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000},
|
|
|
|
{0x0061/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
|
|
|
|
{0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
|
|
|
|
{0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000},
|
|
|
|
{0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
|
|
|
|
};
|
|
|
|
|
|
|
|
const static UChar testTargetCases[][MAX_TOKEN_LEN] = {
|
|
|
|
{0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
|
|
|
|
{0x0045/*'E'*/, 0x006d/*'m'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000},
|
|
|
|
{0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000},
|
|
|
|
{0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
|
|
|
|
{0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
|
|
|
|
{0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
|
|
|
|
{0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
|
|
|
|
{0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
|
|
|
|
{0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000},
|
|
|
|
};
|
|
|
|
|
|
|
|
const static UCollationResult results[] = {
|
|
|
|
UCOL_LESS,
|
|
|
|
UCOL_LESS,
|
|
|
|
UCOL_GREATER,
|
|
|
|
UCOL_LESS,
|
|
|
|
UCOL_LESS,
|
|
|
|
/* test primary > 5*/
|
|
|
|
UCOL_LESS,
|
|
|
|
UCOL_EQUAL,
|
|
|
|
UCOL_LESS,
|
|
|
|
UCOL_EQUAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void addSpanishCollTest(TestNode** root)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
addTest(root, &TestPrimary, "tscoll/cestst/TestPrimary");
|
|
|
|
addTest(root, &TestTertiary, "tscoll/cestst/TestTertiary");
|
|
|
|
|
|
|
|
}
|
2000-11-21 04:05:39 +00:00
|
|
|
|
|
|
|
static void doTest(UCollator* myCollation, const UChar source[], const UChar target[], UCollationResult result)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-06-12 22:42:50 +00:00
|
|
|
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
|
|
|
int32_t temp;
|
1999-08-16 21:50:52 +00:00
|
|
|
UCollationResult compareResult, keyResult;
|
|
|
|
uint8_t *sortKey1, *sortKey2;
|
|
|
|
|
|
|
|
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
|
|
|
|
2000-06-12 22:42:50 +00:00
|
|
|
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
|
|
|
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
|
|
|
|
|
|
|
sortklenmax = (sortklen1>sortklen2?sortklen1:sortklen2);
|
|
|
|
sortklenmin = (sortklen1<sortklen2?sortklen1:sortklen2);
|
|
|
|
|
|
|
|
sortKey1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklenmax+1));
|
|
|
|
ucol_getSortKey(myCollation, source, u_strlen(source), sortKey1, sortklen1+1);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-06-12 22:42:50 +00:00
|
|
|
sortKey2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklenmax+1));
|
|
|
|
ucol_getSortKey(myCollation, target, u_strlen(target), sortKey2, sortklen2+1);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
2000-06-12 22:42:50 +00:00
|
|
|
temp= memcmp(sortKey1, sortKey2, sortklenmin);
|
1999-08-16 21:50:52 +00:00
|
|
|
if(temp < 0) keyResult=UCOL_LESS;
|
|
|
|
else if(temp > 0) keyResult= UCOL_GREATER;
|
|
|
|
else keyResult = UCOL_EQUAL;
|
|
|
|
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
|
2000-06-12 22:42:50 +00:00
|
|
|
free(sortKey1);
|
|
|
|
free(sortKey2);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestTertiary( )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int32_t i;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
myCollation = ucol_open("es_ES", &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
log_verbose("Testing Spanish Collation with Tertiary strength\n");
|
|
|
|
ucol_setStrength(myCollation, UCOL_TERTIARY);
|
|
|
|
for (i = 0; i < 5 ; i++)
|
|
|
|
{
|
|
|
|
doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
|
|
|
|
}
|
|
|
|
ucol_close(myCollation);
|
|
|
|
}
|
|
|
|
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestPrimary()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int32_t i;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
myCollation = ucol_open("es_ES", &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
1999-08-16 21:50:52 +00:00
|
|
|
log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
log_verbose("Testing Spanish Collation with Primary strength\n");
|
|
|
|
ucol_setStrength(myCollation, UCOL_PRIMARY);
|
|
|
|
for (i = 5; i < 9; i++)
|
|
|
|
{
|
|
|
|
doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
|
|
|
|
}
|
|
|
|
ucol_close(myCollation);
|
|
|
|
}
|
|
|
|
|