summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew J. Francis <mjay.francis@gmail.com>2014-08-29 18:18:40 +0800
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-09-01 10:10:42 +0200
commitc369013edb76cd47ef7e8c193a18a57ff165ddfb (patch)
tree32fcf0402aeeb593ab0165bf180a5681a19c0917
parent542ae4e06f9f70e328a3e85f1272ead558b36766 (diff)
fdo#83178 fix Chinese Conversion crash
Reviewed on: https://gerrit.libreoffice.org/11187 Change-Id: Ifa9c7c1a29d7076903e038d3132c635b1143e2d8
-rw-r--r--editeng/source/editeng/textconv.cxx2
-rw-r--r--sw/inc/hhcwrp.hxx2
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx122
-rw-r--r--sw/source/uibase/lingu/hhcwrp.cxx4
4 files changed, 126 insertions, 4 deletions
diff --git a/editeng/source/editeng/textconv.cxx b/editeng/source/editeng/textconv.cxx
index 307d0e8fc974..f843f8330873 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 df973d0c513b..9ff03b66ca8c 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 0665f492d080..6cb67f7aeae9 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 b83dd99f9f46..7bc308468315 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)