2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2001-03-21 20:09:56 +00:00
|
|
|
* Copyright (c) 1997-2001, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
2000-05-23 20:51:39 +00:00
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
2000-08-14 21:42:36 +00:00
|
|
|
* 05/22/2000 Madhu Added tests for testing new API for utf16 support and more
|
2000-05-23 20:51:39 +00:00
|
|
|
**********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "citrtest.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/schriter.h"
|
2000-06-22 01:09:15 +00:00
|
|
|
#include "unicode/uchriter.h"
|
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include <string.h>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
CharIterTest::CharIterTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void CharIterTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (exec) logln("TestSuite LocaleTest: ");
|
|
|
|
switch (index) {
|
|
|
|
case 0: name = "TestConstructionAndEquality"; if (exec) TestConstructionAndEquality(); break;
|
2000-06-22 01:09:15 +00:00
|
|
|
case 1: name = "TestConstructionAndEqualityUChariter"; if (exec) TestConstructionAndEqualityUChariter(); break;
|
|
|
|
case 2: name = "TestIteration"; if (exec) TestIteration(); break;
|
|
|
|
case 3: name = "TestIterationUChar32"; if (exec) TestIterationUChar32(); break;
|
2000-05-23 20:51:39 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
default: name = ""; break; //needed to end loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CharIterTest::TestConstructionAndEquality() {
|
|
|
|
UnicodeString testText("Now is the time for all good men to come to the aid of their country.");
|
|
|
|
UnicodeString testText2("Don't bother using this string.");
|
2000-06-22 01:09:15 +00:00
|
|
|
UnicodeString result1, result2, result3;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
CharacterIterator* test1 = new StringCharacterIterator(testText);
|
2000-06-22 01:09:15 +00:00
|
|
|
CharacterIterator* test1b= new StringCharacterIterator(testText, -1);
|
|
|
|
CharacterIterator* test1c= new StringCharacterIterator(testText, 100);
|
|
|
|
CharacterIterator* test1d= new StringCharacterIterator(testText, -2, 100, 5);
|
|
|
|
CharacterIterator* test1e= new StringCharacterIterator(testText, 100, 20, 5);
|
1999-08-16 21:50:52 +00:00
|
|
|
CharacterIterator* test2 = new StringCharacterIterator(testText, 5);
|
|
|
|
CharacterIterator* test3 = new StringCharacterIterator(testText, 2, 20, 5);
|
|
|
|
CharacterIterator* test4 = new StringCharacterIterator(testText2);
|
|
|
|
CharacterIterator* test5 = test1->clone();
|
|
|
|
|
2000-09-27 20:12:18 +00:00
|
|
|
if (test1d->startIndex() < 0)
|
|
|
|
errln("Construction failed: startIndex is negative");
|
|
|
|
if (test1d->endIndex() > testText.length())
|
|
|
|
errln("Construction failed: endIndex is greater than the text length");
|
|
|
|
if (test1d->getIndex() < test1d->startIndex() || test1d->endIndex() < test1d->getIndex())
|
2000-09-28 05:46:28 +00:00
|
|
|
errln("Construction failed: index is invalid");
|
2000-09-27 20:12:18 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
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 (test1->hashCode() == test2->hashCode() || test1->hashCode() == test3->hashCode()
|
|
|
|
|| test1->hashCode() == test4->hashCode())
|
|
|
|
errln("hashCode() failed: different objects have same hash code");
|
|
|
|
|
|
|
|
if (test1->hashCode() != test5->hashCode())
|
|
|
|
errln("hashCode() failed: identical objects have different hash codes");
|
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
|
|
|
|
test1->getText(result1);
|
|
|
|
test1b->getText(result2);
|
|
|
|
test1c->getText(result3);
|
|
|
|
if(result1 != result2 || result1 != result3)
|
|
|
|
errln("construction failed or getText() failed");
|
|
|
|
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
test1->setIndex(5);
|
|
|
|
if (*test1 != *test2 || *test1 == *test5)
|
|
|
|
errln("setIndex() failed");
|
|
|
|
|
|
|
|
*((StringCharacterIterator*)test1) = *((StringCharacterIterator*)test3);
|
|
|
|
if (*test1 != *test3 || *test1 == *test5)
|
|
|
|
errln("operator= failed");
|
|
|
|
|
|
|
|
delete test2;
|
|
|
|
delete test3;
|
|
|
|
delete test4;
|
|
|
|
delete test5;
|
2000-06-22 01:09:15 +00:00
|
|
|
delete test1b;
|
|
|
|
delete test1c;
|
|
|
|
delete test1d;
|
|
|
|
delete test1e;
|
|
|
|
|
|
|
|
|
|
|
|
StringCharacterIterator* testChar1=new StringCharacterIterator(testText);
|
|
|
|
StringCharacterIterator* testChar2=new StringCharacterIterator(testText2);
|
|
|
|
StringCharacterIterator* testChar3=(StringCharacterIterator*)test1->clone();
|
|
|
|
|
|
|
|
testChar1->getText(result1);
|
|
|
|
testChar2->getText(result2);
|
|
|
|
testChar3->getText(result3);
|
|
|
|
if(result1 != result3 || result1 == result2)
|
|
|
|
errln("getText() failed");
|
|
|
|
testChar3->setText(testText2);
|
|
|
|
testChar3->getText(result3);
|
|
|
|
if(result1 == result3 || result2 != result3)
|
|
|
|
errln("setText() or getText() failed");
|
|
|
|
testChar3->setText(testText);
|
|
|
|
testChar3->getText(result3);
|
|
|
|
if(result1 != result3 || result1 == result2)
|
|
|
|
errln("setText() or getText() round-trip failed");
|
|
|
|
|
|
|
|
delete testChar1;
|
|
|
|
delete testChar2;
|
|
|
|
delete testChar3;
|
2000-06-29 19:42:17 +00:00
|
|
|
delete test1;
|
2000-06-22 01:09:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
void CharIterTest::TestConstructionAndEqualityUChariter() {
|
2001-11-12 18:09:10 +00:00
|
|
|
U_STRING_DECL(testText, "Now is the time for all good men to come to the aid of their country.", 69);
|
|
|
|
U_STRING_DECL(testText2, "Don't bother using this string.", 31);
|
2000-06-22 01:09:15 +00:00
|
|
|
|
2001-11-12 18:09:10 +00:00
|
|
|
U_STRING_INIT(testText, "Now is the time for all good men to come to the aid of their country.", 69);
|
|
|
|
U_STRING_INIT(testText2, "Don't bother using this string.", 31);
|
2000-09-28 05:46:28 +00:00
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
UnicodeString result, result4, result5;
|
2000-09-28 05:46:28 +00:00
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
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);
|
|
|
|
UCharCharacterIterator* test4 = new UCharCharacterIterator(testText2, u_strlen(testText2));
|
|
|
|
UCharCharacterIterator* test5 = (UCharCharacterIterator*)test1->clone();
|
2000-12-09 03:08:42 +00:00
|
|
|
UCharCharacterIterator* test6 = new UCharCharacterIterator(*test1);
|
2000-06-22 01:09:15 +00:00
|
|
|
|
2001-11-12 18:09:10 +00:00
|
|
|
// j785: length=-1 will use u_strlen()
|
2000-06-22 01:09:15 +00:00
|
|
|
UCharCharacterIterator* test7a = new UCharCharacterIterator(testText, -1);
|
|
|
|
UCharCharacterIterator* test7b = new UCharCharacterIterator(testText, -1);
|
|
|
|
UCharCharacterIterator* test7c = new UCharCharacterIterator(testText, -1, 2, 20, 5);
|
2000-09-28 05:46:28 +00:00
|
|
|
|
|
|
|
// 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");
|
2001-11-12 18:09:10 +00:00
|
|
|
if (test8b->endIndex() != u_strlen(testText))
|
|
|
|
errln("Construction failed: endIndex is different from the text length");
|
2000-09-28 05:46:28 +00:00
|
|
|
if (test8c->getIndex() < test8c->startIndex() || test8c->endIndex() < test8c->getIndex())
|
|
|
|
errln("Construction failed: index is invalid");
|
2000-06-22 01:09:15 +00:00
|
|
|
|
|
|
|
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");
|
2000-09-28 05:46:28 +00:00
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
if (*test6 != *test1 )
|
|
|
|
errln("copy construction or equals() failed: Two copies tested unequal");
|
|
|
|
|
|
|
|
if (test1->hashCode() == test2->hashCode() || test1->hashCode() == test3->hashCode()
|
|
|
|
|| test1->hashCode() == test4->hashCode())
|
|
|
|
errln("hashCode() failed: different objects have same hash code");
|
|
|
|
|
|
|
|
if (test1->hashCode() != test5->hashCode())
|
|
|
|
errln("hashCode() failed: identical objects have different hash codes");
|
|
|
|
|
|
|
|
test7a->getText(result);
|
|
|
|
test7b->getText(result4);
|
|
|
|
test7c->getText(result5);
|
|
|
|
|
2001-11-12 18:09:10 +00:00
|
|
|
if(result != UnicodeString(testText) || result4 != result || result5 != result)
|
2000-06-22 01:09:15 +00:00
|
|
|
errln("error in construction");
|
|
|
|
|
|
|
|
test1->getText(result);
|
|
|
|
test4->getText(result4);
|
|
|
|
test5->getText(result5);
|
|
|
|
if(result != result5 || result == result4)
|
|
|
|
errln("getText() failed");
|
|
|
|
test5->setText(testText2, u_strlen(testText2));
|
|
|
|
test5->getText(result5);
|
|
|
|
if(result == result5 || result4 != result5)
|
|
|
|
errln("setText() or getText() failed");
|
|
|
|
test5->setText(testText, u_strlen(testText));
|
|
|
|
test5->getText(result5);
|
|
|
|
if(result != result5 || result == result4)
|
|
|
|
errln("setText() or getText() round-trip failed");
|
|
|
|
|
|
|
|
|
|
|
|
test1->setIndex(5);
|
|
|
|
if (*test1 != *test2 || *test1 == *test5)
|
|
|
|
errln("setIndex() failed");
|
2001-11-12 18:09:10 +00:00
|
|
|
test8b->setIndex32(5);
|
|
|
|
if (test8b->getIndex()!=5)
|
2000-09-28 05:46:28 +00:00
|
|
|
errln("setIndex32() failed");
|
2000-06-22 01:09:15 +00:00
|
|
|
|
|
|
|
*test1 = *test3;
|
|
|
|
if (*test1 != *test3 || *test1 == *test5)
|
|
|
|
errln("operator= failed");
|
|
|
|
|
|
|
|
delete test1;
|
|
|
|
delete test2;
|
|
|
|
delete test3;
|
|
|
|
delete test4;
|
|
|
|
delete test5;
|
|
|
|
delete test6;
|
|
|
|
delete test7a;
|
|
|
|
delete test7b;
|
|
|
|
delete test7c;
|
2001-03-10 02:06:11 +00:00
|
|
|
delete test8a;
|
|
|
|
delete test8b;
|
|
|
|
delete test8c;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void CharIterTest::TestIteration() {
|
|
|
|
UnicodeString text("Now is the time for all good men to come to the aid of their country.");
|
|
|
|
|
|
|
|
UChar c;
|
|
|
|
UTextOffset i;
|
|
|
|
{
|
|
|
|
StringCharacterIterator iter(text, 5);
|
|
|
|
|
|
|
|
UnicodeString iterText;
|
|
|
|
iter.getText(iterText);
|
|
|
|
if (iterText != text)
|
|
|
|
errln("iter.getText() failed");
|
|
|
|
|
|
|
|
if (iter.current() != text[(UTextOffset)5])
|
|
|
|
errln("Iterator didn't start out in the right place.");
|
|
|
|
|
|
|
|
c = iter.first();
|
|
|
|
i = 0;
|
|
|
|
|
1999-12-08 02:11:04 +00:00
|
|
|
if (iter.startIndex() != 0 || iter.endIndex() != text.length())
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("startIndex() or endIndex() failed");
|
|
|
|
|
|
|
|
logln("Testing forward iteration...");
|
|
|
|
do {
|
1999-12-08 02:11:04 +00:00
|
|
|
if (c == CharacterIterator::DONE && i != text.length())
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("Iterator reached end prematurely");
|
|
|
|
else if (c != text[i])
|
|
|
|
errln((UnicodeString)"Character mismatch at position " + i +
|
|
|
|
", iterator has " + UCharToUnicodeString(c) +
|
|
|
|
", string has " + UCharToUnicodeString(text[i]));
|
|
|
|
|
|
|
|
if (iter.current() != c)
|
|
|
|
errln("current() isn't working right");
|
|
|
|
if (iter.getIndex() != i)
|
|
|
|
errln("getIndex() isn't working right");
|
|
|
|
|
|
|
|
if (c != CharacterIterator::DONE) {
|
|
|
|
c = iter.next();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
} while (c != CharacterIterator::DONE);
|
2000-06-22 01:09:15 +00:00
|
|
|
c=iter.next();
|
|
|
|
if(c!= CharacterIterator::DONE)
|
|
|
|
errln("next() didn't return DONE at the end");
|
|
|
|
c=iter.setIndex(text.length()+1);
|
|
|
|
if(c!= CharacterIterator::DONE)
|
|
|
|
errln("setIndex(len+1) didn't return DONE");
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
c = iter.last();
|
1999-12-08 02:11:04 +00:00
|
|
|
i = text.length() - 1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
logln("Testing backward iteration...");
|
|
|
|
do {
|
|
|
|
if (c == CharacterIterator::DONE && i >= 0)
|
|
|
|
errln("Iterator reached end prematurely");
|
|
|
|
else if (c != text[i])
|
|
|
|
errln((UnicodeString)"Character mismatch at position " + i +
|
|
|
|
", iterator has " + UCharToUnicodeString(c) +
|
|
|
|
", string has " + UCharToUnicodeString(text[i]));
|
|
|
|
|
|
|
|
if (iter.current() != c)
|
|
|
|
errln("current() isn't working right");
|
2000-08-14 21:42:36 +00:00
|
|
|
if (iter.getIndex() != i)
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("getIndex() isn't working right");
|
2000-08-14 21:42:36 +00:00
|
|
|
if(iter.setIndex(i) != c)
|
|
|
|
errln("setIndex() isn't working right");
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if (c != CharacterIterator::DONE) {
|
|
|
|
c = iter.previous();
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
} while (c != CharacterIterator::DONE);
|
2000-05-23 20:51:39 +00:00
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
c=iter.previous();
|
|
|
|
if(c!= CharacterIterator::DONE)
|
|
|
|
errln("previous didn't return DONE at the beginning");
|
2000-08-14 21:42:36 +00:00
|
|
|
|
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
//testing firstPostInc, nextPostInc, setTostart
|
2000-05-23 20:51:39 +00:00
|
|
|
i = 0;
|
2000-08-14 21:42:36 +00:00
|
|
|
c=iter.firstPostInc();
|
|
|
|
if(c != text[i])
|
|
|
|
errln((UnicodeString)"firstPostInc failed. Expected->" +
|
|
|
|
UCharToUnicodeString(text[i]) + " Got->" + UCharToUnicodeString(c));
|
|
|
|
if(iter.getIndex() != i+1)
|
|
|
|
errln((UnicodeString)"getIndex() after firstPostInc() failed");
|
|
|
|
|
|
|
|
iter.setToStart();
|
|
|
|
i=0;
|
2000-05-23 20:51:39 +00:00
|
|
|
if (iter.startIndex() != 0)
|
|
|
|
errln("setToStart failed");
|
2000-08-14 21:42:36 +00:00
|
|
|
|
2000-05-23 20:51:39 +00:00
|
|
|
logln("Testing forward iteration...");
|
|
|
|
do {
|
2000-08-14 21:42:36 +00:00
|
|
|
if (c != CharacterIterator::DONE)
|
2000-05-23 20:51:39 +00:00
|
|
|
c = iter.nextPostInc();
|
2000-08-14 21:42:36 +00:00
|
|
|
|
2000-05-23 20:51:39 +00:00
|
|
|
if(c != text[i])
|
|
|
|
errln((UnicodeString)"Character mismatch at position " + i +
|
|
|
|
(UnicodeString)", iterator has " + UCharToUnicodeString(c) +
|
|
|
|
(UnicodeString)", string has " + UCharToUnicodeString(text[i]));
|
2000-08-14 21:42:36 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
if(iter.getIndex() != i)
|
|
|
|
errln("getIndex() aftr nextPostInc() isn't working right");
|
|
|
|
if(iter.current() != text[i])
|
|
|
|
errln("current() after nextPostInc() isn't working right");
|
|
|
|
} while (iter.hasNext());
|
2000-06-22 01:09:15 +00:00
|
|
|
c=iter.nextPostInc();
|
|
|
|
if(c!= CharacterIterator::DONE)
|
|
|
|
errln("nextPostInc() didn't return DONE at the beginning");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
StringCharacterIterator iter(text, 5, 15, 10);
|
|
|
|
if (iter.startIndex() != 5 || iter.endIndex() != 15)
|
|
|
|
errln("creation of a restricted-range iterator failed");
|
|
|
|
|
|
|
|
if (iter.getIndex() != 10 || iter.current() != text[(UTextOffset)10])
|
|
|
|
errln("starting the iterator in the middle didn't work");
|
|
|
|
|
|
|
|
c = iter.first();
|
|
|
|
i = 5;
|
|
|
|
|
|
|
|
logln("Testing forward iteration over a range...");
|
|
|
|
do {
|
|
|
|
if (c == CharacterIterator::DONE && i != 15)
|
|
|
|
errln("Iterator reached end prematurely");
|
|
|
|
else if (c != text[i])
|
|
|
|
errln((UnicodeString)"Character mismatch at position " + i +
|
|
|
|
", iterator has " + UCharToUnicodeString(c) +
|
|
|
|
", string has " + UCharToUnicodeString(text[i]));
|
|
|
|
|
|
|
|
if (iter.current() != c)
|
|
|
|
errln("current() isn't working right");
|
|
|
|
if (iter.getIndex() != i)
|
|
|
|
errln("getIndex() isn't working right");
|
2000-08-14 21:42:36 +00:00
|
|
|
if(iter.setIndex(i) != c)
|
|
|
|
errln("setIndex() isn't working right");
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if (c != CharacterIterator::DONE) {
|
|
|
|
c = iter.next();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
} while (c != CharacterIterator::DONE);
|
|
|
|
|
|
|
|
c = iter.last();
|
|
|
|
i = 14;
|
|
|
|
|
|
|
|
logln("Testing backward iteration over a range...");
|
|
|
|
do {
|
|
|
|
if (c == CharacterIterator::DONE && i >= 5)
|
|
|
|
errln("Iterator reached end prematurely");
|
|
|
|
else if (c != text[i])
|
|
|
|
errln((UnicodeString)"Character mismatch at position " + i +
|
|
|
|
", iterator has " + UCharToUnicodeString(c) +
|
|
|
|
", string has " + UCharToUnicodeString(text[i]));
|
|
|
|
|
|
|
|
if (iter.current() != c)
|
|
|
|
errln("current() isn't working right");
|
|
|
|
if (iter.getIndex() != i)
|
|
|
|
errln("getIndex() isn't working right");
|
|
|
|
|
|
|
|
if (c != CharacterIterator::DONE) {
|
|
|
|
c = iter.previous();
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
} while (c != CharacterIterator::DONE);
|
2000-05-23 20:51:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2001-03-10 02:06:11 +00:00
|
|
|
|
2000-05-23 20:51:39 +00:00
|
|
|
//Tests for new API for utf-16 support
|
|
|
|
void CharIterTest::TestIterationUChar32() {
|
|
|
|
UChar textChars[]={ 0x0061, 0x0062, 0xd841, 0xdc02, 0x20ac, 0xd7ff, 0xd842, 0xdc06, 0xd801, 0xdc00, 0x0061, 0x0000};
|
|
|
|
UnicodeString text(textChars);
|
|
|
|
UChar32 c;
|
|
|
|
UTextOffset i;
|
|
|
|
{
|
|
|
|
StringCharacterIterator iter(text, 1);
|
|
|
|
|
|
|
|
UnicodeString iterText;
|
|
|
|
iter.getText(iterText);
|
|
|
|
if (iterText != text)
|
|
|
|
errln("iter.getText() failed");
|
|
|
|
|
|
|
|
if (iter.current32() != text[(UTextOffset)1])
|
|
|
|
errln("Iterator didn't start out in the right place.");
|
2000-06-22 01:09:15 +00:00
|
|
|
|
|
|
|
c=iter.setToStart();
|
|
|
|
i=0;
|
|
|
|
i=iter.move32(1, CharacterIterator::kStart);
|
|
|
|
c=iter.current32();
|
|
|
|
if(c != text.char32At(1) || i!=1)
|
|
|
|
errln((UnicodeString)"move32(1, kStart) didn't work correctly expected " + c + " got " + text.char32At(1) );
|
|
|
|
|
|
|
|
i=iter.move32(2, CharacterIterator::kCurrent);
|
|
|
|
c=iter.current32();
|
|
|
|
if(c != text.char32At(4) || i!=4)
|
|
|
|
errln((UnicodeString)"move32(2, kCurrent) didn't work correctly expected " + c + " got " + text.char32At(4) + "i=" + i);
|
|
|
|
|
|
|
|
i=iter.move32(-2, CharacterIterator::kCurrent);
|
|
|
|
c=iter.current32();
|
|
|
|
if(c != text.char32At(1) || i!=1)
|
|
|
|
errln((UnicodeString)"move32(-2, kCurrent) didn't work correctly expected " + c + " got " + text.char32At(1) + "i=" + i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i=iter.move32(-2, CharacterIterator::kEnd);
|
|
|
|
c=iter.current32();
|
|
|
|
if(c != text.char32At((text.length()-3)) || i!=(text.length()-3))
|
|
|
|
errln((UnicodeString)"move32(-2, kEnd) didn't work correctly expected " + c + " got " + text.char32At((text.length()-3)) + "i=" + i);
|
|
|
|
|
2000-05-23 20:51:39 +00:00
|
|
|
|
|
|
|
c = iter.first32();
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
if (iter.startIndex() != 0 || iter.endIndex() != text.length())
|
|
|
|
errln("startIndex() or endIndex() failed");
|
|
|
|
|
|
|
|
logln("Testing forward iteration...");
|
|
|
|
do {
|
2001-03-10 02:06:11 +00:00
|
|
|
/* logln("c=%d i=%d char32At=%d", c, i, text.char32At(i)); */
|
2000-05-23 20:51:39 +00:00
|
|
|
if (c == CharacterIterator::DONE && i != text.length())
|
|
|
|
errln("Iterator reached end prematurely");
|
2000-08-14 21:42:36 +00:00
|
|
|
else if(iter.hasNext() == FALSE && i != text.length())
|
|
|
|
errln("Iterator reached end prematurely. Failed at hasNext");
|
2000-05-23 20:51:39 +00:00
|
|
|
else if (c != text.char32At(i))
|
|
|
|
errln((UnicodeString)"Character mismatch at position " + i +
|
|
|
|
(UnicodeString)", iterator has " + c +
|
|
|
|
(UnicodeString)", string has " + text.char32At(i));
|
|
|
|
|
|
|
|
if (iter.current32() != c)
|
|
|
|
errln("current32() isn't working right");
|
2000-08-14 21:42:36 +00:00
|
|
|
if(iter.setIndex32(i) != c)
|
|
|
|
errln("setIndex32() isn't working right");
|
2000-05-23 20:51:39 +00:00
|
|
|
if (c != CharacterIterator::DONE) {
|
|
|
|
c = iter.next32();
|
2000-08-14 21:42:36 +00:00
|
|
|
i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i+2 : i+1;
|
2000-05-23 20:51:39 +00:00
|
|
|
}
|
|
|
|
} while (c != CharacterIterator::DONE);
|
|
|
|
if(iter.hasNext() == TRUE)
|
|
|
|
errln("hasNext() returned true at the end of the string");
|
2000-08-14 21:42:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c=iter.setToEnd();
|
|
|
|
if(iter.getIndex() != text.length() || iter.hasNext() != FALSE)
|
|
|
|
errln("setToEnd failed");
|
2000-05-23 20:51:39 +00:00
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
c=iter.next32();
|
|
|
|
if(c!= CharacterIterator::DONE)
|
|
|
|
errln("next32 didn't return DONE at the end");
|
|
|
|
c=iter.setIndex32(text.length()+1);
|
|
|
|
if(c!= CharacterIterator::DONE)
|
|
|
|
errln("setIndex32(len+1) didn't return DONE");
|
|
|
|
|
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
c = iter.last32();
|
2000-05-23 20:51:39 +00:00
|
|
|
i = text.length()-1;
|
|
|
|
logln("Testing backward iteration...");
|
|
|
|
do {
|
|
|
|
if (c == CharacterIterator::DONE && i >= 0)
|
|
|
|
errln((UnicodeString)"Iterator reached start prematurely for i=" + i);
|
2000-08-14 21:42:36 +00:00
|
|
|
else if(iter.hasPrevious() == FALSE && i>0)
|
|
|
|
errln((UnicodeString)"Iterator reached start prematurely for i=" + i);
|
2000-05-23 20:51:39 +00:00
|
|
|
else if (c != text.char32At(i))
|
|
|
|
errln(prettify((UnicodeString)"Character mismatch at position " + i +
|
|
|
|
(UnicodeString)", iterator has " + c +
|
|
|
|
(UnicodeString)", string has " + text.char32At(i)));
|
2000-08-14 21:42:36 +00:00
|
|
|
|
2000-05-23 20:51:39 +00:00
|
|
|
if (iter.current32() != c)
|
|
|
|
errln("current32() isn't working right");
|
|
|
|
if(iter.setIndex32(i) != c)
|
2000-08-14 21:42:36 +00:00
|
|
|
errln("setIndex32() isn't working right");
|
|
|
|
if (iter.getIndex() != i)
|
2000-05-23 20:51:39 +00:00
|
|
|
errln("getIndex() isn't working right");
|
|
|
|
if (c != CharacterIterator::DONE) {
|
|
|
|
c = iter.previous32();
|
2000-08-14 21:42:36 +00:00
|
|
|
i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i-2 : i-1;
|
2000-05-23 20:51:39 +00:00
|
|
|
}
|
|
|
|
} while (c != CharacterIterator::DONE);
|
2000-08-14 21:42:36 +00:00
|
|
|
if(iter.hasPrevious() == TRUE)
|
|
|
|
errln("hasPrevious returned true after reaching the start");
|
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
c=iter.previous32();
|
|
|
|
if(c!= CharacterIterator::DONE)
|
|
|
|
errln("previous32 didn't return DONE at the beginning");
|
2000-05-23 20:51:39 +00:00
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
//testing first32PostInc, next32PostInc, setTostart
|
2000-05-23 20:51:39 +00:00
|
|
|
i = 0;
|
2000-08-14 21:42:36 +00:00
|
|
|
c=iter.first32PostInc();
|
|
|
|
if(c != text.char32At(i))
|
|
|
|
errln((UnicodeString)"first32PostInc failed. Expected->" + text.char32At(i) + " Got->" + c);
|
|
|
|
if(iter.getIndex() != UTF16_CHAR_LENGTH(c) + i)
|
|
|
|
errln((UnicodeString)"getIndex() after first32PostInc() failed");
|
|
|
|
|
|
|
|
iter.setToStart();
|
|
|
|
i=0;
|
2000-05-23 20:51:39 +00:00
|
|
|
if (iter.startIndex() != 0)
|
|
|
|
errln("setToStart failed");
|
|
|
|
|
|
|
|
logln("Testing forward iteration...");
|
|
|
|
do {
|
2000-08-14 21:42:36 +00:00
|
|
|
if (c != CharacterIterator::DONE)
|
2000-05-23 20:51:39 +00:00
|
|
|
c = iter.next32PostInc();
|
2000-08-14 21:42:36 +00:00
|
|
|
|
2000-05-23 20:51:39 +00:00
|
|
|
if(c != text.char32At(i))
|
|
|
|
errln((UnicodeString)"Character mismatch at position " + i +
|
|
|
|
(UnicodeString)", iterator has " + c +
|
|
|
|
(UnicodeString)", string has " + text.char32At(i));
|
2000-08-14 21:42:36 +00:00
|
|
|
|
|
|
|
i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i+2 : i+1;
|
|
|
|
if(iter.getIndex() != i)
|
|
|
|
errln("getIndex() aftr next32PostInc() isn't working right");
|
|
|
|
if(iter.current32() != text.char32At(i))
|
|
|
|
errln("current() after next32PostInc() isn't working right");
|
|
|
|
} while (iter.hasNext());
|
2000-06-22 01:09:15 +00:00
|
|
|
c=iter.next32PostInc();
|
|
|
|
if(c!= CharacterIterator::DONE)
|
|
|
|
errln("next32PostInc() didn't return DONE at the beginning");
|
2000-05-23 20:51:39 +00:00
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
|
2000-05-23 20:51:39 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
{
|
2000-05-23 20:51:39 +00:00
|
|
|
StringCharacterIterator iter(text, 1, 11, 10);
|
|
|
|
if (iter.startIndex() != 1 || iter.endIndex() != 11)
|
|
|
|
errln("creation of a restricted-range iterator failed");
|
|
|
|
|
|
|
|
if (iter.getIndex() != 10 || iter.current32() != text.char32At(10))
|
|
|
|
errln("starting the iterator in the middle didn't work");
|
|
|
|
|
|
|
|
c = iter.first32();
|
2000-06-22 01:09:15 +00:00
|
|
|
|
2000-05-23 20:51:39 +00:00
|
|
|
i = 1;
|
|
|
|
|
|
|
|
logln("Testing forward iteration over a range...");
|
|
|
|
do {
|
|
|
|
if (c == CharacterIterator::DONE && i != 11)
|
|
|
|
errln("Iterator reached end prematurely");
|
2000-08-14 21:42:36 +00:00
|
|
|
else if(iter.hasNext() == FALSE)
|
|
|
|
errln("Iterator reached end prematurely");
|
2000-05-23 20:51:39 +00:00
|
|
|
else if (c != text.char32At(i))
|
|
|
|
errln((UnicodeString)"Character mismatch at position " + i +
|
|
|
|
(UnicodeString)", iterator has " + c +
|
|
|
|
(UnicodeString)", string has " + text.char32At(i));
|
|
|
|
|
|
|
|
if (iter.current32() != c)
|
|
|
|
errln("current32() isn't working right");
|
2000-08-14 21:42:36 +00:00
|
|
|
if(iter.setIndex32(i) != c)
|
|
|
|
errln("setIndex32() isn't working right");
|
2000-05-23 20:51:39 +00:00
|
|
|
|
|
|
|
if (c != CharacterIterator::DONE) {
|
|
|
|
c = iter.next32();
|
2000-08-14 21:42:36 +00:00
|
|
|
i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i+2 : i+1;
|
2000-05-23 20:51:39 +00:00
|
|
|
}
|
|
|
|
} while (c != CharacterIterator::DONE);
|
2000-06-22 01:09:15 +00:00
|
|
|
c=iter.next32();
|
|
|
|
if(c != CharacterIterator::DONE)
|
|
|
|
errln("error in next32()");
|
|
|
|
|
2000-05-23 20:51:39 +00:00
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
|
|
|
|
c=iter.last32();
|
2000-05-23 20:51:39 +00:00
|
|
|
i = 10;
|
|
|
|
logln("Testing backward iteration over a range...");
|
|
|
|
do {
|
|
|
|
if (c == CharacterIterator::DONE && i >= 5)
|
|
|
|
errln("Iterator reached start prematurely");
|
2000-08-14 21:42:36 +00:00
|
|
|
else if(iter.hasPrevious() == FALSE && i > 5)
|
|
|
|
errln("Iterator reached start prematurely");
|
2000-05-23 20:51:39 +00:00
|
|
|
else if (c != text.char32At(i))
|
|
|
|
errln((UnicodeString)"Character mismatch at position " + i +
|
|
|
|
(UnicodeString)", iterator has " + c +
|
|
|
|
(UnicodeString)", string has " + text.char32At(i));
|
|
|
|
if (iter.current32() != c)
|
|
|
|
errln("current32() isn't working right");
|
|
|
|
if (iter.getIndex() != i)
|
|
|
|
errln("getIndex() isn't working right");
|
2000-08-14 21:42:36 +00:00
|
|
|
if(iter.setIndex32(i) != c)
|
|
|
|
errln("setIndex32() isn't working right");
|
2000-05-23 20:51:39 +00:00
|
|
|
|
|
|
|
if (c != CharacterIterator::DONE) {
|
|
|
|
c = iter.previous32();
|
|
|
|
i=UTF16_NEED_MULTIPLE_UCHAR(c) ? i-2 : i-1;
|
|
|
|
}
|
2000-06-22 01:09:15 +00:00
|
|
|
|
2000-05-23 20:51:39 +00:00
|
|
|
} while (c != CharacterIterator::DONE);
|
2000-06-22 01:09:15 +00:00
|
|
|
c=iter.previous32();
|
|
|
|
if(c!= CharacterIterator::DONE)
|
|
|
|
errln("error on previous32");
|
2000-05-23 20:51:39 +00:00
|
|
|
|
2000-06-22 01:09:15 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|