/* -*- 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/.
*/
// Get the tooltip of the field.
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
SwPaM* pCursor = pWrtShell->GetCursor(); auto pField = dynamic_cast<SwAuthorityField*>(
SwCursorShell::GetFieldAtCursor(pCursor, /*bIncludeInputFieldAtStart=*/true));
CPPUNIT_ASSERT(pField); const SwRootFrame* pLayout = pWrtShell->GetLayout();
OUString aTooltip = pField->GetAuthority(pLayout);
// Without the accompanying fix in place, generating this tooltip text was not possible without // first inserting an empty bibliography table into the document.
CPPUNIT_ASSERT_EQUAL(u"ARJ00: Ar, J, mytitle, 2020"_ustr, aTooltip);
}
// Field: Chapter Format: Chapter number and name
xField.set(xFields->nextElement(), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"Chapter 2 - Another title"_ustr, xField->getPresentation(false));
// SwModify::Add() enumerates in invalid (mostly reverse) order, not like in document
std::vector<OUString> aFieldValues = {
u"Followed by tab"_ustr, // #1
u"I.I.I.I"_ustr, // #16
u">I.I.I.I< Followed by newline"_ustr, // #15 Linefeed is replaced by space
u">I.I.I.I<"_ustr, // #14
u"Followed by newline"_ustr, // #13
u"I.I.I"_ustr, // #12
u">I.I.I_ustr, // #11 Nothing between text & outline
u">I.I.I<"_ustr, // #10
u"Followed by nothing"_ustr, // #9
u"I.I"_ustr, // #8
u">I.I< Followed by space"_ustr, // #7 Space as is
u">I.I<"_ustr, // #6
u"Followed by space"_ustr, // #5
u"I"_ustr, // #4
u">I< Followed by tab"_ustr, // #3 Here is a tab, but replaced by space in field
u">I<"_ustr, // #2
};
/// If there is referenced text both above and below, STYLEREF searches up
CPPUNIT_TEST_FIXTURE(Test, testStyleRefSearchUp)
{ // Arrange // Create a document with headings both above and below a cursor
createSwDoc();
InsertHeading(xCursor, u"Heading far above field"_ustr);
InsertHeading(xCursor, u"Heading above field"_ustr);
InsertParagraphBreak(xCursor);
InsertHeading(xCursor, u"Heading below field"_ustr);
InsertHeading(xCursor, u"Heading far below field"_ustr);
uno::Reference<text::XParagraphCursor> xParagraphCursor(xCursor, uno::UNO_QUERY);
xParagraphCursor->gotoPreviousParagraph(false); // Heading far below...
xParagraphCursor->gotoPreviousParagraph(false); // Heading below...
xParagraphCursor->gotoPreviousParagraph(false); // Blank space
// Act // Insert a STYLEREF field which looks for "Heading 1"s
uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextField> xField(
xFactory->createInstance(u"com.sun.star.text.TextField.GetReference"_ustr), uno::UNO_QUERY);
// Assert // Make sure the field has the right text
CPPUNIT_ASSERT_EQUAL(u"Heading above field"_ustr, xField->getPresentation(false));
}
/// If there is referenced text only below, STYLEREF searches down
CPPUNIT_TEST_FIXTURE(Test, testStyleRefSearchDown)
{ // Arrange // Create a document with headings below a cursor
createSwDoc();
InsertParagraphBreak(xCursor);
InsertHeading(xCursor, u"Heading below field"_ustr);
InsertHeading(xCursor, u"Heading far below field"_ustr);
uno::Reference<text::XParagraphCursor> xParagraphCursor(xCursor, uno::UNO_QUERY);
xParagraphCursor->gotoPreviousParagraph(false); // Heading far below...
xParagraphCursor->gotoPreviousParagraph(false); // Heading below...
xParagraphCursor->gotoPreviousParagraph(false); // Blank space
// Act // Insert a STYLEREF field which looks for "Heading 1"s
uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextField> xField(
xFactory->createInstance(u"com.sun.star.text.TextField.GetReference"_ustr), uno::UNO_QUERY);
// Assert // Make sure the field has the right text
CPPUNIT_ASSERT_EQUAL(u"Heading below field"_ustr, xField->getPresentation(false));
}
/// STYLEREFs in marginals (headers or footers) should search in the page they are on first, regardless if there is anything above them
CPPUNIT_TEST_FIXTURE(Test, testMarginalStyleRef)
{ // Arrange // Create a document with 2 headings
createSwDoc();
InsertHeading(xCursor, u"Top heading on page"_ustr);
InsertHeading(xCursor, u"Bottom heading on page"_ustr);
// Act // Insert a STYLEREF field which looks for "Heading 1"s into the footer
uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextField> xField(
xFactory->createInstance(u"com.sun.star.text.TextField.GetReference"_ustr), uno::UNO_QUERY);
// Assert // Make sure the field has the right text
CPPUNIT_ASSERT_EQUAL(u"Top heading on page"_ustr, xField->getPresentation(false));
}
/// STYLEREFs in footnotes should search from the point of the reference mark
CPPUNIT_TEST_FIXTURE(Test, testFootnoteStyleRef)
{ // Arrange // Create a document with headings both above and below a cursor
createSwDoc();
uno::Reference<text::XParagraphCursor> xParagraphCursor(xCursor, uno::UNO_QUERY);
xParagraphCursor->gotoPreviousParagraph(false); // Heading far below...
xParagraphCursor->gotoPreviousParagraph(false); // Heading below...
xParagraphCursor->gotoPreviousParagraph(false); // Blank space
// Act // Insert a STYLEREF field which looks for "Heading 1"s into a footnote
uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
// Assert // Make sure the field has the right text
CPPUNIT_ASSERT_EQUAL(u"Heading above reference mark"_ustr, xField->getPresentation(false));
}
/// STYLEREFs with the REFFLDFLAG_HIDE_NON_NUMERICAL flag should hide all characters that are not numerical or delimiters
CPPUNIT_TEST_FIXTURE(Test, testNumericalStyleRef)
{
createSwDoc("suppress-non-numerical.docx");
/// We should be able to import these flags from OOXML documents /// (Note: in Word, STYLEREF 'search bottom up' flag does nothing unless it's in a marginal, we place no such limitation but /// this docx only has such stylerefs to avoid confusion)
CPPUNIT_TEST_FIXTURE(Test, testOOXMLStyleRefFlags)
{
createSwDoc("styleref-flags.docx");
// Similarly to testChapterFieldsFollowedBy, the fields are enumerated with #1 first and everything else in reverse order
std::vector<std::pair<OUString, OUString>> aFieldValues = {
{ " Heading 2", "2.1" }, // #1
{ " Heading 1", "3" }, // #5
{ " Heading 1", "A top level heading at the top of the page" }, // #4
{ " Heading 1", "The last top level heading" }, // #3
{ " Heading 2", "Heading 2.1" }, // #2
};
/// We should be able to import these flags from OOXML documents /// (Note: in Word, STYLEREF 'search bottom up' flag does nothing unless it's in a marginal, we place no such limitation but /// this docx only has such stylerefs to avoid confusion)
CPPUNIT_TEST_FIXTURE(Test, testODFStyleRef)
{ // if createSwDoc is used then calcLayout is called and the field values are different
loadFromFile(u"styleref.odt");
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.