summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-01-30 10:21:08 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-01-30 16:36:37 +0100
commit24073d986988c51425b3eb3c8d6aef171e914eaf (patch)
treec8ab1c8b745839859c7ce638f95059732ef34b02 /sw/qa
parent14e306efae35f01fa63237ce005ad4067ca16909 (diff)
DOCX export: implement support for user fields
Updating the field doesn't work yet, that'll need additional markup in settings.xml. (cherry picked from commit 676862bb8aa043f116615e5d0dac59254eaa8138) Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport14.cxx Change-Id: I562ae62cebcbd5ca474bd0f7a181773f8e515f5e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87729 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport13.cxx32
1 files changed, 32 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index 8706782b6d9c..32e7ad309664 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -17,6 +17,7 @@
#include <com/sun/star/drawing/XControlShape.hpp>
#include <com/sun/star/style/LineSpacing.hpp>
#include <com/sun/star/style/LineSpacingMode.hpp>
+#include <com/sun/star/text/XDependentTextField.hpp>
#include <sfx2/docfile.hxx>
#include <sfx2/docfilt.hxx>
@@ -417,6 +418,37 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testZeroLineSpacing)
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:spacing", "line", "0");
}
+CPPUNIT_TEST_FIXTURE(SwModelTestBase, testUserField)
+{
+ // Create an in-memory empty document with a user field.
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XDependentTextField> xField(
+ xFactory->createInstance("com.sun.star.text.TextField.User"), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xMaster(
+ xFactory->createInstance("com.sun.star.text.FieldMaster.User"), uno::UNO_QUERY);
+ xMaster->setPropertyValue("Name", uno::makeAny(OUString("foo")));
+ xField->attachTextFieldMaster(xMaster);
+ xField->getTextFieldMaster()->setPropertyValue("Content", uno::makeAny(OUString("bar")));
+ uno::Reference<text::XTextDocument> xDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> xText = xDocument->getText();
+ xText->insertTextContent(xText->createTextCursor(), xField, /*bAbsorb=*/false);
+
+ // Export to docx.
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= OUString("Office Open XML Text");
+ xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+ mbExported = true;
+ xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+ CPPUNIT_ASSERT(pXmlDoc);
+
+ // Without the accompanying fix in place, this test would have failed, the user field was
+ // exported as <w:t>User Field foo = bar</w:t>.
+ assertXPathContent(pXmlDoc, "//w:p/w:r[2]/w:instrText", " DOCVARIABLE foo ");
+ assertXPathContent(pXmlDoc, "//w:p/w:r[4]/w:t", "bar");
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */