/*
* Created on May 5, 2004
- *
- * Copyright (C) 2004-2010 International Business Machines Corporation and others.
+ *
+ * Copyright (C) 2004-2013 International Business Machines Corporation and others.
* All Rights Reserved.
*
*/
import com.ibm.icu.impl.Utility;
import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.text.BreakIterator;
-import com.ibm.icu.text.RuleBasedBreakIterator;
import com.ibm.icu.text.UTF16;
import com.ibm.icu.util.ULocale;
*
*/
public class RBBITestExtended extends TestFmwk {
-
+
public static void main(String[] args)throws Exception {
new RBBITestExtended().run(args);
}
-
-
-public RBBITestExtended() {
+
+
+public RBBITestExtended() {
}
public void TestExtended() {
-
TestParams tp = new TestParams();
errln("Could not open test data file rbbitst.txt");
return;
}
- isr = new InputStreamReader(is, "UTF-8");
+ isr = new InputStreamReader(is, "UTF-8");
int c;
int count = 0;
for (;;) {
// BOM in the test data file. Discard it.
continue;
}
-
+
UTF16.append(testFileBuf, c);
}
-
+
} catch (IOException e) {
errln(e.toString());
return;
}
-
+
String testString = testFileBuf.toString();
-
+
final int PARSE_COMMENT = 1;
final int PARSE_TAG = 2;
if (c == -1) {
errln("Error in named character in test file at line " + lineNum +
", col " + column);
- } else {
+ } else {
// Named code point was recognized. Insert it
// into the test data.
UTF16.append(tp.dataToBreak, c);
tp.srcLine[i] = lineNum;
tp.srcCol[i] = column;
}
-
+
}
if (nameEndIdx > charIdx) {
charIdx = nameEndIdx+1;
if (c == CH_BACKSLASH) {
// Check for \ at end of line, a line continuation.
// Advance over (discard) the newline
- int cp = UTF16.charAt(testString, charIdx);
+ int cp = UTF16.charAt(testString, charIdx);
if (cp == CH_CR && charIdx<len && UTF16.charAt(testString, charIdx+1) == CH_LF) {
// We have a CR LF
// Need an extra increment of the input ptr to move over both of them
tp.srcLine[i] = lineNum;
tp.srcCol[i] = column;
}
-
+
break;
}
// Normal, non-escaped data char.
UTF16.append(tp.dataToBreak, c);
-
+
// Save the mapping from offset in the data to line/column numbers in
// the original input file. Will be used for better error messages only.
// If there's an expected break before this char, the slot in the mapping
errln("Syntax Error in test file at line "+ lineNum +", col %d" + column);
return;
-
+
// parseState = PARSE_COMMENT; // TODO: unreachable. Don't stop on errors.
// break;
}
-
+
}
}
if (t.bi == null) {
return;
}
-
+
t.bi.setText(t.dataToBreak.toString());
//
// Run the iterator forward
// and this one.
for (i=prevBP+1; i<bp; i++) {
if (t.expectedBreaks[i] != 0) {
- errln("Forward Iteration, break expected, but not found. Pos=" + i +
+ errln("Forward Iteration, break expected, but not found. Pos=" + i +
" File line,col= " + t.srcLine[i] + ", " + t.srcCol[i]);
}
}
// Check that the break we did find was expected
if (t.expectedBreaks[bp] == 0) {
- errln("Forward Iteration, break found, but not expected. Pos=" + bp +
+ errln("Forward Iteration, break found, but not expected. Pos=" + bp +
" File line,col= " + t.srcLine[bp] + ", " + t.srcCol[bp]);
} else {
// The break was expected.
expectedTagVal = 0;
}
int line = t.srcLine[bp];
- int rs = ((RuleBasedBreakIterator)t.bi).getRuleStatus();
+ int rs = t.bi.getRuleStatus();
if (rs != expectedTagVal) {
errln("Incorrect status for forward break. Pos = " + bp +
". File line,col = " + line + ", " + t.srcCol[bp] + "\n" +
" Actual, Expected status = " + rs + ", " + expectedTagVal);
}
+ int[] fillInArray = new int[4];
+ int numStatusVals = t.bi.getRuleStatusVec(fillInArray);
+ assertTrue("", numStatusVals >= 1);
+ assertEquals("", expectedTagVal, fillInArray[0]);
}
// Verify that there were no missed expected breaks after the last one found
for (i=prevBP+1; i<t.dataToBreak.length()+1; i++) {
if (t.expectedBreaks[i] != 0) {
- errln("Forward Iteration, break expected, but not found. Pos=" + i +
+ errln("Forward Iteration, break expected, but not found. Pos=" + i +
" File line,col= " + t.srcLine[i] + ", " + t.srcCol[i]);
}
}
+
//
// Run the iterator backwards, verify that the same breaks are found.
//
break;
}
- // Check that there were we didn't miss an expected break between the last one
+ // Check that we didn't miss an expected break between the last one
// and this one. (UVector returns zeros for index out of bounds.)
for (i=prevBP-1; i>bp; i--) {
if (t.expectedBreaks[i] != 0) {
- errln("Reverse Itertion, break expected, but not found. Pos=" + i +
+ errln("Reverse Itertion, break expected, but not found. Pos=" + i +
" File line,col= " + t.srcLine[i] + ", " + t.srcCol[i]);
}
}
// Check that the break we did find was expected
if (t.expectedBreaks[bp] == 0) {
- errln("Reverse Itertion, break found, but not expected. Pos=" + bp +
+ errln("Reverse Itertion, break found, but not expected. Pos=" + bp +
" File line,col= " + t.srcLine[bp] + ", " + t.srcCol[bp]);
} else {
// The break was expected.
expectedTagVal = 0;
}
int line = t.srcLine[bp];
- int rs = ((RuleBasedBreakIterator)t.bi).getRuleStatus();
+ int rs = t.bi.getRuleStatus();
if (rs != expectedTagVal) {
errln("Incorrect status for reverse break. Pos= " + bp +
"File line,col= " + line + ", " + t.srcCol[bp] + "\n" +
" Actual, Expected status = " + rs + ", " + expectedTagVal);
- }
+ }
}
prevBP = bp;
// Verify that there were no missed breaks prior to the last one found
for (i=prevBP-1; i>=0; i--) {
if (t.expectedBreaks[i] != 0) {
- errln("Forward Itertion, break expected, but not found. Pos=" + i +
+ errln("Reverse Itertion, break expected, but not found. Pos=" + i +
" File line,col= " + t.srcLine[i] + ", " + t.srcCol[i]);
}
}
+ // Check isBoundary()
+ for (i=0; i<=t.dataToBreak.length(); i++) {
+ boolean boundaryExpected = (t.expectedBreaks[i] != 0);
+ boolean boundaryFound = t.bi.isBoundary(i);
+ if (boundaryExpected != boundaryFound) {
+ errln("isBoundary(" + i + ") incorrect.\n" +
+ " File line,col= " + t.srcLine[i] + ", " + t.srcCol[i] +
+ " Expected, Actual= " + boundaryExpected + ", " + boundaryFound);
+ }
+ }
+
+ // Check following()
+ for (i=0; i<=t.dataToBreak.length(); i++) {
+ int actualBreak = t.bi.following(i);
+ int expectedBreak = BreakIterator.DONE;
+ for (int j=i+1; j < t.expectedBreaks.length; j++) {
+ if (t.expectedBreaks[j] != 0) {
+ expectedBreak = j;
+ break;
+ }
+ }
+ if (expectedBreak != actualBreak) {
+ errln("following(" + i + ") incorrect.\n" +
+ " File line,col= " + t.srcLine[i] + ", " + t.srcCol[i] +
+ " Expected, Actual= " + expectedBreak + ", " + actualBreak);
+ }
+ }
+
+ // Check preceding()
+ for (i=t.dataToBreak.length(); i>=0; i--) {
+ int actualBreak = t.bi.preceding(i);
+ int expectedBreak = BreakIterator.DONE;
+
+ for (int j=i-1; j >= 0; j--) {
+ if (t.expectedBreaks[j] != 0) {
+ expectedBreak = j;
+ break;
+ }
+ }
+ if (expectedBreak != actualBreak) {
+ errln("preceding(" + i + ") incorrect.\n" +
+ " File line,col= " + t.srcLine[i] + ", " + t.srcCol[i] +
+ " Expected, Actual= " + expectedBreak + ", " + actualBreak);
+ }
+ }
+
}