/* -*- 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 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(testTdf117504_numberingIndent, "tdf117504_numberingIndent.docx") { OUString sName = getProperty(getParagraph(1), "NumberingStyleName"); CPPUNIT_ASSERT_MESSAGE("Paragraph has numbering style", !sName.isEmpty()); } 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: */