summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2018-06-12 08:19:51 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2018-06-12 14:07:47 +0200
commitab665e1c939ec231338f9eac256d37cb1c5afcc9 (patch)
tree3412430b79b91fa604b4a6459197eaaa7b3497b7
parent89f896d2cfd84b711583f98a6343e9835a9aed11 (diff)
tdf#118113 Add unit test
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 <l.lunak@collabora.com> Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r--sw/qa/extras/mailmerge/data/tdf118113.odsbin0 -> 7637 bytes
-rw-r--r--sw/qa/extras/mailmerge/data/tdf118113.odtbin0 -> 21041 bytes
-rw-r--r--sw/qa/extras/mailmerge/mailmerge.cxx42
3 files changed, 42 insertions, 0 deletions
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
--- /dev/null
+++ b/sw/qa/extras/mailmerge/data/tdf118113.ods
Binary files 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
--- /dev/null
+++ b/sw/qa/extras/mailmerge/data/tdf118113.odt
Binary files 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<SwXTextDocument *>(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<drawing::XDrawPageSupplier> xDrawPageSupplier(mxMMComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> 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<sal_uInt16> expectedPageNumbers {1, 3, 5, 9};
+ uno::Reference<beans::XPropertySet> 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]