tdf#129221 DOCX import: fix missing restart of numbering

Regression from e49d2b31fb2020d065b4ad940d1031d07b10f32b (fdo#78939
[DOCX] Hang while opening due to incorrect modification of Style,
2014-06-06), the problem was that the 2nd sub-list of the bugdoc was not
restarted in Writer, while it was in Word.

The PR2 paragraph style inherits from the PR1 one and only that sets the
numId; tweaking the bugdoc to state the numId directly in PR2 would work
around the problem.

Fix the issue by improving DomainMapper_Impl::finishParagraph(), so that
it uses lcl_getListId() rather than calling
pStyleSheetProperties->GetListId() directly; since the previous knows
how to walk up the parent chain if needed.

(cherry picked from commit 63d3ac37865460ff51348a6e792bbacf2f7c4653)

Conflicts:
	writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx

Change-Id: I1c460919b0389d5b053b4ca1c9210279d6cd183c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88426
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Tested-by: Jenkins
diff --git a/writerfilter/CppunitTest_writerfilter_dmapper.mk b/writerfilter/CppunitTest_writerfilter_dmapper.mk
index 37a3dc5..695dcf9 100644
--- a/writerfilter/CppunitTest_writerfilter_dmapper.mk
+++ b/writerfilter/CppunitTest_writerfilter_dmapper.mk
@@ -18,6 +18,7 @@ $(eval $(call gb_CppunitTest_use_externals,writerfilter_dmapper,\
$(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_dmapper, \
    writerfilter/qa/cppunittests/dmapper/CellColorHandler \
    writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler \
    writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl \
    writerfilter/qa/cppunittests/dmapper/PropertyMap \
))

diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
new file mode 100644
index 0000000..a7274c6
--- /dev/null
+++ b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
@@ -0,0 +1,88 @@
/* -*- 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 <test/bootstrapfixture.hxx>
#include <unotest/macros_test.hxx>

#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/style/BreakType.hpp>

#include <comphelper/processfactory.hxx>

using namespace ::com::sun::star;

namespace
{
/// Tests for writerfilter/source/dmapper/DomainMapper_Impl.cxx.
class Test : public test::BootstrapFixture, public unotest::MacrosTest
{
private:
    uno::Reference<uno::XComponentContext> mxComponentContext;
    uno::Reference<lang::XComponent> mxComponent;

public:
    void setUp() override;
    void tearDown() override;
    uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
};

void Test::setUp()
{
    test::BootstrapFixture::setUp();

    mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
    mxDesktop.set(frame::Desktop::create(mxComponentContext));
}

void Test::tearDown()
{
    if (mxComponent.is())
        mxComponent->dispose();

    test::BootstrapFixture::tearDown();
}

char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/dmapper/data/";

CPPUNIT_TEST_FIXTURE(Test, testNumberingRestartStyleParent)
{
    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "num-restart-style-parent.docx";
    getComponent() = loadFromDesktop(aURL);

    // The paragraphs are A 1 2 B 1 2.
    uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY);
    uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
                                                                  uno::UNO_QUERY);
    uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
    uno::Reference<beans::XPropertySet> xPara;
    OUStringLiteral aProp("ListLabelString");
    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(OUString("A."), xPara->getPropertyValue(aProp).get<OUString>());
    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(OUString("1."), xPara->getPropertyValue(aProp).get<OUString>());
    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(OUString("2."), xPara->getPropertyValue(aProp).get<OUString>());
    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(OUString("B."), xPara->getPropertyValue(aProp).get<OUString>());
    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
    // Without the accompanying fix in place, this test would have failed with:
    // - Expected: 1.
    // - Actual  : 3.
    // i.e. the numbering was not restarted after B.
    CPPUNIT_ASSERT_EQUAL(OUString("1."), xPara->getPropertyValue(aProp).get<OUString>());
    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(OUString("2."), xPara->getPropertyValue(aProp).get<OUString>());
}
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/qa/cppunittests/dmapper/data/num-restart-style-parent.docx b/writerfilter/qa/cppunittests/dmapper/data/num-restart-style-parent.docx
new file mode 100644
index 0000000..f908d94
--- /dev/null
+++ b/writerfilter/qa/cppunittests/dmapper/data/num-restart-style-parent.docx
Binary files differ
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index c24cc03..fc189d7 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1652,8 +1652,10 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
                        (isNumberingViaStyle || itNumberingRules != aProperties.end()))
                    {
                        assert(dynamic_cast<ParagraphPropertyMap*>(pPropertyMap.get()));
                        // Use lcl_getListId(), so we find the list ID in parent styles as well.
                        bool bNumberingFromBaseStyle = false;
                        sal_Int32 const nListId( isNumberingViaStyle
                            ? pStyleSheetProperties->GetListId()
                            ? lcl_getListId(pEntry, GetStyleSheetTable(), bNumberingFromBaseStyle)
                            : static_cast<ParagraphPropertyMap*>(pPropertyMap.get())->GetListId());
                        if (ListDef::Pointer const& pList = m_pListTable->GetList(nListId))
                        {   // styles could refer to non-existing lists...