From 992d86b1b67a6bd28bbf5e63b2d2406881f476b7 Mon Sep 17 00:00:00 2001 From: Vasily Melenchuk Date: Tue, 28 Mar 2023 13:15:09 +0300 Subject: tdf#150542: DOCX import: support for document varibles Writer does insert document variables only if they are in document body as DOCVARIABLE fields. But ones given in settings.xml (w:docVars/w:docVar) were ignored. Moreover variables in settings should have priority and overwrite ones in fields. Word by default does show only field results, but refreshing field values will override values with ones from settings. Change-Id: I7103c90eef59ab18f8a25e616dcf8a8b1c6dcb08 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149646 Tested-by: Jenkins Reviewed-by: Thorsten Behrens --- sw/qa/extras/ooxmlexport/data/tdf150542.docx | Bin 0 -> 2978 bytes sw/qa/extras/ooxmlexport/ooxmlexport16.cxx | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 sw/qa/extras/ooxmlexport/data/tdf150542.docx (limited to 'sw/qa') diff --git a/sw/qa/extras/ooxmlexport/data/tdf150542.docx b/sw/qa/extras/ooxmlexport/data/tdf150542.docx new file mode 100644 index 000000000000..3f115fa69370 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf150542.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx index 0394c03495a6..6d501548ad25 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx @@ -994,6 +994,27 @@ CPPUNIT_TEST_FIXTURE(Test, Test_ShadowDirection) "rotWithShape", "0"); } +CPPUNIT_TEST_FIXTURE(Test, testTdf150542) +{ + loadAndSave("tdf150542.docx"); + + xmlDocUniquePtr pSettingsDoc = parseExport("word/settings.xml"); + // Ensure that all docvars from input are written back and with correct values. + // Order of document variables is not checked. So this can fail at some time if order is changed. + assertXPath(pSettingsDoc, + "/w:settings/w:docVars/w:docVar[1]", "name", u"LocalChars\u00C1\u0072\u0076\u00ED\u007A\u0074\u0075\u0072\u006F\u0054\u00FC\u006B\u00F6\u0072\u0066\u00FA\u0072\u00F3\u0067\u00E9\u0070"); + assertXPath(pSettingsDoc, + "/w:settings/w:docVars/w:docVar[1]", "val", u"Correct value (\u00E1\u0072\u0076\u00ED\u007A\u0074\u0075\u0072\u006F\u0020\u0074\u00FC\u006B\u00F6\u0072\u0066\u00FA\u0072\u00F3\u0067\u00E9\u0070)"); + assertXPath(pSettingsDoc, + "/w:settings/w:docVars/w:docVar[2]", "name", "DocVar1"); + assertXPath(pSettingsDoc, + "/w:settings/w:docVars/w:docVar[2]", "val", "DocVar1 Value"); + assertXPath(pSettingsDoc, + "/w:settings/w:docVars/w:docVar[3]", "name", "DocVar3"); + assertXPath(pSettingsDoc, + "/w:settings/w:docVars/w:docVar[3]", "val", "DocVar3 Value"); +} + CPPUNIT_TEST_FIXTURE(Test, testTdf139549) { loadAndSave("tdf139549.docx"); -- cgit