diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-02-18 14:18:06 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-02-18 14:18:06 +0000 |
commit | e8f92e54b9058a96ad2e0955e4c8c8e6ebb7ee64 (patch) | |
tree | b7ed6d0a8ab8c6947ddfe06932010b0c85969522 /i18npool/qa | |
parent | fcd4ea7f43ce180de067927b4b7aae407c022f65 (diff) |
Try and protect the Indic grapheme/cell skipping with a unit test.
Diffstat (limited to 'i18npool/qa')
-rw-r--r-- | i18npool/qa/cppunit/test_breakiterator.cxx | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/i18npool/qa/cppunit/test_breakiterator.cxx b/i18npool/qa/cppunit/test_breakiterator.cxx index a6ea552e2727..3f52cdbdad4f 100644 --- a/i18npool/qa/cppunit/test_breakiterator.cxx +++ b/i18npool/qa/cppunit/test_breakiterator.cxx @@ -36,6 +36,7 @@ #include <cppuhelper/bootstrap.hxx> #include <cppuhelper/basemutex.hxx> #include <com/sun/star/i18n/XBreakIterator.hpp> +#include <com/sun/star/i18n/CharacterIteratorMode.hpp> #include <string.h> @@ -51,24 +52,23 @@ public: virtual void tearDown(); void testLineBreaking(); + void testGraphemeIteration(); CPPUNIT_TEST_SUITE(TestBreakIterator); CPPUNIT_TEST(testLineBreaking); + CPPUNIT_TEST(testGraphemeIteration); CPPUNIT_TEST_SUITE_END(); private: uno::Reference<uno::XComponentContext> m_xContext; uno::Reference<lang::XMultiComponentFactory> m_xFactory; uno::Reference<lang::XMultiServiceFactory> m_xMSF; + uno::Reference<i18n::XBreakIterator> m_xBreak; }; //See https://bugs.freedesktop.org/show_bug.cgi?id=31271 for motivation void TestBreakIterator::testLineBreaking() { - uno::Reference< i18n::XBreakIterator > xBreak(m_xMSF->createInstance( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.BreakIterator"))),uno::UNO_QUERY); - CPPUNIT_ASSERT_MESSAGE("Expected Break Iterator", xBreak.is()); - ::rtl::OUString aTest1(RTL_CONSTASCII_USTRINGPARAM("(some text here)")); i18n::LineBreakHyphenationOptions aHyphOptions; @@ -80,22 +80,75 @@ void TestBreakIterator::testLineBreaking() { //Here we want the line break to leave text here) on the next line - i18n::LineBreakResults aResult = xBreak->getLineBreak(aTest1, strlen("(some tex"), aLocale, 0, aHyphOptions, aUserOptions); + i18n::LineBreakResults aResult = m_xBreak->getLineBreak(aTest1, strlen("(some tex"), aLocale, 0, aHyphOptions, aUserOptions); CPPUNIT_ASSERT_MESSAGE("Expected a break at the the start of the word", aResult.breakIndex == 6); } { //Here we want the line break to leave "here)" on the next line - i18n::LineBreakResults aResult = xBreak->getLineBreak(aTest1, strlen("(some text here"), aLocale, 0, aHyphOptions, aUserOptions); + i18n::LineBreakResults aResult = m_xBreak->getLineBreak(aTest1, strlen("(some text here"), aLocale, 0, aHyphOptions, aUserOptions); CPPUNIT_ASSERT_MESSAGE("Expected a break at the the start of the word", aResult.breakIndex == 11); } } +//See http://qa.openoffice.org/issues/show_bug.cgi?id=111152 for motivation +void TestBreakIterator::testGraphemeIteration() +{ + lang::Locale aLocale; + aLocale.Language = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bn")); + aLocale.Country = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IN")); + + { + sal_Unicode BA_HALANT_LA[] = { 0x09AC, 0x09CD, 0x09AF }; + ::rtl::OUString aTest1(BA_HALANT_LA, SAL_N_ELEMENTS(BA_HALANT_LA)); + + sal_Int32 nDone=0; + sal_Int32 nPos; + nPos = m_xBreak->nextCharacters(aTest1, 0, aLocale, + i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); + CPPUNIT_ASSERT_MESSAGE("Should skip full grapheme", nPos == SAL_N_ELEMENTS(BA_HALANT_LA)); + nPos = m_xBreak->previousCharacters(aTest1, SAL_N_ELEMENTS(BA_HALANT_LA), aLocale, + i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); + CPPUNIT_ASSERT_MESSAGE("Should skip full grapheme", nPos == 0); + } + + { + sal_Unicode HA_HALANT_NA_VOWELSIGNI[] = { 0x09B9, 0x09CD, 0x09A3, 0x09BF }; + ::rtl::OUString aTest1(HA_HALANT_NA_VOWELSIGNI, SAL_N_ELEMENTS(HA_HALANT_NA_VOWELSIGNI)); + + sal_Int32 nDone=0; + sal_Int32 nPos; + nPos = m_xBreak->nextCharacters(aTest1, 0, aLocale, + i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); + CPPUNIT_ASSERT_MESSAGE("Should skip full grapheme", nPos == SAL_N_ELEMENTS(HA_HALANT_NA_VOWELSIGNI)); + nPos = m_xBreak->previousCharacters(aTest1, SAL_N_ELEMENTS(HA_HALANT_NA_VOWELSIGNI), aLocale, + i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); + CPPUNIT_ASSERT_MESSAGE("Should skip full grapheme", nPos == 0); + } + + { + sal_Unicode TA_HALANT_MA_HALANT_YA [] = { 0x09A4, 0x09CD, 0x09AE, 0x09CD, 0x09AF }; + ::rtl::OUString aTest1(TA_HALANT_MA_HALANT_YA, SAL_N_ELEMENTS(TA_HALANT_MA_HALANT_YA)); + + sal_Int32 nDone=0; + sal_Int32 nPos; + nPos = m_xBreak->nextCharacters(aTest1, 0, aLocale, + i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); + CPPUNIT_ASSERT_MESSAGE("Should skip full grapheme", nPos == SAL_N_ELEMENTS(TA_HALANT_MA_HALANT_YA)); + nPos = m_xBreak->previousCharacters(aTest1, SAL_N_ELEMENTS(TA_HALANT_MA_HALANT_YA), aLocale, + i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); + CPPUNIT_ASSERT_MESSAGE("Should skip full grapheme", nPos == 0); + } +} + TestBreakIterator::TestBreakIterator() { m_xContext = cppu::defaultBootstrap_InitialComponentContext(); m_xFactory = m_xContext->getServiceManager(); m_xMSF = uno::Reference<lang::XMultiServiceFactory>(m_xFactory, uno::UNO_QUERY_THROW); + m_xBreak = uno::Reference< i18n::XBreakIterator >(m_xMSF->createInstance( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.BreakIterator"))), + uno::UNO_QUERY_THROW); } void TestBreakIterator::setUp() |