summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2018-10-09 14:03:37 +0300
committerJustin Luth <justin_luth@sil.org>2018-10-12 05:56:01 +0200
commit579c0749bef8c980507229439715e72060c1b077 (patch)
tree3e0f842e4be9066c666f8dac944f2008551503e1 /sw
parent3fa8f934195cabb9c6fa9cd09ee0a05c7ded46ab (diff)
tdf120224 writerfilter: consume excess bookmark from fields
Although this follows a very different code path, copy the ww8 import idea of "consuming" the bookmark of a BOOK_FIELD. This is particularly important for textcontrols, especially since LO keeps duplicating bookmarks as it adds another bookmark for the field name at each save. Existing unit tests that this matches are fdo53985.docx and tdf111964.docx. I expected more, but apparently most fields don't contain or represent any bookmarks. This patch is for import only. A followup patch stops the creation of duplicate bookmarks during export. Change-Id: I1e11980e52dc523393fd6d621191228d676e9a17 Reviewed-on: https://gerrit.libreoffice.org/61615 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf120224_textControlCrossRef.docxbin0 -> 16356 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport12.cxx39
2 files changed, 39 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf120224_textControlCrossRef.docx b/sw/qa/extras/ooxmlexport/data/tdf120224_textControlCrossRef.docx
new file mode 100644
index 000000000000..c76bbd691c47
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf120224_textControlCrossRef.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
index 2b55c3f1ecfd..7c24fa3751fc 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
@@ -723,6 +723,45 @@ DECLARE_OOXMLEXPORT_TEST(testObjectCrossReference, "object_cross_reference.odt")
CPPUNIT_ASSERT_EQUAL(sal_uInt16(21), nIndex);
}
+DECLARE_OOXMLEXPORT_TEST(testTdf120224_textControlCrossRef, "tdf120224_textControlCrossRef.docx")
+{
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
+ uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
+ xRunEnum->nextElement(); //Text
+ uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
+
+ CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"),
+ getProperty<OUString>(xPropertySet, "TextPortionType"));
+ uno::Reference<container::XNamed> xBookmark(
+ getProperty<uno::Reference<beans::XPropertySet>>(xPropertySet, "Bookmark"), uno::UNO_QUERY);
+
+ // Critical test: does TextField's bookmark name match cross-reference?
+ const OUString& sTextFieldName(xBookmark->getName());
+ uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xFieldsAccess(
+ xTextFieldsSupplier->getTextFields());
+ uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+ CPPUNIT_ASSERT(xFields->hasMoreElements());
+ xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(sTextFieldName, getProperty<OUString>(xPropertySet, "SourceName"));
+
+ uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xBookmarksByIdx(xBookmarksSupplier->getBookmarks(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xBookmarksByName(xBookmarksSupplier->getBookmarks(),
+ uno::UNO_QUERY);
+ // TextFields should not be turned into real bookmarks.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xBookmarksByIdx->getCount());
+
+ // The actual name isn't critical, but if it fails, it is worth asking why.
+ CPPUNIT_ASSERT_EQUAL(OUString("Text1"), sTextFieldName);
+}
+
DECLARE_OOXMLEXPORT_TEST(testTdf117504_numberingIndent, "tdf117504_numberingIndent.docx")
{
OUString sName = getProperty<OUString>(getParagraph(1), "NumberingStyleName");