Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 



Bilddatei

txtexport.cxx


products/sources/formale Sprachen/C/LibreOffice/sw/qa/extras/txtexport/txtexport.cxx

/* -*- 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 #include #include #include #include #include namespace { class TxtExportTest : public SwModelTestBase { public: TxtExportTest() : SwModelTestBase(u"/sw/qa/extras/txtexport/data/"_ustr, u"Text"_ustr) { } protected: template std::vector readMemoryStream() { SvMemoryStream aMemoryStream; SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); aStream.ReadStream(aMemoryStream); const T* pData = static_cast(aMemoryStream.GetData()); sal_uInt64 size = aMemoryStream.GetSize(); CPPUNIT_ASSERT_EQUAL(sal_uInt64(0), size % sizeof(T)); return std::vector(pData, pData + size / sizeof(T)); } OString readExportedFile() { std::vector aMemStream = readMemoryStream(); int offset = 0; if (aMemStream.size() > 2 && aMemStream[0] == '\xEF' && aMemStream[1] == '\xBB' && aMemStream[2] == '\xBF') offset = 3; return OString(aMemStream.data() + offset, aMemStream.size() - offset); } }; CPPUNIT_TEST_FIXTURE(TxtExportTest, testBullets) { createSwDoc("bullets.odt"); save(mpFilter); OString aData = readExportedFile(); OUString aString = OStringToOUString( "1 Heading 1" SAL_NEWLINE_STRING "1.A Heading 2" SAL_NEWLINE_STRING "Paragraph" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING " \xe2\x80\xa2 First bullet" SAL_NEWLINE_STRING " \xe2\x80\xa2 Second bullet" SAL_NEWLINE_STRING " \xe2\x97\xa6 Sub-second bullet" SAL_NEWLINE_STRING " Third bullet, but deleted" SAL_NEWLINE_STRING " \xe2\x80\xa2 Fourth bullet" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING "Numbering" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING " 1. First" SAL_NEWLINE_STRING " 2. Second" SAL_NEWLINE_STRING " 1. Second-first" SAL_NEWLINE_STRING " Third, but deleted" SAL_NEWLINE_STRING " 3. Actual third" SAL_NEWLINE_STRING "" SAL_NEWLINE_STRING "Paragraph after numbering" SAL_NEWLINE_STRING "Next paragraph" SAL_NEWLINE_STRING "Final paragraph" SAL_NEWLINE_STRING, RTL_TEXTENCODING_UTF8); // To get the stuff back in the system's encoding OString aExpected(OUStringToOString(aString, osl_getThreadTextEncoding())); CPPUNIT_ASSERT_EQUAL(aExpected, aData); } CPPUNIT_TEST_FIXTURE(TxtExportTest, testTdf120574_utf8bom) { createSwDoc("UTF8BOMCRLF.txt"); save(mpFilter); std::vector aMemStream = readMemoryStream(); OString aData(std::string_view(aMemStream.data(), aMemStream.size())); CPPUNIT_ASSERT_EQUAL(u8"\uFEFFAB\r\nCD\r\n"_ostr, aData); } CPPUNIT_TEST_FIXTURE(TxtExportTest, testTdf120574_utf16lebom) { createSwDoc("UTF16LEBOMCRLF.txt"); save(mpFilter); std::vector aMemStream = readMemoryStream(); OUString aData(aMemStream.data(), aMemStream.size()); CPPUNIT_ASSERT_EQUAL(u"\uFEFFAB\r\nCD\r\n"_ustr, aData); } CPPUNIT_TEST_FIXTURE(TxtExportTest, testTdf142669_utf8) { createSwDoc("UTF8CRLF.txt"); save(mpFilter); std::vector aMemStream = readMemoryStream(); OString aData(std::string_view(aMemStream.data(), aMemStream.size())); CPPUNIT_ASSERT_EQUAL(u8"AB\r\nCD\r\n"_ostr, aData); } CPPUNIT_TEST_FIXTURE(TxtExportTest, testTdf142669_utf16le) { createSwDoc("UTF16LECRLF.txt"); save(mpFilter); std::vector aMemStream = readMemoryStream(); OUString aData(aMemStream.data(), aMemStream.size()); CPPUNIT_ASSERT_EQUAL(u"AB\r\nCD\r\n"_ustr, aData); } CPPUNIT_TEST_FIXTURE(TxtExportTest, testClearingBreakExport) { // Given a document with a clearing break: createSwDoc(); uno::Reference xMSF(mxComponent, uno::UNO_QUERY); uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); uno::Reference xLineBreak( xMSF->createInstance(u"com.sun.star.text.LineBreak"_ustr), uno::UNO_QUERY); uno::Reference xLineBreakProps(xLineBreak, uno::UNO_QUERY); auto eClear = static_cast(SwLineBreakClear::ALL); xLineBreakProps->setPropertyValue(u"Clear"_ustr, uno::Any(eClear)); uno::Reference xText = xTextDocument->getText(); uno::Reference xCursor = xText->createTextCursor(); xText->insertString(xCursor, u"foo"_ustr, /*bAbsorb=*/false); xText->insertTextContent(xCursor, xLineBreak, /*bAbsorb=*/false); xText->insertString(xCursor, u"bar"_ustr, /*bAbsorb=*/false); // When exporting to plain text: save(mpFilter); // Then make sure that the newline is not lost: OString aActual = readExportedFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: foo\nbar // - Actual : foobar // i.e. the clearing break was not downgraded to a plain line break. CPPUNIT_ASSERT_EQUAL("foo\nbar" SAL_NEWLINE_STRING ""_ostr, aActual); } } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge