Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Unified Diff: source/test/intltest/rbbiapts.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/test/intltest/rbbiapts.h ('k') | source/test/intltest/rbbitst.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/test/intltest/rbbiapts.cpp
diff --git a/source/test/intltest/rbbiapts.cpp b/source/test/intltest/rbbiapts.cpp
index 4930a645a2b649fcf618b17d1e04eae9e36bf569..622107e7f74f9477634714d13b468738eef839e9 100644
--- a/source/test/intltest/rbbiapts.cpp
+++ b/source/test/intltest/rbbiapts.cpp
@@ -1,5 +1,5 @@
/********************************************************************
- * Copyright (c) 1999-2013, International Business Machines
+ * Copyright (c) 1999-2014, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************
* Date Name Description
@@ -23,7 +23,10 @@
#include "unicode/ustring.h"
#include "unicode/utext.h"
#include "cmemory.h"
-
+#if !UCONFIG_NO_BREAK_ITERATION && U_HAVE_STD_STRING
+#include "unicode/filteredbrk.h"
+#include <stdio.h> // for sprintf
+#endif
/**
* API Test the RuleBasedBreakIterator class
*/
@@ -643,8 +646,8 @@ void RBBIAPITest::TestRuleStatus() {
//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
+ // 012345678901234567 8 9 0
+ // Katakana
str, 30);
UnicodeString testString1(str);
int32_t bounds1[] = {0, 5, 6, 10, 11, 17, 18, 20, 21};
@@ -878,7 +881,7 @@ void RBBIAPITest::TestRegistration() {
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));
@@ -886,7 +889,7 @@ void RBBIAPITest::TestRegistration() {
delete ja_char;
delete root_word;
delete root_char;
-
+
return;
}
@@ -1057,7 +1060,7 @@ void RBBIAPITest::TestRoundtripRules() {
// 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
+// 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
@@ -1083,7 +1086,7 @@ void RBBIAPITest::TestCreateFromRBBIData() {
uprv_free( rulesCopy );
}
}
-
+
// Now try the non-adopting constructor
brkItr = new RBBIWithProtectedFunctions(builtRules, RBBIWithProtectedFunctions::kDontAdopt, status);
if ( U_SUCCESS(status) ) {
@@ -1168,7 +1171,7 @@ void RBBIAPITest::TestRefreshInputText() {
TEST_ASSERT(7 == bi->next());
TEST_ASSERT(8 == bi->next());
TEST_ASSERT(UBRK_DONE == bi->next());
-
+
utext_close(&ut1);
utext_close(&ut2);
}
@@ -1176,6 +1179,231 @@ void RBBIAPITest::TestRefreshInputText() {
}
+#if !UCONFIG_NO_BREAK_ITERATION && U_HAVE_STD_STRING && !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 && U_HAVE_STD_STRING && !UCONFIG_NO_FILTERED_BREAK_ITERATION
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<FilteredBreakIteratorBuilder> builder;
+ LocalPointer<BreakIterator> baseBI;
+ LocalPointer<BreakIterator> filteredBI;
+
+ 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);
+ }
+ }
+ }
+
+
+ {
+ 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);
+ }
+ }
+ }
+
+#if 0
+ // 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);
+
+ 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(20 == filteredBI->next());
+ TEST_ASSERT(84 == filteredBI->next());
+ filteredBI->first();
+ prtbrks(filteredBI.getAlias(), text, *this);
+ }
+ }
+#endif
+
+#else
+ logln("Skipped- not: !UCONFIG_NO_BREAK_ITERATION && U_HAVE_STD_STRING && !UCONFIG_NO_FILTERED_BREAK_ITERATION");
+#endif
+}
//---------------------------------------------
// runIndexedTest
@@ -1210,6 +1438,11 @@ void RBBIAPITest::runIndexedTest( int32_t index, UBool exec, const char* &name,
#endif
case 14: name = "TestRefreshInputText"; if (exec) TestRefreshInputText(); break;
+#if !UCONFIG_NO_BREAK_ITERATION && U_HAVE_STD_STRING
+ case 15: name = "TestFilteredBreakIteratorBuilder"; if(exec) TestFilteredBreakIteratorBuilder(); break;
+#else
+ case 15: name="skip"; break;
+#endif
default: name = ""; break; // needed to end loop
}
}
« no previous file with comments | « source/test/intltest/rbbiapts.h ('k') | source/test/intltest/rbbitst.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698