2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2001-03-21 19:46:49 +00:00
|
|
|
* Copyright (c) 1997-2001, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
/********************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File CCOLLTST.C
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
* Name Description
|
|
|
|
* Madhu Katragadda Creation
|
|
|
|
*********************************************************************************
|
|
|
|
*/
|
2000-08-28 21:43:03 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cintltst.h"
|
|
|
|
#include "ccolltst.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ucol.h"
|
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-04-03 00:32:05 +00:00
|
|
|
UChar U_CALLCONV testInc(void *context);
|
2001-03-02 00:42:43 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void addCollTest(TestNode** root)
|
|
|
|
{
|
|
|
|
addCollAPITest(root);
|
|
|
|
addCurrencyTest(root);
|
|
|
|
addNormTest(root);
|
|
|
|
addDanishCollTest(root);
|
|
|
|
addGermanCollTest(root);
|
|
|
|
addSpanishCollTest(root);
|
|
|
|
addFrenchCollTest(root);
|
|
|
|
addKannaCollTest(root);
|
|
|
|
addTurkishCollTest(root);
|
|
|
|
addEnglishCollTest(root);
|
2001-04-03 00:32:05 +00:00
|
|
|
addFinnishCollTest(root);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-26 00:12:23 +00:00
|
|
|
/* WEIVTODO: return tests here */
|
2001-02-27 07:28:58 +00:00
|
|
|
addRuleBasedCollTest(root);
|
|
|
|
addCollIterTest(root);
|
|
|
|
addAllCollTest(root);
|
2001-03-03 02:03:05 +00:00
|
|
|
addMiscCollTest(root);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*Internal functions used*/
|
|
|
|
|
|
|
|
void reportCResult( const UChar source[], const UChar target[],
|
|
|
|
uint8_t *sourceKey, uint8_t *targetKey,
|
|
|
|
UCollationResult compareResult,
|
|
|
|
UCollationResult keyResult,
|
2000-12-12 21:35:26 +00:00
|
|
|
UCollationResult incResult,
|
1999-08-16 21:50:52 +00:00
|
|
|
UCollationResult expectedResult )
|
|
|
|
{
|
|
|
|
UChar *sResult, *sExpect;
|
|
|
|
sResult=(UChar*)malloc(sizeof(UChar) * 10);
|
|
|
|
sExpect=(UChar*)malloc(sizeof(UChar) * 10);
|
|
|
|
if (expectedResult < -1 || expectedResult > 1)
|
|
|
|
{
|
|
|
|
log_err("***** invalid call to reportCResult ****\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compareResult != expectedResult)
|
|
|
|
{
|
|
|
|
|
|
|
|
appendCompareResult(compareResult, sResult);
|
|
|
|
appendCompareResult(expectedResult, sExpect);
|
2001-03-13 23:43:54 +00:00
|
|
|
log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source), aescstrdup(target),
|
1999-08-16 21:50:52 +00:00
|
|
|
austrdup(sResult), austrdup(sExpect) );
|
|
|
|
}
|
|
|
|
|
2000-12-12 21:35:26 +00:00
|
|
|
if (incResult != expectedResult)
|
|
|
|
{
|
|
|
|
|
2001-02-06 06:50:16 +00:00
|
|
|
appendCompareResult(incResult, sResult);
|
2000-12-12 21:35:26 +00:00
|
|
|
appendCompareResult(expectedResult, sExpect);
|
2001-03-13 23:43:54 +00:00
|
|
|
log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source), aescstrdup(target),
|
2000-12-12 21:35:26 +00:00
|
|
|
austrdup(sResult), austrdup(sExpect) );
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if (keyResult != expectedResult)
|
|
|
|
{
|
|
|
|
|
|
|
|
appendCompareResult(keyResult, sResult);
|
|
|
|
appendCompareResult(expectedResult, sExpect);
|
|
|
|
|
2001-03-13 23:43:54 +00:00
|
|
|
log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source), aescstrdup(target),
|
1999-08-16 21:50:52 +00:00
|
|
|
austrdup(sResult), austrdup(sExpect) );
|
|
|
|
|
|
|
|
|
2000-12-05 01:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (keyResult != compareResult)
|
|
|
|
{
|
|
|
|
|
|
|
|
appendCompareResult(keyResult, sResult);
|
|
|
|
appendCompareResult(compareResult, sExpect);
|
|
|
|
|
2001-03-13 23:43:54 +00:00
|
|
|
log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source), aescstrdup(target),
|
2000-12-05 01:04:44 +00:00
|
|
|
austrdup(sResult), austrdup(sExpect) );
|
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
free(sExpect);
|
|
|
|
free(sResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar* appendCompareResult(UCollationResult result, UChar* target)
|
|
|
|
{
|
|
|
|
if (result == UCOL_LESS)
|
|
|
|
{
|
|
|
|
u_uastrcpy(target, "LESS");
|
|
|
|
}
|
|
|
|
else if (result == UCOL_EQUAL)
|
|
|
|
{
|
|
|
|
u_uastrcpy(target, "EQUAL");
|
|
|
|
}
|
|
|
|
else if (result == UCOL_GREATER)
|
|
|
|
{
|
|
|
|
u_uastrcpy(target, "GREATER");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u_uastrcpy(target, "huh???");
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2000-07-16 13:42:38 +00:00
|
|
|
UChar* CharsToUChars(const char* str) {
|
|
|
|
/* Might be faster to just use uprv_strlen() as the preflight len - liu */
|
|
|
|
int32_t len = u_unescape(str, 0, 0); /* preflight */
|
|
|
|
UChar *buf = (UChar*) malloc(sizeof(UChar) * len);
|
|
|
|
u_unescape(str, buf, len);
|
|
|
|
return buf;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-12-12 21:35:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Support for testing incremental strcoll */
|
|
|
|
typedef struct {
|
|
|
|
const UChar *start;
|
|
|
|
const UChar *end;
|
|
|
|
} testContext;
|
|
|
|
|
2001-03-13 07:30:28 +00:00
|
|
|
UChar U_CALLCONV testInc(void *context) {
|
2000-12-12 21:35:26 +00:00
|
|
|
testContext *s = (testContext *)context;
|
|
|
|
if(s->start == s->end) {
|
|
|
|
return 0xFFFF;
|
|
|
|
} else {
|
|
|
|
return *(s->start++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This is test for incremental */
|
|
|
|
UCollationResult
|
|
|
|
ctst_strcollTestIncremental( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
|
|
|
testContext tcSource, tcTarget;
|
|
|
|
|
|
|
|
if(sourceLength == -1) {
|
|
|
|
sourceLength = u_strlen(source);
|
|
|
|
}
|
|
|
|
if(targetLength == -1) {
|
|
|
|
targetLength = u_strlen(target
|
|
|
|
);
|
|
|
|
}
|
|
|
|
tcSource.start = source;
|
|
|
|
tcSource.end = source+sourceLength;
|
|
|
|
tcTarget.start = target;
|
|
|
|
tcTarget.end = target + targetLength;
|
|
|
|
|
|
|
|
return ucol_strcollinc(coll, testInc, &tcSource, testInc, &tcTarget);
|
|
|
|
|
|
|
|
}
|