summaryrefslogtreecommitdiffstats
path: root/i18npool/qa/cppunit/test_textsearch.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'i18npool/qa/cppunit/test_textsearch.cxx')
-rw-r--r--i18npool/qa/cppunit/test_textsearch.cxx140
1 files changed, 130 insertions, 10 deletions
diff --git a/i18npool/qa/cppunit/test_textsearch.cxx b/i18npool/qa/cppunit/test_textsearch.cxx
index 31c66d94cd8d..2efb2b9cdc37 100644
--- a/i18npool/qa/cppunit/test_textsearch.cxx
+++ b/i18npool/qa/cppunit/test_textsearch.cxx
@@ -27,7 +27,6 @@
#include <unicode/regex.h>
using namespace ::com::sun::star;
-typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
class TestTextSearch : public test::BootstrapFixtureBase
{
@@ -39,12 +38,14 @@ public:
void testSearches();
void testWildcardSearch();
void testApostropheSearch();
+ void testTdf138410();
CPPUNIT_TEST_SUITE(TestTextSearch);
CPPUNIT_TEST(testICU);
CPPUNIT_TEST(testSearches);
CPPUNIT_TEST(testWildcardSearch);
CPPUNIT_TEST(testApostropheSearch);
+ CPPUNIT_TEST(testTdf138410);
CPPUNIT_TEST_SUITE_END();
private:
uno::Reference<util::XTextSearch> m_xSearch;
@@ -59,11 +60,11 @@ void TestTextSearch::testICU()
OUString aString( "abcdefgh" );
OUString aPattern( "e" );
- IcuUniString aSearchPat( reinterpret_cast<const UChar*>(aPattern.getStr()), aPattern.getLength() );
+ icu::UnicodeString aSearchPat( reinterpret_cast<const UChar*>(aPattern.getStr()), aPattern.getLength() );
std::unique_ptr<icu::RegexMatcher> pRegexMatcher(new icu::RegexMatcher( aSearchPat, nSearchFlags, nErr ));
- IcuUniString aSource( reinterpret_cast<const UChar*>(aString.getStr()), aString.getLength() );
+ icu::UnicodeString aSource( reinterpret_cast<const UChar*>(aString.getStr()), aString.getLength() );
pRegexMatcher->reset( aSource );
CPPUNIT_ASSERT( pRegexMatcher->find( 0, nErr ) );
@@ -76,10 +77,10 @@ void TestTextSearch::testICU()
OUString aString2( "acababaabcababadcdaa" );
OUString aPattern2( "a" );
- IcuUniString aSearchPat2( reinterpret_cast<const UChar*>(aPattern2.getStr()), aPattern2.getLength() );
+ icu::UnicodeString aSearchPat2( reinterpret_cast<const UChar*>(aPattern2.getStr()), aPattern2.getLength() );
pRegexMatcher.reset(new icu::RegexMatcher( aSearchPat2, nSearchFlags, nErr ));
- IcuUniString aSource2( reinterpret_cast<const UChar*>(aString2.getStr()), aString2.getLength() );
+ icu::UnicodeString aSource2( reinterpret_cast<const UChar*>(aString2.getStr()), aString2.getLength() );
pRegexMatcher->reset( aSource2 );
CPPUNIT_ASSERT( pRegexMatcher->find( 0, nErr ) );
@@ -293,7 +294,7 @@ void TestTextSearch::testWildcardSearch()
void TestTextSearch::testApostropheSearch()
{
// A) find typographic apostrophes also by using ASCII apostrophe in searchString
- OUString str( u"It\u2019s an apostrophe." );
+ OUString str( u"It\u2019s an apostrophe."_ustr );
sal_Int32 startPos = 0, endPos = str.getLength();
// set options
@@ -354,7 +355,7 @@ void TestTextSearch::testApostropheSearch()
CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(2), aRes.endOffset[0] );
// C) search typographic apostrophe in a text with ASCII apostrophes (no result)
- aOptions.searchString = OUString(u"\u2019");
+ aOptions.searchString = u"\u2019"_ustr;
m_xSearch->setOptions( aOptions );
aRes = m_xSearch->searchForward( str, startPos, endPos );
@@ -379,9 +380,9 @@ void TestTextSearch::testApostropheSearch()
CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(2), aRes.endOffset[0] );
// E) search mixed apostrophes in a text with mixed apostrophes:
- aOptions.searchString = OUString(u"'\u2019");
+ aOptions.searchString = u"'\u2019"_ustr;
m_xSearch->setOptions( aOptions );
- str = u"test: \u2019'";
+ str = u"test: \u2019'"_ustr;
// search forward
aRes = m_xSearch->searchForward( str, startPos, str.getLength());
@@ -392,7 +393,7 @@ void TestTextSearch::testApostropheSearch()
CPPUNIT_ASSERT( aRes.subRegExpressions > 0 );
// F) search mixed apostrophes in a text with ASCII apostrophes:
- str = u"test: ''";
+ str = u"test: ''"_ustr;
// search forward
aRes = m_xSearch->searchForward( str, startPos, str.getLength());
@@ -403,6 +404,125 @@ void TestTextSearch::testApostropheSearch()
CPPUNIT_ASSERT( aRes.subRegExpressions > 0 );
}
+void TestTextSearch::testTdf138410()
+{
+ OUString str(u"\u0643\u064f\u062a\u064f\u0628 \u0643\u062a\u0628"_ustr);
+ sal_Int32 startPos = 0, endPos = str.getLength();
+
+ util::SearchOptions aOptions;
+ aOptions.algorithmType = util::SearchAlgorithms_ABSOLUTE;
+
+ util::SearchResult aRes;
+
+ // A) base alone
+ // The search string will be found whether it is followed by a mark in the
+ // text or not, and whether IGNORE_DIACRITICS_CTL is set or not.
+
+ // set options
+ aOptions.searchString = u"\u0643"_ustr;
+ aOptions.transliterateFlags = 0;
+ m_xSearch->setOptions(aOptions);
+
+ // search forward
+ aRes = m_xSearch->searchForward(str, startPos, endPos);
+ CPPUNIT_ASSERT(aRes.subRegExpressions > 0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aRes.startOffset[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aRes.endOffset[0]);
+
+ // search backwards
+ aRes = m_xSearch->searchBackward(str, endPos, startPos);
+ CPPUNIT_ASSERT(aRes.subRegExpressions > 0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(7), aRes.startOffset[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6), aRes.endOffset[0]);
+
+ // check with transliteration
+ aOptions.transliterateFlags = static_cast<int>(TransliterationFlags::IGNORE_DIACRITICS_CTL);
+ m_xSearch->setOptions(aOptions);
+
+ // search forward
+ aRes = m_xSearch->searchForward(str, startPos, endPos);
+ CPPUNIT_ASSERT(aRes.subRegExpressions > 0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aRes.startOffset[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aRes.endOffset[0]);
+
+ // search backwards
+ aRes = m_xSearch->searchBackward(str, endPos, startPos);
+ CPPUNIT_ASSERT(aRes.subRegExpressions > 0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(7), aRes.startOffset[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6), aRes.endOffset[0]);
+
+ // b) base+mark
+ // The search string will be found when followed by a mark in the text, or
+ // when IGNORE_DIACRITICS_CTL is set whether it is followed by a mark or
+ // not.
+
+ // set options
+ aOptions.searchString = u"\u0643\u064f"_ustr;
+ aOptions.transliterateFlags = 0;
+ m_xSearch->setOptions(aOptions);
+
+ // search forward
+ aRes = m_xSearch->searchForward(str, startPos, endPos);
+ CPPUNIT_ASSERT(aRes.subRegExpressions > 0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aRes.startOffset[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aRes.endOffset[0]);
+
+ // search backwards
+ aRes = m_xSearch->searchBackward(str, endPos, startPos);
+ CPPUNIT_ASSERT(aRes.subRegExpressions > 0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aRes.startOffset[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aRes.endOffset[0]);
+
+ // check with transliteration
+ aOptions.transliterateFlags = static_cast<int>(TransliterationFlags::IGNORE_DIACRITICS_CTL);
+ m_xSearch->setOptions(aOptions);
+
+ // search forward
+ aRes = m_xSearch->searchForward(str, startPos, endPos);
+ CPPUNIT_ASSERT(aRes.subRegExpressions > 0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aRes.startOffset[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aRes.endOffset[0]);
+
+ // search backwards
+ aRes = m_xSearch->searchBackward(str, endPos, startPos);
+ CPPUNIT_ASSERT(aRes.subRegExpressions > 0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(7), aRes.startOffset[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6), aRes.endOffset[0]);
+
+ // b) mark alone
+ // The search string will be found only when IGNORE_DIACRITICS_CTL is not
+ // set.
+
+ // set options
+ aOptions.searchString = u"\u064f"_ustr;
+ aOptions.transliterateFlags = 0;
+ m_xSearch->setOptions(aOptions);
+
+ // search forward
+ aRes = m_xSearch->searchForward(str, startPos, endPos);
+ CPPUNIT_ASSERT(aRes.subRegExpressions > 0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aRes.startOffset[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aRes.endOffset[0]);
+
+ // search backwards
+ aRes = m_xSearch->searchBackward(str, endPos, startPos);
+ CPPUNIT_ASSERT(aRes.subRegExpressions > 0);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), aRes.startOffset[0]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), aRes.endOffset[0]);
+
+ // with ignore marks the mark will not be found
+ aOptions.transliterateFlags = static_cast<int>(TransliterationFlags::IGNORE_DIACRITICS_CTL);
+ m_xSearch->setOptions(aOptions);
+
+ // search forward
+ aRes = m_xSearch->searchForward(str, startPos, endPos);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aRes.subRegExpressions);
+
+ // search backwards
+ aRes = m_xSearch->searchBackward(str, endPos, startPos);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aRes.subRegExpressions);
+}
+
void TestTextSearch::setUp()
{
BootstrapFixtureBase::setUp();