summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2019-10-15 09:04:22 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2019-10-15 22:35:08 +0200
commit758516295e5f69393bd78bb4af6e7214d48ece0b (patch)
tree58f8c59d17af7f41706df3ac64cc3164388f90bf /sw
parent9271152c5fb64a698de167861e39f6b073a60ad6 (diff)
tdf#128148 Add unit test
The implementation of 'SwEditShell::ApplyAdvancedClassification' helped to find out how to access the text in the header. Change-Id: If044eea2e7d012ef56c0fff38a17af4aa59fea25 Reviewed-on: https://gerrit.libreoffice.org/80815 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/mailmerge/data/tdf128148.odtbin0 -> 9289 bytes
-rw-r--r--sw/qa/extras/mailmerge/mailmerge.cxx47
2 files changed, 47 insertions, 0 deletions
diff --git a/sw/qa/extras/mailmerge/data/tdf128148.odt b/sw/qa/extras/mailmerge/data/tdf128148.odt
new file mode 100644
index 000000000000..08b283fc6cf2
--- /dev/null
+++ b/sw/qa/extras/mailmerge/data/tdf128148.odt
Binary files differ
diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx b/sw/qa/extras/mailmerge/mailmerge.cxx
index 7144bd80f358..40d32634ad9a 100644
--- a/sw/qa/extras/mailmerge/mailmerge.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge.cxx
@@ -1215,6 +1215,53 @@ DECLARE_FILE_MAILMERGE_TEST(testTdf123057_file, "pagecounttest.ott", "db_pagecou
}
}
+// 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();
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxMMComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+
+ // 4 documents with 2 pages each => 8 pages in total
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), pTextDoc->GetDocShell()->GetWrtShell()->GetPhyPageNum());
+
+ SwDoc* pDocMM = pTextDoc->GetDocShell()->GetDoc();
+ uno::Reference<frame::XModel> xModel = pTextDoc->GetDocShell()->GetBaseModel();
+ uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
+ uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
+
+ // 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();
+ const bool bIsEvenPage = ((nPageNum % 2) == 0);
+
+ const OUString& sPageStyle = pPageFrm->GetPageDesc()->GetName();
+ uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(sPageStyle), uno::UNO_QUERY);
+
+ bool bHeaderIsOn = false;
+ xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn;
+
+ // 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(OUString("Page 2 of 2"), sHeaderText);
+ }
+
+ pPageFrm = static_cast<const SwPageFrame*>(pPageFrm->GetNext());
+ }
+}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */