summaryrefslogtreecommitdiffstats
path: root/sw/qa/extras/txtimport
diff options
context:
space:
mode:
Diffstat (limited to 'sw/qa/extras/txtimport')
-rw-r--r--sw/qa/extras/txtimport/data/GB18030.txt1
-rw-r--r--sw/qa/extras/txtimport/data/UTF16BEWITHBOM.txtbin0 -> 1290 bytes
-rw-r--r--sw/qa/extras/txtimport/data/UTF16BEWITHOUTBOM.txtbin0 -> 1288 bytes
-rw-r--r--sw/qa/extras/txtimport/data/UTF16LEWITHBOM.txtbin0 -> 1290 bytes
-rw-r--r--sw/qa/extras/txtimport/data/UTF16LEWITHOUTBOM.txtbin0 -> 1288 bytes
-rw-r--r--sw/qa/extras/txtimport/data/UTF8WITHBOM.txt2
-rw-r--r--sw/qa/extras/txtimport/data/UTF8WITHOUTBOM.txt2
-rw-r--r--sw/qa/extras/txtimport/data/bullets.odtbin0 -> 10379 bytes
-rw-r--r--sw/qa/extras/txtimport/txtimport.cxx194
9 files changed, 199 insertions, 0 deletions
diff --git a/sw/qa/extras/txtimport/data/GB18030.txt b/sw/qa/extras/txtimport/data/GB18030.txt
new file mode 100644
index 000000000..ef75274e2
--- /dev/null
+++ b/sw/qa/extras/txtimport/data/GB18030.txt
@@ -0,0 +1 @@
+盖闻天地之数,有十二万九千六百岁为一元。
diff --git a/sw/qa/extras/txtimport/data/UTF16BEWITHBOM.txt b/sw/qa/extras/txtimport/data/UTF16BEWITHBOM.txt
new file mode 100644
index 000000000..2e0455704
--- /dev/null
+++ b/sw/qa/extras/txtimport/data/UTF16BEWITHBOM.txt
Binary files differ
diff --git a/sw/qa/extras/txtimport/data/UTF16BEWITHOUTBOM.txt b/sw/qa/extras/txtimport/data/UTF16BEWITHOUTBOM.txt
new file mode 100644
index 000000000..0551ae547
--- /dev/null
+++ b/sw/qa/extras/txtimport/data/UTF16BEWITHOUTBOM.txt
Binary files differ
diff --git a/sw/qa/extras/txtimport/data/UTF16LEWITHBOM.txt b/sw/qa/extras/txtimport/data/UTF16LEWITHBOM.txt
new file mode 100644
index 000000000..43ed8143e
--- /dev/null
+++ b/sw/qa/extras/txtimport/data/UTF16LEWITHBOM.txt
Binary files differ
diff --git a/sw/qa/extras/txtimport/data/UTF16LEWITHOUTBOM.txt b/sw/qa/extras/txtimport/data/UTF16LEWITHOUTBOM.txt
new file mode 100644
index 000000000..d2cc98e78
--- /dev/null
+++ b/sw/qa/extras/txtimport/data/UTF16LEWITHOUTBOM.txt
Binary files differ
diff --git a/sw/qa/extras/txtimport/data/UTF8WITHBOM.txt b/sw/qa/extras/txtimport/data/UTF8WITHBOM.txt
new file mode 100644
index 000000000..afd812fe6
--- /dev/null
+++ b/sw/qa/extras/txtimport/data/UTF8WITHBOM.txt
@@ -0,0 +1,2 @@
+锘挎饥a'
+褰笺伅鑳屽緦銇伈銇濄亱銇冻闊炽倰鑱炪亜銇熴傘仢銈屻伅銇傘伨銈婅壇銇勬剰鍛炽倰绀恒仚銈傘伄銇с伅銇亜銆傝銇屻亾銈撱仾澶滄洿銇戙伀銆併仐銇嬨倐銇撱倱銇鐏伄銇婄矖鏈仾娓銇嫮銇勫皬閬撱仹褰笺倰銇ゃ亼銇︽潵銈嬨仺銇勩亞銇仩銆備汉鐢熴伄鑸矾銈掓嵒銇樻洸銇掋併仢銇嵅鐗┿仺鍏便伀绔嬨仭鍘汇倣銇嗐仺銇椼仸銇勩倠銆併仢銇竵搴︿粖銆 褰笺伄銇撱伄浠曚簨銇搞伄鎭愩倢銈掑拰銈夈亽銈嬨仧銈併伀銆佹暟澶氥亜浠查枔銇腑銇悓銇樿冦亪銈掓姳銇嶃佸郊銈掕瀹堛倞銆佸緟銇c仸銇勩倠鑰呫亴銇勩倠銇ㄣ亜銇嗐伄銇嬨傘仢銈屻仺銈傝儗寰屻伄瓒抽煶銇富銇併亾銇銇劇鏁般伀銇勩倠娉曠洠瑕栧焦銇с佸挤闈仾缃般倰銇欍亹銇倐褰笺伄鎵嬮銇偓銈枫儯銉炽仺涓嬨仚銇ㄣ亜銇嗐伄銇嬨傚郊銇冻闊炽亴姝€伨銇c仧銇撱仺銇皸銇岀潃銇勩仧銆傘亗銈忋仸銇﹁竞銈娿倰瑕嬪洖銇欍傘伒銇ㄧ嫮銇勬姕銇戦亾銇洰銇屾銇俱倠銆 褰笺伅绱犳棭銇忓彸銇韩銈掔炕銇椼佸缓鐗┿伄闁撱伀娑堛亪鍘汇仯銇熴傘仢銇檪褰笺伅銆併倐銇嗗皯銇椼仹閬撱伄鐪熶腑銇虎銇屻仯銇︺亜銇熴仈銇裤儛銈便儎銇簱銇嶈虎銇躲仺銇撱倣銇犮仯銇熴 褰笺伅鏆楅棁銇腑銇ч亾銈掔⒑銇嬨倎銈堛亞銇ㄣ仒銇c仺瑕嬨仱銈併仧銆傘仼銇嗐倓銈夎嚜鍒嗐伄閫氥仯銇︺亶銇熼亾浠ュ銇亾銇腑搴亱銈夈伄鍑洪亾銇仾銇勩倛銇嗐仩銆 瓒抽煶銇仩銈撱仩銈撹繎銇ャ亶銆佸郊銇伅瑙掋倰鏇层亴銈嬮粧銇勪汉褰便亴瑕嬨亪銇熴傚郊銇洰銇銇棁銇腑銈掑繀姝汇伀銇曘伨銈堛亜銆侀冦亽閬撱倰鎺€仚銆傘倐銇嗐仚銇广仸銇祩銈忋倞銇伄銇嬨傘仚銇广仸銇嫤鍔淬仺婧栧倷銇按銇场銇犮仺銇勩亞銇亱銆 绐佺劧銆佸郊銇í銇ф墘銇岄ⅷ銇徍銈夈亷銆併伝銈撱伄銈忋仛銇嬨伀銇嶃仐銈銇倰鑱炪亜銇熸檪銆佸郊銇儗涓倰澹併伀鎶笺仐浠樸亼銆佽拷璺¤呫伀瑕嬩粯銇戙倝銈屻仾銇勩亾銇ㄣ倰椤樸仯銇熴傘亾銇墘銇湜銇裤伄缍便仺銇椼仸鎶曘亽銇嬨亼銈夈倢銇熴佸郊銇偢銉兂銉炪亱銈夈伄鍑哄彛銇伄銇犮倣銇嗐亱銆傝儗涓倰澹併伀銇淬仯銇熴倞鎶笺仐浠樸亼銇熴伨銇俱併倖銇c亸銈娿仺褰笺伅闁嬨亜銇︺亜銈嬫墘銇柟銇搞仺韬倰鍕曘亱銇椼仸琛屻仯銇熴傘亾銇墘銇郊銇晳銇勩仺銇倠銇仩銈嶃亞銇嬨
diff --git a/sw/qa/extras/txtimport/data/UTF8WITHOUTBOM.txt b/sw/qa/extras/txtimport/data/UTF8WITHOUTBOM.txt
new file mode 100644
index 000000000..b8362e9e7
--- /dev/null
+++ b/sw/qa/extras/txtimport/data/UTF8WITHOUTBOM.txt
@@ -0,0 +1,2 @@
+婕'
+褰笺伅鑳屽緦銇伈銇濄亱銇冻闊炽倰鑱炪亜銇熴傘仢銈屻伅銇傘伨銈婅壇銇勬剰鍛炽倰绀恒仚銈傘伄銇с伅銇亜銆傝銇屻亾銈撱仾澶滄洿銇戙伀銆併仐銇嬨倐銇撱倱銇鐏伄銇婄矖鏈仾娓銇嫮銇勫皬閬撱仹褰笺倰銇ゃ亼銇︽潵銈嬨仺銇勩亞銇仩銆備汉鐢熴伄鑸矾銈掓嵒銇樻洸銇掋併仢銇嵅鐗┿仺鍏便伀绔嬨仭鍘汇倣銇嗐仺銇椼仸銇勩倠銆併仢銇竵搴︿粖銆 褰笺伄銇撱伄浠曚簨銇搞伄鎭愩倢銈掑拰銈夈亽銈嬨仧銈併伀銆佹暟澶氥亜浠查枔銇腑銇悓銇樿冦亪銈掓姳銇嶃佸郊銈掕瀹堛倞銆佸緟銇c仸銇勩倠鑰呫亴銇勩倠銇ㄣ亜銇嗐伄銇嬨傘仢銈屻仺銈傝儗寰屻伄瓒抽煶銇富銇併亾銇銇劇鏁般伀銇勩倠娉曠洠瑕栧焦銇с佸挤闈仾缃般倰銇欍亹銇倐褰笺伄鎵嬮銇偓銈枫儯銉炽仺涓嬨仚銇ㄣ亜銇嗐伄銇嬨傚郊銇冻闊炽亴姝€伨銇c仧銇撱仺銇皸銇岀潃銇勩仧銆傘亗銈忋仸銇﹁竞銈娿倰瑕嬪洖銇欍傘伒銇ㄧ嫮銇勬姕銇戦亾銇洰銇屾銇俱倠銆 褰笺伅绱犳棭銇忓彸銇韩銈掔炕銇椼佸缓鐗┿伄闁撱伀娑堛亪鍘汇仯銇熴傘仢銇檪褰笺伅銆併倐銇嗗皯銇椼仹閬撱伄鐪熶腑銇虎銇屻仯銇︺亜銇熴仈銇裤儛銈便儎銇簱銇嶈虎銇躲仺銇撱倣銇犮仯銇熴 褰笺伅鏆楅棁銇腑銇ч亾銈掔⒑銇嬨倎銈堛亞銇ㄣ仒銇c仺瑕嬨仱銈併仧銆傘仼銇嗐倓銈夎嚜鍒嗐伄閫氥仯銇︺亶銇熼亾浠ュ銇亾銇腑搴亱銈夈伄鍑洪亾銇仾銇勩倛銇嗐仩銆 瓒抽煶銇仩銈撱仩銈撹繎銇ャ亶銆佸郊銇伅瑙掋倰鏇层亴銈嬮粧銇勪汉褰便亴瑕嬨亪銇熴傚郊銇洰銇銇棁銇腑銈掑繀姝汇伀銇曘伨銈堛亜銆侀冦亽閬撱倰鎺€仚銆傘倐銇嗐仚銇广仸銇祩銈忋倞銇伄銇嬨傘仚銇广仸銇嫤鍔淬仺婧栧倷銇按銇场銇犮仺銇勩亞銇亱銆 绐佺劧銆佸郊銇í銇ф墘銇岄ⅷ銇徍銈夈亷銆併伝銈撱伄銈忋仛銇嬨伀銇嶃仐銈銇倰鑱炪亜銇熸檪銆佸郊銇儗涓倰澹併伀鎶笺仐浠樸亼銆佽拷璺¤呫伀瑕嬩粯銇戙倝銈屻仾銇勩亾銇ㄣ倰椤樸仯銇熴傘亾銇墘銇湜銇裤伄缍便仺銇椼仸鎶曘亽銇嬨亼銈夈倢銇熴佸郊銇偢銉兂銉炪亱銈夈伄鍑哄彛銇伄銇犮倣銇嗐亱銆傝儗涓倰澹併伀銇淬仯銇熴倞鎶笺仐浠樸亼銇熴伨銇俱併倖銇c亸銈娿仺褰笺伅闁嬨亜銇︺亜銈嬫墘銇柟銇搞仺韬倰鍕曘亱銇椼仸琛屻仯銇熴傘亾銇墘銇郊銇晳銇勩仺銇倠銇仩銈嶃亞銇嬨
diff --git a/sw/qa/extras/txtimport/data/bullets.odt b/sw/qa/extras/txtimport/data/bullets.odt
new file mode 100644
index 000000000..43e0c2123
--- /dev/null
+++ b/sw/qa/extras/txtimport/data/bullets.odt
Binary files differ
diff --git a/sw/qa/extras/txtimport/txtimport.cxx b/sw/qa/extras/txtimport/txtimport.cxx
new file mode 100644
index 000000000..4ae113320
--- /dev/null
+++ b/sw/qa/extras/txtimport/txtimport.cxx
@@ -0,0 +1,194 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <shellio.hxx>
+#include <unotextrange.hxx>
+#include <iodetect.hxx>
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+#include <wrtsh.hxx>
+
+class TxtImportTest : public SwModelTestBase
+{
+public:
+ TxtImportTest()
+ : SwModelTestBase("/sw/qa/extras/txtimport/data/", "Text")
+ {
+ }
+
+ // Export & assert part of the document (defined by SwPaM).
+ void assertExportedRange(const OString& aExpected, SwPaM& rPaM)
+ {
+ WriterRef rAsciiWriter;
+ SwReaderWriter::GetWriter(FILTER_TEXT, OUString(), rAsciiWriter);
+ CPPUNIT_ASSERT(rAsciiWriter.is());
+
+ // no start char
+ rAsciiWriter->m_bUCS2_WithStartChar = false;
+
+ SvMemoryStream aMemoryStream;
+
+ SwWriter aWriter(aMemoryStream, rPaM);
+ ErrCode nError = aWriter.Write(rAsciiWriter);
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, nError);
+
+ const char* pData = static_cast<const char*>(aMemoryStream.GetData());
+ OString aResult(pData, aMemoryStream.GetSize());
+
+ CPPUNIT_ASSERT_EQUAL(aExpected, aResult);
+ }
+};
+
+CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf112191)
+{
+ load(mpTestDocumentPath, "bullets.odt");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+
+ // just the 5th paragraph - no bullet
+ uno::Reference<text::XTextRange> xPara(getParagraph(5));
+ SwUnoInternalPaM aPaM(*pDoc);
+ bool bSuccess = sw::XTextRangeToSwPaM(aPaM, xPara);
+ CPPUNIT_ASSERT(bSuccess);
+
+ assertExportedRange("First bullet", aPaM);
+
+ // but when we extend to the next paragraph - now there are bullets
+ xPara = getParagraph(6);
+ SwUnoInternalPaM aPaM2(*pDoc);
+ bSuccess = sw::XTextRangeToSwPaM(aPaM2, xPara);
+ CPPUNIT_ASSERT(bSuccess);
+
+ OUString aString = OStringToOUString(" \xe2\x80\xa2 First bullet" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 Second bullet",
+ RTL_TEXTENCODING_UTF8);
+
+ SwPaM aPaM3(*aPaM2.GetMark(), *aPaM.GetPoint());
+ assertExportedRange(OUStringToOString(aString, osl_getThreadTextEncoding()), aPaM3);
+}
+
+CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf8withoutbom)
+{
+ load(mpTestDocumentPath, "UTF8WITHOUTBOM.txt");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+
+ uno::Reference<text::XTextRange> xPara(getParagraph(1));
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"婕'"), xPara->getString());
+}
+
+CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf8withbom)
+{
+ load(mpTestDocumentPath, "UTF8WITHBOM.txt");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+
+ uno::Reference<text::XTextRange> xPara(getParagraph(1));
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"婕'"), xPara->getString());
+}
+
+CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf16lewithoutbom)
+{
+ load(mpTestDocumentPath, "UTF16LEWITHOUTBOM.txt");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+
+ uno::Reference<text::XTextRange> xPara(getParagraph(1));
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"婕'"), xPara->getString());
+}
+
+CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf16lewithbom)
+{
+ load(mpTestDocumentPath, "UTF16LEWITHBOM.txt");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+
+ uno::Reference<text::XTextRange> xPara(getParagraph(1));
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"婕'"), xPara->getString());
+}
+
+CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf92161_gb18030)
+{
+ load(mpTestDocumentPath, "GB18030.txt");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+
+ uno::Reference<text::XTextRange> xPara(getParagraph(1));
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"鐩栭椈澶╁湴涔嬫暟锛屾湁鍗佷簩涓囦節鍗冨叚鐧惧瞾涓轰竴鍏冦"), xPara->getString());
+}
+
+CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf16bewithoutbom)
+{
+ load(mpTestDocumentPath, "UTF16BEWITHOUTBOM.txt");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+
+ uno::Reference<text::XTextRange> xPara(getParagraph(1));
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"婕'"), xPara->getString());
+}
+
+CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf16bewithbom)
+{
+ load(mpTestDocumentPath, "UTF16BEWITHBOM.txt");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+
+ uno::Reference<text::XTextRange> xPara(getParagraph(1));
+
+ CPPUNIT_ASSERT_EQUAL(OUString(u"婕'"), xPara->getString());
+}
+
+CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf115088)
+{
+ SwDoc* pDoc = createSwDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->Insert("1");
+ pWrtShell->SplitNode();
+ pWrtShell->Insert("1");
+
+ pWrtShell->SelAll();
+ dispatchCommand(mxComponent, ".uno:Cut", {});
+ pWrtShell->Insert("test");
+ pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 4, /*bBasicCall=*/false);
+ dispatchCommand(mxComponent, ".uno:PasteUnformatted", {});
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ OUString aActual = xTextDocument->getText()->getString().copy(0, 2);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 1\n
+ // - Actual : 1t
+ CPPUNIT_ASSERT_EQUAL(OUString("1\n"), aActual.replaceAll("\r", "\n"));
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */