X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..e4f10fab0c078f399c9deef476d9c9b73b47dff8:/icuSources/test/intltest/citrtest.cpp?ds=sidebyside diff --git a/icuSources/test/intltest/citrtest.cpp b/icuSources/test/intltest/citrtest.cpp index 5a7e1049..bc9d7439 100644 --- a/icuSources/test/intltest/citrtest.cpp +++ b/icuSources/test/intltest/citrtest.cpp @@ -1,20 +1,24 @@ -/******************************************************************** +/**************************************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2002, International Business Machines Corporation and + * Copyright (c) 1997-2012, 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" #include "unicode/schriter.h" #include "unicode/uchriter.h" #include "unicode/uiter.h" +#include "unicode/putil.h" +#include "unicode/utf16.h" #include "citrtest.h" @@ -36,16 +40,16 @@ public: text = newText; } - virtual void getText(UnicodeString& result){ + 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; } @@ -58,7 +62,7 @@ public: } virtual UChar nextPostInc(void){ return text.charAt(pos++);} virtual UChar32 next32PostInc(void){return text.char32At(pos++);} - virtual UBool hasNext(){ return TRUE;}; + virtual UBool hasNext() { return TRUE;}; virtual UChar first(){return DONE;}; virtual UChar32 first32(){return DONE;}; virtual UChar last(){return DONE;}; @@ -99,20 +103,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: @@ -121,7 +125,7 @@ public: return pos; }; - virtual UBool hasPrevious(){return TRUE;}; + virtual UBool hasPrevious() {return TRUE;}; SCharacterIterator& operator=(const SCharacterIterator& that){ text = that.text; @@ -142,7 +146,7 @@ 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; @@ -222,9 +226,9 @@ void CharIterTest::TestConstructionAndEquality() { if (test1->hashCode() != test5->hashCode()) errln("hashCode() failed: identical objects have different hash codes"); - if(test1->getLength() != testText.length()){ - errln("getLength of CharacterIterator failed"); - } + if(test1->getLength() != testText.length()){ + errln("getLength of CharacterIterator failed"); + } test1->getText(result1); test1b->getText(result2); test1c->getText(result3); @@ -663,7 +667,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(); @@ -910,36 +914,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 ------------------------------- @@ -1065,7 +1084,7 @@ public: virtual UBool operator==(const ForwardCharacterIterator &that) const { return this==&that || - getDynamicClassID()==that.getDynamicClassID() && pos==((SubCharIter &)that).pos; + (typeid(*this)==typeid(that) && pos==((SubCharIter &)that).pos); } virtual int32_t hashCode() const { @@ -1101,14 +1120,14 @@ public: } // RTTI - virtual UClassID getDynamicClassID() const { - return getStaticClassID(); - } - static UClassID getStaticClassID() { return (UClassID)(&fgClassID); } + virtual UClassID getDynamicClassID() const { + return getStaticClassID(); + } + private: // dummy string data UChar s[4];