scuffed-code/icu4c/source/test/cintltst/ccolltst.c

129 lines
3.6 KiB
C
Raw Normal View History

/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2008, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/********************************************************************************
1999-08-16 21:50:52 +00:00
*
* File CCOLLTST.C
*
* Modification History:
* Name Description
* Madhu Katragadda Creation
*********************************************************************************
*/
#include <stdio.h>
#include "unicode/utypes.h"
#if !UCONFIG_NO_COLLATION
1999-08-16 21:50:52 +00:00
#include "cintltst.h"
#include "ccolltst.h"
#include "unicode/ucol.h"
#include "unicode/ustring.h"
#include "cmemory.h"
1999-08-16 21:50:52 +00:00
void addCollTest(TestNode** root);
1999-08-16 21:50:52 +00:00
void addCollTest(TestNode** root)
{
addCollAPITest(root);
addCurrencyCollTest(root);
1999-08-16 21:50:52 +00:00
addNormTest(root);
addGermanCollTest(root);
addSpanishCollTest(root);
addFrenchCollTest(root);
addKannaCollTest(root);
addTurkishCollTest(root);
addEnglishCollTest(root);
addFinnishCollTest(root);
1999-08-16 21:50:52 +00:00
/* WEIVTODO: return tests here */
2001-02-27 07:28:58 +00:00
addRuleBasedCollTest(root);
addCollIterTest(root);
addAllCollTest(root);
addMiscCollTest(root);
addSearchTest(root);
1999-08-16 21:50:52 +00:00
}
/*Internal functions used*/
static char* dumpSk(uint8_t *sourceKey, char *sk) {
uint32_t kLen = (uint32_t)strlen((const char *)sourceKey);
uint32_t i = 0;
*sk = 0;
for(i = 0; i<kLen; i++) {
sprintf(sk+2*i, "%02X", sourceKey[i]);
}
return sk;
}
1999-08-16 21:50:52 +00:00
static const char *getCompareResult(UCollationResult result)
{
if (result == UCOL_LESS)
{
return "LESS";
}
else if (result == UCOL_EQUAL)
{
return "EQUAL";
}
else if (result == UCOL_GREATER)
{
return "GREATER";
}
return "invalid UCollationResult?";
}
1999-08-16 21:50:52 +00:00
void reportCResult( const UChar source[], const UChar target[],
uint8_t *sourceKey, uint8_t *targetKey,
UCollationResult compareResult,
UCollationResult keyResult,
UCollationResult incResult,
1999-08-16 21:50:52 +00:00
UCollationResult expectedResult )
{
if (expectedResult < -1 || expectedResult > 1)
{
log_err("***** invalid call to reportCResult ****\n");
return;
}
if (compareResult != expectedResult)
{
log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
getCompareResult(compareResult), getCompareResult(expectedResult) );
1999-08-16 21:50:52 +00:00
}
if (incResult != expectedResult)
{
log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
getCompareResult(incResult), getCompareResult(expectedResult) );
}
1999-08-16 21:50:52 +00:00
if (keyResult != expectedResult)
{
log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
getCompareResult(keyResult), getCompareResult(expectedResult) );
}
if (keyResult != compareResult)
{
log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
getCompareResult(keyResult), getCompareResult(compareResult));
1999-08-16 21:50:52 +00:00
}
if(keyResult != expectedResult || keyResult != compareResult)
{
char sk[10000];
log_verbose("SortKey1: %s\n", dumpSk(sourceKey, sk));
log_verbose("SortKey2: %s\n", dumpSk(targetKey, sk));
1999-08-16 21:50:52 +00:00
}
}
#endif /* #if !UCONFIG_NO_COLLATION */