mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
ICU-5354 better testing of utext clone(), improved code coverage.
X-SVN-Rev: 20190
This commit is contained in:
parent
dfffb6fcc2
commit
050e6b861d
2 changed files with 53 additions and 2 deletions
|
@ -539,11 +539,42 @@ cleanupAndReturn:
|
|||
}
|
||||
|
||||
//
|
||||
// TestAccess() Test the read only access functions on a UText.
|
||||
// TestAccess Test the read only access functions on a UText, including cloning.
|
||||
// The text is accessed in a variety of ways, and compared with
|
||||
// the reference UnicodeString.
|
||||
//
|
||||
void UTextTest::TestAccess(const UnicodeString &us, UText *ut, int cpCount, m *cpMap) {
|
||||
// Run the standard tests on the caller-supplied UText.
|
||||
TestAccessNoClone(us, ut, cpCount, cpMap);
|
||||
|
||||
// Re-run tests on a shallow clone.
|
||||
utext_setNativeIndex(ut, 0);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UText *shallowClone = utext_clone(NULL, ut, FALSE /*deep*/, FALSE /*readOnly*/, &status);
|
||||
TEST_SUCCESS(status);
|
||||
TestAccessNoClone(us, shallowClone, cpCount, cpMap);
|
||||
|
||||
//
|
||||
// Rerun again on a deep clone.
|
||||
// Note that text providers are not required to provide deep cloning,
|
||||
// so unsupported errors are ignored.
|
||||
//
|
||||
status = U_ZERO_ERROR;
|
||||
utext_setNativeIndex(shallowClone, 0);
|
||||
UText *deepClone = utext_clone(NULL, shallowClone, TRUE, FALSE, &status);
|
||||
if (status != U_UNSUPPORTED_ERROR) {
|
||||
TEST_SUCCESS(status);
|
||||
TestAccessNoClone(us, deepClone, cpCount, cpMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// TestAccessNoClone() Test the read only access functions on a UText.
|
||||
// The text is accessed in a variety of ways, and compared with
|
||||
// the reference UnicodeString.
|
||||
//
|
||||
void UTextTest::TestAccessNoClone(const UnicodeString &us, UText *ut, int cpCount, m *cpMap) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
gTestNum++;
|
||||
|
||||
|
@ -1280,6 +1311,25 @@ U_CDECL_END
|
|||
// Initialized in the open function.
|
||||
UTextFuncs fragmentFuncs;
|
||||
|
||||
// Clone function for fragmented text provider.
|
||||
// Didn't really want to provide this, but it's easier to provide it than to keep it
|
||||
// out of the tests.
|
||||
//
|
||||
UText *
|
||||
cloneFragmentedUnicodeString(UText *dest, const UText *src, UBool deep, UErrorCode *status) {
|
||||
if (U_FAILURE(*status)) {
|
||||
return NULL;
|
||||
}
|
||||
if (deep) {
|
||||
*status = U_UNSUPPORTED_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
dest = utext_openUnicodeString(dest, (UnicodeString *)src->context, status);
|
||||
utext_setNativeIndex(dest, utext_getNativeIndex(src));
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
// Open function for the fragmented text provider.
|
||||
UText *
|
||||
openFragmentedUnicodeString(UText *ut, UnicodeString *s, UErrorCode *status) {
|
||||
|
@ -1292,6 +1342,7 @@ openFragmentedUnicodeString(UText *ut, UnicodeString *s, UErrorCode *status) {
|
|||
// and replace the entry for the access function.
|
||||
memcpy(&fragmentFuncs, ut->pFuncs, sizeof(fragmentFuncs));
|
||||
fragmentFuncs.access = fragTextAccess;
|
||||
fragmentFuncs.clone = cloneFragmentedUnicodeString;
|
||||
ut->pFuncs = &fragmentFuncs;
|
||||
|
||||
ut->chunkContents = (UChar *)&ut->b;
|
||||
|
@ -1299,4 +1350,3 @@ openFragmentedUnicodeString(UText *ut, UnicodeString *s, UErrorCode *status) {
|
|||
return ut;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ private:
|
|||
|
||||
void TestString(const UnicodeString &s);
|
||||
void TestAccess(const UnicodeString &us, UText *ut, int cpCount, m *cpMap);
|
||||
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,
|
||||
|
|
Loading…
Add table
Reference in a new issue