From 579c0749bef8c980507229439715e72060c1b077 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Tue, 9 Oct 2018 14:03:37 +0300 Subject: 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 --- .../data/tdf120224_textControlCrossRef.docx | Bin 0 -> 16356 bytes sw/qa/extras/ooxmlexport/ooxmlexport12.cxx | 39 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 sw/qa/extras/ooxmlexport/data/tdf120224_textControlCrossRef.docx (limited to 'sw') 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 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf120224_textControlCrossRef.docx 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 xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xRunEnumAccess(xParaEnum->nextElement(), + uno::UNO_QUERY); + uno::Reference xRunEnum = xRunEnumAccess->createEnumeration(); + xRunEnum->nextElement(); //Text + uno::Reference xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY); + + CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), + getProperty(xPropertySet, "TextPortionType")); + uno::Reference xBookmark( + getProperty>(xPropertySet, "Bookmark"), uno::UNO_QUERY); + + // Critical test: does TextField's bookmark name match cross-reference? + const OUString& sTextFieldName(xBookmark->getName()); + uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess( + xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + CPPUNIT_ASSERT(xFields->hasMoreElements()); + xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sTextFieldName, getProperty(xPropertySet, "SourceName")); + + uno::Reference xBookmarksSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + uno::Reference xBookmarksByName(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + // TextFields should not be turned into real bookmarks. + CPPUNIT_ASSERT_EQUAL(static_cast(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(getParagraph(1), "NumberingStyleName"); -- cgit v1.2.3