mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-847 Test for upper and lower bound APIs - preliminary version
X-SVN-Rev: 7470
This commit is contained in:
parent
429d200e9d
commit
b497a53be5
2 changed files with 43 additions and 0 deletions
|
@ -108,6 +108,7 @@ void addCollAPITest(TestNode** root)
|
|||
addTest(root, &TestDecomposition, "tscoll/capitst/TestDecomposition");
|
||||
addTest(root, &TestSafeClone, "tscoll/capitst/TestSafeClone");
|
||||
addTest(root, &TestGetSetAttr, "tscoll/capitst/TestGetSetAttr");
|
||||
addTest(root, &TestBounds, "tscoll/capitst/TestBounds");
|
||||
|
||||
}
|
||||
|
||||
|
@ -977,3 +978,40 @@ void TestGetAll()
|
|||
|
||||
|
||||
}
|
||||
|
||||
void TestBounds() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
UCollator *coll = ucol_open("en_US", &status);
|
||||
|
||||
uint8_t sortkey[512], lower[512], upper[512];
|
||||
UChar buffer[512];
|
||||
|
||||
const char *test[] = {
|
||||
"John Smith",
|
||||
"JOHN SMITH",
|
||||
"john SMITH",
|
||||
"j\\u00F6hn sm\\u00EFth",
|
||||
"J\\u00F6hn Sm\\u00EFth",
|
||||
"J\\u00D6HN SM\\u00CFTH"
|
||||
};
|
||||
|
||||
int32_t i = 0, j = 0, buffSize = 0, skSize = 0, lowerSize = 0, upperSize = 0;
|
||||
|
||||
UColAttributeValue strength = UCOL_SECONDARY;
|
||||
|
||||
for(i = 0; i<sizeof(test)/sizeof(test[0]); i++) {
|
||||
buffSize = u_unescape(test[i], buffer, 512);
|
||||
skSize = ucol_getSortKey(coll, buffer, buffSize, sortkey, 512);
|
||||
lowerSize = ucol_getLowerBoundSortKey(coll, sortkey, skSize, strength, lower, 512, &status);
|
||||
upperSize = ucol_getUpperBoundSortKey(coll, sortkey, skSize, strength, upper, 512, &status);
|
||||
for(j = i+1; j<sizeof(test)/sizeof(test[0]); j++) {
|
||||
buffSize = u_unescape(test[j], buffer, 512);
|
||||
skSize = ucol_getSortKey(coll, buffer, buffSize, sortkey, 512);
|
||||
if(strcmp(lower, sortkey) == 1 || strcmp(upper, sortkey) != 1) {
|
||||
log_err("Problem! i = %i, j = %i (%s vs %s)\n", i, j, test[i], test[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
ucol_close(coll);
|
||||
}
|
|
@ -68,4 +68,9 @@
|
|||
**/
|
||||
void TestSafeClone(void);
|
||||
|
||||
/**
|
||||
* Test getting bounds for a sortkey
|
||||
*/
|
||||
void TestBounds(void);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue