summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJan-Marek Glogowski <jan-marek.glogowski@extern.cib.de>2020-01-31 16:53:47 +0000
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2020-02-03 14:42:59 +0100
commit4db184ea279a2974679b05eaa8ca52ec087f68af (patch)
treee3bc3315d9d2ed1324602719462010e0e57a066c /sw
parentf7c4be8d8ab59859f32062f4a6401a9cf9001e4d (diff)
Unit test for stable at-page anchored fly position
This is the unit test for commit 5cee586a97a11c23dd252accc42099bd5e9b4187 ("sw: fix moving of at-page anchored flys to different page"). Originally the error was just triggered by toggling "View -> Field Names". Luckily it's also triggered by adding some text to page four, so no need for some UI test. Change-Id: I3a63b50dd898788607c3d24a848d8f43ae966377 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87776 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de> (cherry picked from commit 5fed8bb5f6f65963fed27f96de3be14dff830d38) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87847 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/layout/data/stable-at-page-anchored-fly-position.odtbin0 -> 11244 bytes
-rw-r--r--sw/qa/extras/layout/layout.cxx43
2 files changed, 43 insertions, 0 deletions
diff --git a/sw/qa/extras/layout/data/stable-at-page-anchored-fly-position.odt b/sw/qa/extras/layout/data/stable-at-page-anchored-fly-position.odt
new file mode 100644
index 000000000000..e5a3779c54c5
--- /dev/null
+++ b/sw/qa/extras/layout/data/stable-at-page-anchored-fly-position.odt
Binary files differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index a3fe52906677..3ca4171a205b 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -3615,6 +3615,49 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf117982)
//the source document.
}
+static SwRect lcl_getVisibleFlyObjRect(SwWrtShell* pWrtShell)
+{
+ SwRootFrame* pRoot = pWrtShell->GetLayout();
+ SwPageFrame* pPage = static_cast<SwPageFrame*>(pRoot->GetLower());
+ pPage = static_cast<SwPageFrame*>(pPage->GetNext());
+ pPage = static_cast<SwPageFrame*>(pPage->GetNext());
+ SwSortedObjs* pDrawObjs = pPage->GetDrawObjs();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDrawObjs->size());
+ SwAnchoredObject* pDrawObj = (*pDrawObjs)[0];
+ CPPUNIT_ASSERT_EQUAL(OUString("Rahmen8"), pDrawObj->GetFrameFormat().GetName());
+ pPage = static_cast<SwPageFrame*>(pPage->GetNext());
+ pDrawObjs = pPage->GetDrawObjs();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDrawObjs->size());
+ pDrawObj = (*pDrawObjs)[0];
+ CPPUNIT_ASSERT_EQUAL(OUString("Rahmen123"), pDrawObj->GetFrameFormat().GetName());
+ SwRect aFlyRect = pDrawObj->GetObjRect();
+ CPPUNIT_ASSERT(pPage->getFrameArea().IsInside(aFlyRect));
+ return aFlyRect;
+}
+
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testStableAtPageAnchoredFlyPosition)
+{
+ // this doc has two page-anchored frames: one tiny on page 3 and one large on page 4.
+ // it also has a style:master-page named "StandardEntwurf", which contains some fields.
+ // if you add a break to page 2, or append some text to page 4 (or just toggle display field names),
+ // the page anchored frame on page 4 vanishes, as it is incorrectly moved out of the page bounds.
+ SwDoc* pDoc = createDoc("stable-at-page-anchored-fly-position.odt");
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+ // look up the layout position of the page-bound frame on page four
+ SwRect aOrigRect = lcl_getVisibleFlyObjRect(pWrtShell);
+
+ // append some text to the document to trigger bug / relayout
+ pWrtShell->SttEndDoc(false);
+ pWrtShell->Insert("foo");
+
+ // get the current position of the frame on page four
+ SwRect aRelayoutRect = lcl_getVisibleFlyObjRect(pWrtShell);
+
+ // the anchored frame should not have moved
+ CPPUNIT_ASSERT_EQUAL(aOrigRect, aRelayoutRect);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */