/* -*- 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 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(testTdf79435_legacyInputFields, "tdf79435_legacyInputFields.doc") { //using .doc input file to verify cross-format compatibility. uno::Reference xFormField; xFormField = getProperty>(getRun(getParagraph(5), 3), "Bookmark"); uno::Reference xParameters(xFormField->getParameters()); OUString sTmp; // Doc import problems, so disabling tests //xParameters->getByName("EntryMacro") >>= sTmp; //CPPUNIT_ASSERT_EQUAL(OUString("test"), sTmp); //xParameters->getByName("Help") >>= sTmp; //CPPUNIT_ASSERT_EQUAL(OUString("F1Help"), sTmp); //xParameters->getByName("ExitMacro") >>= sTmp; //CPPUNIT_ASSERT_EQUAL(OUString("test"), sTmp); xParameters->getByName("Hint") >>= sTmp; CPPUNIT_ASSERT_EQUAL(OUString("StatusHelp"), sTmp); //xParameters->getByName("Content") >>= sTmp; //CPPUNIT_ASSERT_EQUAL(OUString("Camelcase"), sTmp); //xParameters->getByName("Format") >>= sTmp; //CPPUNIT_ASSERT_EQUAL(OUString("TITLE CASE"), sTmp); sal_uInt16 nMaxLength = 0; xParameters->getByName("MaxLength") >>= nMaxLength; CPPUNIT_ASSERT_EQUAL_MESSAGE("Max Length", sal_uInt16(10), nMaxLength); // too bad this is based on character runs - just found try trial and error. xFormField = getProperty>(getRun(getParagraph(6), 2), "Bookmark"); xParameters.set(xFormField->getParameters()); xParameters->getByName("Type") >>= sTmp; CPPUNIT_ASSERT_EQUAL(OUString("calculated"), sTmp); xFormField = getProperty>(getRun(getParagraph(7), 2), "Bookmark"); xParameters.set(xFormField->getParameters()); xParameters->getByName("Type") >>= sTmp; CPPUNIT_ASSERT_EQUAL(OUString("currentDate"), sTmp); xFormField = getProperty>(getRun(getParagraph(7), 6), "Bookmark"); xParameters.set(xFormField->getParameters()); xParameters->getByName("Type") >>= sTmp; CPPUNIT_ASSERT_EQUAL(OUString("currentTime"), sTmp); xFormField = getProperty>(getRun(getParagraph(8), 2), "Bookmark"); xParameters.set(xFormField->getParameters()); xParameters->getByName("Type") >>= sTmp; CPPUNIT_ASSERT_EQUAL(OUString("number"), sTmp); xFormField = getProperty>(getRun(getParagraph(8), 6), "Bookmark"); xParameters.set(xFormField->getParameters()); xParameters->getByName("Type") >>= sTmp; CPPUNIT_ASSERT_EQUAL(OUString("date"), sTmp); } 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"); CPPUNIT_ASSERT_MESSAGE("Paragraph has numbering style", !sName.isEmpty()); uno::Reference xPropertySet( getStyles("ParagraphStyles")->getByName("Revision"), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(353), getProperty(xPropertySet, "ParaBottomMargin")); xPropertySet.set(getStyles("ParagraphStyles")->getByName("Body Note"), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xPropertySet, "ParaBottomMargin")); } 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); } DECLARE_OOXMLEXPORT_TEST(testTdf73547, "tdf73547-dash.docx") { xmlDocPtr pXmlDoc = parseExport("word/document.xml"); if (!pXmlDoc) return; double nD = getXPath(pXmlDoc, "//a:custDash/a:ds[1]", "d").toDouble(); CPPUNIT_ASSERT_DOUBLES_EQUAL(105000.0, nD, 5000.0); // was 100000 double nSp = getXPath(pXmlDoc, "//a:custDash/a:ds[1]", "sp").toDouble(); CPPUNIT_ASSERT_DOUBLES_EQUAL(35000.0, nSp, 5000.0); // was 100000 } DECLARE_OOXMLEXPORT_TEST(testTdf119143, "tdf119143.docx") { // The runs inside were ignored const OUString sParaText = getParagraph(1)->getString(); CPPUNIT_ASSERT_EQUAL( OUString::fromUtf8( u8"عندما يريد العالم أن يتكلّم ‬ ، فهو يتحدّث " u8"بلغة " u8"يونيكود. تسجّل الآن لحضور المؤتمر الدولي العاشر " u8"ليونيكود (Unicode Conference)، الذي سيعقد في 10-12 " u8"آذار 1997 بمدينة مَايِنْتْس، ألمانيا. و سيجمع المؤتمر " u8"بين خبراء من كافة قطاعات الصناعة على الشبكة " u8"العالمية انترنيت ويونيكود، حيث ستتم، على الصعيدين " u8"الدولي والمحلي على حد سواء مناقشة سبل استخدام " u8"يونكود في النظم القائمة وفيما يخص التطبيقات " u8"الحاسوبية، الخطوط، تصميم النصوص والحوسبة متعددة " u8"اللغات."), sParaText); } DECLARE_OOXMLEXPORT_TEST(testTdf105444, "tdf105444.docx") { xmlDocPtr pXmlComm = parseExport("word/comments.xml"); if (!pXmlComm) return; // there is no extra paragraph on Win32, only a single one. assertXPath(pXmlComm, "/w:comments/w:comment/w:p", 1); } DECLARE_OOXMLEXPORT_TEST(testTdf117137, "tdf117137.docx") { // Paragraphs were not part of a numbering anymore after roundtrip. uno::Reference xPara1(getParagraph(1), uno::UNO_QUERY); CPPUNIT_ASSERT(xPara1.is()); CPPUNIT_ASSERT(xPara1->getPropertyValue("NumberingRules").hasValue()); uno::Reference xPara2(getParagraph(2), uno::UNO_QUERY); CPPUNIT_ASSERT(xPara2.is()); CPPUNIT_ASSERT(xPara2->getPropertyValue("NumberingRules").hasValue()); uno::Reference xPara3(getParagraph(3), uno::UNO_QUERY); CPPUNIT_ASSERT(xPara3.is()); CPPUNIT_ASSERT(xPara3->getPropertyValue("NumberingRules").hasValue()); } DECLARE_OOXMLEXPORT_TEST(testTdf99631, "tdf99631.docx") { xmlDocPtr pXmlDoc = parseExport("word/document.xml"); if (!pXmlDoc) return; assertXPath(pXmlDoc, "//w:object", 2); assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:object", 2); // first XSLX OLE object (1:1 scale) assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[1]/w:object[1]", "dxaOrig", "2560"); assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[1]/w:object[1]", "dyaOrig", "513"); // second XLSX OLE object (same content + 1 row, but zoomed) assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:object[1]", "dxaOrig", "2560"); assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:object[1]", "dyaOrig", "768"); } DECLARE_OOXMLEXPORT_TEST(testTdf122563, "tdf122563.docx") { xmlDocPtr pXmlDoc = parseExport("word/document.xml"); if (!pXmlDoc) return; assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:object", 1); // Size of the embedded OLE spreadsheet was the bad "width:28.35pt;height:28.35pt" assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[1]/w:object/v:shape", "style", "width:255.75pt;height:63.75pt"); } CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */