X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..7393aa2fd2c40c89f12c2db881842a563afdb429:/icuSources/test/cintltst/custrtst.c diff --git a/icuSources/test/cintltst/custrtst.c b/icuSources/test/cintltst/custrtst.c index 31d388e6..76cae0be 100644 --- a/icuSources/test/cintltst/custrtst.c +++ b/icuSources/test/cintltst/custrtst.c @@ -1,7 +1,7 @@ /* ****************************************************************************** * -* Copyright (C) 2002-2003, International Business Machines +* Copyright (C) 2002-2006, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** @@ -16,15 +16,11 @@ * Tests of ustring.h Unicode string API functions. */ -#include "unicode/utypes.h" #include "unicode/ustring.h" -#include "unicode/uloc.h" #include "unicode/ucnv.h" #include "unicode/uiter.h" #include "cintltst.h" -#include "cucdtst.h" #include -#include #define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) @@ -42,6 +38,7 @@ static void TestUnescape(void); static void TestCountChar32(void); static void TestUCharIterator(void); static void TestUNormIterator(void); +static void TestBadUNormIterator(void); void addUStringTest(TestNode** root); @@ -55,15 +52,7 @@ void addUStringTest(TestNode** root) addTest(root, &TestCountChar32, "tsutil/custrtst/TestCountChar32"); addTest(root, &TestUCharIterator, "tsutil/custrtst/TestUCharIterator"); addTest(root, &TestUNormIterator, "tsutil/custrtst/TestUNormIterator"); - - /* cstrcase.c functions, declared in cucdtst.h */ - addTest(root, &TestCaseLower, "tsutil/custrtst/TestCaseLower"); - addTest(root, &TestCaseUpper, "tsutil/custrtst/TestCaseUpper"); -#if !UCONFIG_NO_BREAK_ITERATION - addTest(root, &TestCaseTitle, "tsutil/custrtst/TestCaseTitle"); -#endif - addTest(root, &TestCaseFolding, "tsutil/custrtst/TestCaseFolding"); - addTest(root, &TestCaseCompare, "tsutil/custrtst/TestCaseCompare"); + addTest(root, &TestBadUNormIterator, "tsutil/custrtst/TestBadUNormIterator"); } /* test data for TestStringFunctions ---------------------------------------- */ @@ -1533,6 +1522,11 @@ TestUNormIterator() { /* test nothing */ } +static void +TestBadUNormIterator(void) { + /* test nothing, as well */ +} + #else #include "unicode/unorm.h" @@ -1555,6 +1549,14 @@ compareIterNoIndexes(UCharIterator *iter1, const char *n1, UChar32 c1, c2; UErrorCode errorCode; + /* code coverage for unorm_it.c/unormIteratorGetIndex() */ + if( + iter2->getIndex(iter2, UITER_START)!=0 || + iter2->getIndex(iter2, UITER_LENGTH)!=UITER_UNKNOWN_INDEX + ) { + log_err("UNormIterator.getIndex() failed\n"); + } + /* set into the middle */ iter1->move(iter1, middle, UITER_ZERO); iter2->move(iter2, middle, UITER_ZERO); @@ -1618,6 +1620,16 @@ compareIterNoIndexes(UCharIterator *iter1, const char *n1, return; } + /* iterate backward */ + do { + c1=iter1->previous(iter1); + c2=iter2->previous(iter2); + if(c1!=c2) { + log_err("%s->previous()=U+%04x != U+%04x=%s->previous() at %d\n", n1, c1, c2, n2, iter1->getIndex(iter1, UITER_CURRENT)); + return; + } + } while(c1>=0); + /* back to the middle */ iter1->move(iter1, middle, UITER_ZERO); iter2->move(iter2, middle, UITER_ZERO); @@ -1687,7 +1699,7 @@ compareIterNoIndexes(UCharIterator *iter1, const char *n1, static void testUNormIteratorWithText(const UChar *text, int32_t textLength, int32_t middle, const char *name1, const char *n2) { - UChar buffer[300]; + UChar buffer[600]; char name2[40]; UCharIterator iter1, iter2, *iter; @@ -1747,7 +1759,7 @@ TestUNormIterator() { 0x6e, 0xd900, 0x6a, 0xdc00, 0xd900, 0xdc00, 0x61 }; - UChar longText[300]; + UChar longText[600]; int32_t i, middle, length; length=LENGTHOF(text); @@ -1755,20 +1767,51 @@ TestUNormIterator() { testUNormIteratorWithText(text, length, length, "UCharIterEnd", "UNormIterEnd1"); /* test again, this time with an insane string to cause internal buffer overflows */ - middle=u_strchr(text, 0x327)-text; /* see comment at text[] */ + middle=(int32_t)(u_strchr(text, 0x327)-text); /* see comment at text[] */ memcpy(longText, text, middle*U_SIZEOF_UCHAR); for(i=0; i<150; ++i) { longText[middle+i]=0x30a; /* insert many rings between 'A-ring' and cedilla */ } memcpy(longText+middle+i, text+middle, (LENGTHOF(text)-middle)*U_SIZEOF_UCHAR); - length=LENGTHOF(text)+i; - testUNormIteratorWithText(longText, length, length/2, "UCharIterLong", "UNormIterLong1"); + + /* append another copy of this string for more overflows */ + memcpy(longText+length, longText, length*U_SIZEOF_UCHAR); + length*=2; + + /* the first test of the following two starts at length/4, inside the sea of combining rings */ + testUNormIteratorWithText(longText, length, length/4, "UCharIterLong", "UNormIterLong1"); testUNormIteratorWithText(longText, length, length, "UCharIterLongEnd", "UNormIterLongEnd1"); length=LENGTHOF(surrogateText); - testUNormIteratorWithText(surrogateText, length, length/2, "UCharIterSurr", "UNormIterSurr1"); + testUNormIteratorWithText(surrogateText, length, length/4, "UCharIterSurr", "UNormIterSurr1"); testUNormIteratorWithText(surrogateText, length, length, "UCharIterSurrEnd", "UNormIterSurrEnd1"); } +static void +TestBadUNormIterator(void) { +#if !UCONFIG_NO_NORMALIZATION + UErrorCode status = U_ILLEGAL_ESCAPE_SEQUENCE; + UNormIterator *uni; + + unorm_setIter(NULL, NULL, UNORM_NONE, &status); + if (status != U_ILLEGAL_ESCAPE_SEQUENCE) { + log_err("unorm_setIter changed the error code to: %s\n", u_errorName(status)); + } + status = U_ZERO_ERROR; + unorm_setIter(NULL, NULL, UNORM_NONE, &status); + if (status != U_ILLEGAL_ARGUMENT_ERROR) { + log_err("unorm_setIter didn't react correctly to bad arguments: %s\n", u_errorName(status)); + } + status = U_ZERO_ERROR; + uni=unorm_openIter(NULL, 0, &status); + if(U_FAILURE(status)) { + log_err("unorm_openIter() fails: %s\n", u_errorName(status)); + return; + } + unorm_setIter(uni, NULL, UNORM_NONE, &status); + unorm_closeIter(uni); +#endif +} + #endif