ICU-96 added C tests for incremental compare
X-SVN-Rev: 3203
This commit is contained in:
parent
6f6c6c0cad
commit
d201784ec9
@ -417,11 +417,11 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
{
|
||||
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
||||
int32_t temp;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
|
||||
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
incResult = ctst_strcollTestIncremental(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
||||
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
||||
|
||||
@ -439,7 +439,7 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
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 );
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ void reportCResult( const UChar source[], const UChar target[],
|
||||
uint8_t *sourceKey, uint8_t *targetKey,
|
||||
UCollationResult compareResult,
|
||||
UCollationResult keyResult,
|
||||
UCollationResult incResult,
|
||||
UCollationResult expectedResult )
|
||||
{
|
||||
UChar *sResult, *sExpect;
|
||||
@ -82,6 +83,15 @@ void reportCResult( const UChar source[], const UChar target[],
|
||||
austrdup(sResult), austrdup(sExpect) );
|
||||
}
|
||||
|
||||
if (incResult != expectedResult)
|
||||
{
|
||||
|
||||
appendCompareResult(compareResult, sResult);
|
||||
appendCompareResult(expectedResult, sExpect);
|
||||
log_err("incCompare(%s , %s) returned: %s expected: %s\n", austrdup(source), austrdup(target),
|
||||
austrdup(sResult), austrdup(sExpect) );
|
||||
}
|
||||
|
||||
if (keyResult != expectedResult)
|
||||
{
|
||||
|
||||
@ -139,3 +149,46 @@ UChar* CharsToUChars(const char* str) {
|
||||
u_unescape(str, buf, len);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/* Support for testing incremental strcoll */
|
||||
typedef struct {
|
||||
const UChar *start;
|
||||
const UChar *end;
|
||||
} testContext;
|
||||
|
||||
UChar testInc(void *context) {
|
||||
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);
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ void reportCResult( const UChar source[], const UChar target[],
|
||||
uint8_t *sourceKey, uint8_t *targetKey,
|
||||
UCollationResult compareResult,
|
||||
UCollationResult keyResult,
|
||||
UCollationResult incResult,
|
||||
UCollationResult expectedResult );
|
||||
|
||||
UChar* appendCompareResult(UCollationResult result, UChar* target);
|
||||
@ -31,4 +32,12 @@ UChar* appendCompareResult(UCollationResult result, UChar* target);
|
||||
|
||||
UChar* CharsToUChars(const char* chars);
|
||||
|
||||
UCollationResult
|
||||
ctst_strcollTestIncremental( const UCollator *coll,
|
||||
const UChar *source,
|
||||
int32_t sourceLength,
|
||||
const UChar *target,
|
||||
int32_t targetLength);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -63,7 +63,7 @@ void currTest()
|
||||
UCollator *c;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
UCollationResult expectedResult = UCOL_EQUAL;
|
||||
log_verbose("Testing currency of all locales\n");
|
||||
c = ucol_open(NULL, &status);
|
||||
@ -96,6 +96,7 @@ void currTest()
|
||||
}
|
||||
|
||||
compareResult = ucol_strcoll(c, source, u_strlen(source), target, u_strlen(target));
|
||||
incResult = ctst_strcollTestIncremental(c, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
@ -113,8 +114,7 @@ void currTest()
|
||||
else if (res > 0) keyResult = (UCollationResult)1;
|
||||
else keyResult = (UCollationResult)0;
|
||||
|
||||
reportCResult(source, target, sortKey1, sortKey2,
|
||||
compareResult, keyResult, expectedResult);
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, expectedResult );
|
||||
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
|
@ -193,10 +193,11 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
{
|
||||
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
||||
int32_t temp;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
|
||||
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
incResult = ctst_strcollTestIncremental(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
||||
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
||||
@ -215,7 +216,7 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
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 );
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
}
|
||||
|
@ -96,10 +96,11 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
{
|
||||
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
||||
int32_t temp;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
|
||||
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
incResult = ctst_strcollTestIncremental(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
||||
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
||||
@ -118,7 +119,7 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
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 );
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
}
|
||||
|
@ -80,10 +80,11 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
{
|
||||
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
||||
int32_t temp;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
|
||||
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
incResult = ctst_strcollTestIncremental(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
||||
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
||||
@ -102,7 +103,7 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
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 );
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
}
|
||||
|
@ -71,10 +71,11 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
{
|
||||
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
||||
int32_t temp;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
|
||||
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
incResult = ctst_strcollTestIncremental(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
||||
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
||||
@ -93,7 +94,7 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
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 );
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
}
|
||||
|
@ -140,10 +140,11 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
{
|
||||
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
||||
int32_t temp;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
|
||||
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
incResult = ctst_strcollTestIncremental(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
||||
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
||||
@ -165,7 +166,7 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
keyResult= UCOL_GREATER;
|
||||
else
|
||||
keyResult = UCOL_EQUAL;
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
}
|
||||
|
@ -164,10 +164,11 @@ static void doTest(UCollator *myCollation, const UChar source[], const UChar tar
|
||||
{
|
||||
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
||||
int32_t temp;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
|
||||
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
incResult = ctst_strcollTestIncremental(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
||||
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
||||
@ -186,7 +187,7 @@ static void doTest(UCollator *myCollation, const UChar source[], const UChar tar
|
||||
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 );
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
}
|
||||
|
@ -83,10 +83,11 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
{
|
||||
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
||||
int32_t temp;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
|
||||
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
incResult = ctst_strcollTestIncremental(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
||||
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
||||
@ -108,7 +109,7 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
keyResult= UCOL_GREATER;
|
||||
else
|
||||
keyResult = UCOL_EQUAL;
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
}
|
||||
|
@ -87,10 +87,11 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
{
|
||||
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
||||
int32_t temp;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
|
||||
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
incResult = ctst_strcollTestIncremental(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
||||
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
||||
@ -109,7 +110,7 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
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 );
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
}
|
||||
|
@ -258,10 +258,11 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
{
|
||||
int32_t sortklen1, sortklen2, sortklenmax, sortklenmin;
|
||||
int32_t temp;
|
||||
UCollationResult compareResult, keyResult;
|
||||
UCollationResult compareResult, keyResult, incResult;
|
||||
uint8_t *sortKey1, *sortKey2;
|
||||
|
||||
compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
incResult = ctst_strcollTestIncremental(myCollation, source, u_strlen(source), target, u_strlen(target));
|
||||
|
||||
sortklen1=ucol_getSortKey(myCollation, source, u_strlen(source), NULL, 0);
|
||||
sortklen2=ucol_getSortKey(myCollation, target, u_strlen(target), NULL, 0);
|
||||
@ -280,7 +281,7 @@ static void doTest(UCollator* myCollation, const UChar source[], const UChar tar
|
||||
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 );
|
||||
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
|
||||
free(sortKey1);
|
||||
free(sortKey2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user