]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/rbbiapts.cpp
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / rbbiapts.cpp
index aa52454bd2c32c4a7bc807de2e6183b98a50190f..6d2ff7d0c037ede1ef182b170bba8bc4b8926289 100644 (file)
@@ -1,5 +1,7 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /********************************************************************
- * Copyright (c) 1999-2010, International Business Machines
+ * Copyright (c) 1999-2016, International Business Machines
  * Corporation and others. All Rights Reserved.
  ********************************************************************
  *   Date        Name        Description
 #include "rbbidata.h"
 #include "cstring.h"
 #include "ubrkimpl.h"
+#include "unicode/locid.h"
 #include "unicode/ustring.h"
 #include "unicode/utext.h"
 #include "cmemory.h"
-
+#if !UCONFIG_NO_BREAK_ITERATION
+#include "unicode/filteredbrk.h"
+#include <stdio.h> // for sprintf
+#endif
 /**
  * API Test the RuleBasedBreakIterator class
  */
 
 
 #define TEST_ASSERT_SUCCESS(status) {if (U_FAILURE(status)) {\
-errln("Failure at file %s, line %d, error = %s", __FILE__, __LINE__, u_errorName(status));}}
+dataerrln("Failure at file %s, line %d, error = %s", __FILE__, __LINE__, u_errorName(status));}}
 
-#define TEST_ASSERT(expr) {if ((expr)==FALSE) { \
-errln("Test Failure at file %s, line %d", __FILE__, __LINE__);}}
+#define TEST_ASSERT(expr) {if ((expr) == FALSE) { \
+    errln("Test Failure at file %s, line %d: \"%s\" is false.\n", __FILE__, __LINE__, #expr);};}
 
 void RBBIAPITest::TestCloneEquals()
 {
@@ -156,10 +162,13 @@ void RBBIAPITest::TestBoilerPlate()
     if(*a!=*b){
         errln("Failed: boilerplate method operator!= does not return correct results");
     }
-    BreakIterator* c = BreakIterator::createWordInstance(Locale("ja"),status);
-    if(a && c){
-        if(*c==*a){
-            errln("Failed: boilerplate method opertator== does not return correct results");
+    // Japanese word break iterators are identical to root with
+    // a dictionary-based break iterator
+    BreakIterator* c = BreakIterator::createCharacterInstance(Locale("ja"),status);
+    BreakIterator* d = BreakIterator::createCharacterInstance(Locale("root"),status);
+    if(c && d){
+        if(*c!=*d){
+            errln("Failed: boilerplate method operator== does not return correct results");
         }
     }else{
         errln("creation of break iterator failed");
@@ -167,6 +176,7 @@ void RBBIAPITest::TestBoilerPlate()
     delete a;
     delete b;
     delete c;
+    delete d;
 }
 
 void RBBIAPITest::TestgetRules()
@@ -635,25 +645,25 @@ void RBBIAPITest::TestQuoteGrouping() {
 //
 void RBBIAPITest::TestRuleStatus() {
      UChar str[30];
-     u_unescape("plain word 123.45 \\u9160\\u9161 \\u30a1\\u30a2 \\u3041\\u3094",
-              // 012345678901234567  8      9    0  1      2    3  4      5    6
-              //                    Ideographic    Katakana       Hiragana
+     //no longer test Han or hiragana breaking here: ruleStatusVec would return nothing
+     // changed UBRK_WORD_KANA to UBRK_WORD_IDEO
+     u_unescape("plain word 123.45 \\u30a1\\u30a2 ",
+              // 012345678901234567  8      9    0
+              //                     Katakana
                 str, 30);
      UnicodeString testString1(str);
-     int32_t bounds1[] = {0, 5, 6, 10, 11, 17, 18, 19, 20, 21, 23, 24, 25, 26};
+     int32_t bounds1[] = {0, 5, 6, 10, 11, 17, 18, 20, 21};
      int32_t tag_lo[]  = {UBRK_WORD_NONE,     UBRK_WORD_LETTER, UBRK_WORD_NONE,    UBRK_WORD_LETTER,
                           UBRK_WORD_NONE,     UBRK_WORD_NUMBER, UBRK_WORD_NONE,
-                          UBRK_WORD_IDEO,     UBRK_WORD_IDEO,   UBRK_WORD_NONE,
-                          UBRK_WORD_KANA,     UBRK_WORD_NONE,   UBRK_WORD_KANA,    UBRK_WORD_KANA};
+                          UBRK_WORD_IDEO,     UBRK_WORD_NONE};
 
      int32_t tag_hi[]  = {UBRK_WORD_NONE_LIMIT, UBRK_WORD_LETTER_LIMIT, UBRK_WORD_NONE_LIMIT, UBRK_WORD_LETTER_LIMIT,
                           UBRK_WORD_NONE_LIMIT, UBRK_WORD_NUMBER_LIMIT, UBRK_WORD_NONE_LIMIT,
-                          UBRK_WORD_IDEO_LIMIT, UBRK_WORD_IDEO_LIMIT,   UBRK_WORD_NONE_LIMIT,
-                          UBRK_WORD_KANA_LIMIT, UBRK_WORD_NONE_LIMIT,   UBRK_WORD_KANA_LIMIT, UBRK_WORD_KANA_LIMIT};
+                          UBRK_WORD_IDEO_LIMIT, UBRK_WORD_NONE_LIMIT};
 
      UErrorCode status=U_ZERO_ERROR;
 
-     RuleBasedBreakIterator *bi = (RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getEnglish(), status);
+     BreakIterator *bi = BreakIterator::createWordInstance(Locale::getEnglish(), status);
      if(U_FAILURE(status)) {
          errcheckln(status, "Fail : in construction - %s", u_errorName(status));
      } else {
@@ -690,8 +700,7 @@ void RBBIAPITest::TestRuleStatus() {
      testString1 =   "test line. \n";
      // break type    s    s     h
 
-     bi = (RuleBasedBreakIterator *)
-         BreakIterator::createLineInstance(Locale::getEnglish(), status);
+     bi = BreakIterator::createLineInstance(Locale::getEnglish(), status);
      if(U_FAILURE(status)) {
          errcheckln(status, "failed to create word break iterator. - %s", u_errorName(status));
      } else {
@@ -870,27 +879,29 @@ void RBBIAPITest::TestRegistration() {
 #if !UCONFIG_NO_SERVICE
     UErrorCode status = U_ZERO_ERROR;
     BreakIterator* ja_word = BreakIterator::createWordInstance("ja_JP", status);
-
     // ok to not delete these if we exit because of error?
     BreakIterator* ja_char = BreakIterator::createCharacterInstance("ja_JP", status);
     BreakIterator* root_word = BreakIterator::createWordInstance("", status);
     BreakIterator* root_char = BreakIterator::createCharacterInstance("", status);
-    
+
     if (status == U_MISSING_RESOURCE_ERROR || status == U_FILE_ACCESS_ERROR) {
         dataerrln("Error creating instances of break interactors - %s", u_errorName(status));
+
         delete ja_word;
         delete ja_char;
         delete root_word;
         delete root_char;
-        
+
         return;
     }
 
     URegistryKey key = BreakIterator::registerInstance(ja_word, "xx", UBRK_WORD, status);
     {
+#if 0 // With a dictionary based word breaking, ja_word is identical to root.
         if (ja_word && *ja_word == *root_word) {
             errln("japan not different from root");
         }
+#endif
     }
 
     {
@@ -1017,7 +1028,7 @@ void RBBIAPITest::RoundtripRule(const char *dataFile) {
     const uint8_t *builtRules;
 
     if (U_FAILURE(status)) {
-        errcheckln(status, "Can't open \"%s\" - %s", dataFile, u_errorName(status));
+        errcheckln(status, "%s:%d Can't open \"%s\" - %s", __FILE__, __LINE__, dataFile, u_errorName(status));
         return;
     }
 
@@ -1025,14 +1036,15 @@ void RBBIAPITest::RoundtripRule(const char *dataFile) {
     builtSource = (const UChar *)(builtRules + ((RBBIDataHeader*)builtRules)->fRuleSource);
     RuleBasedBreakIterator *brkItr = new RuleBasedBreakIterator(builtSource, parseError, status);
     if (U_FAILURE(status)) {
-        errln("createRuleBasedBreakIterator: ICU Error \"%s\"  at line %d, column %d\n",
-                u_errorName(status), parseError.line, parseError.offset);
+        errln("%s:%d createRuleBasedBreakIterator: ICU Error \"%s\"  at line %d, column %d\n",
+                __FILE__, __LINE__, u_errorName(status), parseError.line, parseError.offset);
+        errln(UnicodeString(builtSource));
         return;
     };
     rbbiRules = brkItr->getBinaryRules(length);
     logln("Comparing \"%s\" len=%d", dataFile, length);
     if (memcmp(builtRules, rbbiRules, (int32_t)length) != 0) {
-        errln("Built rules and rebuilt rules are different %s", dataFile);
+        errln("%s:%d Built rules and rebuilt rules are different %s", __FILE__, __LINE__, dataFile);
         return;
     }
     delete brkItr;
@@ -1045,51 +1057,349 @@ void RBBIAPITest::TestRoundtripRules() {
     RoundtripRule("line");
     RoundtripRule("char");
     if (!quick) {
-        RoundtripRule("word_ja");
         RoundtripRule("word_POSIX");
     }
 }
 
-// Try out the RuleBasedBreakIterator constructors that take RBBIDataHeader*
-// (these are protected so we access them via a local class RBBIWithProtectedFunctions).
-// This is just a sanity check, not a thorough test (e.g. we don't check that the 
-// first delete actually frees rulesCopy).
-void RBBIAPITest::TestCreateFromRBBIData() {
-    // Get some handy RBBIData
-    const char *brkName = "word"; // or "sent", "line", "char", etc.
+
+// Check getBinaryRules() and construction of a break iterator from those rules.
+
+void RBBIAPITest::TestGetBinaryRules() {
+    UErrorCode status=U_ZERO_ERROR;
+    LocalPointer<BreakIterator> bi(BreakIterator::createLineInstance(Locale::getEnglish(), status));
+    if (U_FAILURE(status)) {
+        dataerrln("FAIL: BreakIterator::createLineInstance for Locale::getEnglish(): %s", u_errorName(status));
+        return;
+    }
+    RuleBasedBreakIterator *rbbi = dynamic_cast<RuleBasedBreakIterator *>(bi.getAlias());
+    if (rbbi == NULL) {
+        dataerrln("FAIL: RuleBasedBreakIterator is NULL");
+        return;
+    }
+
+    // Check that the new line break iterator is nominally functional.
+    UnicodeString helloWorld("Hello, World!");
+    rbbi->setText(helloWorld);
+    int n = 0;
+    while (bi->next() != UBRK_DONE) {
+        ++n;
+    }
+    TEST_ASSERT(n == 2);
+
+    // Extract the binary rules as a uint8_t blob.
+    uint32_t ruleLength;
+    const uint8_t *binRules = rbbi->getBinaryRules(ruleLength);
+    TEST_ASSERT(ruleLength > 0);
+    TEST_ASSERT(binRules != NULL);
+
+    // Clone the binary rules, and create a break iterator from that.
+    // The break iterator does not adopt the rules; we must delete when we are finished with the iterator.
+    uint8_t *clonedRules = new uint8_t[ruleLength];
+    memcpy(clonedRules, binRules, ruleLength);
+    RuleBasedBreakIterator clonedBI(clonedRules, ruleLength, status);
+    TEST_ASSERT_SUCCESS(status);
+    
+    // Check that the cloned line break iterator is nominally alive.
+    clonedBI.setText(helloWorld);
+    n = 0;
+    while (clonedBI.next() != UBRK_DONE) {
+        ++n;
+    }
+    TEST_ASSERT(n == 2);
+
+    delete[] clonedRules;
+}
+
+
+void RBBIAPITest::TestRefreshInputText() {
+    /*
+     *  RefreshInput changes out the input of a Break Iterator without
+     *    changing anything else in the iterator's state.  Used with Java JNI,
+     *    when Java moves the underlying string storage.   This test
+     *    runs BreakIterator::next() repeatedly, moving the text in the middle of the sequence.
+     *    The right set of boundaries should still be found.
+     */
+    UChar testStr[]  = {0x20, 0x41, 0x20, 0x42, 0x20, 0x43, 0x20, 0x44, 0x0};  /* = " A B C D"  */
+    UChar movedStr[] = {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,  0};
     UErrorCode status = U_ZERO_ERROR;
-    LocalUDataMemoryPointer data(udata_open(U_ICUDATA_BRKITR, "brk", brkName, &status));
-    if ( U_SUCCESS(status) ) {
-        const RBBIDataHeader * builtRules = (const RBBIDataHeader *)udata_getMemory(data.getAlias());
-        uint32_t length = builtRules->fLength;
-        RBBIWithProtectedFunctions * brkItr;
-
-        // Try the memory-adopting constructor, need to copy the data first
-        RBBIDataHeader * rulesCopy = (RBBIDataHeader *) uprv_malloc(length);
-        if ( rulesCopy ) {
-            uprv_memcpy( rulesCopy, builtRules, length );
-
-            brkItr = new RBBIWithProtectedFunctions(rulesCopy, status);
-            if ( U_SUCCESS(status) ) {
-                delete brkItr; // this should free rulesCopy
-            } else {
-                errln("create RuleBasedBreakIterator from RBBIData (adopted): ICU Error \"%s\"\n", u_errorName(status) );
-                status = U_ZERO_ERROR;// reset for the next test
-                uprv_free( rulesCopy );
-            }
+    UText ut1 = UTEXT_INITIALIZER;
+    UText ut2 = UTEXT_INITIALIZER;
+    RuleBasedBreakIterator *bi = (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status);
+    TEST_ASSERT_SUCCESS(status);
+
+    utext_openUChars(&ut1, testStr, -1, &status);
+    TEST_ASSERT_SUCCESS(status);
+
+    if (U_SUCCESS(status)) {
+        bi->setText(&ut1, status);
+        TEST_ASSERT_SUCCESS(status);
+
+        /* Line boundaries will occur before each letter in the original string */
+        TEST_ASSERT(1 == bi->next());
+        TEST_ASSERT(3 == bi->next());
+
+        /* Move the string, kill the original string.  */
+        u_strcpy(movedStr, testStr);
+        u_memset(testStr, 0x20, u_strlen(testStr));
+        utext_openUChars(&ut2, movedStr, -1, &status);
+        TEST_ASSERT_SUCCESS(status);
+        RuleBasedBreakIterator *returnedBI = &bi->refreshInputText(&ut2, status);
+        TEST_ASSERT_SUCCESS(status);
+        TEST_ASSERT(bi == returnedBI);
+
+        /* Find the following matches, now working in the moved string. */
+        TEST_ASSERT(5 == bi->next());
+        TEST_ASSERT(7 == bi->next());
+        TEST_ASSERT(8 == bi->next());
+        TEST_ASSERT(UBRK_DONE == bi->next());
+
+        utext_close(&ut1);
+        utext_close(&ut2);
+    }
+    delete bi;
+
+}
+
+#if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILTERED_BREAK_ITERATION
+static void prtbrks(BreakIterator* brk, const UnicodeString &ustr, IntlTest &it) {
+  static const UChar PILCROW=0x00B6, CHSTR=0x3010, CHEND=0x3011; // lenticular brackets
+  it.logln(UnicodeString("String:'")+ustr+UnicodeString("'"));
+
+  int32_t *pos = new int32_t[ustr.length()];
+  int32_t posCount = 0;
+
+  // calculate breaks up front, so we can print out
+  // sans any debugging
+  for(int32_t n = 0; (n=brk->next())!=UBRK_DONE; ) {
+    pos[posCount++] = n;
+    if(posCount>=ustr.length()) {
+      it.errln("brk count exceeds string length!");
+      return;
+    }
+  }
+  UnicodeString out;
+  out.append((UChar)CHSTR);
+  int32_t prev = 0;
+  for(int32_t i=0;i<posCount;i++) {
+    int32_t n=pos[i];
+    out.append(ustr.tempSubString(prev,n-prev));
+    out.append((UChar)PILCROW);
+    prev=n;
+  }
+  out.append(ustr.tempSubString(prev,ustr.length()-prev));
+  out.append((UChar)CHEND);
+  it.logln(out);
+
+  out.remove();
+  for(int32_t i=0;i<posCount;i++) {
+    char tmp[100];
+    sprintf(tmp,"%d ",pos[i]);
+    out.append(UnicodeString(tmp));
+  }
+  it.logln(out);
+  delete [] pos;
+}
+#endif
+
+void RBBIAPITest::TestFilteredBreakIteratorBuilder() {
+#if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILTERED_BREAK_ITERATION
+  UErrorCode status = U_ZERO_ERROR;
+  LocalPointer<FilteredBreakIteratorBuilder> builder;
+  LocalPointer<BreakIterator> baseBI;
+  LocalPointer<BreakIterator> filteredBI;
+  LocalPointer<BreakIterator> frenchBI;
+
+  const UnicodeString text("In the meantime Mr. Weston arrived with his small ship, which he had now recovered. Capt. Gorges, who informed the Sgt. here that one purpose of his going east was to meet with Mr. Weston, took this opportunity to call him to account for some abuses he had to lay to his charge."); // (William Bradford, public domain. http://catalog.hathitrust.org/Record/008651224 ) - edited.
+  const UnicodeString ABBR_MR("Mr.");
+  const UnicodeString ABBR_CAPT("Capt.");
+
+  {
+    logln("Constructing empty builder\n");
+    builder.adoptInstead(FilteredBreakIteratorBuilder::createInstance(status));
+    TEST_ASSERT_SUCCESS(status);
+
+    logln("Constructing base BI\n");
+    baseBI.adoptInstead(BreakIterator::createSentenceInstance(Locale::getEnglish(), status));
+    TEST_ASSERT_SUCCESS(status);
+
+       logln("Building new BI\n");
+    filteredBI.adoptInstead(builder->build(baseBI.orphan(), status));
+    TEST_ASSERT_SUCCESS(status);
+
+       if (U_SUCCESS(status)) {
+        logln("Testing:");
+        filteredBI->setText(text);
+        TEST_ASSERT(20 == filteredBI->next()); // Mr.
+        TEST_ASSERT(84 == filteredBI->next()); // recovered.
+        TEST_ASSERT(90 == filteredBI->next()); // Capt.
+        TEST_ASSERT(181 == filteredBI->next()); // Mr.
+        TEST_ASSERT(278 == filteredBI->next()); // charge.
+        filteredBI->first();
+        prtbrks(filteredBI.getAlias(), text, *this);
+    }
+  }
+
+  {
+    logln("Constructing empty builder\n");
+    builder.adoptInstead(FilteredBreakIteratorBuilder::createInstance(status));
+    TEST_ASSERT_SUCCESS(status);
+
+    if (U_SUCCESS(status)) {
+        logln("Adding Mr. as an exception\n");
+        TEST_ASSERT(TRUE == builder->suppressBreakAfter(ABBR_MR, status));
+        TEST_ASSERT(FALSE == builder->suppressBreakAfter(ABBR_MR, status)); // already have it
+        TEST_ASSERT(TRUE == builder->unsuppressBreakAfter(ABBR_MR, status));
+        TEST_ASSERT(FALSE == builder->unsuppressBreakAfter(ABBR_MR, status)); // already removed it
+        TEST_ASSERT(TRUE == builder->suppressBreakAfter(ABBR_MR, status));
+        TEST_ASSERT_SUCCESS(status);
+
+        logln("Constructing base BI\n");
+        baseBI.adoptInstead(BreakIterator::createSentenceInstance(Locale::getEnglish(), status));
+        TEST_ASSERT_SUCCESS(status);
+
+        logln("Building new BI\n");
+        filteredBI.adoptInstead(builder->build(baseBI.orphan(), status));
+        TEST_ASSERT_SUCCESS(status);
+
+        logln("Testing:");
+        filteredBI->setText(text);
+        TEST_ASSERT(84 == filteredBI->next());
+        TEST_ASSERT(90 == filteredBI->next());// Capt.
+        TEST_ASSERT(278 == filteredBI->next());
+        filteredBI->first();
+        prtbrks(filteredBI.getAlias(), text, *this);
+    }
+  }
+
+
+  {
+    logln("Constructing empty builder\n");
+    builder.adoptInstead(FilteredBreakIteratorBuilder::createInstance(status));
+    TEST_ASSERT_SUCCESS(status);
+
+    if (U_SUCCESS(status)) {
+        logln("Adding Mr. and Capt as an exception\n");
+        TEST_ASSERT(TRUE == builder->suppressBreakAfter(ABBR_MR, status));
+        TEST_ASSERT(TRUE == builder->suppressBreakAfter(ABBR_CAPT, status));
+        TEST_ASSERT_SUCCESS(status);
+
+        logln("Constructing base BI\n");
+        baseBI.adoptInstead(BreakIterator::createSentenceInstance(Locale::getEnglish(), status));
+        TEST_ASSERT_SUCCESS(status);
+
+        logln("Building new BI\n");
+        filteredBI.adoptInstead(builder->build(baseBI.orphan(), status));
+        TEST_ASSERT_SUCCESS(status);
+
+        logln("Testing:");
+        filteredBI->setText(text);
+        TEST_ASSERT(84 == filteredBI->next());
+        TEST_ASSERT(278 == filteredBI->next());
+        filteredBI->first();
+        prtbrks(filteredBI.getAlias(), text, *this);
+    }
+  }
+
+
+  {
+    logln("Constructing English builder\n");
+    builder.adoptInstead(FilteredBreakIteratorBuilder::createInstance(Locale::getEnglish(), status));
+    TEST_ASSERT_SUCCESS(status);
+
+    logln("Constructing base BI\n");
+    baseBI.adoptInstead(BreakIterator::createSentenceInstance(Locale::getEnglish(), status));
+    TEST_ASSERT_SUCCESS(status);
+
+    if (U_SUCCESS(status)) {
+        logln("unsuppressing 'Capt'");
+        TEST_ASSERT(TRUE == builder->unsuppressBreakAfter(ABBR_CAPT, status));
+
+        logln("Building new BI\n");
+        filteredBI.adoptInstead(builder->build(baseBI.orphan(), status));
+        TEST_ASSERT_SUCCESS(status);
+
+        if(filteredBI.isValid()) {
+          logln("Testing:");
+          filteredBI->setText(text);
+          TEST_ASSERT(84 == filteredBI->next());
+          TEST_ASSERT(90 == filteredBI->next());
+          TEST_ASSERT(278 == filteredBI->next());
+          filteredBI->first();
+          prtbrks(filteredBI.getAlias(), text, *this);
         }
-        
-        // Now try the non-adopting constructor
-        brkItr = new RBBIWithProtectedFunctions(builtRules, RBBIWithProtectedFunctions::kDontAdopt, status);
-        if ( U_SUCCESS(status) ) {
-            delete brkItr; // this should NOT attempt to free builtRules
-            if (builtRules->fLength != length) { // sanity check
-                errln("create RuleBasedBreakIterator from RBBIData (non-adopted): delete affects data\n" );
-            }
-        } else {
-            errln("create RuleBasedBreakIterator from RBBIData (non-adopted): ICU Error \"%s\"\n", u_errorName(status) );
+    }
+  }
+
+
+  {
+    logln("Constructing English builder\n");
+    builder.adoptInstead(FilteredBreakIteratorBuilder::createInstance(Locale::getEnglish(), status));
+    TEST_ASSERT_SUCCESS(status);
+
+    logln("Constructing base BI\n");
+    baseBI.adoptInstead(BreakIterator::createSentenceInstance(Locale::getEnglish(), status));
+    TEST_ASSERT_SUCCESS(status);
+
+    if (U_SUCCESS(status)) {
+        logln("Building new BI\n");
+        filteredBI.adoptInstead(builder->build(baseBI.orphan(), status));
+        TEST_ASSERT_SUCCESS(status);
+
+        if(filteredBI.isValid()) {
+          logln("Testing:");
+          filteredBI->setText(text);
+          TEST_ASSERT(84 == filteredBI->next());
+          TEST_ASSERT(278 == filteredBI->next());
+          filteredBI->first();
+          prtbrks(filteredBI.getAlias(), text, *this);
         }
     }
+  }
+
+  // reenable once french is in
+  {
+    logln("Constructing French builder");
+    builder.adoptInstead(FilteredBreakIteratorBuilder::createInstance(Locale::getFrench(), status));
+    TEST_ASSERT_SUCCESS(status);
+
+    logln("Constructing base BI\n");
+    baseBI.adoptInstead(BreakIterator::createSentenceInstance(Locale::getFrench(), status));
+    TEST_ASSERT_SUCCESS(status);
+
+    if (U_SUCCESS(status)) {
+        logln("Building new BI\n");
+        frenchBI.adoptInstead(builder->build(baseBI.orphan(), status));
+        TEST_ASSERT_SUCCESS(status);
+    }
+
+    if(frenchBI.isValid()) {
+      logln("Testing:");
+      UnicodeString frText("C'est MM. Duval.");
+      frenchBI->setText(frText);
+      TEST_ASSERT(16 == frenchBI->next());
+      TEST_ASSERT(BreakIterator::DONE == frenchBI->next());
+      frenchBI->first();
+      prtbrks(frenchBI.getAlias(), frText, *this);
+      logln("Testing against English:");
+      filteredBI->setText(frText);
+      TEST_ASSERT(10 == filteredBI->next()); // wrong for french, but filterBI is english.
+      TEST_ASSERT(16 == filteredBI->next());
+      TEST_ASSERT(BreakIterator::DONE == filteredBI->next());
+      filteredBI->first();
+      prtbrks(filteredBI.getAlias(), frText, *this);
+
+      // Verify ==
+      TEST_ASSERT_TRUE(*frenchBI   == *frenchBI);
+      TEST_ASSERT_TRUE(*filteredBI != *frenchBI);
+      TEST_ASSERT_TRUE(*frenchBI   != *filteredBI);
+    } else {
+      dataerrln("French BI: not valid.");
+       }
+  }
+
+#else
+  logln("Skipped- not: !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILTERED_BREAK_ITERATION");
+#endif
 }
 
 //---------------------------------------------
@@ -1099,40 +1409,38 @@ void RBBIAPITest::TestCreateFromRBBIData() {
 void RBBIAPITest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
 {
     if (exec) logln((UnicodeString)"TestSuite RuleBasedBreakIterator API ");
-    switch (index) {
-     //   case 0: name = "TestConstruction"; if (exec) TestConstruction(); break;
+    TESTCASE_AUTO_BEGIN;
 #if !UCONFIG_NO_FILE_IO
-        case  0: name = "TestCloneEquals"; if (exec) TestCloneEquals(); break;
-        case  1: name = "TestgetRules"; if (exec) TestgetRules(); break;
-        case  2: name = "TestHashCode"; if (exec) TestHashCode(); break;
-        case  3: name = "TestGetSetAdoptText"; if (exec) TestGetSetAdoptText(); break;
-        case  4: name = "TestIteration"; if (exec) TestIteration(); break;
-#else
-        case  0: case  1: case  2: case  3: case  4: name = "skip"; break;
+    TESTCASE_AUTO(TestCloneEquals);
+    TESTCASE_AUTO(TestgetRules);
+    TESTCASE_AUTO(TestHashCode);
+    TESTCASE_AUTO(TestGetSetAdoptText);
+    TESTCASE_AUTO(TestIteration);
 #endif
-        case  5: name = "TestBuilder"; if (exec) TestBuilder(); break;
-        case  6: name = "TestQuoteGrouping"; if (exec) TestQuoteGrouping(); break;
-        case  7: name = "TestRuleStatusVec"; if (exec) TestRuleStatusVec(); break;
-        case  8: name = "TestBug2190"; if (exec) TestBug2190(); break;
+    TESTCASE_AUTO(TestBuilder);
+    TESTCASE_AUTO(TestQuoteGrouping);
+    TESTCASE_AUTO(TestRuleStatusVec);
+    TESTCASE_AUTO(TestBug2190);
 #if !UCONFIG_NO_FILE_IO
-        case  9: name = "TestRegistration"; if (exec) TestRegistration(); break;
-        case 10: name = "TestBoilerPlate"; if (exec) TestBoilerPlate(); break;
-        case 11: name = "TestRuleStatus"; if (exec) TestRuleStatus(); break;
-        case 12: name = "TestRoundtripRules"; if (exec) TestRoundtripRules(); break;
-        case 13: name = "TestCreateFromRBBIData"; if (exec) TestCreateFromRBBIData(); break;
-#else
-        case  9: case 10: case 11: case 12: case 13: name = "skip"; break;
+    TESTCASE_AUTO(TestRegistration);
+    TESTCASE_AUTO(TestBoilerPlate);
+    TESTCASE_AUTO(TestRuleStatus);
+    TESTCASE_AUTO(TestRoundtripRules);
+    TESTCASE_AUTO(TestGetBinaryRules);
 #endif
-
-        default: name = ""; break; // needed to end loop
-    }
+    TESTCASE_AUTO(TestRefreshInputText);
+#if !UCONFIG_NO_BREAK_ITERATION
+    TESTCASE_AUTO(TestFilteredBreakIteratorBuilder);
+#endif
+    TESTCASE_AUTO_END;
 }
 
+
 //---------------------------------------------
 //Internal subroutines
 //---------------------------------------------
 
-void RBBIAPITest::doBoundaryTest(RuleBasedBreakIterator& bi, UnicodeString& text, int32_t *boundaries){
+void RBBIAPITest::doBoundaryTest(BreakIterator& bi, UnicodeString& text, int32_t *boundaries){
      logln((UnicodeString)"testIsBoundary():");
         int32_t p = 0;
         UBool isB;
@@ -1169,18 +1477,4 @@ void RBBIAPITest::doTest(UnicodeString& testString, int32_t start, int32_t gotof
         logln(prettify("****selected \"" + selected + "\""));
 }
 
-//---------------------------------------------
-//RBBIWithProtectedFunctions class functions
-//---------------------------------------------
-
-RBBIWithProtectedFunctions::RBBIWithProtectedFunctions(RBBIDataHeader* data, UErrorCode &status)
-    : RuleBasedBreakIterator(data, status)
-{
-}
-
-RBBIWithProtectedFunctions::RBBIWithProtectedFunctions(const RBBIDataHeader* data, enum EDontAdopt, UErrorCode &status)
-    : RuleBasedBreakIterator(data, RuleBasedBreakIterator::kDontAdopt, status)
-{
-}
-
 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */