From ab665e1c939ec231338f9eac256d37cb1c5afcc9 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Tue, 12 Jun 2018 08:19:51 +0200 Subject: tdf#118113 Add unit test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The unit test uses the sample documents attached to the Bugzilla issue. Change-Id: I7233903212b9c79930e1b1af737d915755f737e9 Reviewed-on: https://gerrit.libreoffice.org/55656 Reviewed-by: Luboš Luňák Tested-by: Jenkins --- sw/qa/extras/mailmerge/data/tdf118113.ods | Bin 0 -> 7637 bytes sw/qa/extras/mailmerge/data/tdf118113.odt | Bin 0 -> 21041 bytes sw/qa/extras/mailmerge/mailmerge.cxx | 42 ++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 sw/qa/extras/mailmerge/data/tdf118113.ods create mode 100644 sw/qa/extras/mailmerge/data/tdf118113.odt (limited to 'sw/qa/extras/mailmerge') diff --git a/sw/qa/extras/mailmerge/data/tdf118113.ods b/sw/qa/extras/mailmerge/data/tdf118113.ods new file mode 100644 index 000000000000..1d7e3cfb5dec Binary files /dev/null and b/sw/qa/extras/mailmerge/data/tdf118113.ods differ diff --git a/sw/qa/extras/mailmerge/data/tdf118113.odt b/sw/qa/extras/mailmerge/data/tdf118113.odt new file mode 100644 index 000000000000..89e7bc304869 Binary files /dev/null and b/sw/qa/extras/mailmerge/data/tdf118113.odt differ diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx b/sw/qa/extras/mailmerge/mailmerge.cxx index da7b168b61e3..5a647efff1c0 100644 --- a/sw/qa/extras/mailmerge/mailmerge.cxx +++ b/sw/qa/extras/mailmerge/mailmerge.cxx @@ -677,6 +677,48 @@ DECLARE_FILE_MAILMERGE_TEST(testTdf102010, "empty.odt", "10-testing-addresses.od loadMailMergeDocument( 1 ); } +DECLARE_SHELL_MAILMERGE_TEST(testTdf118113, "tdf118113.odt", "tdf118113.ods", "testing-addresses") +{ + executeMailMerge(); + + // The document contains a text box anchored to the page and a conditionally hidden + // section that is only shown for one of the 4 recipients, namely the 3rd record. + // In case the hidden section is shown, the page count is 3 for a single data entry, otherwise 1. + // Previously, the page number was calculated incorrectly which led to the + // text box being anchored to the wrong page. + + SwXTextDocument* pTextDoc = dynamic_cast(mxMMComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + // 3 documents with 1 page size each + 1 document with 3 pages + // + an additional page after each of the first 3 documents to make + // sure that each document starts on an odd page number + sal_uInt16 nPhysPages = pTextDoc->GetDocShell()->GetWrtShell()->GetPhyPageNum(); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(9), nPhysPages); + + // verify that there is a text box for each data record + uno::Reference xDrawPageSupplier(mxMMComponent, uno::UNO_QUERY); + uno::Reference xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xDraws->getCount()); + + // verify the text box for each data record is anchored to the first page of the given data record's pages + std::vector expectedPageNumbers {1, 3, 5, 9}; + uno::Reference xPropertySet; + for (sal_Int32 i = 0; i < xDraws->getCount(); i++) + { + xPropertySet.set(xDraws->getByIndex(i), uno::UNO_QUERY); + + text::TextContentAnchorType nAnchorType; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue( UNO_NAME_ANCHOR_TYPE ) >>= nAnchorType); + CPPUNIT_ASSERT_EQUAL( text::TextContentAnchorType_AT_PAGE, nAnchorType ); + + sal_uInt16 nAnchorPageNo = {}; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue( UNO_NAME_ANCHOR_PAGE_NO ) >>= nAnchorPageNo); + + CPPUNIT_ASSERT_EQUAL(expectedPageNumbers.at(i), nAnchorPageNo); + } +} + + namespace { constexpr char const* const EmptyValuesLegacyData[][8] -- cgit