diff options
Diffstat (limited to 'sw/qa/extras/txtimport')
-rw-r--r-- | sw/qa/extras/txtimport/data/GB18030.txt | 1 | ||||
-rw-r--r-- | sw/qa/extras/txtimport/data/UTF16BEWITHBOM.txt | bin | 0 -> 1290 bytes | |||
-rw-r--r-- | sw/qa/extras/txtimport/data/UTF16BEWITHOUTBOM.txt | bin | 0 -> 1288 bytes | |||
-rw-r--r-- | sw/qa/extras/txtimport/data/UTF16LEWITHBOM.txt | bin | 0 -> 1290 bytes | |||
-rw-r--r-- | sw/qa/extras/txtimport/data/UTF16LEWITHOUTBOM.txt | bin | 0 -> 1288 bytes | |||
-rw-r--r-- | sw/qa/extras/txtimport/data/UTF8WITHBOM.txt | 2 | ||||
-rw-r--r-- | sw/qa/extras/txtimport/data/UTF8WITHOUTBOM.txt | 2 | ||||
-rw-r--r-- | sw/qa/extras/txtimport/data/bullets.odt | bin | 0 -> 10379 bytes | |||
-rw-r--r-- | sw/qa/extras/txtimport/txtimport.cxx | 194 |
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 Binary files differnew file mode 100644 index 000000000..2e0455704 --- /dev/null +++ b/sw/qa/extras/txtimport/data/UTF16BEWITHBOM.txt diff --git a/sw/qa/extras/txtimport/data/UTF16BEWITHOUTBOM.txt b/sw/qa/extras/txtimport/data/UTF16BEWITHOUTBOM.txt Binary files differnew file mode 100644 index 000000000..0551ae547 --- /dev/null +++ b/sw/qa/extras/txtimport/data/UTF16BEWITHOUTBOM.txt diff --git a/sw/qa/extras/txtimport/data/UTF16LEWITHBOM.txt b/sw/qa/extras/txtimport/data/UTF16LEWITHBOM.txt Binary files differnew file mode 100644 index 000000000..43ed8143e --- /dev/null +++ b/sw/qa/extras/txtimport/data/UTF16LEWITHBOM.txt diff --git a/sw/qa/extras/txtimport/data/UTF16LEWITHOUTBOM.txt b/sw/qa/extras/txtimport/data/UTF16LEWITHOUTBOM.txt Binary files differnew file mode 100644 index 000000000..d2cc98e78 --- /dev/null +++ b/sw/qa/extras/txtimport/data/UTF16LEWITHOUTBOM.txt 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 Binary files differnew file mode 100644 index 000000000..43e0c2123 --- /dev/null +++ b/sw/qa/extras/txtimport/data/bullets.odt 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: */ |