ICU-6847 UText problems with nul-terminated strings

X-SVN-Rev: 25804
This commit is contained in:
Andy Heninger 2009-04-16 23:41:36 +00:00
parent 5169e13179
commit 2eb88b2772
3 changed files with 49 additions and 8 deletions

View File

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2005-2008, International Business Machines
* Copyright (C) 2005-2009, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -2449,7 +2449,13 @@ ucstrTextAccess(UText *ut, int64_t index, UBool forward) {
if (U16_IS_LEAD(str[chunkLimit-1])) {
--chunkLimit;
}
// Null-terminated chunk with end still unknown.
// Update the chunk length to reflect what has been scanned thus far.
// That the full length is still unknown is (still) flagged by
// ut->a being < 0.
ut->chunkNativeLimit = chunkLimit;
ut->nativeIndexingLimit = chunkLimit;
ut->chunkLength = chunkLimit;
}
}

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2005-2008, International Business Machines Corporation and
* Copyright (c) 2005-2009, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/************************************************************************
@ -54,8 +54,10 @@ UTextTest::runIndexedTest(int32_t index, UBool exec,
if (exec) ErrorTest(); break;
case 2: name = "FreezeTest";
if (exec) FreezeTest(); break;
case 3: name = "Ticket5560";
if (exec) Ticket5560(); break;
case 3: name = "Ticket5560";
if (exec) Ticket5560(); break;
case 4: name = "Ticket6847";
if (exec) Ticket6847(); break;
default: name = ""; break;
}
}
@ -1398,3 +1400,35 @@ void UTextTest::Ticket5560() {
utext_close(&ut2);
}
// Test for Ticket 6847
//
void UTextTest::Ticket6847() {
const int STRLEN = 90;
UChar s[STRLEN];
u_memset(s, 0x41, STRLEN);
UErrorCode status = U_ZERO_ERROR;
UText *ut = utext_openUChars(NULL, s, -1, &status);
utext_setNativeIndex(ut, 0);
int32_t count = 0;
UChar32 c = 0;
int32_t nativeIndex = UTEXT_GETNATIVEINDEX(ut);
TEST_ASSERT(nativeIndex == 0);
while ((c = utext_next32(ut)) != U_SENTINEL) {
TEST_ASSERT(c == 0x41);
TEST_ASSERT(count < STRLEN);
if (count >= STRLEN) {
break;
}
count++;
nativeIndex = UTEXT_GETNATIVEINDEX(ut);
TEST_ASSERT(nativeIndex == count);
}
TEST_ASSERT(count == STRLEN);
nativeIndex = UTEXT_GETNATIVEINDEX(ut);
TEST_ASSERT(nativeIndex == STRLEN);
utext_close(ut);
}

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2005-2007, International Business Machines Corporation and
* Copyright (c) 2005-2009, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/************************************************************************
@ -31,7 +31,8 @@ public:
void TextTest();
void ErrorTest();
void FreezeTest();
void Ticket5560();
void Ticket5560();
void Ticket6847();
private:
struct m { // Map between native indices & code points.
@ -44,8 +45,8 @@ private:
void TestAccessNoClone(const UnicodeString &us, UText *ut, int cpCount, m *cpMap);
void TestCMR (const UnicodeString &us, UText *ut, int cpCount, m *nativeMap, m *utf16Map);
void TestCopyMove(const UnicodeString &us, UText *ut, UBool move,
int32_t nativeStart, int32_t nativeLimit, int32_t nativeDest,
int32_t u16Start, int32_t u16Limit, int32_t u16Dest);
int32_t nativeStart, int32_t nativeLimit, int32_t nativeDest,
int32_t u16Start, int32_t u16Limit, int32_t u16Dest);
void TestReplace(const UnicodeString &us, // reference UnicodeString in which to do the replace
UText *ut, // UnicodeText object under test.
int32_t nativeStart, // Range to be replaced, in UText native units.