sw/qa/core/uwriter.cxx | 46 ++++++++++++++++++++++++++++++++++++++ sw/source/core/txtnode/txtedt.cxx | 6 ++-- 2 files changed, 49 insertions(+), 3 deletions(-)
New commits: commit 0d89580eeb61ae01f1c1f2836f77ffef6a146770 Author: Michael Stahl <[email protected]> Date: Thu Mar 28 16:45:51 2013 +0100 sw: ... and was sentenced to write a unit test for it Change-Id: I2fb6f97130910e3ae123242505aed0fb57fee512 diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index fc3d8be..7d590f5 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -34,8 +34,12 @@ #include <rtl/strbuf.hxx> #include <osl/file.hxx> +#include <com/sun/star/i18n/TransliterationModulesExtra.hpp> + +#include <comphelper/processfactory.hxx> #include <tools/urlobj.hxx> #include <unotools/tempfile.hxx> +#include <unotools/transliterationwrapper.hxx> #include <editeng/langitem.hxx> #include <editeng/charhiddenitem.hxx> @@ -92,8 +96,10 @@ public: void testGraphicAnchorDeletion(); void testFdo57938(); void testFdo59573(); + void testTransliterate(); CPPUNIT_TEST_SUITE(SwDocTest); + CPPUNIT_TEST(testTransliterate); CPPUNIT_TEST(randomTest); CPPUNIT_TEST(testPageDescName); CPPUNIT_TEST(testFileNameFields); @@ -918,6 +924,46 @@ void SwDocTest::testFdo59573() CPPUNIT_ASSERT_EQUAL(true, aPaM.HasReadonlySel(false)); } +static OUString +translitTest(SwDoc & rDoc, SwPaM & rPaM, sal_uInt32 const nType) +{ + utl::TransliterationWrapper aTrans( + ::comphelper::getProcessComponentContext(), nType); + rDoc.TransliterateText(rPaM, aTrans); + return rPaM.GetTxt(); +} + +void SwDocTest::testTransliterate() +{ + // just some simple test to see if it's totally broken + SwNodeIndex aIdx(m_pDoc->GetNodes().GetEndOfContent(), -1); + SwPaM aPaM(aIdx); + m_pDoc->InsertString(aPaM, OUString("foobar")); + aPaM.SetMark(); + aPaM.GetPoint()->nContent = 0; + CPPUNIT_ASSERT_EQUAL(String("foobar"), aPaM.GetTxt()); + + CPPUNIT_ASSERT_EQUAL(OUString("FOOBAR"), + translitTest(*m_pDoc, aPaM, + i18n::TransliterationModules_LOWERCASE_UPPERCASE)); + CPPUNIT_ASSERT_EQUAL(OUString("Foobar"), + translitTest(*m_pDoc, aPaM, + i18n::TransliterationModulesExtra::TITLE_CASE)); + CPPUNIT_ASSERT_EQUAL(OUString("fOOBAR"), + translitTest(*m_pDoc, aPaM, + i18n::TransliterationModulesExtra::TOGGLE_CASE)); + CPPUNIT_ASSERT_EQUAL(OUString("foobar"), + translitTest(*m_pDoc, aPaM, + i18n::TransliterationModules_UPPERCASE_LOWERCASE)); + CPPUNIT_ASSERT_EQUAL(OUString("Foobar"), + translitTest(*m_pDoc, aPaM, + i18n::TransliterationModulesExtra::SENTENCE_CASE)); + CPPUNIT_ASSERT_EQUAL(OUString("Foobar"), + translitTest(*m_pDoc, aPaM, + i18n::TransliterationModules_HIRAGANA_KATAKANA)); +} + + void SwDocTest::setUp() { BootstrapFixture::setUp(); commit 233ab7729585becf9952b6ddf95d7dab1d07340a Author: Michael Stahl <[email protected]> Date: Thu Mar 28 16:39:25 2013 +0100 sw: some idiot broke text transliteration (regression from 8d25fde680beb9dafb7c9c861b5c00d1ae4f4985) Change-Id: I00556cd87115fa8e67f32502fc88a4d1eee2a423 diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index 39cb9ca..bfc312f 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -1670,7 +1670,7 @@ void SwTxtNode::TransliterateText( GetTxt(), GetLang(nStt), nStt, nLen, &aOffsets) ); assert(nStt < m_Text.getLength()); - if (0 == rtl_ustr_shortenedCompare_WithLength( + if (0 != rtl_ustr_shortenedCompare_WithLength( m_Text.getStr() + nStt, m_Text.getLength() - nStt, sChgd.getStr(), sChgd.getLength(), nLen)) { @@ -1754,7 +1754,7 @@ void SwTxtNode::TransliterateText( GetLang(nCurrentStart), nCurrentStart, nLen, &aOffsets) ); assert(nStt < m_Text.getLength()); - if (0 == rtl_ustr_shortenedCompare_WithLength( + if (0 != rtl_ustr_shortenedCompare_WithLength( m_Text.getStr() + nStt, m_Text.getLength() - nStt, sChgd.getStr(), sChgd.getLength(), nLen)) { @@ -1808,7 +1808,7 @@ void SwTxtNode::TransliterateText( m_Text, nLang, nStt, nLen, &aOffsets) ); assert(nStt < m_Text.getLength()); - if (0 == rtl_ustr_shortenedCompare_WithLength( + if (0 != rtl_ustr_shortenedCompare_WithLength( m_Text.getStr() + nStt, m_Text.getLength() - nStt, sChgd.getStr(), sChgd.getLength(), nLen)) { _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
