ICU-6554 Close collator and usearch object after use.
X-SVN-Rev: 25561
This commit is contained in:
parent
2213bd3046
commit
0a55b20859
@ -2266,36 +2266,35 @@ exitTestForwardBackward :
|
||||
{if ((x)==FALSE) {log_err("%s:%d: FAIL: test assertion failure \"%s\"\n", __FILE__, __LINE__, #x);\
|
||||
}}
|
||||
|
||||
static void TestSearchForNull(void)
|
||||
{
|
||||
UCollator *coll;
|
||||
UErrorCode ec;
|
||||
UStringSearch *search;
|
||||
int pos;
|
||||
int len;
|
||||
int expectedPos;
|
||||
int expectedLen;
|
||||
int expectedNum;
|
||||
int count = 0;
|
||||
static void TestSearchForNull(void) {
|
||||
UCollator *coll;
|
||||
UErrorCode ec;
|
||||
UStringSearch *search;
|
||||
int pos;
|
||||
int len;
|
||||
int expectedPos;
|
||||
int expectedLen;
|
||||
int expectedNum;
|
||||
int count = 0;
|
||||
const UChar zerodigit = 0x0030; /* 0 */
|
||||
const UChar nulldigit = 0x0000; /* null */
|
||||
|
||||
/* static const UChar var[(length)+1]=U_DECLARE_UTF16(cs) */
|
||||
|
||||
/* static const UChar var[(length)+1]=U_DECLARE_UTF16(cs) */
|
||||
#define PATTERN_LEN 4
|
||||
#define TEXT_LEN 10
|
||||
|
||||
U_STRING_DECL (_pattern, "IS 0", PATTERN_LEN);
|
||||
U_STRING_DECL (_text, "_0IS 0 OK?", TEXT_LEN);
|
||||
U_STRING_DECL(_pattern, "IS 0", PATTERN_LEN);
|
||||
U_STRING_DECL(_text, "_0IS 0 OK?", TEXT_LEN);
|
||||
UChar pattern[PATTERN_LEN + 1], text[TEXT_LEN + 1];
|
||||
|
||||
U_STRING_INIT (_pattern, "IS 0", PATTERN_LEN);
|
||||
U_STRING_INIT (_text, "_0IS 0 OK?", TEXT_LEN);
|
||||
expectedPos = 2;
|
||||
expectedLen = 4;
|
||||
expectedNum = 1;
|
||||
|
||||
for(pos = 0; pos < PATTERN_LEN; pos++) {
|
||||
if(_pattern[pos] == zerodigit) {
|
||||
U_STRING_INIT(_pattern, "IS 0", PATTERN_LEN);
|
||||
U_STRING_INIT(_text, "_0IS 0 OK?", TEXT_LEN);
|
||||
expectedPos = 2;
|
||||
expectedLen = 4;
|
||||
expectedNum = 1;
|
||||
|
||||
for (pos = 0; pos < PATTERN_LEN; pos++) {
|
||||
if (_pattern[pos] == zerodigit) {
|
||||
pattern[pos] = nulldigit;
|
||||
} else {
|
||||
pattern[pos] = _pattern[pos];
|
||||
@ -2303,8 +2302,8 @@ static void TestSearchForNull(void)
|
||||
}
|
||||
pattern[PATTERN_LEN] = 0x0000;
|
||||
|
||||
for(pos = 0; pos < TEXT_LEN; pos++) {
|
||||
if(_text[pos] == zerodigit) {
|
||||
for (pos = 0; pos < TEXT_LEN; pos++) {
|
||||
if (_text[pos] == zerodigit) {
|
||||
text[pos] = nulldigit;
|
||||
} else {
|
||||
text[pos] = _text[pos];
|
||||
@ -2312,42 +2311,45 @@ static void TestSearchForNull(void)
|
||||
}
|
||||
text[TEXT_LEN] = 0x0000;
|
||||
|
||||
ec = U_ZERO_ERROR;
|
||||
ec = U_ZERO_ERROR;
|
||||
|
||||
/* create a US-English collator */
|
||||
coll = ucol_open ("en_US", &ec);
|
||||
/* create a US-English collator */
|
||||
coll = ucol_open("en_US", &ec);
|
||||
|
||||
/* make sure we didn't fail. */
|
||||
TEST_ASSERT (U_SUCCESS (ec));
|
||||
/* make sure we didn't fail. */
|
||||
TEST_ASSERT (U_SUCCESS (ec));
|
||||
|
||||
ucol_setStrength( coll, UCOL_IDENTICAL);
|
||||
ucol_setStrength(coll, UCOL_IDENTICAL);
|
||||
|
||||
/* open a search looking for 0 */
|
||||
search = usearch_openFromCollator (pattern, PATTERN_LEN, text, TEXT_LEN, coll, NULL, &ec);
|
||||
TEST_ASSERT (U_SUCCESS (ec));
|
||||
/* open a search looking for 0 */
|
||||
search = usearch_openFromCollator(pattern, PATTERN_LEN, text,
|
||||
TEXT_LEN, coll, NULL, &ec);
|
||||
TEST_ASSERT (U_SUCCESS (ec));
|
||||
|
||||
pos = usearch_first(search, &ec);
|
||||
len = usearch_getMatchedLength(search);
|
||||
if(pos != expectedPos)
|
||||
{
|
||||
log_err("Expected search result: %d; Got instead: %d\n", expectedPos, pos);
|
||||
}
|
||||
|
||||
if(len != expectedLen)
|
||||
{
|
||||
log_err("Expected search result length: %d; Got instead: %d\n", expectedLen, len);
|
||||
}
|
||||
|
||||
for(pos = usearch_first (search, &ec); pos != USEARCH_DONE; pos = usearch_next(search, &ec))
|
||||
{
|
||||
pos = usearch_first(search, &ec);
|
||||
len = usearch_getMatchedLength(search);
|
||||
if (pos != expectedPos) {
|
||||
log_err("Expected search result: %d; Got instead: %d\n", expectedPos,
|
||||
pos);
|
||||
}
|
||||
|
||||
if (len != expectedLen) {
|
||||
log_err("Expected search result length: %d; Got instead: %d\n",
|
||||
expectedLen, len);
|
||||
}
|
||||
|
||||
for (pos = usearch_first(search, &ec); pos != USEARCH_DONE; pos
|
||||
= usearch_next(search, &ec)) {
|
||||
log_verbose("Match at %d\n", pos);
|
||||
count += 1;
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
|
||||
if(count != expectedNum)
|
||||
{
|
||||
log_err("Expected %d search hits, found %d\n", expectedNum, count);
|
||||
}
|
||||
if (count != expectedNum) {
|
||||
log_err("Expected %d search hits, found %d\n", expectedNum, count);
|
||||
}
|
||||
|
||||
ucol_close(coll);
|
||||
usearch_close(search);
|
||||
}
|
||||
|
||||
static void TestStrengthIdentical(void)
|
||||
|
Loading…
Reference in New Issue
Block a user