summaryrefslogtreecommitdiff
path: root/xmloff/qa/unit
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-09-03 16:42:46 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-09-03 19:01:08 +0200
commitf38406ba7905678a1cb703b8ff177e5f5008d3ee (patch)
tree0d626a1ff516e355e6d28a87087d96bf88e159ee /xmloff/qa/unit
parentcac7c02f52204eb3cea0a8594ed2d2c9313d4ede (diff)
tdf#62032 ODT export: handle style:list-level="..." for para styles
ODT import was already working. The spec also says to only take this into account when applying the style, so it seems only the UI remains for the bug to be closed, the rest is done. Change-Id: I27da4dc171b4ced75f143bbcecb3f8c748a26b02 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121607 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'xmloff/qa/unit')
-rw-r--r--xmloff/qa/unit/data/para-style-list-level.fodt2
-rw-r--r--xmloff/qa/unit/text.cxx39
2 files changed, 39 insertions, 2 deletions
diff --git a/xmloff/qa/unit/data/para-style-list-level.fodt b/xmloff/qa/unit/data/para-style-list-level.fodt
index 88f96e349ee2..3cf0fd6f5315 100644
--- a/xmloff/qa/unit/data/para-style-list-level.fodt
+++ b/xmloff/qa/unit/data/para-style-list-level.fodt
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
<office:styles>
- <style:style style:name="mystyle" style:family="paragraph" style:list-style-name="WWNum1" style:list-level="2"/>
+ <style:style style:name="mystyle" style:family="paragraph" style:list-style-name="mylist" style:list-level="2"/>
<text:list-style style:name="mylist">
</text:list-style>
</office:styles>
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index 79acb8cb08bf..78ebaf75e1bc 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -9,6 +9,7 @@
#include <test/bootstrapfixture.hxx>
#include <unotest/macros_test.hxx>
+#include <test/xmltesttools.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/Desktop.hpp>
@@ -16,18 +17,22 @@
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/text/BibliographyDataType.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
+#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
#include <comphelper/propertysequence.hxx>
#include <comphelper/propertyvalue.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <unotools/tempfile.hxx>
+#include <unotools/ucbstreamhelper.hxx>
using namespace ::com::sun::star;
constexpr OUStringLiteral DATA_DIRECTORY = u"/xmloff/qa/unit/data/";
/// Covers xmloff/source/text/ fixes.
-class XmloffStyleTest : public test::BootstrapFixture, public unotest::MacrosTest
+class XmloffStyleTest : public test::BootstrapFixture,
+ public unotest::MacrosTest,
+ public XmlTestTools
{
private:
uno::Reference<lang::XComponent> mxComponent;
@@ -35,9 +40,15 @@ private:
public:
void setUp() override;
void tearDown() override;
+ void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override;
uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
};
+void XmloffStyleTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
+{
+ XmlTestTools::registerODFNamespaces(pXmlXpathCtx);
+}
+
void XmloffStyleTest::setUp()
{
test::BootstrapFixture::setUp();
@@ -181,6 +192,32 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testParaStyleListLevel)
sal_Int16 nNumberingLevel{};
CPPUNIT_ASSERT(xStyle->getPropertyValue("NumberingLevel") >>= nNumberingLevel);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(2), nNumberingLevel);
+
+ // Test the export as well:
+
+ // Given a doc model that has a para style with NumberingLevel=2:
+ uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
+
+ // When exporting that to ODT:
+ uno::Sequence<beans::PropertyValue> aStoreProps = comphelper::InitPropertySequence({
+ { "FilterName", uno::makeAny(OUString("writer8")) },
+ });
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ xStorable->storeToURL(aTempFile.GetURL(), aStoreProps);
+
+ // Then make sure we save the style's numbering level:
+ uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
+ = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, aTempFile.GetURL());
+ uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName("styles.xml"),
+ uno::UNO_QUERY);
+ std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
+ xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get());
+ // Without the accompanying fix in place, this failed with:
+ // - XPath '/office:document-styles/office:styles/style:style[@style:name='mystyle']' no attribute 'list-level' exist
+ // i.e. a custom NumberingLevel was lost on save.
+ assertXPath(pXmlDoc, "/office:document-styles/office:styles/style:style[@style:name='mystyle']",
+ "list-level", "2");
}
CPPUNIT_PLUGIN_IMPLEMENT();