ICU-96 added C tests for incremental compare

X-SVN-Rev: 3203
This commit is contained in:
Vladimir Weinstein 2000-12-12 21:35:26 +00:00
parent 6f6c6c0cad
commit d201784ec9
13 changed files with 95 additions and 24 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}