/* -*- 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/.
*/
DECLARE_SHELL_MAILMERGE_TEST(tdf125522_shell, "tdf125522.odt", "10-testing-addresses.ods", "testing-addresses")
{ // prepare unit test and run
executeMailMerge();
// there should be no any text frame in output
CPPUNIT_ASSERT(mxSwTextDocument);
DECLARE_SHELL_MAILMERGE_TEST(testTd78611_shell, "tdf78611.odt", "10-testing-addresses.ods", "testing-addresses")
{ // prepare unit test and run
executeMailMerge();
// check: each page (one page is one sub doc) has different paragraphs and header paragraphs. // All header paragraphs should have numbering.
xmlDocUniquePtr pXmlDoc = parseLayoutDump(static_cast<SfxBaseModel*>(mxSwTextDocument.get()));
DECLARE_SHELL_MAILMERGE_TEST(testTdf122156_shell, "linked-with-condition.odt", "5-with-blanks.ods", "names")
{ // A document with a linked section hidden on an "empty field" condition // For combined documents, hidden sections are removed completely
executeMailMerge();
CPPUNIT_ASSERT(mxSwTextDocument); // 5 documents 1 page each, starting at odd page numbers => 9
CPPUNIT_ASSERT_EQUAL(sal_uInt16(9), mxSwTextDocument->GetDocShell()->GetWrtShell()->GetPhyPageNum());
uno::Reference<container::XIndexAccess> xSections(mxSwTextDocument->getTextSections(),
uno::UNO_QUERY_THROW); // 2 out of 5 dataset records have empty "Title" field => no sections in respective documents
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xSections->getCount());
}
DECLARE_FILE_MAILMERGE_TEST(testTdf122156_file, "linked-with-condition.odt", "5-with-blanks.ods", "names")
{ // A document with a linked section hidden on an "empty field" condition // For separate documents, the sections are removed
executeMailMerge();
{
loadMailMergeDocument(0);
uno::Reference<text::XTextSectionsSupplier> xSectionsSupplier(mxComponent,
uno::UNO_QUERY_THROW);
uno::Reference<container::XIndexAccess> xSections(xSectionsSupplier->getTextSections(),
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSections->getCount());
}
{
loadMailMergeDocument(1);
uno::Reference<text::XTextSectionsSupplier> xSectionsSupplier(mxComponent,
uno::UNO_QUERY_THROW);
uno::Reference<container::XIndexAccess> xSections(xSectionsSupplier->getTextSections(),
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount());
uno::Reference<beans::XPropertySet> xSect(xSections->getByIndex(0), uno::UNO_QUERY_THROW); // Record 2 has non-empty "Title" field => section is shown
CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xSect, u"IsVisible"_ustr));
}
{
loadMailMergeDocument(2);
uno::Reference<text::XTextSectionsSupplier> xSectionsSupplier(mxComponent,
uno::UNO_QUERY_THROW);
uno::Reference<container::XIndexAccess> xSections(xSectionsSupplier->getTextSections(),
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount());
uno::Reference<beans::XPropertySet> xSect(xSections->getByIndex(0), uno::UNO_QUERY_THROW); // Record 3 has non-empty "Title" field => section is shown
CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xSect, u"IsVisible"_ustr));
}
{
loadMailMergeDocument(3);
uno::Reference<text::XTextSectionsSupplier> xSectionsSupplier(mxComponent,
uno::UNO_QUERY_THROW);
uno::Reference<container::XIndexAccess> xSections(xSectionsSupplier->getTextSections(),
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSections->getCount());
}
{
loadMailMergeDocument(4);
uno::Reference<text::XTextSectionsSupplier> xSectionsSupplier(mxComponent,
uno::UNO_QUERY_THROW);
uno::Reference<container::XIndexAccess> xSections(xSectionsSupplier->getTextSections(),
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount());
uno::Reference<beans::XPropertySet> xSect(xSections->getByIndex(0), uno::UNO_QUERY_THROW); // Record 5 has non-empty "Title" field => section is shown
CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xSect, u"IsVisible"_ustr));
}
}
DECLARE_SHELL_MAILMERGE_TEST(testTdf121168, "section_ps.odt", "4_v01.ods", "Tabelle1")
{ // A document starting with a section on a page with non-default page style with header
executeMailMerge();
CPPUNIT_ASSERT(mxSwTextDocument); // 4 documents 1 page each, starting at odd page numbers => 7
CPPUNIT_ASSERT_EQUAL(sal_uInt16(7), mxSwTextDocument->GetDocShell()->GetWrtShell()->GetPhyPageNum());
// get document properties
uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<document::XDocumentProperties> xDocumentProperties(xDocumentPropertiesSupplier->getDocumentProperties());
// check if properties were set
uno::Sequence<OUString> aKeywords(xDocumentProperties->getKeywords());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aKeywords.getLength());
CPPUNIT_ASSERT_EQUAL(u"one two"_ustr, aKeywords[0]);
// check title and subject
CPPUNIT_ASSERT_EQUAL(u"my title"_ustr, xDocumentProperties->getTitle());
CPPUNIT_ASSERT_EQUAL(u"my subject"_ustr, xDocumentProperties->getSubject());
}
}
// problem was: field content was duplicated & truncated
DECLARE_SHELL_MAILMERGE_TEST(testTdf81750_shell, "tdf81750.odt", "10-testing-addresses.ods", "testing-addresses")
{ // prepare unit test and run
executeMailMerge();
// both sections visible, page num is 2
CPPUNIT_ASSERT_EQUAL(2, getPages());
CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xSect0, u"IsVisible"_ustr));
CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xSect1, u"IsVisible"_ustr)); break; case 1:
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount());
xSect0.set(xSections->getByIndex(0), uno::UNO_QUERY_THROW);
// second section removed, page num is 1
CPPUNIT_ASSERT_EQUAL(1, getPages());
CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xSect0, u"IsVisible"_ustr)); break; case 2:
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount());
xSect0.set(xSections->getByIndex(0), uno::UNO_QUERY_THROW);
// first section removed, page num is 1
CPPUNIT_ASSERT_EQUAL(1, getPages());
CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xSect0, u"IsVisible"_ustr)); break; case 3:
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSections->getCount()); // both sections removed, page num is 1
CPPUNIT_ASSERT_EQUAL(1, getPages()); break;
}
}
}
// The document has a header with page number and total page count on page 2 // (which uses page style "Default Style") but doesn't have a header set // for the first page (which uses page style "First Page"). // Fields in the header hadn't been replaced properly.
DECLARE_SHELL_MAILMERGE_TEST(testTdf128148, "tdf128148.odt", "4_v01.ods", "Tabelle1")
{
executeMailMerge();
CPPUNIT_ASSERT(mxSwTextDocument);
// 4 documents with 2 pages each => 8 pages in total
CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), mxSwTextDocument->GetDocShell()->GetWrtShell()->GetPhyPageNum());
// All odd pages have no header, all even pages should have header with text "Page 2 of 2" const SwRootFrame* pLayout = pDocMM->getIDocumentLayoutAccess().GetCurrentLayout(); const SwPageFrame* pPageFrm = static_cast<const SwPageFrame*>(pLayout->Lower()); while (pPageFrm)
{ const sal_uInt16 nPageNum = pPageFrm->GetPhyPageNum(); constbool bIsEvenPage = ((nPageNum % 2) == 0);
// first page for every data record shouldn't have header, second should
CPPUNIT_ASSERT_EQUAL(bIsEvenPage, bHeaderIsOn); if (bIsEvenPage)
{ // text in header on even pages with correctly replaced fields is "Page 2 of 2"
uno::Reference<text::XText> xHeaderText;
xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText; const OUString sHeaderText = xHeaderText->getString();
CPPUNIT_ASSERT_EQUAL(u"Page 2 of 2"_ustr, sHeaderText);
}
// check font is Arial - comes from theme (wrong result was "" - nothing)
uno::Reference<text::XText> const xCell(xTable->getCellByName(u"A1"_ustr), uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> const xParaA1(getParagraphOrTable(1, xCell->getText()), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(u"Arial"_ustr, getProperty<OUString>(xParaA1, u"CharFontName"_ustr));
}
CPPUNIT_TEST_FIXTURE(MMTest2, testTdf156061)
{ // Given a document with a paragraph with a database field having empty content
createSwDoc("empty-db-field.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump(); // The first paragraph is a text followed by the DB field; the second is empty. // Check that both are visible (have proper height).
assertXPath(pXmlDoc, "//txt", 2);
// Without the fix, it was "0"
CPPUNIT_ASSERT_GREATER(sal_Int32(260),
getXPath(pXmlDoc, "//txt[1]/infos/bounds", "height").toInt32());
CPPUNIT_ASSERT_GREATER(sal_Int32(260),
getXPath(pXmlDoc, "//txt[2]/infos/bounds", "height").toInt32());
}
// The document has a MM field referencing a date in the data source having a single record. // The check ensures that the date arrives correctly to the merged document.
DECLARE_SHELL_MAILMERGE_TEST(testTdf168252, "mm-single-date.fodt", "single-date.ods", "Sheet1")
{
executeMailMerge();
CPPUNIT_ASSERT(mxSwTextDocument);
// Without the fix, this would fail with // - Expected: 2025-08-31 // - Actual : 2025-09-02 // because the DB filed code assumed obsolete null date.
CPPUNIT_ASSERT_EQUAL(u"2025-08-31"_ustr, mxSwTextDocument->getText()->getString());
}
} // end of anonymous namespace namespace com::sun::star::table {
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.