]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - jars/icu4j-52_1/main/tests/core/src/com/ibm/icu/dev/test/rbbi/RBBITestExtended.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / main / tests / core / src / com / ibm / icu / dev / test / rbbi / RBBITestExtended.java
similarity index 86%
rename from jars/icu4j-4_8_1_1/main/tests/core/src/com/ibm/icu/dev/test/rbbi/RBBITestExtended.java
rename to jars/icu4j-52_1/main/tests/core/src/com/ibm/icu/dev/test/rbbi/RBBITestExtended.java
index f0e938b345a92eff646fbc2bacafee335f422191..57f3485050272d4d88dcc9984136602ce5aea4e4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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.
  *
  */
@@ -16,7 +16,6 @@ import com.ibm.icu.dev.test.TestFmwk;
 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;
 
@@ -29,13 +28,13 @@ 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() {
     }
 
 
@@ -51,7 +50,6 @@ static class TestParams {
 
 
 public void TestExtended() {
-
     TestParams     tp = new TestParams();
 
 
@@ -66,7 +64,7 @@ public void TestExtended() {
             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 (;;) {
@@ -79,17 +77,17 @@ public void TestExtended() {
                // 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;
@@ -240,7 +238,7 @@ public void TestExtended() {
                 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);
@@ -248,7 +246,7 @@ public void TestExtended() {
                         tp.srcLine[i] = lineNum;
                         tp.srcCol[i]  = column;
                     }
-                    
+
                  }
                 if (nameEndIdx > charIdx) {
                     charIdx = nameEndIdx+1;
@@ -280,7 +278,7 @@ public void TestExtended() {
             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
@@ -307,7 +305,7 @@ public void TestExtended() {
                         tp.srcLine[i] = lineNum;
                         tp.srcCol[i]  = column;
                     }
-                    
+
                     break;
                 }
 
@@ -321,7 +319,7 @@ public void TestExtended() {
 
             // 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
@@ -361,13 +359,13 @@ public void TestExtended() {
 
             errln("Syntax Error in test file at line "+ lineNum +", col %d" + column);
             return;
-            
+
             // parseState = PARSE_COMMENT;   // TODO: unreachable.  Don't stop on errors.
             // break;
         }
 
 
+
     }
 }
 
@@ -379,7 +377,7 @@ void executeTest(TestParams t) {
     if (t.bi == null) {
         return;
     }
-    
+
     t.bi.setText(t.dataToBreak.toString());
     //
     //  Run the iterator forward
@@ -397,14 +395,14 @@ void executeTest(TestParams t) {
         //  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.
@@ -414,12 +412,16 @@ void executeTest(TestParams t) {
                 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]);
         }
 
 
@@ -429,11 +431,12 @@ void executeTest(TestParams t) {
     // 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.
     //
@@ -446,18 +449,18 @@ void executeTest(TestParams t) {
             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.
@@ -467,12 +470,12 @@ void executeTest(TestParams t) {
                 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;
@@ -481,10 +484,56 @@ void executeTest(TestParams t) {
     // 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);
+        }
+    }
+
 }