From 457208b260cbcc0b3aa1f045702d18a31d6dc671 Mon Sep 17 00:00:00 2001 From: Mark Hung Date: Thu, 29 Mar 2018 21:35:42 +0800 Subject: [PATCH] Split ooxmlexport10 into two unit test modules. Change-Id: Ibd714f81f76717ac159897f6ee9f907a8098cabe Reviewed-on: https://gerrit.libreoffice.org/52153 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/CppunitTest_sw_ooxmlexport12.mk | 14 + sw/Module_sw.mk | 1 + sw/qa/extras/ooxmlexport/ooxmlexport10.cxx | 605 ---------------- sw/qa/extras/ooxmlexport/ooxmlexport12.cxx | 762 +++++++++++++++++++++ 4 files changed, 777 insertions(+), 605 deletions(-) create mode 100644 sw/CppunitTest_sw_ooxmlexport12.mk create mode 100644 sw/qa/extras/ooxmlexport/ooxmlexport12.cxx diff --git a/sw/CppunitTest_sw_ooxmlexport12.mk b/sw/CppunitTest_sw_ooxmlexport12.mk new file mode 100644 index 000000000000..241c642ba1fc --- /dev/null +++ b/sw/CppunitTest_sw_ooxmlexport12.mk @@ -0,0 +1,14 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# 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/. +# +#************************************************************************* + +$(eval $(call sw_ooxmlexport_test,12)) + +# vim: set noet sw=4 ts=4: diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk index 4ef524d1fd94..79b6f566d3f2 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -71,6 +71,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ CppunitTest_sw_ooxmlexport9 \ CppunitTest_sw_ooxmlexport10 \ CppunitTest_sw_ooxmlexport11 \ + CppunitTest_sw_ooxmlexport12 \ CppunitTest_sw_ooxmlfieldexport \ CppunitTest_sw_ooxmllinks \ CppunitTest_sw_ooxmlw14export \ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx index 624155cc9f27..fac212c3cfe9 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx @@ -1197,611 +1197,6 @@ DECLARE_OOXMLEXPORT_TEST( testTdf107359, "tdf107359-char-pitch.docx" ) CPPUNIT_ASSERT_EQUAL( sal_Int32(convertTwipToMm100(24 * 20)), nBaseWidth ); } -DECLARE_OOXMLEXPORT_TEST( testTableCrossReference, "table_cross_reference.odt" ) -{ - // tdf#42346: Cross references to tables were not saved - // MSO uses simple bookmarks for referencing table caption, so we do the same by export - if (!mbExported) - return; - - // Check whether we have all the necessary bookmarks exported and imported back - uno::Reference xBookmarksSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(static_cast(4), xBookmarksByIdx->getCount()); - uno::Reference xBookmarksByName(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_full")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_label_and_number")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_caption_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_number_only")); - - // Check bookmark text ranges - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table0_full"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Table 1: Table caption"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table0_label_and_number"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Table 1"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table0_caption_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table0_number_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("1"), xRange->getString()); - } - - // Check reference fields - uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); - uno::Reference xFields(xFieldsAccess->createEnumeration()); - CPPUNIT_ASSERT(xFields->hasMoreElements()); - - sal_uInt16 nIndex = 0; - while (xFields->hasMoreElements()) - { - uno::Reference xServiceInfo(xFields->nextElement(), uno::UNO_QUERY); - uno::Reference xPropertySet(xServiceInfo, uno::UNO_QUERY); - switch (nIndex) - { - // Full reference to table caption - case 0: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - sal_Int16 nValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Table 1: Table caption"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_full"), sValue); - xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; - CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); - break; - } - // Page style reference / exported as simple page reference - case 1: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - sal_Int16 nValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_full"), sValue); - xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; - CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); - break; - } - // Reference to table number - case 2: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - sal_Int16 nValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_number_only"), sValue); - xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; - CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); - break; - } - // Reference to caption only - case 3: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - sal_Int16 nValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_caption_only"), sValue); - xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; - CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); - break; - } - // Reference to category and number - case 4: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - sal_Int16 nValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Table 1"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_label_and_number"), sValue); - xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; - CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); - break; - } - // Reference to page of the table - case 5: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - sal_Int16 nValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_full"), sValue); - xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; - CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); - break; - } - // Above / below reference - case 6: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - sal_Int16 nValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("above"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_full"), sValue); - xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; - CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); - break; - } - default: - break; - } - ++nIndex; - } - - CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), nIndex); -} - -DECLARE_OOXMLEXPORT_TEST( testTableCrossReferenceCustomFormat, "table_cross_reference_custom_format.odt" ) -{ - // tdf#42346: Cross references to tables were not saved - // Check also captions with custom formatting - if (!mbExported) - return; - - // Check whether we have all the necessary bookmarks exported and imported back - uno::Reference xBookmarksSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(static_cast(16), xBookmarksByIdx->getCount()); - uno::Reference xBookmarksByName(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_full")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_label_and_number")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_caption_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_number_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table1_full")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table1_label_and_number")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table1_caption_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table1_number_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table2_full")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table2_label_and_number")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table2_caption_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table2_number_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table3_full")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table3_label_and_number")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table3_caption_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table3_number_only")); - - // Check bookmark text ranges - // First table's caption - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table0_full"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("1. Table: Table caption"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table0_label_and_number"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("1. Table"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table0_caption_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table0_number_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("1"), xRange->getString()); - } - // Second table's caption - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table1_full"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("2. TableTable caption"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table1_label_and_number"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("2. Table"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table1_caption_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table1_number_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("2"), xRange->getString()); - } - // Third table's caption - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table2_full"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("3) Table Table caption"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table2_label_and_number"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("3) Table"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table2_caption_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table2_number_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("3"), xRange->getString()); - } - // Fourth table's caption - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table3_full"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Table 4- Table caption"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table3_label_and_number"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Table 4"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table3_caption_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Table3_number_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("4"), xRange->getString()); - } -} - -DECLARE_OOXMLEXPORT_TEST( testObjectCrossReference, "object_cross_reference.odt" ) -{ - // tdf#42346: Cross references to objects were not saved - // MSO uses simple bookmarks for referencing table caption, so we do the same by export - if (!mbExported) - return; - - // Check whether we have all the necessary bookmarks exported and imported back - uno::Reference xBookmarksSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(static_cast(15), xBookmarksByIdx->getCount()); - uno::Reference xBookmarksByName(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Drawing0_full")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Drawing0_label_and_number")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Drawing0_caption_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Drawing0_number_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Drawing1_full")); - - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Illustration0_full")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Illustration0_label_and_number")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Illustration0_caption_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Illustration0_number_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Illustration1_caption_only")); - - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Text0_full")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Text0_label_and_number")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Text0_caption_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Text0_number_only")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Text1_label_and_number")); - - // Check bookmark text ranges - // Cross references to shapes - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Drawing0_full"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Drawing 1: A rectangle"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Drawing0_label_and_number"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Drawing 1"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Drawing0_caption_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("A rectangle"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Drawing0_number_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("1"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Drawing1_full"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Drawing 2: a circle"), xRange->getString()); - } - - // Cross references to pictures - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Illustration0_full"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Illustration 1: A picture"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Illustration0_label_and_number"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Illustration 1"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Illustration0_caption_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("A picture"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Illustration0_number_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("1"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Illustration1_caption_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("an other image"), xRange->getString()); - } - - // Cross references to text frames - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Text0_full"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Text 1: A frame"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Text0_label_and_number"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Text 1"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Text0_caption_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("A frame"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Text0_number_only"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("1"), xRange->getString()); - } - { - uno::Reference xContent(xBookmarksByName->getByName("Ref_Text1_label_and_number"), uno::UNO_QUERY); - uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Text 2"), xRange->getString()); - } - - // Check reference fields - uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); - uno::Reference xFields(xFieldsAccess->createEnumeration()); - CPPUNIT_ASSERT(xFields->hasMoreElements()); - - sal_uInt16 nIndex = 0; - while (xFields->hasMoreElements()) - { - uno::Reference xServiceInfo(xFields->nextElement(), uno::UNO_QUERY); - uno::Reference xPropertySet(xServiceInfo, uno::UNO_QUERY); - switch (nIndex) - { - // Reference to image number - case 0: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Illustration0_number_only"), sValue); - break; - } - // Full reference to the circle shape - case 1: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Drawing 2: a circle"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Drawing1_full"), sValue); - break; - } - // Caption only reference to the second picture - case 2: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("an other image"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Illustration1_caption_only"), sValue); - break; - } - // Category and number reference to second text frame - case 3: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Text 2"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Text1_label_and_number"), sValue); - break; - } - // Full reference to rectangle shape - case 4: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Drawing 1: A rectangle"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Drawing0_full"), sValue); - break; - } - // Caption only reference to rectangle shape - case 5: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("A rectangle"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Drawing0_caption_only"), sValue); - break; - } - // Category and number reference to rectangle shape - case 6: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Drawing 1"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Drawing0_label_and_number"), sValue); - break; - } - // Reference to rectangle shape's number - case 7: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Drawing0_number_only"), sValue); - break; - } - // Full reference to first text frame - case 8: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Text 1: A frame"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Text0_full"), sValue); - break; - } - // Caption only reference to first text frame - case 9: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("A frame"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Text0_caption_only"), sValue); - break; - } - // Category and number reference to first text frame - case 10: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Text 1"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Text0_label_and_number"), sValue); - break; - } - // Number only reference to first text frame - case 11: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Text0_number_only"), sValue); - break; - } - // Full reference to first picture - case 12: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Illustration 1: A picture"), sValue.trim()); // failes on MAC without trim - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Illustration0_full"), sValue); - break; - } - // Reference to first picture' caption - case 13: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("A picture"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Illustration0_caption_only"), sValue); - break; - } - // Category and number reference to first picture - case 14: - { - CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); - OUString sValue; - xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Illustration 1"), sValue); - xPropertySet->getPropertyValue("SourceName") >>= sValue; - CPPUNIT_ASSERT_EQUAL(OUString("Ref_Illustration0_label_and_number"), sValue); - break; - } - default: - break; - } - ++nIndex; - } - - CPPUNIT_ASSERT_EQUAL(sal_uInt16(21), nIndex); -} - -DECLARE_OOXMLEXPORT_TEST(testWatermark, "watermark.docx") -{ - uno::Reference xShape(getShape(1), uno::UNO_QUERY); - uno::Reference xPropertySet(xShape, uno::UNO_QUERY); - - sal_Int32 nHeight = xShape->getSize().Height; - - // Rounding errors - sal_Int32 nDifference = 5150 - nHeight; - std::stringstream ss; - ss << "Difference: " << nDifference << " TotalHeight: " << nHeight; -#ifndef _WIN32 - // FIXME why does this sometimes fail? - CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference <= 4); - CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference >= -4); -#endif -} - -DECLARE_OOXMLEXPORT_TEST(testWatermarkTrim, "tdf114308.docx") -{ - uno::Reference xShape(getShape(1), uno::UNO_QUERY); - - // Rounding errors - sal_Int32 nHeight = xShape->getSize().Height; - sal_Int32 nDifference = 8729 - nHeight; - std::stringstream ss; - ss << "Difference: " << nDifference << " TotalHeight: " << nHeight; - CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference <= 4); - CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference >= -4); -} - CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx new file mode 100644 index 000000000000..eefb014e3501 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx @@ -0,0 +1,762 @@ +/* -*- 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 +#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 +#include +#include + +#include + +class Test : public SwModelTestBase +{ +public: + Test() + : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "Office Open XML Text") + { + } + +protected: + /** + * Blacklist handling + */ + bool mustTestImportOf(const char* filename) const override + { + // If the testcase is stored in some other format, it's pointless to test. + return OString(filename).endsWith(".docx"); + } +}; + +DECLARE_OOXMLEXPORT_TEST(testTableCrossReference, "table_cross_reference.odt") +{ + // tdf#42346: Cross references to tables were not saved + // MSO uses simple bookmarks for referencing table caption, so we do the same by export + if (!mbExported) + return; + + // Check whether we have all the necessary bookmarks exported and imported back + uno::Reference xBookmarksSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(static_cast(4), xBookmarksByIdx->getCount()); + uno::Reference xBookmarksByName(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_full")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_label_and_number")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_caption_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_number_only")); + + // Check bookmark text ranges + { + uno::Reference xContent(xBookmarksByName->getByName("Ref_Table0_full"), + uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Table 1: Table caption"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table0_label_and_number"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Table 1"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table0_caption_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table0_number_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xRange->getString()); + } + + // Check reference fields + uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess( + xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + CPPUNIT_ASSERT(xFields->hasMoreElements()); + + sal_uInt16 nIndex = 0; + while (xFields->hasMoreElements()) + { + uno::Reference xServiceInfo(xFields->nextElement(), uno::UNO_QUERY); + uno::Reference xPropertySet(xServiceInfo, uno::UNO_QUERY); + switch (nIndex) + { + // Full reference to table caption + case 0: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + sal_Int16 nValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Table 1: Table caption"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_full"), sValue); + xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); + break; + } + // Page style reference / exported as simple page reference + case 1: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + sal_Int16 nValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_full"), sValue); + xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); + break; + } + // Reference to table number + case 2: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + sal_Int16 nValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_number_only"), sValue); + xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); + break; + } + // Reference to caption only + case 3: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + sal_Int16 nValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_caption_only"), sValue); + xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); + break; + } + // Reference to category and number + case 4: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + sal_Int16 nValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Table 1"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_label_and_number"), sValue); + xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); + break; + } + // Reference to page of the table + case 5: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + sal_Int16 nValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_full"), sValue); + xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); + break; + } + // Above / below reference + case 6: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + sal_Int16 nValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("above"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Table0_full"), sValue); + xPropertySet->getPropertyValue("SequenceNumber") >>= nValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue); + break; + } + default: + break; + } + ++nIndex; + } + + CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), nIndex); +} + +DECLARE_OOXMLEXPORT_TEST(testTableCrossReferenceCustomFormat, + "table_cross_reference_custom_format.odt") +{ + // tdf#42346: Cross references to tables were not saved + // Check also captions with custom formatting + if (!mbExported) + return; + + // Check whether we have all the necessary bookmarks exported and imported back + uno::Reference xBookmarksSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(static_cast(16), xBookmarksByIdx->getCount()); + uno::Reference xBookmarksByName(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_full")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_label_and_number")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_caption_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table0_number_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table1_full")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table1_label_and_number")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table1_caption_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table1_number_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table2_full")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table2_label_and_number")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table2_caption_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table2_number_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table3_full")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table3_label_and_number")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table3_caption_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Table3_number_only")); + + // Check bookmark text ranges + // First table's caption + { + uno::Reference xContent(xBookmarksByName->getByName("Ref_Table0_full"), + uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1. Table: Table caption"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table0_label_and_number"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1. Table"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table0_caption_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table0_number_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xRange->getString()); + } + // Second table's caption + { + uno::Reference xContent(xBookmarksByName->getByName("Ref_Table1_full"), + uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2. TableTable caption"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table1_label_and_number"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2. Table"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table1_caption_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table1_number_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2"), xRange->getString()); + } + // Third table's caption + { + uno::Reference xContent(xBookmarksByName->getByName("Ref_Table2_full"), + uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("3) Table Table caption"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table2_label_and_number"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("3) Table"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table2_caption_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table2_number_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("3"), xRange->getString()); + } + // Fourth table's caption + { + uno::Reference xContent(xBookmarksByName->getByName("Ref_Table3_full"), + uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Table 4- Table caption"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table3_label_and_number"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Table 4"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table3_caption_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Table caption"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Table3_number_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("4"), xRange->getString()); + } +} + +DECLARE_OOXMLEXPORT_TEST(testObjectCrossReference, "object_cross_reference.odt") +{ + // tdf#42346: Cross references to objects were not saved + // MSO uses simple bookmarks for referencing table caption, so we do the same by export + if (!mbExported) + return; + + // Check whether we have all the necessary bookmarks exported and imported back + uno::Reference xBookmarksSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(static_cast(15), xBookmarksByIdx->getCount()); + uno::Reference xBookmarksByName(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Drawing0_full")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Drawing0_label_and_number")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Drawing0_caption_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Drawing0_number_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Drawing1_full")); + + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Illustration0_full")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Illustration0_label_and_number")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Illustration0_caption_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Illustration0_number_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Illustration1_caption_only")); + + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Text0_full")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Text0_label_and_number")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Text0_caption_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Text0_number_only")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("Ref_Text1_label_and_number")); + + // Check bookmark text ranges + // Cross references to shapes + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Drawing0_full"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Drawing 1: A rectangle"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Drawing0_label_and_number"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Drawing 1"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Drawing0_caption_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("A rectangle"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Drawing0_number_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Drawing1_full"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Drawing 2: a circle"), xRange->getString()); + } + + // Cross references to pictures + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Illustration0_full"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Illustration 1: A picture"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Illustration0_label_and_number"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Illustration 1"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Illustration0_caption_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("A picture"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Illustration0_number_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Illustration1_caption_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("an other image"), xRange->getString()); + } + + // Cross references to text frames + { + uno::Reference xContent(xBookmarksByName->getByName("Ref_Text0_full"), + uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Text 1: A frame"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Text0_label_and_number"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Text 1"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Text0_caption_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("A frame"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Text0_number_only"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xRange->getString()); + } + { + uno::Reference xContent( + xBookmarksByName->getByName("Ref_Text1_label_and_number"), uno::UNO_QUERY); + uno::Reference xRange(xContent->getAnchor(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Text 2"), xRange->getString()); + } + + // Check reference fields + uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess( + xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + CPPUNIT_ASSERT(xFields->hasMoreElements()); + + sal_uInt16 nIndex = 0; + while (xFields->hasMoreElements()) + { + uno::Reference xServiceInfo(xFields->nextElement(), uno::UNO_QUERY); + uno::Reference xPropertySet(xServiceInfo, uno::UNO_QUERY); + switch (nIndex) + { + // Reference to image number + case 0: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Illustration0_number_only"), sValue); + break; + } + // Full reference to the circle shape + case 1: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Drawing 2: a circle"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Drawing1_full"), sValue); + break; + } + // Caption only reference to the second picture + case 2: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("an other image"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Illustration1_caption_only"), sValue); + break; + } + // Category and number reference to second text frame + case 3: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Text 2"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Text1_label_and_number"), sValue); + break; + } + // Full reference to rectangle shape + case 4: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Drawing 1: A rectangle"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Drawing0_full"), sValue); + break; + } + // Caption only reference to rectangle shape + case 5: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("A rectangle"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Drawing0_caption_only"), sValue); + break; + } + // Category and number reference to rectangle shape + case 6: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Drawing 1"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Drawing0_label_and_number"), sValue); + break; + } + // Reference to rectangle shape's number + case 7: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Drawing0_number_only"), sValue); + break; + } + // Full reference to first text frame + case 8: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Text 1: A frame"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Text0_full"), sValue); + break; + } + // Caption only reference to first text frame + case 9: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("A frame"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Text0_caption_only"), sValue); + break; + } + // Category and number reference to first text frame + case 10: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Text 1"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Text0_label_and_number"), sValue); + break; + } + // Number only reference to first text frame + case 11: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("1"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Text0_number_only"), sValue); + break; + } + // Full reference to first picture + case 12: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Illustration 1: A picture"), + sValue.trim()); // failes on MAC without trim + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Illustration0_full"), sValue); + break; + } + // Reference to first picture' caption + case 13: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("A picture"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Illustration0_caption_only"), sValue); + break; + } + // Category and number reference to first picture + case 14: + { + CPPUNIT_ASSERT( + xServiceInfo->supportsService("com.sun.star.text.TextField.GetReference")); + OUString sValue; + xPropertySet->getPropertyValue("CurrentPresentation") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Illustration 1"), sValue); + xPropertySet->getPropertyValue("SourceName") >>= sValue; + CPPUNIT_ASSERT_EQUAL(OUString("Ref_Illustration0_label_and_number"), sValue); + break; + } + default: + break; + } + ++nIndex; + } + + CPPUNIT_ASSERT_EQUAL(sal_uInt16(21), nIndex); +} + +DECLARE_OOXMLEXPORT_TEST(testWatermark, "watermark.docx") +{ + uno::Reference xShape(getShape(1), uno::UNO_QUERY); + uno::Reference xPropertySet(xShape, uno::UNO_QUERY); + + sal_Int32 nHeight = xShape->getSize().Height; + + // Rounding errors + sal_Int32 nDifference = 5150 - nHeight; + std::stringstream ss; + ss << "Difference: " << nDifference << " TotalHeight: " << nHeight; +#ifndef _WIN32 + // FIXME why does this sometimes fail? + CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference <= 4); + CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference >= -4); +#endif +} + +DECLARE_OOXMLEXPORT_TEST(testWatermarkTrim, "tdf114308.docx") +{ + uno::Reference xShape(getShape(1), uno::UNO_QUERY); + + // Rounding errors + sal_Int32 nHeight = xShape->getSize().Height; + sal_Int32 nDifference = 8729 - nHeight; + std::stringstream ss; + ss << "Difference: " << nDifference << " TotalHeight: " << nHeight; + CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference <= 4); + CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference >= -4); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */