001: /**
002: *******************************************************************************
003: * Copyright (C) 1996-2005, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */package com.ibm.icu.dev.test.lang;
007:
008: import com.ibm.icu.dev.test.TestFmwk;
009:
010: /**
011: * Testing class for UCharacterIterator
012: * @author Syn Wee Quek
013: * @since april 02 2002
014: */
015: public final class UCharacterIteratorTest extends TestFmwk {
016: // constructor -----------------------------------------------------
017:
018: /**
019: * Constructor
020: */
021: public UCharacterIteratorTest() {
022: }
023:
024: // public methods --------------------------------------------------
025:
026: /**
027: * Testing cloning
028: */
029: /*
030: public void TestClone()
031: {
032: UnicodeCharacterIterator iterator = new UnicodeCharacterIterator("testing");
033: UnicodeCharacterIterator cloned = (UnicodeCharacterIterator)iterator.clone();
034: char completed = 0;
035: while (completed != UnicodeCharacterIterator.DONE) {
036: completed = iterator.next();
037: if (completed != cloned.next()) {
038: errln("Cloned operation failed");
039: }
040: }
041: }
042: *
043:
044: /**
045: * Testing iteration
046: */
047: /*
048: public void TestIteration()
049: {
050: UnicodeCharacterIterator iterator = new UnicodeCharacterIterator(
051: ITERATION_STRING_);
052: UnicodeCharacterIterator iterator2 = new UnicodeCharacterIterator(
053: ITERATION_STRING_);
054: if (iterator.first() != ITERATION_STRING_.charAt(0)) {
055: errln("Iterator failed retrieving first character");
056: }
057: if (iterator.last() != ITERATION_STRING_.charAt(
058: ITERATION_STRING_.length() - 1)) {
059: errln("Iterator failed retrieving last character");
060: }
061: if (iterator.getBeginIndex() != 0 ||
062: iterator.getEndIndex() != ITERATION_STRING_.length()) {
063: errln("Iterator failed determining begin and end index");
064: }
065: iterator2.setIndex(0);
066: iterator.setIndex(0);
067: int ch = 0;
068: while (ch != UnicodeCharacterIterator.DONE_CODEPOINT) {
069: int index = iterator2.getIndex();
070: ch = iterator2.nextCodePoint();
071: if (index != ITERATION_SUPPLEMENTARY_INDEX) {
072: if (ch != (int)iterator.next() &&
073: ch != UnicodeCharacterIterator.DONE_CODEPOINT) {
074: errln("Error mismatch in next() and nextCodePoint()");
075: }
076: }
077: else {
078: if (UTF16.getLeadSurrogate(ch) != iterator.next() ||
079: UTF16.getTrailSurrogate(ch) != iterator.next()) {
080: errln("Error mismatch in next and nextCodePoint for " +
081: "supplementary characters");
082: }
083: }
084: }
085: iterator.setIndex(ITERATION_STRING_.length());
086: iterator2.setIndex(ITERATION_STRING_.length());
087: while (ch != UnicodeCharacterIterator.DONE_CODEPOINT) {
088: int index = iterator2.getIndex();
089: ch = iterator2.previousCodePoint();
090: if (index != ITERATION_SUPPLEMENTARY_INDEX) {
091: if (ch != (int)iterator.previous() &&
092: ch != UnicodeCharacterIterator.DONE_CODEPOINT) {
093: errln("Error mismatch in previous() and " +
094: "previousCodePoint()");
095: }
096: }
097: else {
098: if (UTF16.getLeadSurrogate(ch) != iterator.previous() ||
099: UTF16.getTrailSurrogate(ch) != iterator.previous()) {
100: errln("Error mismatch in previous and " +
101: "previousCodePoint for supplementary characters");
102: }
103: }
104: }
105: }
106: */
107: public static void main(String[] arg) {
108: try {
109: UCharacterIteratorTest test = new UCharacterIteratorTest();
110: test.run(arg);
111: } catch (Exception e) {
112: e.printStackTrace();
113: }
114: }
115:
116: // private data members ---------------------------------------------
117:
118: //private static final String ITERATION_STRING_ =
119: // "Testing 1 2 3 \ud800\udc00 456";
120: //private static final int ITERATION_SUPPLEMENTARY_INDEX = 14;
121: }
|