From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- xmloff/qa/unit/data/clearing-break.fodt | 28 + xmloff/qa/unit/data/comment-table-border.fodt | 16 + xmloff/qa/unit/data/content-control-checkbox.fodt | 8 + xmloff/qa/unit/data/content-control-date.fodt | 8 + xmloff/qa/unit/data/content-control-dropdown.docx | Bin 0 -> 65391 bytes xmloff/qa/unit/data/content-control-dropdown.fodt | 8 + xmloff/qa/unit/data/content-control-picture.fodt | 13 + xmloff/qa/unit/data/content-control.fodt | 8 + xmloff/qa/unit/data/continue-numbering-word.odt | Bin 0 -> 6151 bytes xmloff/qa/unit/data/fill-image-base64.fodg | 230 ++++++ xmloff/qa/unit/data/list-id.fodt | 23 + xmloff/qa/unit/data/mail-merge-editeng.odt | Bin 0 -> 9382 bytes xmloff/qa/unit/data/para-style-list-level.fodt | 14 + xmloff/qa/unit/data/refer-to-theme.odp | Bin 0 -> 20677 bytes xmloff/qa/unit/data/rtl-gutter.fodt | 16 + xmloff/qa/unit/data/table-in-shape.fodt | 22 + xmloff/qa/unit/data/tdf141301_Extrusion_Skew.odg | Bin 0 -> 9838 bytes .../data/tdf145700_3D_metal_type_MSCompatible.doc | Bin 0 -> 27136 bytes .../unit/data/tdf147580_extrusion-specularity.doc | Bin 0 -> 27136 bytes xmloff/qa/unit/data/tdf148714_CurvedArrowsOld.odp | Bin 0 -> 17679 bytes .../qa/unit/data/tdf150407_PosRelBottomMargin.docx | Bin 0 -> 17439 bytes xmloff/qa/unit/data/tdf150407_PosRelTopMargin.docx | Bin 0 -> 17432 bytes .../unit/data/tdf150407_WritingModeBTLR_style.odt | Bin 0 -> 11181 bytes xmloff/qa/unit/data/textbox-loss.docx | Bin 0 -> 42192 bytes xmloff/qa/unit/data/theme.odp | Bin 0 -> 13253 bytes xmloff/qa/unit/data/video-snapshot.odp | Bin 0 -> 17605 bytes xmloff/qa/unit/draw.cxx | 558 ++++++++++++++ xmloff/qa/unit/style.cxx | 393 ++++++++++ xmloff/qa/unit/text.cxx | 857 +++++++++++++++++++++ xmloff/qa/unit/tokenmap-test.cxx | 92 +++ xmloff/qa/unit/uxmloff.cxx | 231 ++++++ xmloff/qa/unoapi/knownissues.xcl | 43 ++ xmloff/qa/unoapi/testdocuments/emptyChart.sds | Bin 0 -> 44544 bytes xmloff/qa/unoapi/xmloff.sce | 44 ++ 34 files changed, 2612 insertions(+) create mode 100644 xmloff/qa/unit/data/clearing-break.fodt create mode 100644 xmloff/qa/unit/data/comment-table-border.fodt create mode 100644 xmloff/qa/unit/data/content-control-checkbox.fodt create mode 100644 xmloff/qa/unit/data/content-control-date.fodt create mode 100644 xmloff/qa/unit/data/content-control-dropdown.docx create mode 100644 xmloff/qa/unit/data/content-control-dropdown.fodt create mode 100644 xmloff/qa/unit/data/content-control-picture.fodt create mode 100644 xmloff/qa/unit/data/content-control.fodt create mode 100644 xmloff/qa/unit/data/continue-numbering-word.odt create mode 100644 xmloff/qa/unit/data/fill-image-base64.fodg create mode 100644 xmloff/qa/unit/data/list-id.fodt create mode 100644 xmloff/qa/unit/data/mail-merge-editeng.odt create mode 100644 xmloff/qa/unit/data/para-style-list-level.fodt create mode 100644 xmloff/qa/unit/data/refer-to-theme.odp create mode 100644 xmloff/qa/unit/data/rtl-gutter.fodt create mode 100644 xmloff/qa/unit/data/table-in-shape.fodt create mode 100644 xmloff/qa/unit/data/tdf141301_Extrusion_Skew.odg create mode 100644 xmloff/qa/unit/data/tdf145700_3D_metal_type_MSCompatible.doc create mode 100644 xmloff/qa/unit/data/tdf147580_extrusion-specularity.doc create mode 100644 xmloff/qa/unit/data/tdf148714_CurvedArrowsOld.odp create mode 100644 xmloff/qa/unit/data/tdf150407_PosRelBottomMargin.docx create mode 100644 xmloff/qa/unit/data/tdf150407_PosRelTopMargin.docx create mode 100644 xmloff/qa/unit/data/tdf150407_WritingModeBTLR_style.odt create mode 100644 xmloff/qa/unit/data/textbox-loss.docx create mode 100644 xmloff/qa/unit/data/theme.odp create mode 100644 xmloff/qa/unit/data/video-snapshot.odp create mode 100644 xmloff/qa/unit/draw.cxx create mode 100644 xmloff/qa/unit/style.cxx create mode 100644 xmloff/qa/unit/text.cxx create mode 100644 xmloff/qa/unit/tokenmap-test.cxx create mode 100644 xmloff/qa/unit/uxmloff.cxx create mode 100644 xmloff/qa/unoapi/knownissues.xcl create mode 100644 xmloff/qa/unoapi/testdocuments/emptyChart.sds create mode 100644 xmloff/qa/unoapi/xmloff.sce (limited to 'xmloff/qa') diff --git a/xmloff/qa/unit/data/clearing-break.fodt b/xmloff/qa/unit/data/clearing-break.fodt new file mode 100644 index 000000000..b80ff0d74 --- /dev/null +++ b/xmloff/qa/unit/data/clearing-break.fodt @@ -0,0 +1,28 @@ + + + + + + + + + + iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAQAAAAAYLlVAAAABGdBTUEAALGPC/xhBQAAAAFz + UkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA + AAJiS0dEAACqjSMyAAAACW9GRnMAAAAGAAAAAAAMc1XTAAAACXBIWXMAAA3XAAAN1wFCKJt4 + AAAACXZwQWcAAABMAAAAQACdMTgbAAABzUlEQVRo3u3ZPU/CQBjA8X+Jxs3ESUDj4iK+LA5+ + BBfjqBE1cXB2MlFAEqMgxvhNNL4sLsK3UPQL6ObkoAETz+FKW2mxCPRYnucWUu76/OC59C49 + cGOCKqrD9kHRc6ddPv7oW2WCwMh0nF63Myz7Tm8hPTNu0pgHMER3scepTbgK6enJNND83RLn + /878yRaPmgBZFDuMsNLeWB9gmFQHP77MIg9gsYciR50NFKvtjIy10yk84pSZA7DYpwR8scmF + QQCMuoQMpzbh0iAARrlnVn90CWHTsZcAiHPPdINQAuqsc2MQAAnKDUKWEhZ10twaBEDSJWQo + YlFj7S9CzwEegkXWIbQsRAQASFJhpplwbRAACS+hANRJBxMiAkDcJeQ4sQkBhYgMoJ+Ozlwo + 2YQ7AJ6CRxyiUGnVy3hVKb0Af9v7hUG2Wy9TEQCUelFTDULB2S+YKYGOMcpM6UIccOQnRA6A + cSp6ibfI+wkGADBGpTEd8xz1AaAfTQ7huA8AvUw5hVjuA0D/C5OaMN8XACRZ8F0zCggKAQhA + AAIQgAAEIAABCEAAAhCAAAQgAAH4zg3feY4w3Xs44M5+oW0qvCWoGcvaIlM3x/f/ab+O738A + hOCNQr34oD4AAAAldEVYdGNyZWF0ZS1kYXRlADIwMTAtMTItMjBUMTc6MDg6MzYrMDE6MDB6 + 5RscAAAAJXRFWHRtb2RpZnktZGF0ZQAyMDEwLTEyLTIwVDE3OjA4OjM3KzAxOjAwgyNmnAAA + AABJRU5ErkJggg== + foobar + + + diff --git a/xmloff/qa/unit/data/comment-table-border.fodt b/xmloff/qa/unit/data/comment-table-border.fodt new file mode 100644 index 000000000..29f54da9a --- /dev/null +++ b/xmloff/qa/unit/data/comment-table-border.fodt @@ -0,0 +1,16 @@ + + + + + + + + + Axb + + + + bZ + + + diff --git a/xmloff/qa/unit/data/content-control-checkbox.fodt b/xmloff/qa/unit/data/content-control-checkbox.fodt new file mode 100644 index 000000000..59c333ab9 --- /dev/null +++ b/xmloff/qa/unit/data/content-control-checkbox.fodt @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/xmloff/qa/unit/data/content-control-date.fodt b/xmloff/qa/unit/data/content-control-date.fodt new file mode 100644 index 000000000..c49e51339 --- /dev/null +++ b/xmloff/qa/unit/data/content-control-date.fodt @@ -0,0 +1,8 @@ + + + + + choose a date + + + diff --git a/xmloff/qa/unit/data/content-control-dropdown.docx b/xmloff/qa/unit/data/content-control-dropdown.docx new file mode 100644 index 000000000..1391c90f1 Binary files /dev/null and b/xmloff/qa/unit/data/content-control-dropdown.docx differ diff --git a/xmloff/qa/unit/data/content-control-dropdown.fodt b/xmloff/qa/unit/data/content-control-dropdown.fodt new file mode 100644 index 000000000..97344d1e8 --- /dev/null +++ b/xmloff/qa/unit/data/content-control-dropdown.fodt @@ -0,0 +1,8 @@ + + + + + choose a color + + + diff --git a/xmloff/qa/unit/data/content-control-picture.fodt b/xmloff/qa/unit/data/content-control-picture.fodt new file mode 100644 index 000000000..ae47bfa0d --- /dev/null +++ b/xmloff/qa/unit/data/content-control-picture.fodt @@ -0,0 +1,13 @@ + + + + + + iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAAEElEQVR4nGJgAQAAAP//AwAA + BgAFV7+r1AAAAABJRU5ErkJggg== + + + + + + diff --git a/xmloff/qa/unit/data/content-control.fodt b/xmloff/qa/unit/data/content-control.fodt new file mode 100644 index 000000000..97769c662 --- /dev/null +++ b/xmloff/qa/unit/data/content-control.fodt @@ -0,0 +1,8 @@ + + + + + test + + + diff --git a/xmloff/qa/unit/data/continue-numbering-word.odt b/xmloff/qa/unit/data/continue-numbering-word.odt new file mode 100644 index 000000000..278a1fa65 Binary files /dev/null and b/xmloff/qa/unit/data/continue-numbering-word.odt differ diff --git a/xmloff/qa/unit/data/fill-image-base64.fodg b/xmloff/qa/unit/data/fill-image-base64.fodg new file mode 100644 index 000000000..ce0df9d1d --- /dev/null +++ b/xmloff/qa/unit/data/fill-image-base64.fodg @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAQAAAAAYLlVAAAABGdBTUEAALGPC/xhBQAAAAFz + UkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA + AAJiS0dEAACqjSMyAAAACW9GRnMAAAAGAAAAAAAMc1XTAAAACXBIWXMAAA3XAAAN1wFCKJt4 + AAAACXZwQWcAAABMAAAAQACdMTgbAAABzUlEQVRo3u3ZPU/CQBjA8X+Jxs3ESUDj4iK+LA5+ + BBfjqBE1cXB2MlFAEqMgxvhNNL4sLsK3UPQL6ObkoAETz+FKW2mxCPRYnucWUu76/OC59C49 + cGOCKqrD9kHRc6ddPv7oW2WCwMh0nF63Myz7Tm8hPTNu0pgHMER3scepTbgK6enJNND83RLn + /878yRaPmgBZFDuMsNLeWB9gmFQHP77MIg9gsYciR50NFKvtjIy10yk84pSZA7DYpwR8scmF + QQCMuoQMpzbh0iAARrlnVn90CWHTsZcAiHPPdINQAuqsc2MQAAnKDUKWEhZ10twaBEDSJWQo + YlFj7S9CzwEegkXWIbQsRAQASFJhpplwbRAACS+hANRJBxMiAkDcJeQ4sQkBhYgMoJ+Ozlwo + 2YQ7AJ6CRxyiUGnVy3hVKb0Af9v7hUG2Wy9TEQCUelFTDULB2S+YKYGOMcpM6UIccOQnRA6A + cSp6ibfI+wkGADBGpTEd8xz1AaAfTQ7huA8AvUw5hVjuA0D/C5OaMN8XACRZ8F0zCggKAQhA + AAIQgAAEIAABCEAAAhCAAAQgAAH4zg3feY4w3Xs44M5+oW0qvCWoGcvaIlM3x/f/ab+O738A + hOCNQr34oD4AAAAldEVYdGNyZWF0ZS1kYXRlADIwMTAtMTItMjBUMTc6MDg6MzYrMDE6MDB6 + 5RscAAAAJXRFWHRtb2RpZnktZGF0ZQAyMDEwLTEyLTIwVDE3OjA4OjM3KzAxOjAwgyNmnAAA + AABJRU5ErkJggg== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xmloff/qa/unit/data/list-id.fodt b/xmloff/qa/unit/data/list-id.fodt new file mode 100644 index 000000000..377dbcbd6 --- /dev/null +++ b/xmloff/qa/unit/data/list-id.fodt @@ -0,0 +1,23 @@ + + + + + + + + + + + + First + + + Second + + + Third + + + + + diff --git a/xmloff/qa/unit/data/mail-merge-editeng.odt b/xmloff/qa/unit/data/mail-merge-editeng.odt new file mode 100644 index 000000000..e6466e44e Binary files /dev/null and b/xmloff/qa/unit/data/mail-merge-editeng.odt differ diff --git a/xmloff/qa/unit/data/para-style-list-level.fodt b/xmloff/qa/unit/data/para-style-list-level.fodt new file mode 100644 index 000000000..3cf0fd6f5 --- /dev/null +++ b/xmloff/qa/unit/data/para-style-list-level.fodt @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/xmloff/qa/unit/data/refer-to-theme.odp b/xmloff/qa/unit/data/refer-to-theme.odp new file mode 100644 index 000000000..2c413ef76 Binary files /dev/null and b/xmloff/qa/unit/data/refer-to-theme.odp differ diff --git a/xmloff/qa/unit/data/rtl-gutter.fodt b/xmloff/qa/unit/data/rtl-gutter.fodt new file mode 100644 index 000000000..81524fced --- /dev/null +++ b/xmloff/qa/unit/data/rtl-gutter.fodt @@ -0,0 +1,16 @@ + + + + + + + + + + + + + hello + + + diff --git a/xmloff/qa/unit/data/table-in-shape.fodt b/xmloff/qa/unit/data/table-in-shape.fodt new file mode 100644 index 000000000..44c2bcb05 --- /dev/null +++ b/xmloff/qa/unit/data/table-in-shape.fodt @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + A1 + + + diff --git a/xmloff/qa/unit/data/tdf141301_Extrusion_Skew.odg b/xmloff/qa/unit/data/tdf141301_Extrusion_Skew.odg new file mode 100644 index 000000000..757289d43 Binary files /dev/null and b/xmloff/qa/unit/data/tdf141301_Extrusion_Skew.odg differ diff --git a/xmloff/qa/unit/data/tdf145700_3D_metal_type_MSCompatible.doc b/xmloff/qa/unit/data/tdf145700_3D_metal_type_MSCompatible.doc new file mode 100644 index 000000000..99c433654 Binary files /dev/null and b/xmloff/qa/unit/data/tdf145700_3D_metal_type_MSCompatible.doc differ diff --git a/xmloff/qa/unit/data/tdf147580_extrusion-specularity.doc b/xmloff/qa/unit/data/tdf147580_extrusion-specularity.doc new file mode 100644 index 000000000..9efe793d3 Binary files /dev/null and b/xmloff/qa/unit/data/tdf147580_extrusion-specularity.doc differ diff --git a/xmloff/qa/unit/data/tdf148714_CurvedArrowsOld.odp b/xmloff/qa/unit/data/tdf148714_CurvedArrowsOld.odp new file mode 100644 index 000000000..94a4e0b3a Binary files /dev/null and b/xmloff/qa/unit/data/tdf148714_CurvedArrowsOld.odp differ diff --git a/xmloff/qa/unit/data/tdf150407_PosRelBottomMargin.docx b/xmloff/qa/unit/data/tdf150407_PosRelBottomMargin.docx new file mode 100644 index 000000000..0264f89f9 Binary files /dev/null and b/xmloff/qa/unit/data/tdf150407_PosRelBottomMargin.docx differ diff --git a/xmloff/qa/unit/data/tdf150407_PosRelTopMargin.docx b/xmloff/qa/unit/data/tdf150407_PosRelTopMargin.docx new file mode 100644 index 000000000..48f981506 Binary files /dev/null and b/xmloff/qa/unit/data/tdf150407_PosRelTopMargin.docx differ diff --git a/xmloff/qa/unit/data/tdf150407_WritingModeBTLR_style.odt b/xmloff/qa/unit/data/tdf150407_WritingModeBTLR_style.odt new file mode 100644 index 000000000..2ad2ca121 Binary files /dev/null and b/xmloff/qa/unit/data/tdf150407_WritingModeBTLR_style.odt differ diff --git a/xmloff/qa/unit/data/textbox-loss.docx b/xmloff/qa/unit/data/textbox-loss.docx new file mode 100644 index 000000000..9190e662f Binary files /dev/null and b/xmloff/qa/unit/data/textbox-loss.docx differ diff --git a/xmloff/qa/unit/data/theme.odp b/xmloff/qa/unit/data/theme.odp new file mode 100644 index 000000000..da8d18975 Binary files /dev/null and b/xmloff/qa/unit/data/theme.odp differ diff --git a/xmloff/qa/unit/data/video-snapshot.odp b/xmloff/qa/unit/data/video-snapshot.odp new file mode 100644 index 000000000..ca3b7f21d Binary files /dev/null and b/xmloff/qa/unit/data/video-snapshot.odp differ diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx new file mode 100644 index 000000000..f2aeb834c --- /dev/null +++ b/xmloff/qa/unit/draw.cxx @@ -0,0 +1,558 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + +constexpr OUStringLiteral DATA_DIRECTORY = u"/xmloff/qa/unit/data/"; + +/// Covers xmloff/source/draw/ fixes. +class XmloffDrawTest : public test::BootstrapFixture, + public unotest::MacrosTest, + public XmlTestTools +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; + uno::Reference& getComponent() { return mxComponent; } + void save(const OUString& rFilterName, utl::TempFile& rTempFile); + uno::Reference getShape(sal_uInt8 nShapeIndex); +}; + +void XmloffDrawTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void XmloffDrawTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +void XmloffDrawTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) +{ + XmlTestTools::registerODFNamespaces(pXmlXpathCtx); +} + +void XmloffDrawTest::save(const OUString& rFilterName, utl::TempFile& rTempFile) +{ + uno::Reference xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= rFilterName; + rTempFile.EnableKillingFile(); + xStorable->storeToURL(rTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + validate(rTempFile.GetFileName(), test::ODF); +} + +uno::Reference XmloffDrawTest::getShape(sal_uInt8 nShapeIndex) +{ + uno::Reference xDrawPagesSupplier(mxComponent, + uno::UNO_QUERY_THROW); + uno::Reference xDrawPages(xDrawPagesSupplier->getDrawPages()); + uno::Reference xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xShape(xDrawPage->getByIndex(nShapeIndex), + uno::UNO_QUERY_THROW); + return xShape; +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTextBoxLoss) +{ + // Load a document that has a shape with a textbox in it. Save it to ODF and reload. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "textbox-loss.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("writer8"); + xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + getComponent()->dispose(); + getComponent() = loadFromDesktop(aTempFile.GetURL()); + + // Make sure that the shape is still a textbox. + uno::Reference xDrawPageSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY); + bool bTextBox = false; + xShape->getPropertyValue("TextBox") >>= bTextBox; + + // Without the accompanying fix in place, this test would have failed, as the shape only had + // editeng text, losing the image part of the shape text. + CPPUNIT_ASSERT(bTextBox); +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTdf141301_Extrusion_Angle) +{ + // Load a document that has a custom shape with extrusion direction as set by LO as its default. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf141301_Extrusion_Skew.odg"; + getComponent() = loadFromDesktop(aURL, "com.sun.star.comp.drawing.DrawingDocument"); + + // Prepare use of XPath + utl::TempFile aTempFile; + save("draw8", aTempFile); + uno::Reference xNameAccess + = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, aTempFile.GetURL()); + uno::Reference xInputStream(xNameAccess->getByName("content.xml"), + uno::UNO_QUERY); + std::unique_ptr pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + + // Without fix draw:extrusion-skew="50 -135" was not written to file although "50 -135" is not + // default in ODF, but only default inside LO. + assertXPath(pXmlDoc, "//draw:enhanced-geometry", "extrusion-skew", "50 -135"); +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeExport) +{ + // Create an Impress document which has a master page which has a theme associated with it. + getComponent() = loadFromDesktop("private:factory/simpress"); + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage( + xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); + uno::Reference xMasterPage(xDrawPage->getMasterPage(), uno::UNO_QUERY); + comphelper::SequenceAsHashMap aMap; + aMap["Name"] <<= OUString("mytheme"); + aMap["ColorSchemeName"] <<= OUString("mycolorscheme"); + uno::Sequence aColorScheme + = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb }; + aMap["ColorScheme"] <<= aColorScheme; + uno::Any aTheme(aMap.getAsConstPropertyValueList()); + xMasterPage->setPropertyValue("Theme", aTheme); + + // Export to ODP: + utl::TempFile aTempFile; + save("impress8", aTempFile); + + // Check if the 12 colors are written in the XML: + std::unique_ptr pStream = parseExportStream(aTempFile, "styles.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 12 + // - Actual : 0 + // - XPath '//style:master-page/loext:theme/loext:color-table/loext:color' number of nodes is incorrect + // i.e. the theme was lost on exporting to ODF. + assertXPath(pXmlDoc, "//style:master-page/loext:theme/loext:color-table/loext:color", 12); +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testVideoSnapshot) +{ + // Execute ODP import: + OUString aURL = m_directories.getURLFromSrc(u"xmloff/qa/unit/data/video-snapshot.odp"); + getComponent() = loadFromDesktop(aURL, "com.sun.star.presentation.PresentationDocument"); + uno::Reference xDrawPagesSupplier(getComponent(), + uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDrawPagesSupplier.is()); + uno::Reference xDrawPages(xDrawPagesSupplier->getDrawPages()); + uno::Reference xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDrawPage.is()); + auto pUnoPage = dynamic_cast(xDrawPage.get()); + SdrPage* pSdrPage = pUnoPage->GetSdrPage(); + auto pMedia = dynamic_cast(pSdrPage->GetObj(0)); + + // Check that the preview was imported: + const avmedia::MediaItem& rItem = pMedia->getMediaProperties(); + const Graphic& rGraphic = rItem.getGraphic(); + CPPUNIT_ASSERT(!rGraphic.IsNone()); + + // Check that the crop was imported: + const text::GraphicCrop& rCrop = rItem.getCrop(); + CPPUNIT_ASSERT_EQUAL(static_cast(0), rCrop.Top); + CPPUNIT_ASSERT_EQUAL(static_cast(0), rCrop.Bottom); + CPPUNIT_ASSERT_EQUAL(static_cast(1356), rCrop.Left); + CPPUNIT_ASSERT_EQUAL(static_cast(1356), rCrop.Right); + + // Execute ODP export: + utl::TempFile aTempFile; + save("impress8", aTempFile); + + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Check that the preview was exported: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // - XPath '//draw:frame[@draw:style-name='gr1']/draw:image' number of nodes is incorrect + // i.e. the preview wasn't exported to ODP. + assertXPath(pXmlDoc, "//draw:frame[@draw:style-name='gr1']/draw:image", "href", + "Pictures/MediaPreview1.png"); + // Check that the crop was exported: + assertXPath(pXmlDoc, "//style:style[@style:name='gr1']/style:graphic-properties", "clip", + "rect(0cm, 1.356cm, 0cm, 1.356cm)"); +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeImport) +{ + // Given a document that has a master page with a theme associated: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "theme.odp"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure the doc model has a master page with a theme: + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage( + xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); + uno::Reference xMasterpage(xDrawPage->getMasterPage(), uno::UNO_QUERY); + comphelper::SequenceAsHashMap aMap(xMasterpage->getPropertyValue("Theme")); + // Without the accompanying fix in place, this test would have failed with: + // Cannot extract an Any(void) to string! + // i.e. the master page had no theme. + CPPUNIT_ASSERT_EQUAL(OUString("Office Theme"), aMap["Name"].get()); + CPPUNIT_ASSERT_EQUAL(OUString("Office"), aMap["ColorSchemeName"].get()); + auto aColorScheme = aMap["ColorScheme"].get>(); + CPPUNIT_ASSERT_EQUAL(static_cast(12), aColorScheme.getLength()); + CPPUNIT_ASSERT_EQUAL(static_cast(0x954F72), aColorScheme[11]); +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testReferToTheme) +{ + // Given a document that refers to a theme color: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "refer-to-theme.odp"; + + // When loading and saving that document: + getComponent() = loadFromDesktop(aURL); + utl::TempFile aTempFile; + save("impress8", aTempFile); + + // Make sure the export result has the theme reference: + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//style:style[@style:name='T1']/style:text-properties' no attribute 'theme-color' exist + // i.e. only the direct color was written, but not the theme reference. + assertXPath(pXmlDoc, "//style:style[@style:name='T1']/style:text-properties", "theme-color", + "accent1"); + assertXPathNoAttribute(pXmlDoc, "//style:style[@style:name='T1']/style:text-properties", + "color-lum-mod"); + assertXPathNoAttribute(pXmlDoc, "//style:style[@style:name='T1']/style:text-properties", + "color-lum-off"); + + assertXPath(pXmlDoc, "//style:style[@style:name='T2']/style:text-properties", "theme-color", + "accent1"); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//style:style[@style:name='T2']/style:text-properties' no attribute 'color-lum-mod' exist + // i.e. effects on a referenced theme color were lost. + assertXPath(pXmlDoc, "//style:style[@style:name='T2']/style:text-properties", "color-lum-mod", + "40%"); + assertXPath(pXmlDoc, "//style:style[@style:name='T2']/style:text-properties", "color-lum-off", + "60%"); + + assertXPath(pXmlDoc, "//style:style[@style:name='T3']/style:text-properties", "theme-color", + "accent1"); + assertXPath(pXmlDoc, "//style:style[@style:name='T3']/style:text-properties", "color-lum-mod", + "75%"); + assertXPathNoAttribute(pXmlDoc, "//style:style[@style:name='T3']/style:text-properties", + "color-lum-off"); + + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//style:style[@style:name='gr2']/style:graphic-properties' no attribute 'fill-theme-color' exist + // i.e. only the direct color was written, but not the theme reference. + assertXPath(pXmlDoc, "//style:style[@style:name='gr2']/style:graphic-properties", + "fill-theme-color", "accent1"); + + // Shape fill, 60% lighter. + assertXPath(pXmlDoc, "//style:style[@style:name='gr3']/style:graphic-properties", + "fill-theme-color", "accent1"); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//style:style[@style:name='gr3']/style:graphic-properties' no attribute 'fill-color-lum-mod' exist + // i.e. the themed color was fine, but its effects were lost. + assertXPath(pXmlDoc, "//style:style[@style:name='gr3']/style:graphic-properties", + "fill-color-lum-mod", "40%"); + assertXPath(pXmlDoc, "//style:style[@style:name='gr3']/style:graphic-properties", + "fill-color-lum-off", "60%"); + + // Shape fill, 25% darker. + assertXPath(pXmlDoc, "//style:style[@style:name='gr4']/style:graphic-properties", + "fill-theme-color", "accent1"); + assertXPath(pXmlDoc, "//style:style[@style:name='gr4']/style:graphic-properties", + "fill-color-lum-mod", "75%"); + assertXPathNoAttribute(pXmlDoc, "//style:style[@style:name='gr4']/style:graphic-properties", + "fill-color-lum-off"); +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTableInShape) +{ + // Given a document with a shape with a "FrameX" parent style (starts with Frame, but is not + // Frame): + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "table-in-shape.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure the table inside the shape is not lost: + uno::Reference xDrawPageSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xText(xShape->getText(), uno::UNO_QUERY); + uno::Reference xEnum = xText->createEnumeration(); + uno::Reference xTable(xEnum->nextElement(), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have crashed, as xTable was an empty + // reference, i.e. the table inside the shape was lost. + uno::Reference xCell(xTable->getCellByName("A1"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("A1"), xCell->getString()); +} + +// Tests for save/load of new (LO 7.4) attribute loext:extrusion-metal-type +namespace +{ +void lcl_assertMetalProperties(std::string_view sInfo, uno::Reference& rxShape) +{ + uno::Reference xShapeProps(rxShape, uno::UNO_QUERY); + uno::Sequence aGeoPropSeq; + xShapeProps->getPropertyValue("CustomShapeGeometry") >>= aGeoPropSeq; + comphelper::SequenceAsHashMap aGeoPropMap(aGeoPropSeq); + uno::Sequence aExtrusionSeq; + aGeoPropMap.getValue("Extrusion") >>= aExtrusionSeq; + comphelper::SequenceAsHashMap aExtrusionPropMap(aExtrusionSeq); + + bool bIsMetal(false); + aExtrusionPropMap.getValue("Metal") >>= bIsMetal; + OString sMsg = OString::Concat(sInfo) + " Metal"; + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), bIsMetal); + + sal_Int16 nMetalType(-1); + aExtrusionPropMap.getValue("MetalType") >>= nMetalType; + sMsg = OString::Concat(sInfo) + " MetalType"; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + sMsg.getStr(), css::drawing::EnhancedCustomShapeMetalType::MetalMSCompatible, nMetalType); +} +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testExtrusionMetalTypeExtended) +{ + // import + getComponent() = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + + "tdf145700_3D_metal_type_MSCompatible.doc", + "com.sun.star.text.TextDocument"); + // verify properties + uno::Reference xShape(getShape(0)); + lcl_assertMetalProperties("from doc", xShape); + + // Test, that new attribute is written with loext namespace. Adapt when attribute is added to ODF. + utl::TempFile aTempFile; + save("writer8", aTempFile); + + // assert XML. + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//draw:enhanced-geometry", "extrusion-metal", "true"); + assertXPath(pXmlDoc, + "//draw:enhanced-geometry[@loext:extrusion-metal-type='loext:MetalMSCompatible']"); + + // reload + getComponent()->dispose(); + getComponent() = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument"); + // verify properties + uno::Reference xShapeReload(getShape(0)); + lcl_assertMetalProperties("from ODF 1.3 extended", xShapeReload); +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testExtrusionMetalTypeStrict) +{ + // import + getComponent() = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + + "tdf145700_3D_metal_type_MSCompatible.doc", + "com.sun.star.text.TextDocument"); + + // save ODF 1.3 strict and test, that new attribute is not written. Adapt when attribute is + // added to ODF. + const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion(GetODFDefaultVersion()); + SetODFDefaultVersion(SvtSaveOptions::ODFVER_013); + utl::TempFile aTempFile; + save("writer8", aTempFile); + + // assert XML. + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//draw:enhanced-geometry", "extrusion-metal", "true"); + assertXPath(pXmlDoc, "//draw:enhanced-geometry[@loext:extrusion-metal-type]", 0); + + SetODFDefaultVersion(nCurrentODFVersion); +} + +namespace +{ +void lcl_assertSpecularityProperty(std::string_view sInfo, uno::Reference& rxShape) +{ + uno::Reference xShapeProps(rxShape, uno::UNO_QUERY); + uno::Sequence aGeoPropSeq; + xShapeProps->getPropertyValue("CustomShapeGeometry") >>= aGeoPropSeq; + comphelper::SequenceAsHashMap aGeoPropMap(aGeoPropSeq); + uno::Sequence aExtrusionSeq; + aGeoPropMap.getValue("Extrusion") >>= aExtrusionSeq; + comphelper::SequenceAsHashMap aExtrusionPropMap(aExtrusionSeq); + + double fSpecularity(-1.0); + aExtrusionPropMap.getValue("Specularity") >>= fSpecularity; + OString sMsg = OString::Concat(sInfo) + "Specularity"; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sMsg.getStr(), 122.0703125, fSpecularity); +} +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testExtrusionSpecularityExtended) +{ + // import + getComponent() = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + + "tdf147580_extrusion-specularity.doc", + "com.sun.star.text.TextDocument"); + // verify property + uno::Reference xShape(getShape(0)); + lcl_assertSpecularityProperty("from doc", xShape); + + // Test, that attribute is written in draw namespace with value 100% and in loext namespace with + // value 122.0703125%. + utl::TempFile aTempFile; + save("writer8", aTempFile); + + // assert XML. + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//draw:enhanced-geometry[@draw:extrusion-specularity='100%']"); + assertXPath(pXmlDoc, + "//draw:enhanced-geometry[@loext:extrusion-specularity-loext='122.0703125%']"); + + // reload and verify, that the loext value is used + getComponent()->dispose(); + getComponent() = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument"); + // verify properties + uno::Reference xShapeReload(getShape(0)); + lcl_assertSpecularityProperty("from ODF 1.3 extended", xShapeReload); +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testExtrusionSpecularity) +{ + // import + getComponent() = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + + "tdf147580_extrusion-specularity.doc", + "com.sun.star.text.TextDocument"); + + // The file has c3DSpecularAmt="80000" which results internally in specularity=122%. + // Save to ODF 1.3 strict and make sure it does not produce a validation error. + const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion(GetODFDefaultVersion()); + SetODFDefaultVersion(SvtSaveOptions::ODFVER_013); + utl::TempFile aTempFile; + save("writer8", aTempFile); + + SetODFDefaultVersion(nCurrentODFVersion); +} + +namespace +{ +bool lcl_getShapeSegments(uno::Sequence& rSegments, + const uno::Reference& xShape) +{ + uno::Reference xShapeProps(xShape, uno::UNO_QUERY_THROW); + uno::Any anotherAny = xShapeProps->getPropertyValue("CustomShapeGeometry"); + uno::Sequence aCustomShapeGeometry; + if (!(anotherAny >>= aCustomShapeGeometry)) + return false; + uno::Sequence aPathProps; + for (beans::PropertyValue const& rProp : std::as_const(aCustomShapeGeometry)) + { + if (rProp.Name == "Path") + { + rProp.Value >>= aPathProps; + break; + } + } + + for (beans::PropertyValue const& rProp : std::as_const(aPathProps)) + { + if (rProp.Name == "Segments") + { + rProp.Value >>= rSegments; + break; + } + } + if (rSegments.getLength() > 2) + return true; + else + return false; +} +} + +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTdf148714_CurvedArrowsOld) +{ + // Load a document with CurveArrow shapes with faulty path as written by older LO versions. + OUString sURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf148714_CurvedArrowsOld.odp"; + getComponent() = loadFromDesktop(sURL, "com.sun.star.presentation.PresentationDocument"); + + // Make sure, that the error has been corrected on opening. + for (sal_Int32 nShapeIndex = 0; nShapeIndex < 4; nShapeIndex++) + { + uno::Reference xShape(getShape(nShapeIndex)); + uno::Sequence aSegments; + CPPUNIT_ASSERT(lcl_getShapeSegments(aSegments, xShape)); + + if (nShapeIndex == 0 || nShapeIndex == 3) + { + // curvedDownArrow or curvedLeftArrow. Segments should start with VW. Without fix it was + // V with count 2, which means VV. + CPPUNIT_ASSERT_EQUAL( + sal_Int16(drawing::EnhancedCustomShapeSegmentCommand::CLOCKWISEARC), + aSegments[0].Command); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), aSegments[0].Count); + CPPUNIT_ASSERT_EQUAL( + sal_Int16(drawing::EnhancedCustomShapeSegmentCommand::CLOCKWISEARCTO), + aSegments[1].Command); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), aSegments[1].Count); + } + else + { + // curvedUpArrow or curvedRightArrow. Segments should start with BA. Without fix is was + // B with count 2, which means BB. + CPPUNIT_ASSERT_EQUAL(sal_Int16(drawing::EnhancedCustomShapeSegmentCommand::ARC), + aSegments[0].Command); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), aSegments[0].Count); + CPPUNIT_ASSERT_EQUAL(sal_Int16(drawing::EnhancedCustomShapeSegmentCommand::ARCTO), + aSegments[1].Command); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), aSegments[1].Count); + } + } +} +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/qa/unit/style.cxx b/xmloff/qa/unit/style.cxx new file mode 100644 index 000000000..c01f188c7 --- /dev/null +++ b/xmloff/qa/unit/style.cxx @@ -0,0 +1,393 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + +constexpr OUStringLiteral DATA_DIRECTORY = u"/xmloff/qa/unit/data/"; + +/// Covers xmloff/source/style/ fixes. +class XmloffStyleTest : public test::BootstrapFixture, + public unotest::MacrosTest, + public XmlTestTools +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; + uno::Reference& getComponent() { return mxComponent; } + void load(std::u16string_view rURL); + void save(const OUString& rFilterName, utl::TempFile& rTempFile); +}; + +void XmloffStyleTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void XmloffStyleTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +void XmloffStyleTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) +{ + XmlTestTools::registerODFNamespaces(pXmlXpathCtx); +} + +void XmloffStyleTest::load(std::u16string_view rFileName) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFileName; + mxComponent = loadFromDesktop(aURL); +} + +void XmloffStyleTest::save(const OUString& rFilterName, utl::TempFile& rTempFile) +{ + uno::Reference xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= rFilterName; + rTempFile.EnableKillingFile(); + xStorable->storeToURL(rTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + validate(rTempFile.GetFileName(), test::ODF); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testFillImageBase64) +{ + // Load a flat ODG that has base64-encoded bitmap as a fill style. + load(u"fill-image-base64.fodg"); + uno::Reference xFactory(getComponent(), uno::UNO_QUERY); + uno::Reference xBitmaps( + xFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY); + + // Without the accompanying fix in place, this test would have failed, as the base64 stream was + // not considered when parsing the fill-image style. + CPPUNIT_ASSERT(xBitmaps->hasByName("libreoffice_0")); +} + +namespace +{ +struct XmlFont +{ + OString aName; + OString aFontFamilyGeneric; + bool operator<(const XmlFont& rOther) const + { + sal_Int32 nRet = aName.compareTo(rOther.aName); + if (nRet != 0) + { + return nRet < 0; + } + + return aFontFamilyGeneric.compareTo(rOther.aFontFamilyGeneric) < 0; + } +}; +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testFontSorting) +{ + // Given an empty document with default fonts (Liberation Sans, Lucida Sans, etc): + getComponent() = loadFromDesktop("private:factory/swriter"); + + // When saving that document to ODT: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + + // Then make sure elements are sorted (by style:name="..."): + uno::Reference xNameAccess + = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, aTempFile.GetURL()); + uno::Reference xInputStream(xNameAccess->getByName("content.xml"), + uno::UNO_QUERY); + std::unique_ptr pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + xmlXPathObjectPtr pXPath + = getXPathNode(pXmlDoc, "/office:document-content/office:font-face-decls/style:font-face"); + xmlNodeSetPtr pXmlNodes = pXPath->nodesetval; + int nNodeCount = xmlXPathNodeSetGetLength(pXmlNodes); + std::vector aXMLFonts; + std::vector aSortedFonts; + for (int i = 0; i < nNodeCount; ++i) + { + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[i]; + xmlChar* pName = xmlGetProp(pXmlNode, BAD_CAST("name")); + OString aName(reinterpret_cast(pName)); + + // Ignore numbers at the end, those are just appended to make all names unique. + while (rtl::isAsciiDigit(static_cast(aName[aName.getLength() - 1]))) + { + aName = aName.copy(0, aName.getLength() - 1); + } + + xmlChar* pFontFamilyGeneric = xmlGetProp(pXmlNode, BAD_CAST("font-family-generic")); + OString aFontFamilyGeneric; + if (pFontFamilyGeneric) + { + aFontFamilyGeneric = OString(reinterpret_cast(pFontFamilyGeneric)); + } + + aXMLFonts.push_back(XmlFont{ aName, aFontFamilyGeneric }); + aSortedFonts.push_back(XmlFont{ aName, aFontFamilyGeneric }); + xmlFree(pName); + } + std::sort(aSortedFonts.begin(), aSortedFonts.end()); + size_t nIndex = 0; + for (const auto& rFont : aSortedFonts) + { + // Without the accompanying fix in place, this test would have failed with: + // - Expected: Liberation Sans + // - Actual : Lucida Sans1 + // i.e. the output was not lexicographically sorted, "u" was before "i". + CPPUNIT_ASSERT_EQUAL(rFont.aName, aXMLFonts[nIndex].aName); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: swiss + // - Actual : system + // i.e. the output was not lexicographically sorted when style:name was the same, but + // style:font-family-generic was not the same. + CPPUNIT_ASSERT_EQUAL(rFont.aFontFamilyGeneric, aXMLFonts[nIndex].aFontFamilyGeneric); + ++nIndex; + } + xmlXPathFreeObject(pXPath); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testRtlGutter) +{ + // Given a document with a gutter margin and an RTL writing mode: + // When loading that document from ODF: + load(u"rtl-gutter.fodt"); + + // Then make sure the page style's RtlGutter property is true. + uno::Reference xStyleFamiliesSupplier(getComponent(), + uno::UNO_QUERY); + uno::Reference xStyleFamilies + = xStyleFamiliesSupplier->getStyleFamilies(); + uno::Reference xStyleFamily(xStyleFamilies->getByName("PageStyles"), + uno::UNO_QUERY); + uno::Reference xStandard(xStyleFamily->getByName("Standard"), + uno::UNO_QUERY); + bool bRtlGutter{}; + xStandard->getPropertyValue("RtlGutter") >>= bRtlGutter; + // Without the accompanying fix in place, this test would have failed as + // 's style:writing-mode="..." did not affect RtlGutter. + CPPUNIT_ASSERT(bRtlGutter); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testWritingModeBTLR) +{ + // Load document. It has a frame style with writing-mode bt-lr. + // In ODF 1.3 extended it is written as loext:writing-mode="bt-lr". + // In ODF 1.3 strict, there must not be an attribute at all. + getComponent() = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + + "tdf150407_WritingModeBTLR_style.odt", + "com.sun.star.text.TextDocument"); + + Resetter _([]() { + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Save::ODF::DefaultVersion::set(3, pBatch); + return pBatch->commit(); + }); + + // Save to ODF 1.3 extended. Adapt 3 (=ODFVER_LATEST) to a to be ODFVER_013_EXTENDED when + // attribute value "bt-lr" is included in ODF strict. + { + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Save::ODF::DefaultVersion::set(3, pBatch); + pBatch->commit(); + utl::TempFile aTempFile; + save("writer8", aTempFile); + + // With applied fix for tdf150407 still loext:writing-mode="bt-lr" has to be written. + std::unique_ptr pStream = parseExportStream(aTempFile, "styles.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, + "/office:document-styles/office:styles/style:style[@style:name='FrameBTLR']/" + "style:graphic-properties[@loext:writing-mode]"); + assertXPath(pXmlDoc, + "/office:document-styles/office:styles/style:style[@style:name='FrameBTLR']/" + "style:graphic-properties", + "writing-mode", "bt-lr"); + } + // Save to ODF 1.3 strict. + { + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Save::ODF::DefaultVersion::set(10, pBatch); + pBatch->commit(); + utl::TempFile aTempFile; + save("writer8", aTempFile); + + // Without the fix an faulty 'writing-mode="bt-lr"' attribute was written in productive build. + // A debug build fails assertion in SvXMLNamespaceMap::GetQNameByKey(). + std::unique_ptr pStream = parseExportStream(aTempFile, "styles.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPathNoAttribute(pXmlDoc, + "/office:document-styles/office:styles/" + "style:style[@style:name='FrameBTLR']/style:graphic-properties", + "writing-mode"); + } +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPosRelBottomMargin) +{ + // Load document. It has a frame position with vertical position relative to bottom margin. + // In ODF 1.3 extended it is written as loext:vertical-rel="page-content-bottom". + // In ODF 1.3 strict, there must not be an attribute at all. + getComponent() = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + + "tdf150407_PosRelBottomMargin.docx", + "com.sun.star.text.TextDocument"); + + Resetter _([]() { + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Save::ODF::DefaultVersion::set(3, pBatch); + return pBatch->commit(); + }); + + // Save to ODF 1.3 extended. Adapt 3 (=ODFVER_LATEST) to a to be ODFVER_013_EXTENDED when + // attribute value "page-content-bottom" is included in ODF strict. + { + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Save::ODF::DefaultVersion::set(3, pBatch); + pBatch->commit(); + utl::TempFile aTempFile; + save("writer8", aTempFile); + + // With applied fix for tdf150407 still loext:vertical-rel="page-content-bottom" has to be + // written. + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath( + pXmlDoc, + "/office:document-content/office:automatic-styles/style:style[@style:name='gr1']/" + "style:graphic-properties[@loext:vertical-rel]"); + assertXPath( + pXmlDoc, + "/office:document-content/office:automatic-styles/style:style[@style:name='gr1']/" + "style:graphic-properties", + "vertical-rel", "page-content-bottom"); + } + // Save to ODF 1.3 strict. + { + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Save::ODF::DefaultVersion::set(10, pBatch); + pBatch->commit(); + utl::TempFile aTempFile; + save("writer8", aTempFile); + + // Without the fix an faulty 'vertical-rel="page-content-bottom"' attribute was written in + // productive build. A debug build fails assertion in SvXMLNamespaceMap::GetQNameByKey(). + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPathNoAttribute(pXmlDoc, + "/office:document-content/office:automatic-styles/" + "style:style[@style:name='gr1']/style:graphic-properties", + "vertical-rel"); + } +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPosRelTopMargin) +{ + // Load document. It has a frame position with vertical position relative to top margin. + // In ODF 1.3 extended it is written as loext:vertical-rel="page-content-top". + // In ODF 1.3 strict, there must not be an attribute at all. + getComponent() = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + + "tdf150407_PosRelTopMargin.docx", + "com.sun.star.text.TextDocument"); + + Resetter _([]() { + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Save::ODF::DefaultVersion::set(3, pBatch); + return pBatch->commit(); + }); + + // Save to ODF 1.3 extended. Adapt 3 (=ODFVER_LATEST) to a to be ODFVER_013_EXTENDED when + // attribute value "page-content-top" is included in ODF strict. + { + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Save::ODF::DefaultVersion::set(3, pBatch); + pBatch->commit(); + utl::TempFile aTempFile; + save("writer8", aTempFile); + + // With applied fix for tdf150407 still loext:vertical-rel="page-content-top has to be + // written. + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath( + pXmlDoc, + "/office:document-content/office:automatic-styles/style:style[@style:name='gr1']/" + "style:graphic-properties[@loext:vertical-rel]"); + assertXPath( + pXmlDoc, + "/office:document-content/office:automatic-styles/style:style[@style:name='gr1']/" + "style:graphic-properties", + "vertical-rel", "page-content-top"); + } + // Save to ODF 1.3 strict. + { + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Save::ODF::DefaultVersion::set(10, pBatch); + pBatch->commit(); + utl::TempFile aTempFile; + save("writer8", aTempFile); + + // Without the fix an faulty 'vertical-rel="page-content-top"' attribute was written in + // productive build. A debug build fails assertion in SvXMLNamespaceMap::GetQNameByKey(). + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPathNoAttribute(pXmlDoc, + "/office:document-content/office:automatic-styles/" + "style:style[@style:name='gr1']/style:graphic-properties", + "vertical-rel"); + } +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx new file mode 100644 index 000000000..af0fba426 --- /dev/null +++ b/xmloff/qa/unit/text.cxx @@ -0,0 +1,857 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +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, + public XmlTestTools +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void XmloffStyleTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) +{ + XmlTestTools::registerODFNamespaces(pXmlXpathCtx); +} + +void XmloffStyleTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void XmloffStyleTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testMailMergeInEditeng) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "mail-merge-editeng.odt"; + getComponent() = loadFromDesktop(aURL); + // Without the accompanying fix in place, this test would have failed, as unexpected + // in editeng text aborted the whole import process. +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCommentResolved) +{ + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Sequence aCommentProps = comphelper::InitPropertySequence({ + { "Text", uno::Any(OUString("comment")) }, + }); + dispatchCommand(getComponent(), ".uno:InsertAnnotation", aCommentProps); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + uno::Reference xPortionEnum = xPara->createEnumeration(); + uno::Reference xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); + uno::Reference xField(xPortion->getPropertyValue("TextField"), + uno::UNO_QUERY); + xField->setPropertyValue("Resolved", uno::Any(true)); + + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + getComponent()->dispose(); + + getComponent() = loadFromDesktop(aTempFile.GetURL()); + xTextDocument.set(getComponent(), uno::UNO_QUERY); + xParaEnumAccess.set(xTextDocument->getText(), uno::UNO_QUERY); + xParaEnum = xParaEnumAccess->createEnumeration(); + xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); + xPortionEnum = xPara->createEnumeration(); + xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY); + xField.set(xPortion->getPropertyValue("TextField"), uno::UNO_QUERY); + bool bResolved = false; + xField->getPropertyValue("Resolved") >>= bResolved; + // Without the accompanying fix in place, this test would have failed, as the resolved state was + // not saved for non-range comments. + CPPUNIT_ASSERT(bResolved); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testBibliographyLocalUrl) +{ + // Given a document with a biblio field, with non-empty LocalURL: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference xFactory(getComponent(), uno::UNO_QUERY); + uno::Reference xField( + xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY); + uno::Sequence aFields = { + comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW), + comphelper::makePropertyValue("Identifier", OUString("AT")), + comphelper::makePropertyValue("Author", OUString("Author")), + comphelper::makePropertyValue("Title", OUString("Title")), + comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf#page=1")), + comphelper::makePropertyValue("LocalURL", OUString("file:///home/me/test.pdf")), + }; + xField->setPropertyValue("Fields", uno::Any(aFields)); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + uno::Reference xContent(xField, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false); + + // When invoking ODT export + import on it: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = { + comphelper::makePropertyValue("FilterName", OUString("writer8")), + }; + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + // Without the accompanying fix in place, this test would have resulted in an assertion failure, + // as LocalURL was mapped to XML_TOKEN_INVALID. + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + getComponent()->dispose(); + validate(aTempFile.GetFileName(), test::ODF); + getComponent() = loadFromDesktop(aTempFile.GetURL()); + + // Then make sure that LocalURL is preserved: + xTextDocument.set(getComponent(), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + uno::Reference xPortionEnum = xPara->createEnumeration(); + uno::Reference xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); + xField.set(xPortion->getPropertyValue("TextField"), uno::UNO_QUERY); + comphelper::SequenceAsHashMap aMap(xField->getPropertyValue("Fields")); + CPPUNIT_ASSERT(aMap.find("LocalURL") != aMap.end()); + auto aActual = aMap["LocalURL"].get(); + CPPUNIT_ASSERT_EQUAL(OUString("file:///home/me/test.pdf"), aActual); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCommentTableBorder) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "comment-table-border.fodt"; + // Without the accompanying fix in place, this failed to load, as a comment that started in a + // table and ended outside a table aborted the whole importer. + getComponent() = loadFromDesktop(aURL); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testParaStyleListLevel) +{ + // Given a document with style:list-level="...": + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "para-style-list-level.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure we map that to the paragraph style's numbering level: + uno::Reference xStyleFamiliesSupplier(getComponent(), + uno::UNO_QUERY); + uno::Reference xStyleFamilies + = xStyleFamiliesSupplier->getStyleFamilies(); + uno::Reference xStyleFamily( + xStyleFamilies->getByName("ParagraphStyles"), uno::UNO_QUERY); + uno::Reference xStyle(xStyleFamily->getByName("mystyle"), uno::UNO_QUERY); + sal_Int16 nNumberingLevel{}; + CPPUNIT_ASSERT(xStyle->getPropertyValue("NumberingLevel") >>= nNumberingLevel); + CPPUNIT_ASSERT_EQUAL(static_cast(1), nNumberingLevel); + + // Test the export as well: + + // Given a doc model that has a para style with NumberingLevel=2: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + + // When exporting that to ODT: + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + + // Then make sure we save the style's numbering level: + uno::Reference xNameAccess + = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, aTempFile.GetURL()); + uno::Reference xInputStream(xNameAccess->getByName("styles.xml"), + uno::UNO_QUERY); + std::unique_ptr 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_TEST_FIXTURE(XmloffStyleTest, testContinueNumberingWord) +{ + // Given a document, which is produced by Word and contains text:continue-numbering="true": + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "continue-numbering-word.odt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure that the numbering from the 1st para is continued on the 3rd para: + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + xParaEnum->nextElement(); + xParaEnum->nextElement(); + uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + auto aActual = xPara->getPropertyValue("ListLabelString").get(); + // Without the accompanying fix in place, this failed with: + // - Expected: 2. + // - Actual : 1. + // i.e. the numbering was not continued, like in Word. + CPPUNIT_ASSERT_EQUAL(OUString("2."), aActual); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testListId) +{ + // Given a document with a simple list (no continue-list="..." attribute): + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "list-id.fodt"; + getComponent() = loadFromDesktop(aURL); + + // When storing that document as ODF: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + + // Then make sure that unreferenced xml:id="..." attributes are not written: + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this failed with: + // - XPath '//text:list' unexpected 'id' attribute + // i.e. xml:id="..." was written unconditionally, even when no other list needed it. + assertXPathNoAttribute(pXmlDoc, "//text:list", "id"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testClearingBreakExport) +{ + // Given a document with a clearing break: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference xMSF(getComponent(), uno::UNO_QUERY); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xLineBreak( + xMSF->createInstance("com.sun.star.text.LineBreak"), uno::UNO_QUERY); + uno::Reference xLineBreakProps(xLineBreak, uno::UNO_QUERY); + // SwLineBreakClear::ALL; + sal_Int16 eClear = 3; + xLineBreakProps->setPropertyValue("Clear", uno::Any(eClear)); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + xText->insertTextContent(xCursor, xLineBreak, /*bAbsorb=*/false); + + // When exporting to ODT: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + validate(aTempFile.GetFileName(), test::ODF); + + // Then make sure the expected markup is used: + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this failed with: + // - XPath '//text:line-break' number of nodes is incorrect + // i.e. the clearing break was lost on export. + assertXPath(pXmlDoc, "//text:line-break", "clear", "all"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testClearingBreakImport) +{ + // Given an ODF document with a clearing break: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "clearing-break.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure that the "clear" attribute is not lost on import: + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParagraphsAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference xPortions = xParagraph->createEnumeration(); + // First portion is the image. + xPortions->nextElement(); + // Second portion is "foo". + xPortions->nextElement(); + // Without the accompanying fix in place, this failed with: + // An uncaught exception of type com.sun.star.container.NoSuchElementException + // i.e. the line break was a non-clearing one, so we only had 2 portions, not 4 (image, text, + // linebreak, text). + uno::Reference xPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aTextPortionType; + xPortion->getPropertyValue("TextPortionType") >>= aTextPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("LineBreak"), aTextPortionType); + uno::Reference xLineBreak; + xPortion->getPropertyValue("LineBreak") >>= xLineBreak; + uno::Reference xLineBreakProps(xLineBreak, uno::UNO_QUERY); + sal_Int16 eClear{}; + xLineBreakProps->getPropertyValue("Clear") >>= eClear; + CPPUNIT_ASSERT_EQUAL(static_cast(3), eClear); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testRelativeWidth) +{ + // Given a document with an 50% wide text frame: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference xStyleFamiliesSupplier(getComponent(), + uno::UNO_QUERY); + uno::Reference xStyleFamilies + = xStyleFamiliesSupplier->getStyleFamilies(); + uno::Reference xStyleFamily(xStyleFamilies->getByName("PageStyles"), + uno::UNO_QUERY); + uno::Reference xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY); + // Body frame width is 6cm (2+2cm margin). + xStyle->setPropertyValue("Width", uno::Any(static_cast(10000))); + uno::Reference xMSF(getComponent(), uno::UNO_QUERY); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xTextFrame( + xMSF->createInstance("com.sun.star.text.TextFrame"), uno::UNO_QUERY); + uno::Reference xTextFrameProps(xTextFrame, uno::UNO_QUERY); + xTextFrameProps->setPropertyValue("RelativeWidth", uno::Any(static_cast(50))); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + xText->insertTextContent(xCursor, xTextFrame, /*bAbsorb=*/false); + // Body frame width is 16cm. + xStyle->setPropertyValue("Width", uno::Any(static_cast(20000))); + + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this failed with: + // - Expected: 3.1492in (8cm) + // - Actual : 0.0161in (0.04 cm) + // i.e. the fallback width value wasn't the expected half of the body frame width, but a smaller + // value. + assertXPath(pXmlDoc, "//draw:frame", "width", "3.1492in"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testScaleWidthAndHeight) +{ + // Given a broken document where both IsSyncHeightToWidth and IsSyncWidthToHeight are set to + // true: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference xMSF(getComponent(), uno::UNO_QUERY); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xTextFrame( + xMSF->createInstance("com.sun.star.text.TextFrame"), uno::UNO_QUERY); + uno::Reference xTextFrameProps(xTextFrame, uno::UNO_QUERY); + xTextFrameProps->setPropertyValue("Width", uno::Any(static_cast(2000))); + xTextFrameProps->setPropertyValue("Height", uno::Any(static_cast(1000))); + xTextFrameProps->setPropertyValue("IsSyncHeightToWidth", uno::Any(true)); + xTextFrameProps->setPropertyValue("IsSyncWidthToHeight", uno::Any(true)); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + xText->insertTextContent(xCursor, xTextFrame, /*bAbsorb=*/false); + + // When exporting to ODT: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + + // Then make sure that we still export a non-zero size: + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this failed with: + // - Expected: 0.7874in + // - Actual : 0in + // i.e. the exported size was 0, not 2000 mm100 in inches. + assertXPath(pXmlDoc, "//draw:frame", "width", "0.7874in"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testContentControlExport) +{ + // Given a document with a content control around one or more text portions: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference xMSF(getComponent(), uno::UNO_QUERY); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("ShowingPlaceHolder", uno::Any(true)); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When exporting to ODT: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + validate(aTempFile.GetFileName(), test::ODF); + + // Then make sure the expected markup is used: + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this failed with: + // - XPath '//loext:content-control' number of nodes is incorrect + // i.e. the content control was lost on export. + assertXPath(pXmlDoc, "//loext:content-control", "showing-place-holder", "true"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testContentControlImport) +{ + // Given an ODF document with a content control: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure that the content control is not lost on import: + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParagraphsAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference xPortions = xParagraph->createEnumeration(); + uno::Reference xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + // Without the accompanying fix in place, this failed with: + // - Expected: ContentControl + // - Actual : Text + // i.e. the content control was lost on import. + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference xContentControlRange(xContentControl, uno::UNO_QUERY); + uno::Reference xText = xContentControlRange->getText(); + uno::Reference xContentEnumAccess(xText, uno::UNO_QUERY); + uno::Reference xContentEnum = xContentEnumAccess->createEnumeration(); + uno::Reference xContent(xContentEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("test"), xContent->getString()); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCheckboxContentControlExport) +{ + // Given a document with a checkbox content control around a text portion: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference xMSF(getComponent(), uno::UNO_QUERY); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + xText->insertString(xCursor, OUString(u"☐"), /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("Checkbox", uno::Any(true)); + xContentControlProps->setPropertyValue("Checked", uno::Any(true)); + xContentControlProps->setPropertyValue("CheckedState", uno::Any(OUString(u"☒"))); + xContentControlProps->setPropertyValue("UncheckedState", uno::Any(OUString(u"☐"))); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When exporting to ODT: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + validate(aTempFile.GetFileName(), test::ODF); + + // Then make sure the expected markup is used: + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//loext:content-control", "checkbox", "true"); + assertXPath(pXmlDoc, "//loext:content-control", "checked", "true"); + assertXPath(pXmlDoc, "//loext:content-control", "checked-state", u"☒"); + assertXPath(pXmlDoc, "//loext:content-control", "unchecked-state", u"☐"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCheckboxContentControlImport) +{ + // Given an ODF document with a checkbox content control: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control-checkbox.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure that the content control is not lost on import: + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParagraphsAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference xPortions = xParagraph->createEnumeration(); + uno::Reference xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference xContentControlProps(xContentControl, uno::UNO_QUERY); + bool bCheckbox{}; + xContentControlProps->getPropertyValue("Checkbox") >>= bCheckbox; + // Without the accompanying fix in place, this failed, as the checkbox-related attributes were + // ignored on import. + CPPUNIT_ASSERT(bCheckbox); + bool bChecked{}; + xContentControlProps->getPropertyValue("Checked") >>= bChecked; + CPPUNIT_ASSERT(bChecked); + OUString aCheckedState; + xContentControlProps->getPropertyValue("CheckedState") >>= aCheckedState; + CPPUNIT_ASSERT_EQUAL(OUString(u"☒"), aCheckedState); + OUString aUncheckedState; + xContentControlProps->getPropertyValue("UncheckedState") >>= aUncheckedState; + CPPUNIT_ASSERT_EQUAL(OUString(u"☐"), aUncheckedState); + uno::Reference xContentControlRange(xContentControl, uno::UNO_QUERY); + uno::Reference xText = xContentControlRange->getText(); + uno::Reference xContentEnumAccess(xText, uno::UNO_QUERY); + uno::Reference xContentEnum = xContentEnumAccess->createEnumeration(); + uno::Reference xContent(xContentEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(u"☒"), xContent->getString()); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDropdownContentControlExport) +{ + // Given a document with a dropdown content control around a text portion: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference xMSF(getComponent(), uno::UNO_QUERY); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "choose an item", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference xContentControlProps(xContentControl, uno::UNO_QUERY); + { + uno::Sequence aListItems = { + { + comphelper::makePropertyValue("DisplayText", uno::Any(OUString("red"))), + comphelper::makePropertyValue("Value", uno::Any(OUString("R"))), + }, + { + comphelper::makePropertyValue("DisplayText", uno::Any(OUString("green"))), + comphelper::makePropertyValue("Value", uno::Any(OUString("G"))), + }, + { + comphelper::makePropertyValue("DisplayText", uno::Any(OUString("blue"))), + comphelper::makePropertyValue("Value", uno::Any(OUString("B"))), + }, + }; + xContentControlProps->setPropertyValue("ListItems", uno::Any(aListItems)); + } + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When exporting to ODT: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + validate(aTempFile.GetFileName(), test::ODF); + + // Then make sure the expected markup is used: + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this failed with: + // - Expected: 1 + // - Actual : 0 + // - XPath '//loext:content-control/loext:list-item[1]' number of nodes is incorrect + // i.e. the list items were lost on export. + assertXPath(pXmlDoc, "//loext:content-control/loext:list-item[1]", "display-text", "red"); + assertXPath(pXmlDoc, "//loext:content-control/loext:list-item[1]", "value", "R"); + assertXPath(pXmlDoc, "//loext:content-control/loext:list-item[2]", "display-text", "green"); + assertXPath(pXmlDoc, "//loext:content-control/loext:list-item[2]", "value", "G"); + assertXPath(pXmlDoc, "//loext:content-control/loext:list-item[3]", "display-text", "blue"); + assertXPath(pXmlDoc, "//loext:content-control/loext:list-item[3]", "value", "B"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDropdownContentControlImport) +{ + // Given an ODF document with a dropdown content control: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control-dropdown.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure that the content control is not lost on import: + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParagraphsAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference xPortions = xParagraph->createEnumeration(); + uno::Reference xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference xContentControlProps(xContentControl, uno::UNO_QUERY); + uno::Sequence aListItems; + xContentControlProps->getPropertyValue("ListItems") >>= aListItems; + // Without the accompanying fix in place, this failed with: + // - Expected: 3 + // - Actual : 0 + // i.e. the list items were lost on import. + CPPUNIT_ASSERT_EQUAL(static_cast(3), aListItems.getLength()); + comphelper::SequenceAsHashMap aMap0(aListItems[0]); + CPPUNIT_ASSERT_EQUAL(OUString("red"), aMap0["DisplayText"].get()); + CPPUNIT_ASSERT_EQUAL(OUString("R"), aMap0["Value"].get()); + comphelper::SequenceAsHashMap aMap1(aListItems[1]); + CPPUNIT_ASSERT_EQUAL(OUString("green"), aMap1["DisplayText"].get()); + CPPUNIT_ASSERT_EQUAL(OUString("G"), aMap1["Value"].get()); + comphelper::SequenceAsHashMap aMap2(aListItems[2]); + CPPUNIT_ASSERT_EQUAL(OUString("blue"), aMap2["DisplayText"].get()); + CPPUNIT_ASSERT_EQUAL(OUString("B"), aMap2["Value"].get()); + uno::Reference xContentControlRange(xContentControl, uno::UNO_QUERY); + uno::Reference xText = xContentControlRange->getText(); + uno::Reference xContentEnumAccess(xText, uno::UNO_QUERY); + uno::Reference xContentEnum = xContentEnumAccess->createEnumeration(); + uno::Reference xContent(xContentEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("choose a color"), xContent->getString()); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPictureContentControlExport) +{ + // Given a document with a picture content control around an as-char image: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference xMSF(getComponent(), uno::UNO_QUERY); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + uno::Reference xTextGraphic( + xMSF->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + xTextGraphic->setPropertyValue("AnchorType", + uno::Any(text::TextContentAnchorType_AS_CHARACTER)); + uno::Reference xTextContent(xTextGraphic, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xTextContent, false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("Picture", uno::Any(true)); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When exporting to ODT: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + validate(aTempFile.GetFileName(), test::ODF); + + // Then make sure the expected markup is used: + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//loext:content-control' no attribute 'picture' exist + assertXPath(pXmlDoc, "//loext:content-control", "picture", "true"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPictureContentControlImport) +{ + // Given an ODF document with a picture content control: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control-picture.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure that the content control is not lost on import: + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParagraphsAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference xPortions = xParagraph->createEnumeration(); + uno::Reference xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference xContentControlProps(xContentControl, uno::UNO_QUERY); + bool bPicture{}; + xContentControlProps->getPropertyValue("Picture") >>= bPicture; + // Without the accompanying fix in place, this failed, as the picture attribute was ignored on + // import. + CPPUNIT_ASSERT(bPicture); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDateContentControlExport) +{ + // Given a document with a date content control around a text portion: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference xMSF(getComponent(), uno::UNO_QUERY); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "choose a date", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("Date", uno::Any(true)); + xContentControlProps->setPropertyValue("DateFormat", uno::Any(OUString("YYYY-MM-DD"))); + xContentControlProps->setPropertyValue("DateLanguage", uno::Any(OUString("en-US"))); + xContentControlProps->setPropertyValue("CurrentDate", + uno::Any(OUString("2022-05-25T00:00:00Z"))); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When exporting to ODT: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + validate(aTempFile.GetFileName(), test::ODF); + + // Then make sure the expected markup is used: + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//loext:content-control' no attribute 'date' exist + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//loext:content-control", "date", "true"); + assertXPath(pXmlDoc, "//loext:content-control", "date-format", "YYYY-MM-DD"); + assertXPath(pXmlDoc, "//loext:content-control", "date-rfc-language-tag", "en-US"); + assertXPath(pXmlDoc, "//loext:content-control", "current-date", "2022-05-25T00:00:00Z"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDateContentControlImport) +{ + // Given an ODF document with a date content control: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control-date.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure that the content control is not lost on import: + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParagraphsAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference xPortions = xParagraph->createEnumeration(); + uno::Reference xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference xContentControlProps(xContentControl, uno::UNO_QUERY); + bool bDate{}; + xContentControlProps->getPropertyValue("Date") >>= bDate; + // Without the accompanying fix in place, this test would have failed, the content control was + // imported as a default rich text one. + CPPUNIT_ASSERT(bDate); + OUString aDateFormat; + xContentControlProps->getPropertyValue("DateFormat") >>= aDateFormat; + CPPUNIT_ASSERT_EQUAL(OUString("YYYY-MM-DD"), aDateFormat); + OUString aDateLanguage; + xContentControlProps->getPropertyValue("DateLanguage") >>= aDateLanguage; + CPPUNIT_ASSERT_EQUAL(OUString("en-US"), aDateLanguage); + OUString aCurrentDate; + xContentControlProps->getPropertyValue("CurrentDate") >>= aCurrentDate; + CPPUNIT_ASSERT_EQUAL(OUString("2022-05-25T00:00:00Z"), aCurrentDate); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDropdownContentControlAutostyleExport) +{ + // Given a document with a dropdown content control, and formatting that forms an autostyle in + // ODT: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control-dropdown.docx"; + getComponent() = loadFromDesktop(aURL); + + // When saving that document to ODT, then make sure no assertion failure happens: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + // Without the accompanying fix in place, this test would have failed, we had duplicated XML + // attributes. + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/qa/unit/tokenmap-test.cxx b/xmloff/qa/unit/tokenmap-test.cxx new file mode 100644 index 000000000..395237b8a --- /dev/null +++ b/xmloff/qa/unit/tokenmap-test.cxx @@ -0,0 +1,92 @@ +/* -*- 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 +#include + +using namespace com::sun::star::uno; + +namespace xmloff { + +class TokenmapTest: public CppUnit::TestFixture +{ +public: + + TokenmapTest(); + + void test_roundTrip(); + void test_listEquality(); + + CPPUNIT_TEST_SUITE(TokenmapTest); + + CPPUNIT_TEST(test_roundTrip); + CPPUNIT_TEST(test_listEquality); + + CPPUNIT_TEST_SUITE_END(); + +private: + std::unique_ptr pTokenMap; +}; + +TokenmapTest::TokenmapTest() : pTokenMap(new token::TokenMap) +{ +} + +void TokenmapTest::test_roundTrip() +{ + for ( sal_Int32 nToken = 0; nToken < XML_TOKEN_COUNT; ++nToken ) + { + // check that the getIdentifier <-> getToken roundtrip works + Sequence< sal_Int8 > rUtf8Name = pTokenMap->getUtf8TokenName(nToken); + CPPUNIT_ASSERT_MESSAGE("Token name sequence should not be empty", rUtf8Name.getLength()); + const char* pChar = reinterpret_cast< const char * >(rUtf8Name.getConstArray()); + CPPUNIT_ASSERT_MESSAGE("Token name sequence array pointer failed", pChar); + sal_Int32 ret = token::TokenMap::getTokenFromUTF8( pChar, rUtf8Name.getLength() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("No roundtrip for token", ret, nToken); + } +} + +void TokenmapTest::test_listEquality() +{ + //make sure the two token lists stay in sync + // This depends on same order in three places: XMLTokenEnum in include/xmloff/xmltoken.hxx, + // aTokenList in xmloff/source/core/xmltoken.cxx, and xmloff/source/token/tokens.txt + for ( sal_Int32 nToken = 0; nToken < XML_TOKEN_COUNT; ++nToken ) + { + Sequence< sal_Int8 > rUtf8Name = pTokenMap->getUtf8TokenName(nToken); + const OUString& rName = OUString( reinterpret_cast< const char* >( + rUtf8Name.getConstArray() ), rUtf8Name.getLength(), RTL_TEXTENCODING_UTF8 ); + if ( rName.endsWith("_DUMMY") ) + continue; + const OUString& rTokenName = GetXMLToken( static_cast(nToken) ); + CPPUNIT_ASSERT_EQUAL(rName, rTokenName); + } + + for ( sal_Int32 nToken = xmloff::token::XMLTokenEnum::XML_TOKEN_START + 1; + nToken < xmloff::token::XMLTokenEnum::XML_TOKEN_END; ++nToken ) + { + const OUString& rTokenName = GetXMLToken( static_cast(nToken) ); + Sequence< sal_Int8 > rUtf8Name = pTokenMap->getUtf8TokenName(nToken); + const OUString& rName = OUString( reinterpret_cast< const char* >( + rUtf8Name.getConstArray() ), rUtf8Name.getLength(), RTL_TEXTENCODING_UTF8 ); + if ( !rName.endsWith("_DUMMY") ) + CPPUNIT_ASSERT_EQUAL(rTokenName, rName); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(TokenmapTest); + +} + diff --git a/xmloff/qa/unit/uxmloff.cxx b/xmloff/qa/unit/uxmloff.cxx new file mode 100644 index 000000000..9cad246f9 --- /dev/null +++ b/xmloff/qa/unit/uxmloff.cxx @@ -0,0 +1,231 @@ +/* -*- 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::xmloff::token; +using namespace ::com::sun::star; + +class Test : public test::BootstrapFixture { +public: + Test(); + + virtual void setUp() override; + virtual void tearDown() override; + + void testAutoStylePool(); + void testMetaGenerator(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testAutoStylePool); + CPPUNIT_TEST(testMetaGenerator); + CPPUNIT_TEST_SUITE_END(); +private: + rtl::Reference pExport; +}; + +Test::Test() +{ +} + +void Test::setUp() +{ + BootstrapFixture::setUp(); + + pExport = new SchXMLExport( + comphelper::getProcessComponentContext(), "SchXMLExport.Compact", + SvXMLExportFlags::ALL); +} + +void Test::tearDown() +{ + pExport.clear(); + BootstrapFixture::tearDown(); +} + +void Test::testAutoStylePool() +{ + rtl::Reference< SvXMLAutoStylePoolP > xPool( + new SvXMLAutoStylePoolP( *pExport ) ); + rtl::Reference< XMLPropertySetMapper > xSetMapper( + new XMLChartPropertySetMapper(pExport.get()) ); + rtl::Reference< XMLChartExportPropertyMapper > xExportPropMapper( + new XMLChartExportPropertyMapper( xSetMapper, *pExport ) ); + + xPool->AddFamily( XmlStyleFamily::TEXT_PARAGRAPH, + GetXMLToken( XML_PARAGRAPH ), + xExportPropMapper.get(), + OUString( "Bob" ) ); + + OUString aName = xPool->Add( XmlStyleFamily::TEXT_PARAGRAPH, "", {} ); + + // not that interesting but worth checking + bool bHack = (getenv("LIBO_ONEWAY_STABLE_ODF_EXPORT") != nullptr); + if (bHack) + CPPUNIT_ASSERT_EQUAL_MESSAGE( "style / naming changed", OUString("Bob"), aName ); + else + CPPUNIT_ASSERT_EQUAL_MESSAGE( "style / naming changed", OUString("Bob1"), aName ); + + // find ourselves again: + OUString aSameName = xPool->Find( XmlStyleFamily::TEXT_PARAGRAPH, "", {} ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "same style not found", aName, aSameName ); +} + +void Test::testMetaGenerator() +{ + comphelper::PropertyMapEntry const aInfoMap[] = { + { OUString("BuildId"), 0, ::cppu::UnoType::get(), beans::PropertyAttribute::MAYBEVOID, 0 }, + }; + uno::Reference const xInfoSet( + comphelper::GenericPropertySet_CreateInstance( + new comphelper::PropertySetInfo(aInfoMap))); + + static struct { + char const*const generator; + char const*const buildId; + sal_uInt16 const result; + } const tests [] = { + // foreign + { "AbiWord/2.8.6 (unix, gtk)", "", SvXMLImport::ProductVersionUnknown }, + { "Aspose.Words for Java 13.10.0.0", "", SvXMLImport::ProductVersionUnknown }, + { "CIB jsmerge 1.0.0", "", SvXMLImport::ProductVersionUnknown }, + { "Calligra/2.4.3", "", SvXMLImport::ProductVersionUnknown }, + { "CocoaODFWriter/1339", "", SvXMLImport::ProductVersionUnknown }, + { "KOffice/1.4.1", "", SvXMLImport::ProductVersionUnknown }, + { "KPresenter 1.3", "", SvXMLImport::ProductVersionUnknown }, + { "KSpread 1.3.2", "", SvXMLImport::ProductVersionUnknown }, + { "Lotus Symphony/1.2.0_20081023.1730/Win32", "", SvXMLImport::ProductVersionUnknown }, + { "Microsoft Excel Online", "", SvXMLImport::ProductVersionUnknown }, + { "MicrosoftOffice/12.0 MicrosoftExcel/CalculationVersion-4518", "", SvXMLImport::ProductVersionUnknown }, + { "MicrosoftOffice/15.0 MicrosoftWord", "", SvXMLImport::ProductVersionUnknown }, + { "ODF Converter v1.0.0", "", SvXMLImport::ProductVersionUnknown }, + { "ODF::lpOD 1.121", "", SvXMLImport::ProductVersionUnknown }, + { "ODFDOM/0.6.1$Build-1", "", SvXMLImport::ProductVersionUnknown }, + { "ODFPY/0.9.6", "", SvXMLImport::ProductVersionUnknown }, + { "OpenXML/ODF Translator Command Line Tool 3.0 2.0.0", "", SvXMLImport::ProductVersionUnknown }, + { "Org-7.8.03/Emacs-24.0.93.1", "", SvXMLImport::ProductVersionUnknown }, + { "TeX4ht from eqns_long.tex, options: xhtml,ooffice,refcaption", "", SvXMLImport::ProductVersionUnknown }, + { "TextMaker", "", SvXMLImport::ProductVersionUnknown }, + { "docbook2odf generator (http://open.comsultia.com/docbook2odf/)", "", SvXMLImport::ProductVersionUnknown }, + { "fig2sxd", "", SvXMLImport::ProductVersionUnknown }, + { "gnumeric/1.10.9", "", SvXMLImport::ProductVersionUnknown }, + { "libodfgen/0.1.6", "", SvXMLImport::ProductVersionUnknown }, + + // OOo 1.x + { "StarSuite 6.0 (Linux)", "645$8687", SvXMLImport::OOo_1x }, + { "StarOffice 6.1 (Win32)", "645$8687", SvXMLImport::OOo_1x }, + { "OpenOffice.org 1.1.2RC3.DE (Win32)", "645$8687", SvXMLImport::OOo_1x }, + { "OpenOffice.org 1.1.5 (Win32)", "645$8687", SvXMLImport::OOo_1x }, + { "StarOffice 7 (Win32)", "645$8687", SvXMLImport::OOo_1x }, + + // OOo 2.x + { "Sun_ODF_Plugin_for_Microsoft_Office/1.1$Win32 OpenOffice.org_project/680m5$Build-9221", "680$9221", SvXMLImport::OOo_2x }, + { "StarSuite/8$Win32 OpenOffice.org_project/680m6$Build-9095", "680$9095", SvXMLImport::OOo_2x }, + { "StarOffice/8$Win32 OpenOffice.org_project/680m93$Build-8897", "680$8897", SvXMLImport::OOo_2x }, + { "OpenOffice.org/2.0$Linux OpenOffice.org_project/680m3$Build-8968", "680$8968", SvXMLImport::OOo_2x }, + { "OpenOffice.org/2.1$Win32 OpenOffice.org_project/680m6$Build-9095", "680$9095", SvXMLImport::OOo_2x }, + { "OpenOffice.org/2.4$Win32 OpenOffice.org_project/680m248$Build-9274", "680$9274", SvXMLImport::OOo_2x }, + + // OOo 3.x + { "OpenOffice.org/3.0$Solaris_Sparc OpenOffice.org_project/300m9$Build-9358", "300$9358", SvXMLImport::OOo_30x }, + { "StarSuite/9$Unix OpenOffice.org_project/300m9$Build-9358", "300$9358", SvXMLImport::OOo_30x }, + { "StarOffice/9$Win32 OpenOffice.org_project/300m14$Build-9376", "300$9376", SvXMLImport::OOo_30x }, + { "OpenOffice.org/3.1$Solaris_x86 OpenOffice.org_project/310m11$Build-9399", "310$9399", SvXMLImport::OOo_31x }, + { "IBM_Lotus_Symphony/2.0$Win32 OpenOffice.org_project/310m11$Build-9399", "310$9399", SvXMLImport::OOo_31x }, + { "BrOffice.org/3.1$Linux OpenOffice.org_project/310m11$Build-9399", "310$9399", SvXMLImport::OOo_31x }, + { "StarOffice/9$Solaris_Sparc OpenOffice.org_project/310m19$Build-9420", "310$9420", SvXMLImport::OOo_31x }, + { "OpenOffice.org/3.2$Linux OpenOffice.org_project/320m12$Build-9483", "320$9483", SvXMLImport::OOo_32x }, + { "StarOffice/9$Win32 OpenOffice.org_project/320m12$Build-9483", "320$9483", SvXMLImport::OOo_32x }, + { "OpenOffice.org/3.3$Linux OpenOffice.org_project/330m20$Build-9567", "330$9567", SvXMLImport::OOo_33x }, + { "Oracle_Open_Office/3.3$Win32 OpenOffice.org_project/330m7$Build-9552", "330$9552", SvXMLImport::OOo_33x }, + { "OpenOffice.org/3.4$Unix OpenOffice.org_project/340m1$Build-9590", "340$9590", SvXMLImport::OOo_34x }, + + // AOO versions + { "OpenOffice/4.0.0$Win32 OpenOffice.org_project/400m3$Build-9702", "400$9702", SvXMLImport::AOO_40x }, + { "OpenOffice/4.0.1$Linux OpenOffice.org_project/401m4$Build-9713", "401$9713", SvXMLImport::AOO_40x }, + { "OpenOffice/4.1.1$FreeBSD/amd64 OpenOffice.org_project/411m6$Build-9775", "411$9775", SvXMLImport::AOO_4x }, + { "OpenOffice/4.1.2$OS/2 OpenOffice.org_project/412m3$Build-9782-bww", "412$9782-bww", SvXMLImport::AOO_4x }, + { "OpenOffice/4.1.4$Unix OpenOffice.org_project/414m2$Build-9785", "414$9785", SvXMLImport::AOO_4x }, + + // LO versions + { "LibreOffice/3.3$Linux LibreOffice_project/330m17$Build-3", "330$3;33", SvXMLImport::LO_3x }, + { "BrOffice/3.3$Win32 LibreOffice_project/330m19$Build-8", "330$8;33", SvXMLImport::LO_3x }, + { "LibreOffice/3.4$Linux LibreOffice_project/340m1$Build-1206", "340$1206;34", SvXMLImport::LO_3x }, + { "LibreOffice/3.5$Linux_X86_64 LibreOffice_project/3fa2330-e49ffd2-90d118b-705e248-051e21c", ";35", SvXMLImport::LO_3x }, + { "LibreOffice/3.6$Windows_x86 LibreOffice_project/a9a0717-273e462-768e6e3-978247f-65e65f", ";36", SvXMLImport::LO_3x }, + { "LibreOffice/4.0.2.2$Windows_x86 LibreOffice_project/4c82dcdd6efcd48b1d8bba66bfe1989deee49c3", ";4022", SvXMLImport::LO_41x }, + { "LibreOffice/4.1.2.3$MacOSX_x86 LibreOffice_project/40b2d7fde7e8d2d7bc5a449dc65df4d08a7dd38", ";4123", SvXMLImport::LO_41x }, + { "LibreOffice/4.2.8.2$Windows_x86 LibreOffice_project/48d50dbfc06349262c9d50868e5c1f630a573ebd", ";4282", SvXMLImport::LO_42x }, + { "LibreOffice_from_Collabora_4.2-8/4.2.10.8$Linux_x86 LibreOffice_project/84584cc237b2eb93f7684d8fcd063bb37e87b5fb", ";42108", SvXMLImport::LO_42x }, + { "LibreOffice/4.3.3.2$Linux_x86 LibreOffice_project/9bb7eadab57b6755b1265afa86e04bf45fbfc644", ";4332", SvXMLImport::LO_43x }, + { "LibreOffice_from_Collabora_4.4-10/4.4.10.9$Linux_x86 LibreOffice_project/5600b19b88a01bbb669b0900100760758dff8c26", ";44109", SvXMLImport::LO_44x }, + { "LibreOffice/4.3.3.2$Linux_X86_64 LibreOffice_project/430m0$Build-2", "430$2;4332", SvXMLImport::LO_43x }, + { "LibreOffice/4.4.3.2$Linux_x86 LibreOffice_project/88805f81e9fe61362df02b9941de8e38a9b5fd16", ";4432", SvXMLImport::LO_44x }, + { "LibreOffice/5.0.1.1$Linux_x86 LibreOffice_project/00m0$Build-1", "00$1;5011", SvXMLImport::LO_5x }, + { "LibreOffice/5.0.3.2$Windows_X86_64 LibreOffice_project/e5f16313668ac592c1bfb310f4390624e3dbfb75", ";5032", SvXMLImport::LO_5x }, + { "Collabora_Office/5.0.10.19$Linux_X86_64 LibreOffice_project/95060d44300d8866fa81c16fc8fe2afe22d63777", ";501019", SvXMLImport::LO_5x }, + { "LibreOffice/5.1.6.2.0$Linux_X86_64 LibreOffice_project/10$Build-2", ";51620", SvXMLImport::LO_5x }, + { "Collabora_Office/5.1.10.17$Linux_X86_64 LibreOffice_project/a104cbe76eefca3cf23973da68893d2225fd718b", ";511017", SvXMLImport::LO_5x }, + { "LibreOffice/5.2.1.2$Windows_X86_64 LibreOffice_project/31dd62db80d4e60af04904455ec9c9219178d620", ";5212", SvXMLImport::LO_5x }, + { "LibreOffice_Vanilla/5.2.3.5$MacOSX_X86_64 LibreOffice_project/83adc9c35c74e0badc710d981405858b1179a327", ";5235", SvXMLImport::LO_5x }, + { "LibreOffice/5.3.4.2$Windows_X86_64 LibreOffice_project/f82d347ccc0be322489bf7da61d7e4ad13fe2ff3", ";5342", SvXMLImport::LO_5x }, + { "Collabora_Office/5.3.10.27$Linux_X86_64 LibreOffice_project/7a5a5378661e338a44666c08773cc796b8d1c84a", ";531027", SvXMLImport::LO_5x }, + { "LibreOfficeDev/5.4.7.0.0$Linux_X86_64 LibreOffice_project/ba7461fc88c08e75e315f786020a2946e56166c9", ";54700", SvXMLImport::LO_5x }, + { "LibreOfficeDev/6.0.3.0.0$Linux_X86_64 LibreOffice_project/34442b85bfb0c451738b4db023345a7484463321", ";60300", SvXMLImport::LO_6x }, + { "LibreOffice_powered_by_CIBDev/6.3.9.0.0$Linux_X86_64 LibreOffice_project/c87f331d2900eab70ac3021cbe530926efa6499f", ";63900", SvXMLImport::LO_63x }, + { "LibreOffice_powered_by_CIBDev/6.4.0.0.0$Linux_X86_64 LibreOffice_project/e29e100174c133d27e953934311d68602c4515b7", ";64000", SvXMLImport::LO_63x }, + { "LibreOfficeDev/7.0.6.0.0$Linux_X86_64 LibreOffice_project/dfc40e2292c6e19e285c10ed8c8044d9454107d0", ";70600", SvXMLImport::LO_7x }, + }; + + for (size_t i = 0; i < SAL_N_ELEMENTS(tests); ++i) + { + // the DocumentInfo instance is cached so need fresh SvXMLImport + rtl::Reference const pImport(new SvXMLImport( + comphelper::getProcessComponentContext(), "testdummy", + SvXMLImportFlags::ALL)); + + pImport->initialize(uno::Sequence{ uno::Any(xInfoSet) }); + + SvXMLMetaDocumentContext::setBuildId( + OUString::createFromAscii(tests[i].generator), xInfoSet); + if (tests[i].buildId[0] != '\0') + { + CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(tests[i].buildId), + xInfoSet->getPropertyValue("BuildId").get()); + } + else + { + CPPUNIT_ASSERT(!xInfoSet->getPropertyValue("BuildId").hasValue()); + } + CPPUNIT_ASSERT_EQUAL(tests[i].result, pImport->getGeneratorVersion()); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/qa/unoapi/knownissues.xcl b/xmloff/qa/unoapi/knownissues.xcl new file mode 100644 index 000000000..8b96089fe --- /dev/null +++ b/xmloff/qa/unoapi/knownissues.xcl @@ -0,0 +1,43 @@ +# +# 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/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +### i23394 ### +xmloff.Chart.XMLContentImporter::com::sun::star::xml::sax::XDocumentHandler +xmloff.Chart.XMLImporter::com::sun::star::xml::sax::XDocumentHandler +xmloff.Draw.XMLContentImporter::com::sun::star::xml::sax::XDocumentHandler +xmloff.Draw.XMLImporter::com::sun::star::xml::sax::XDocumentHandler +xmloff.Draw.XMLMetaImporter::com::sun::star::xml::sax::XDocumentHandler +xmloff.Draw.XMLStylesImporter::com::sun::star::xml::sax::XDocumentHandler +xmloff.Impress.XMLContentImporter::com::sun::star::xml::sax::XDocumentHandler +xmloff.Impress.XMLImporter::com::sun::star::xml::sax::XDocumentHandler +xmloff.Impress.XMLMetaImporter::com::sun::star::xml::sax::XDocumentHandler +xmloff.Impress.XMLStylesImporter::com::sun::star::xml::sax::XDocumentHandler + +### i87695 ### +xmloff.Draw.XMLStylesExporter +xmloff.Impress.XMLStylesExporter +#-> disabled in xmloff.sce + +### i112778 ### +xmloff.Draw.XMLContentExporter::com::sun::star::document::XFilter +xmloff.Draw.XMLMetaExporter::com::sun::star::document::XFilter +xmloff.Impress.XMLMetaExporter::com::sun::star::document::XFilter + +### i114211 ### +xmloff.Draw.XMLStylesImporter::com::sun::star::lang::XInitialization +xmloff.Impress.XMLStylesImporter::com::sun::star::lang::XInitialization diff --git a/xmloff/qa/unoapi/testdocuments/emptyChart.sds b/xmloff/qa/unoapi/testdocuments/emptyChart.sds new file mode 100644 index 000000000..853a44a12 Binary files /dev/null and b/xmloff/qa/unoapi/testdocuments/emptyChart.sds differ diff --git a/xmloff/qa/unoapi/xmloff.sce b/xmloff/qa/unoapi/xmloff.sce new file mode 100644 index 000000000..025fd68dd --- /dev/null +++ b/xmloff/qa/unoapi/xmloff.sce @@ -0,0 +1,44 @@ +# +# 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/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +#111102# -o xmloff.Chart.XMLContentExporter +#111102# -o xmloff.Chart.XMLContentImporter +#111102# -o xmloff.Chart.XMLExporter +#111102# -o xmloff.Chart.XMLImporter +#111102# -o xmloff.Chart.XMLStylesExporter +#111102# #i112047 -o xmloff.Chart.XMLStylesImporter +-o xmloff.Draw.XMLContentExporter +-o xmloff.Draw.XMLContentImporter +-o xmloff.Draw.XMLExporter +-o xmloff.Draw.XMLImporter +-o xmloff.Draw.XMLMetaExporter +#i111200 -o xmloff.Draw.XMLMetaImporter +#i111287 -o xmloff.Draw.XMLSettingsExporter +#i111287 -o xmloff.Draw.XMLSettingsImporter +#i87695 -o xmloff.Draw.XMLStylesExporter +-o xmloff.Draw.XMLStylesImporter +#i111224 -o xmloff.Impress.XMLContentExporter +-o xmloff.Impress.XMLContentImporter +#i112048 -o xmloff.Impress.XMLExporter +#i111111# -o xmloff.Impress.XMLImporter +-o xmloff.Impress.XMLMetaExporter +-o xmloff.Impress.XMLMetaImporter +#i111287 -o xmloff.Impress.XMLSettingsExporter +#i111287 -o xmloff.Impress.XMLSettingsImporter +#i87695 -o xmloff.Impress.XMLStylesExporter +-o xmloff.Impress.XMLStylesImporter -- cgit v1.2.3