[Libreoffice-commits] .: i18npool/qa
Caolán McNamara
caolan at kemper.freedesktop.org
Fri Feb 18 06:25:37 PST 2011
i18npool/qa/cppunit/test_breakiterator.cxx | 65 ++++++++++++++++++++++++++---
1 file changed, 59 insertions(+), 6 deletions(-)
New commits:
commit 61e1d71e8d4d5cef9379f555a7e36df29d5b374a
Author: Caolán McNamara <caolanm at redhat.com>
Date: Fri Feb 18 14:18:06 2011 +0000
Try and protect the Indic grapheme/cell skipping with a unit test.
diff --git a/i18npool/qa/cppunit/test_breakiterator.cxx b/i18npool/qa/cppunit/test_breakiterator.cxx
index a6ea552..3f52cdb 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()
More information about the Libreoffice-commits
mailing list