| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <test/unoapi_test.hxx> |
| 11 |
|
| 12 |
#include <comphelper/propertyvalue.hxx> |
| 13 |
#include <unotools/streamwrap.hxx> |
| 14 |
|
| 15 |
#include <com/sun/star/container/XNameContainer.hpp> |
| 16 |
#include <com/sun/star/document/XImporter.hpp> |
| 17 |
#include <com/sun/star/document/XFilter.hpp> |
| 18 |
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> |
| 19 |
#include <com/sun/star/text/XTextDocument.hpp> |
| 20 |
|
| 21 |
using namespace com::sun::star; |
| 22 |
|
| 23 |
namespace |
| 24 |
{ |
| 25 |
/// Tests for sw/source/writerfilter/dmapper/NumberingManager.cxx. |
| 26 |
class Test : public UnoApiTest |
| 27 |
{ |
| 28 |
public: |
| 29 |
Test() |
| 30 |
: UnoApiTest(u"/sw/qa/writerfilter/dmapper/data/"_ustr) |
| 31 |
{ |
| 32 |
} |
| 33 |
}; |
| 34 |
|
| 35 |
CPPUNIT_TEST_FIXTURE(Test, testPasteBulletListStyleName) |
| 36 |
{ |
| 37 |
// Given a document with a WWNum1 list style: |
| 38 |
loadFromURL(u"private:factory/swriter"_ustr); |
| 39 |
uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent, |
| 40 |
uno::UNO_QUERY); |
| 41 |
uno::Reference<container::XNameAccess> xStyleFamilies |
| 42 |
= xStyleFamiliesSupplier->getStyleFamilies(); |
| 43 |
uno::Reference<container::XNameContainer> xStyles; |
| 44 |
xStyleFamilies->getByName(u"NumberingStyles"_ustr) >>= xStyles; |
| 45 |
uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); |
| 46 |
uno::Reference<uno::XInterface> xStyle |
| 47 |
= xFactory->createInstance("com.sun.star.style.NumberingStyle"); |
| 48 |
xStyles->insertByName(u"WWNum1"_ustr, uno::Any(xStyle)); |
| 49 |
|
| 50 |
// When pasting bullets to that document: |
| 51 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 52 |
uno::Reference<text::XTextRange> xText = xTextDocument->getText(); |
| 53 |
uno::Reference<text::XTextRange> xBodyEnd = xText->getEnd(); |
| 54 |
uno::Reference<document::XFilter> xFilter( |
| 55 |
m_xSFactory->createInstance(u"com.sun.star.comp.Writer.RtfFilter"_ustr), uno::UNO_QUERY); |
| 56 |
uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY); |
| 57 |
xImporter->setTargetDocument(mxComponent); |
| 58 |
std::unique_ptr<SvStream> pStream( |
| 59 |
new SvFileStream(createFileURL(u"clipboard-bullets.rtf"), StreamMode::READ)); |
| 60 |
uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(std::move(pStream))); |
| 61 |
uno::Sequence aDescriptor{ comphelper::makePropertyValue(u"InputStream"_ustr, xStream), |
| 62 |
comphelper::makePropertyValue(u"InsertMode"_ustr, true), |
| 63 |
comphelper::makePropertyValue(u"TextInsertModeRange"_ustr, |
| 64 |
xBodyEnd) }; |
| 65 |
CPPUNIT_ASSERT(xFilter->filter(aDescriptor)); |
| 66 |
|
| 67 |
// Then make sure we don't create new list styles, but reuse the existing ones: |
| 68 |
// Without the accompanying fix in place, this test would have failed, new character styles were |
| 69 |
// created again and again on each paste. |
| 70 |
CPPUNIT_ASSERT(!xStyles->hasByName(u"WWNum1a"_ustr)); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |