/* -*- 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/.
*/
// Update it.
uno::Reference<text::XDocumentIndex> xTableIndex(xTable, uno::UNO_QUERY);
xTableIndex->update();
// Paragraph index: Reference, table header, table row. // Portion index: ID, etc; then the URL. auto aActual = getProperty<OUString>(getRun(getParagraph(3), 2), u"HyperLinkURL"_ustr); // Without the accompanying fix in place, this test would have failed with: // An uncaught exception of type com.sun.star.container.NoSuchElementException // i.e. the URL was not clickable and the table row was a single text portion.
CPPUNIT_ASSERT_EQUAL(u"http://www.example.com/test.pdf"_ustr, aActual);
}
// When updating that table:
uno::Reference<text::XDocumentIndex> xTableIndex(xTable, uno::UNO_QUERY);
xTableIndex->update();
// Then the page number from the source's URL should be stripped: // Paragraph index: Reference, table header, table row. // Portion index: ID, etc; then the URL. auto aActual = getProperty<OUString>(getRun(getParagraph(3), 2), u"HyperLinkURL"_ustr); // Without the accompanying fix in place, this test would have failed with: // - Expected: http://www.example.com/test.pdf // - Actual : http://www.example.com/test.pdf#page=1 // i.e. the page number was still part of the bibliography table.
CPPUNIT_ASSERT_EQUAL(u"http://www.example.com/test.pdf"_ustr, aActual);
}
CPPUNIT_TEST_FIXTURE(Test, testAuthorityTableEntryClick)
{ // Given an empty document:
createSwDoc();
SwDoc* pDoc = getSwDoc();
// Then make sure that the field is clickable, since the page part will not be part of the // bibliography table: const SwFieldTypes* pTypes = pDoc->getIDocumentFieldsAccess().GetFieldTypes(); auto it = std::find_if(pTypes->begin(), pTypes->end(),
[](const std::unique_ptr<SwFieldType>& pType) { return pType->Which() == SwFieldIds::TableOfAuthorities;
});
CPPUNIT_ASSERT(it != pTypes->end()); const SwFieldType* pType = it->get();
std::vector<SwFormatField*> aFormatFields;
pType->GatherFields(aFormatFields);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aFormatFields.size());
SwField* pField = aFormatFields[0]->GetField(); // Without the accompanying fix in place, this test would have failed, as the field was not // clickable.
CPPUNIT_ASSERT(pField->IsClickable()); // This is needed, so the mouse has the correct RefHand pointer style.
CPPUNIT_ASSERT(pField->HasClickHdl());
}
CPPUNIT_TEST_FIXTURE(Test, testAuthorityTableEntryRelClick)
{ // Given an empty document with a file:// base URL:
createSwDoc();
SwDoc* pDoc = getSwDoc();
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aArgs = {
comphelper::makePropertyValue(u"FilterName"_ustr, u"writer8"_ustr),
};
xStorable->storeAsURL(maTempFile.GetURL(), aArgs);
// When updating that table:
uno::Reference<text::XDocumentIndex> xTableIndex(xTable, uno::UNO_QUERY);
xTableIndex->update();
// Then the first two fields should be merged to a single source, but not the third.
CPPUNIT_ASSERT_EQUAL(u"AT: Author, Title, , http://www.example.com/test.pdf"_ustr,
getParagraph(3)->getString()); // Without the accompanying fix in place, this test would have failed with: // - Expected: AT: Author, Title, , http://www.example.com/test2.pdf // - Actual : AT: Author, Title, , http://www.example.com/test.pdf // i.e. test.pdf was mentioned twice, without deduplication.
CPPUNIT_ASSERT_EQUAL(u"AT: Author, Title, , http://www.example.com/test2.pdf"_ustr,
getParagraph(4)->getString());
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.