summaryrefslogtreecommitdiff
path: root/sw/qa/extras/uiwriter/uiwriter.cxx
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 /sw/qa/extras/uiwriter/uiwriter.cxx
parent542ae4e06f9f70e328a3e85f1272ead558b36766 (diff)
fdo#83178 fix Chinese Conversion crash
Reviewed on: https://gerrit.libreoffice.org/11187 Change-Id: Ifa9c7c1a29d7076903e038d3132c635b1143e2d8
Diffstat (limited to 'sw/qa/extras/uiwriter/uiwriter.cxx')
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx122
1 files changed, 122 insertions, 0 deletions
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();