/**
* Testing iteration
*/
public void TestIteration()
{
UCharacterIterator iterator = UCharacterIterator.getInstance(
ITERATION_STRING_);
UCharacterIterator iterator2 = UCharacterIterator.getInstance(
ITERATION_STRING_);
iterator.setToStart();
if (iterator.current() != ITERATION_STRING_.charAt(0)) {
errln("Iterator failed retrieving first character");
}
iterator.setToLimit();
if (iterator.previous() != ITERATION_STRING_.charAt(
ITERATION_STRING_.length() - 1)) {
errln("Iterator failed retrieving last character");
}
if (iterator.getLength() != ITERATION_STRING_.length()) {
errln("Iterator failed determining begin and end index");
}
iterator2.setIndex(0);
iterator.setIndex(0);
int ch = 0;
while (ch != UCharacterIterator.DONE) {
int index = iterator2.getIndex();
ch = iterator2.nextCodePoint();
if (index != ITERATION_SUPPLEMENTARY_INDEX) {
if (ch != (int)iterator.next() &&
ch != UCharacterIterator.DONE) {
errln("Error mismatch in next() and nextCodePoint()");
}
}
else {
if (UTF16.getLeadSurrogate(ch) != iterator.next() ||
UTF16.getTrailSurrogate(ch) != iterator.next()) {
errln("Error mismatch in next and nextCodePoint for " +
"supplementary characters");
}
}
}
iterator.setIndex(ITERATION_STRING_.length());
iterator2.setIndex(ITERATION_STRING_.length());
while (ch != UCharacterIterator.DONE) {
int index = iterator2.getIndex();
ch = iterator2.previousCodePoint();
if (index != ITERATION_SUPPLEMENTARY_INDEX) {
if (ch != (int)iterator.previous() &&
ch != UCharacterIterator.DONE) {
errln("Error mismatch in previous() and " +
"previousCodePoint()");