From 4178a62d7339b1f4ec28b9ed56982aca67b618cc Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Thu, 28 Sep 2000 05:46:28 +0000 Subject: [PATCH] ICU-615 Changed the parameter name and tested it. X-SVN-Rev: 2531 --- icu4c/source/common/uchriter.cpp | 27 ++++++++++--------- icu4c/source/common/unicode/uchriter.h | 4 +-- icu4c/source/test/intltest/citrtest.cpp | 35 +++++++++++++++++-------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/icu4c/source/common/uchriter.cpp b/icu4c/source/common/uchriter.cpp index 1ca6876213d..80a985e4bd4 100644 --- a/icu4c/source/common/uchriter.cpp +++ b/icu4c/source/common/uchriter.cpp @@ -116,13 +116,14 @@ UCharCharacterIterator::last() { } UChar -UCharCharacterIterator::setIndex(UTextOffset pos) { - if(pos < begin) { +UCharCharacterIterator::setIndex(UTextOffset position) { + if(position < begin) { pos = begin; - } else if(pos > end) { + } else if(position > end) { pos = end; + } else { + pos = position; } - this->pos = pos; if(pos < end) { return text[pos]; } else { @@ -216,20 +217,20 @@ UCharCharacterIterator::last32() { } UChar32 -UCharCharacterIterator::setIndex32(UTextOffset pos) { - if(pos < begin) { - pos = begin; - } else if(pos > end) { - pos = end; +UCharCharacterIterator::setIndex32(UTextOffset position) { + if(position < begin) { + position = begin; + } else if(position > end) { + position = end; } - if(pos < end) { - UTF_SET_CHAR_START(text, begin, pos); - UTextOffset i = this->pos = pos; + if(position < end) { + UTF_SET_CHAR_START(text, begin, position); + UTextOffset i = this->pos = position; UChar32 c; UTF_NEXT_CHAR(text, i, end, c); return c; } else { - this->pos = pos; + this->pos = position; return DONE; } } diff --git a/icu4c/source/common/unicode/uchriter.h b/icu4c/source/common/unicode/uchriter.h index ec79ff71af7..96f087aa76b 100644 --- a/icu4c/source/common/unicode/uchriter.h +++ b/icu4c/source/common/unicode/uchriter.h @@ -165,7 +165,7 @@ public: * returns that code unit. * @draft */ - virtual UChar setIndex(UTextOffset pos); + virtual UChar setIndex(UTextOffset position); /** * Sets the iterator to refer to the beginning of the code point @@ -176,7 +176,7 @@ public: * (its first code unit). * @draft */ - virtual UChar32 setIndex32(UTextOffset pos); + virtual UChar32 setIndex32(UTextOffset position); /** * Returns the code unit the iterator currently refers to. diff --git a/icu4c/source/test/intltest/citrtest.cpp b/icu4c/source/test/intltest/citrtest.cpp index 535ede06b71..cc147917de8 100644 --- a/icu4c/source/test/intltest/citrtest.cpp +++ b/icu4c/source/test/intltest/citrtest.cpp @@ -55,7 +55,7 @@ void CharIterTest::TestConstructionAndEquality() { if (test1d->endIndex() > testText.length()) errln("Construction failed: endIndex is greater than the text length"); if (test1d->getIndex() < test1d->startIndex() || test1d->endIndex() < test1d->getIndex()) - errln("Construction failed: startIndex is negative"); + errln("Construction failed: index is invalid"); if (*test1 == *test2 || *test1 == *test3 || *test1 == *test4) errln("Construction or operator== failed: Unequal objects compared equal"); @@ -120,18 +120,18 @@ void CharIterTest::TestConstructionAndEquality() { } void CharIterTest::TestConstructionAndEqualityUChariter() { - const char* testTextchars= {"Now is the time for all good men to come to the aid of their country."}; - const char* testText2chars={"Don't bother using this string."}; + const char testTextchars[]= {"Now is the time for all good men to come to the aid of their country."}; + const char testText2chars[]={"Don't bother using this string."}; - UChar *testText = new UChar[strlen(testTextchars)+1]; - UChar *testText2 = new UChar[strlen(testText2chars)+1]; + UChar *testText = new UChar[sizeof(testTextchars)]; + UChar *testText2 = new UChar[sizeof(testText2chars)]; u_uastrcpy(testText, testTextchars); u_uastrcpy(testText2, testText2chars); - + UnicodeString result, result4, result5; - - + + UCharCharacterIterator* test1 = new UCharCharacterIterator(testText, u_strlen(testText)); UCharCharacterIterator* test2 = new UCharCharacterIterator(testText, u_strlen(testText), 5); UCharCharacterIterator* test3 = new UCharCharacterIterator(testText, u_strlen(testText), 2, 20, 5); @@ -142,14 +142,24 @@ void CharIterTest::TestConstructionAndEqualityUChariter() { UCharCharacterIterator* test7a = new UCharCharacterIterator(testText, -1); UCharCharacterIterator* test7b = new UCharCharacterIterator(testText, -1); UCharCharacterIterator* test7c = new UCharCharacterIterator(testText, -1, 2, 20, 5); - - + + // Bad parameters. + UCharCharacterIterator* test8a = new UCharCharacterIterator(testText, -1, -1, 20, 5); + UCharCharacterIterator* test8b = new UCharCharacterIterator(testText, -1, 2, 100, 5); + UCharCharacterIterator* test8c = new UCharCharacterIterator(testText, -1, 2, 20, 100); + + if (test8a->startIndex() < 0) + errln("Construction failed: startIndex is negative"); + if (test8b->endIndex() > sizeof(testTextchars)) + errln("Construction failed: endIndex is greater than the text length"); + if (test8c->getIndex() < test8c->startIndex() || test8c->endIndex() < test8c->getIndex()) + errln("Construction failed: index is invalid"); if (*test1 == *test2 || *test1 == *test3 || *test1 == *test4 ) errln("Construction or operator== failed: Unequal objects compared equal"); if (*test1 != *test5 ) errln("clone() or equals() failed: Two clones tested unequal"); - + if (*test6 != *test1 ) errln("copy construction or equals() failed: Two copies tested unequal"); @@ -185,6 +195,9 @@ void CharIterTest::TestConstructionAndEqualityUChariter() { test1->setIndex(5); if (*test1 != *test2 || *test1 == *test5) errln("setIndex() failed"); + test8b->setIndex32(0); + if (*test8a != *test8b) + errln("setIndex32() failed"); *test1 = *test3; if (*test1 != *test3 || *test1 == *test5)