X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..a01113dcd0f39d5da295ef82785beff9ed86fe38:/icuSources/test/intltest/citrtest.cpp diff --git a/icuSources/test/intltest/citrtest.cpp b/icuSources/test/intltest/citrtest.cpp index dd390cd4..84a2b69e 100644 --- a/icuSources/test/intltest/citrtest.cpp +++ b/icuSources/test/intltest/citrtest.cpp @@ -1,14 +1,18 @@ -/******************************************************************** +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html +/**************************************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation and + * Copyright (c) 1997-2014, International Business Machines Corporation and * others. All Rights Reserved. * Modification History: * * Date Name Description * 05/22/2000 Madhu Added tests for testing new API for utf16 support and more - **********************************************************************/ + ****************************************************************************************/ #include +#include "utypeinfo.h" // for 'typeid' to work + #include "unicode/chariter.h" #include "unicode/ustring.h" #include "unicode/unistr.h" @@ -16,7 +20,9 @@ #include "unicode/uchriter.h" #include "unicode/uiter.h" #include "unicode/putil.h" +#include "unicode/utf16.h" #include "citrtest.h" +#include "cmemory.h" class SCharacterIterator : public CharacterIterator { @@ -40,13 +46,13 @@ public: virtual void getText(UnicodeString& result) { text.extract(0,text.length(),result); } + static UClassID getStaticClassID(void){ + return (UClassID)(&fgClassID); + } virtual UClassID getDynamicClassID(void) const{ return getStaticClassID(); } - static UClassID getStaticClassID(void){ - return (UClassID)(&fgClassID); - } virtual UBool operator==(const ForwardCharacterIterator& /*that*/) const{ return TRUE; } @@ -100,20 +106,20 @@ public: case kStart: pos = begin; if(delta > 0) { - UTF_FWD_N(text, pos, end, delta); + U16_FWD_N(text, pos, end, delta); } break; case kCurrent: if(delta > 0) { - UTF_FWD_N(text, pos, end, delta); + U16_FWD_N(text, pos, end, delta); } else { - UTF_BACK_N(text, begin, pos, -delta); + U16_BACK_N(text, begin, pos, -delta); } break; case kEnd: pos = end; if(delta < 0) { - UTF_BACK_N(text, begin, pos, -delta); + U16_BACK_N(text, begin, pos, -delta); } break; default: @@ -136,14 +142,12 @@ private: }; const char SCharacterIterator::fgClassID=0; -#define LENGTHOF(array) ((int32_t)(sizeof(array)/sizeof((array)[0]))) - CharIterTest::CharIterTest() { } void CharIterTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) { - if (exec) logln("TestSuite LocaleTest: "); + if (exec) logln("TestSuite CharIterTest: "); switch (index) { case 0: name = "TestConstructionAndEquality"; if (exec) TestConstructionAndEquality(); break; case 1: name = "TestConstructionAndEqualityUChariter"; if (exec) TestConstructionAndEqualityUChariter(); break; @@ -607,7 +611,7 @@ void CharIterTest::TestIterationUChar32() { errln("setIndex32() isn't working right"); if (c != CharacterIterator::DONE) { c = iter.next32(); - i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i+2 : i+1; + i += U16_LENGTH(c); } } while (c != CharacterIterator::DONE); if(iter.hasNext() == TRUE) @@ -646,7 +650,7 @@ void CharIterTest::TestIterationUChar32() { errln("getIndex() isn't working right"); if (c != CharacterIterator::DONE) { c = iter.previous32(); - i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i-2 : i-1; + i -= U16_LENGTH(c); } } while (c != CharacterIterator::DONE); if(iter.hasPrevious() == TRUE) @@ -664,7 +668,7 @@ void CharIterTest::TestIterationUChar32() { c=iter.first32PostInc(); if(c != text.char32At(i)) errln("first32PostInc failed. Expected->%X Got->%X", text.char32At(i), c); - if(iter.getIndex() != UTF16_CHAR_LENGTH(c) + i) + if(iter.getIndex() != U16_LENGTH(c) + i) errln((UnicodeString)"getIndex() after first32PostInc() failed"); iter.setToStart(); @@ -680,7 +684,7 @@ void CharIterTest::TestIterationUChar32() { if(c != text.char32At(i)) errln("Character mismatch at position %d, iterator has %X, string has %X", i, c, text.char32At(i)); - i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i+2 : i+1; + i += U16_LENGTH(c); if(iter.getIndex() != i) errln("getIndex() aftr next32PostInc() isn't working right"); if(iter.current32() != text.char32At(i)) @@ -721,7 +725,7 @@ void CharIterTest::TestIterationUChar32() { if (c != CharacterIterator::DONE) { c = iter.next32(); - i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i+2 : i+1; + i += U16_LENGTH(c); } } while (c != CharacterIterator::DONE); c=iter.next32(); @@ -749,7 +753,7 @@ void CharIterTest::TestIterationUChar32() { if (c != CharacterIterator::DONE) { c = iter.previous32(); - i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i-2 : i-1; + i -= U16_LENGTH(c); } } while (c != CharacterIterator::DONE); @@ -911,36 +915,51 @@ void CharIterTest::TestUCharIterator() { if(cIter.getIndex(&cIter, (enum UCharIteratorOrigin)-1) != -1) { - errln("error: UCharIterator(char iter).getIndex did not return error value"); + errln("error: UCharIterator(char iter).getIndex did not return error value"); } if(cIter.move(&cIter, 0, (enum UCharIteratorOrigin)-1) != -1) { - errln("error: UCharIterator(char iter).move did not return error value"); + errln("error: UCharIterator(char iter).move did not return error value"); } if(rIter.getIndex(&rIter, (enum UCharIteratorOrigin)-1) != -1) { - errln("error: UCharIterator(repl iter).getIndex did not return error value"); + errln("error: UCharIterator(repl iter).getIndex did not return error value"); } if(rIter.move(&rIter, 0, (enum UCharIteratorOrigin)-1) != -1) { - errln("error: UCharIterator(repl iter).move did not return error value"); + errln("error: UCharIterator(repl iter).move did not return error value"); } if(sIter.getIndex(&sIter, (enum UCharIteratorOrigin)-1) != -1) { - errln("error: UCharIterator(string iter).getIndex did not return error value"); + errln("error: UCharIterator(string iter).getIndex did not return error value"); } if(sIter.move(&sIter, 0, (enum UCharIteratorOrigin)-1) != -1) { - errln("error: UCharIterator(string iter).move did not return error value"); + errln("error: UCharIterator(string iter).move did not return error value"); } + /* Testing function coverage on bad input */ + UErrorCode status = U_ZERO_ERROR; + uiter_setString(&sIter, NULL, 1); + uiter_setState(&sIter, 1, &status); + if (status != U_UNSUPPORTED_ERROR) { + errln("error: uiter_setState returned %s instead of U_UNSUPPORTED_ERROR", u_errorName(status)); + } + status = U_ZERO_ERROR; + uiter_setState(NULL, 1, &status); + if (status != U_ILLEGAL_ARGUMENT_ERROR) { + errln("error: uiter_setState returned %s instead of U_ILLEGAL_ARGUMENT_ERROR", u_errorName(status)); + } + if (uiter_getState(&sIter) != UITER_NO_STATE) { + errln("error: uiter_getState did not return UITER_NO_STATE on bad input"); + } } // subclass test, and completing API coverage ------------------------------- @@ -949,7 +968,7 @@ class SubCharIter : public CharacterIterator { public: // public default constructor, to get coverage of CharacterIterator() SubCharIter() : CharacterIterator() { - textLength=end=LENGTHOF(s); + textLength=end=UPRV_LENGTHOF(s); s[0]=0x61; // 'a' s[1]=0xd900; // U+50400 s[2]=0xdd00; @@ -958,7 +977,7 @@ public: // useful stuff, mostly dummy but testing coverage and subclassability virtual UChar nextPostInc() { - if(pos