diff --git a/icu4c/source/test/cintltst/usrchdat.c b/icu4c/source/test/cintltst/usrchdat.c index 3e22ee49ef2..b7e51204778 100644 --- a/icu4c/source/test/cintltst/usrchdat.c +++ b/icu4c/source/test/cintltst/usrchdat.c @@ -485,6 +485,10 @@ static const SearchData CONTRACTIONCANONICAL[] = { {NULL, NULL, NULL, UCOL_TERTIARY, NULL, {-1}, {0}} }; +static const SearchData DIACTRICMATCH[] = { + {"\\u0061\\u0061\\u00E1", "\\u0061\\u00E1", NULL, UCOL_SECONDARY, NULL, {1, -1}, {2}} +}; + #endif /* #if !UCONFIG_NO_COLLATION */ #endif diff --git a/icu4c/source/test/cintltst/usrchtst.c b/icu4c/source/test/cintltst/usrchtst.c index 5fba87f31cd..b9fce7f2a9a 100644 --- a/icu4c/source/test/cintltst/usrchtst.c +++ b/icu4c/source/test/cintltst/usrchtst.c @@ -1537,6 +1537,38 @@ static void TestIgnorable(void) ucol_close(collator); } +static void TestDiactricMatch(void) +{ + UChar pattern[128]; + UChar text[128]; + UErrorCode status = U_ZERO_ERROR; + UStringSearch *strsrch; + uint32_t count = 0; + + memset(pattern, 0, 128*sizeof(UChar)); + memset(text, 0, 128*sizeof(UChar)); + + strsrch = usearch_open(pattern, 1, text, 1, uloc_getDefault(), NULL, + &status); + if (U_FAILURE(status)) { + log_err("Error opening string search %s\n", u_errorName(status)); + } + + ucol_setStrength(usearch_getCollator(strsrch), DIACTRICMATCH[count].strength); + + while (DIACTRICMATCH[count].text != NULL) { + u_unescape(DIACTRICMATCH[count].text, text, 128); + u_unescape(DIACTRICMATCH[count].pattern, pattern, 128); + usearch_setText(strsrch, text, -1, &status); + usearch_setPattern(strsrch, pattern, -1, &status); + if (!assertEqualWithUStringSearch(strsrch, DIACTRICMATCH[count])) { + log_err("Error at test number %d\n", count); + } + count ++; + } + usearch_close(strsrch); +} + static void TestCanonical(void) { int count = 0; @@ -2191,6 +2223,7 @@ void addSearchTest(TestNode** root) "tscoll/usrchtst/TestContractionCanonical"); addTest(root, &TestEnd, "tscoll/usrchtst/TestEnd"); addTest(root, &TestNumeric, "tscoll/usrchtst/TestNumeric"); + addTest(root, &TestDiactricMatch, "tscoll/usrchtst/TestDiactricMatch"); } #endif /* #if !UCONFIG_NO_COLLATION */ diff --git a/icu4c/source/test/intltest/srchtest.cpp b/icu4c/source/test/intltest/srchtest.cpp index f768c0d2f8e..cdec4db7363 100644 --- a/icu4c/source/test/intltest/srchtest.cpp +++ b/icu4c/source/test/intltest/srchtest.cpp @@ -154,6 +154,7 @@ void StringSearchTest::runIndexedTest(int32_t index, UBool exec, CASE(33, TestUClassID) CASE(34, TestSubclass) CASE(35, TestCoverage) + CASE(36, TestDiactricMatch) default: name = ""; break; } } @@ -1544,6 +1545,38 @@ void StringSearchTest::TestIgnorable() delete strsrch; delete collator; } + +void StringSearchTest::TestDiactricMatch() +{ + UChar temp[128]; + UErrorCode status = U_ZERO_ERROR; + int count = 0; + + UnicodeString pattern("pattern"); + UnicodeString text("text"); + StringSearch *strsrch = new StringSearch(pattern, text, Locale::getDefault(), NULL, + status); + if (U_FAILURE(status)) { + errln("Error opening string search %s", u_errorName(status)); + return; + } + + strsrch->getCollator()->setStrength(getECollationStrength(DIACTRICMATCH[count].strength)); + + while (DIACTRICMATCH[count].text != NULL) { + u_unescape(DIACTRICMATCH[count].text, temp, 128); + text.setTo(temp, u_strlen(temp)); + u_unescape(DIACTRICMATCH[count].pattern, temp, 128); + pattern.setTo(temp, u_strlen(temp)); + strsrch->setText(text, status); + strsrch->setPattern(pattern, status); + if (!assertEqualWithStringSearch(strsrch, &DIACTRICMATCH[count])) { + errln("Error at test number %d", count); + } + count ++; + } + delete strsrch; +} void StringSearchTest::TestCanonical() { diff --git a/icu4c/source/test/intltest/srchtest.h b/icu4c/source/test/intltest/srchtest.h index 37fafdc3b88..e27ec620bb0 100644 --- a/icu4c/source/test/intltest/srchtest.h +++ b/icu4c/source/test/intltest/srchtest.h @@ -88,6 +88,7 @@ private: void TestUClassID(); void TestSubclass(); void TestCoverage(); + void TestDiactricMatch(); }; #endif /* #if !UCONFIG_NO_COLLATION */