[Libreoffice-commits] core.git: editeng/source sw/inc sw/qa sw/source

Matthew J. Francis mjay.francis at gmail.com
Mon Sep 1 01:12:28 PDT 2014


 editeng/source/editeng/textconv.cxx |    2 
 sw/inc/hhcwrp.hxx                   |    2 
 sw/qa/extras/uiwriter/uiwriter.cxx  |  122 ++++++++++++++++++++++++++++++++++++
 sw/source/uibase/lingu/hhcwrp.cxx   |    4 -
 4 files changed, 126 insertions(+), 4 deletions(-)

New commits:
commit c369013edb76cd47ef7e8c193a18a57ff165ddfb
Author: Matthew J. Francis <mjay.francis at gmail.com>
Date:   Fri Aug 29 18:18:40 2014 +0800

    fdo#83178 fix Chinese Conversion crash
    
    Reviewed on:
    	https://gerrit.libreoffice.org/11187
    
    Change-Id: Ifa9c7c1a29d7076903e038d3132c635b1143e2d8

diff --git a/editeng/source/editeng/textconv.cxx b/editeng/source/editeng/textconv.cxx
index 307d0e8..f843f83 100644
--- a/editeng/source/editeng/textconv.cxx
+++ b/editeng/source/editeng/textconv.cxx
@@ -478,7 +478,7 @@ void TextConvWrapper::ChangeText( const OUString &rNewText,
             }
 
             // end of string also terminates non-matching char sequence
-            if (rOrigText[nIndex] == rNewText[nPos] || nPos == nConvTextLen)
+            if (nPos == nConvTextLen || rOrigText[nIndex] == rNewText[nPos])
             {
                 // substring that needs to be replaced found?
                 if (nChgPos>=0 && nConvChgPos>=0)
diff --git a/sw/inc/hhcwrp.hxx b/sw/inc/hhcwrp.hxx
index df973d0..9ff03b6 100644
--- a/sw/inc/hhcwrp.hxx
+++ b/sw/inc/hhcwrp.hxx
@@ -27,7 +27,7 @@ class SwWrtShell;
 struct SwConversionArgs;
 class SwPaM;
 
-class SwHHCWrapper : public editeng::HangulHanjaConversion
+class SW_DLLPUBLIC SwHHCWrapper : public editeng::HangulHanjaConversion
 {
     SwView *    m_pView;
     Window*     m_pWin;
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 0665f49..6cb67f7 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -6,6 +6,7 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include <com/sun/star/i18n/TextConversionOption.hpp>
 #include <swmodeltestbase.hxx>
 #include <ndtxt.hxx>
 #include <wrtsh.hxx>
@@ -19,6 +20,8 @@
 #include <fmtclds.hxx>
 #include <dcontact.hxx>
 #include <textboxhelper.hxx>
+#include <view.hxx>
+#include <hhcwrp.hxx>
 
 #include <svx/svdpage.hxx>
 #include <svx/svdview.hxx>
@@ -48,6 +51,10 @@ public:
     void testShapeTextboxVertadjust();
     void testShapeTextboxAutosize();
     void testFdo82191();
+    void testChineseConversionBlank();
+    void testChineseConversionNonChineseText();
+    void testChineseConversionTraditionalToSimplified();
+    void testChineseConversionSimplifiedToTraditional();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -65,6 +72,11 @@ public:
     CPPUNIT_TEST(testShapeTextboxVertadjust);
     CPPUNIT_TEST(testShapeTextboxAutosize);
     CPPUNIT_TEST(testFdo82191);
+    CPPUNIT_TEST(testChineseConversionBlank);
+    CPPUNIT_TEST(testChineseConversionNonChineseText);
+    CPPUNIT_TEST(testChineseConversionTraditionalToSimplified);
+    CPPUNIT_TEST(testChineseConversionSimplifiedToTraditional);
+
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -414,6 +426,116 @@ void SwUiWriterTest::testFdo82191()
     CPPUNIT_ASSERT_EQUAL(size_t(2), aTextBoxes.size());
 }
 
+
+// Chinese conversion tests
+
+static const OUString CHINESE_TRADITIONAL_CONTENT(sal_Unicode(0x9F8D));
+static const OUString CHINESE_SIMPLIFIED_CONTENT(sal_Unicode(0x9F99));
+static const OUString NON_CHINESE_CONTENT ("Hippopotamus");
+
+// Tests that a blank document is still blank after conversion
+void SwUiWriterTest::testChineseConversionBlank()
+{
+
+    // Given
+    SwDoc* pDoc = createDoc();
+    SwView* pView = pDoc->GetDocShell()->GetView();
+    const uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
+    SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
+    SwPaM aPaM(aIdx);
+
+    // When
+    SwHHCWrapper aWrap( pView, xContext, LANGUAGE_CHINESE_TRADITIONAL, LANGUAGE_CHINESE_SIMPLIFIED, NULL,
+                        i18n::TextConversionOption::CHARACTER_BY_CHARACTER, false,
+                        true, false, false );
+    aWrap.Convert();
+
+
+    // Then
+    SwTxtNode* pTxtNode = aPaM.GetNode().GetTxtNode();
+    CPPUNIT_ASSERT_EQUAL(OUString(), pTxtNode->GetTxt());
+
+}
+
+// Tests that non Chinese text is unchanged after conversion
+void SwUiWriterTest::testChineseConversionNonChineseText()
+{
+
+    // Given
+    SwDoc* pDoc = createDoc();
+    SwView* pView = pDoc->GetDocShell()->GetView();
+    const uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
+    SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
+    SwPaM aPaM(aIdx);
+    pDoc->getIDocumentContentOperations().InsertString(aPaM, NON_CHINESE_CONTENT);
+
+
+    // When
+    SwHHCWrapper aWrap( pView, xContext, LANGUAGE_CHINESE_TRADITIONAL, LANGUAGE_CHINESE_SIMPLIFIED, NULL,
+                        i18n::TextConversionOption::CHARACTER_BY_CHARACTER, false,
+                        true, false, false );
+    aWrap.Convert();
+
+
+    // Then
+    SwTxtNode* pTxtNode = aPaM.GetNode().GetTxtNode();
+    CPPUNIT_ASSERT_EQUAL(NON_CHINESE_CONTENT, pTxtNode->GetTxt());
+
+}
+
+// Tests conversion of traditional Chinese characters to simplified Chinese
+void SwUiWriterTest::testChineseConversionTraditionalToSimplified()
+{
+
+    // Given
+    SwDoc* pDoc = createDoc();
+    SwView* pView = pDoc->GetDocShell()->GetView();
+    const uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
+    SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
+    SwPaM aPaM(aIdx);
+    pDoc->getIDocumentContentOperations().InsertString(aPaM, CHINESE_TRADITIONAL_CONTENT);
+
+
+    // When
+    SwHHCWrapper aWrap( pView, xContext, LANGUAGE_CHINESE_TRADITIONAL, LANGUAGE_CHINESE_SIMPLIFIED, NULL,
+                        i18n::TextConversionOption::CHARACTER_BY_CHARACTER, false,
+                        true, false, false );
+    aWrap.Convert();
+
+
+    // Then
+    SwTxtNode* pTxtNode = aPaM.GetNode().GetTxtNode();
+    CPPUNIT_ASSERT_EQUAL(CHINESE_SIMPLIFIED_CONTENT, pTxtNode->GetTxt());
+
+}
+
+// Tests conversion of simplified Chinese characters to traditional Chinese
+void SwUiWriterTest::testChineseConversionSimplifiedToTraditional()
+{
+
+    // Given
+    SwDoc* pDoc = createDoc();
+    SwView* pView = pDoc->GetDocShell()->GetView();
+    const uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
+    SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
+    SwPaM aPaM(aIdx);
+    pDoc->getIDocumentContentOperations().InsertString(aPaM, CHINESE_SIMPLIFIED_CONTENT);
+
+
+    // When
+    SwHHCWrapper aWrap( pView, xContext, LANGUAGE_CHINESE_SIMPLIFIED, LANGUAGE_CHINESE_TRADITIONAL, NULL,
+                        i18n::TextConversionOption::CHARACTER_BY_CHARACTER, false,
+                        true, false, false );
+    aWrap.Convert();
+
+
+    // Then
+    SwTxtNode* pTxtNode = aPaM.GetNode().GetTxtNode();
+    CPPUNIT_ASSERT_EQUAL(CHINESE_TRADITIONAL_CONTENT, pTxtNode->GetTxt());
+
+}
+
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/uibase/lingu/hhcwrp.cxx b/sw/source/uibase/lingu/hhcwrp.cxx
index b83dd99..7bc3084 100644
--- a/sw/source/uibase/lingu/hhcwrp.cxx
+++ b/sw/source/uibase/lingu/hhcwrp.cxx
@@ -262,8 +262,8 @@ void SwHHCWrapper::ChangeText( const OUString &rNewText,
                 nIndex = rOrigText.getLength();
             }
 
-            if (rOrigText[nIndex] == rNewText[nPos] ||
-                nPos == nConvTextLen /* end of string also terminates non-matching char sequence */)
+            if (nPos == nConvTextLen || /* end of string also terminates non-matching char sequence */
+                rOrigText[nIndex] == rNewText[nPos])
             {
                 // substring that needs to be replaced found?
                 if (nChgPos != -1 && nConvChgPos != -1)


More information about the Libreoffice-commits mailing list