1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <swmodeltestbase.hxx>
14 #include <IDocumentLayoutAccess.hxx>
15 #include <rootfrm.hxx>
16 #include <sortedobjs.hxx>
17 #include <anchoredobject.hxx>
18 #include <pagefrm.hxx>
25 /// Covers sw/source/core/text/frmform.cxx fixes.
26 class Test
: public SwModelTestBase
30 : SwModelTestBase("/sw/qa/core/text/data/")
35 CPPUNIT_TEST_FIXTURE(Test
, testFloattableNegativeVertOffset
)
37 // Given a document with 2 paragraphs, floating table is between the two (so anchored to the
38 // 2nd) and with a negative vertical offset:
39 createSwDoc("floattable-negative-vert-offset.docx");
41 // When laying out that document:
44 // Then make sure that the negative vertical offset shifts both paragraphs down:
45 SwDoc
* pDoc
= getSwDoc();
46 SwRootFrame
* pLayout
= pDoc
->getIDocumentLayoutAccess().GetCurrentLayout();
47 auto pPage
= dynamic_cast<SwPageFrame
*>(pLayout
->Lower());
48 CPPUNIT_ASSERT(pPage
);
49 CPPUNIT_ASSERT(pPage
->GetSortedObjs());
50 const SwSortedObjs
& rPageObjs
= *pPage
->GetSortedObjs();
51 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs
.size());
52 SwAnchoredObject
* pPageObj
= rPageObjs
[0];
53 const SwRect
& rFlyRect
= pPageObj
->GetObjRectWithSpaces();
54 SwFrame
* pBody
= pPage
->FindBodyCont();
55 SwFrame
* pPara1
= pBody
->GetLower();
56 SwFrame
* pPara2
= pPara1
->GetNext();
57 // Without the accompanying fix in place, this test would have failed with:
58 // - Expected less than: 993
60 // i.e. the expectation that the fly doesn't overlap with the 2nd paragraph was not true.
61 // Instead we got a layout loop, aborted by the loop control, and the fly overlapped with the
63 CPPUNIT_ASSERT_LESS(pPara2
->getFrameArea().Top(), rFlyRect
.Bottom());
66 CPPUNIT_TEST_FIXTURE(Test
, testFloattableAvoidManipOfst
)
68 // Given a document with a 6-page floating table and some anchor text:
69 createSwDoc("floattable-avoid-manip-ofst.docx");
71 // When laying out that document:
74 // Then make sure all anchor text is on the last page:
75 SwDoc
* pDoc
= getSwDoc();
76 SwRootFrame
* pLayout
= pDoc
->getIDocumentLayoutAccess().GetCurrentLayout();
77 SwPageFrame
* pLastPage
= pLayout
->GetLastPage();
78 SwLayoutFrame
* pBodyFrame
= pLastPage
->FindBodyCont();
79 SwTextFrame
* pAnchor
= pBodyFrame
->GetLower()->DynCastTextFrame();
80 // If this is not 0, that means some of the anchor text is shifted to a previous page, while
81 // anchors of non-last split fly frames should contain no text.
82 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), pAnchor
->GetOffset().get());
85 CPPUNIT_TEST_FIXTURE(Test
, testFloattableAvoidLastManipOfst
)
87 // Given a document with a 5-page floating table and some anchor text:
88 createSwDoc("floattable-avoid-last-manip-ofst.docx");
89 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
90 pWrtShell
->SttEndDoc(/*bStt=*/false);
91 pWrtShell
->Insert2("dt");
93 // When expanding dummy text on the last page:
94 dispatchCommand(mxComponent
, ".uno:ExpandGlossary", {});
96 // Then make sure the expanded text starts on page 5:
97 SwDoc
* pDoc
= getSwDocShell()->GetDoc();
98 SwRootFrame
* pLayout
= pDoc
->getIDocumentLayoutAccess().GetCurrentLayout();
99 auto pPage1
= dynamic_cast<SwPageFrame
*>(pLayout
->Lower());
100 CPPUNIT_ASSERT(pPage1
);
101 auto pPage2
= dynamic_cast<SwPageFrame
*>(pPage1
->GetNext());
102 CPPUNIT_ASSERT(pPage2
);
103 auto pPage3
= dynamic_cast<SwPageFrame
*>(pPage2
->GetNext());
104 CPPUNIT_ASSERT(pPage3
);
105 auto pPage4
= dynamic_cast<SwPageFrame
*>(pPage3
->GetNext());
106 CPPUNIT_ASSERT(pPage4
);
107 auto pPage5
= dynamic_cast<SwPageFrame
*>(pPage4
->GetNext());
108 CPPUNIT_ASSERT(pPage5
);
109 SwContentFrame
* pAnchor
= pPage5
->FindFirstBodyContent();
110 SwTextFrame
* pAnchorText
= pAnchor
->DynCastTextFrame();
111 // Without the accompanying fix in place, this test would have failed with:
114 // i.e. the expand result went to page 4 and page 5 (page 5's content had no zero offset),
115 // instead of starting on page 5 (and creating a 6th page).
116 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0),
117 static_cast<sal_Int32
>(pAnchorText
->GetOffset()));
120 CPPUNIT_TEST_FIXTURE(Test
, testFloattableBadFlyPos
)
122 // Given a document with an inner floating table on page 2 -> 4:
123 // When laying out that document:
124 createSwDoc("floattable-bad-fly-pos.docx");
126 // Then make sure that pages 2 -> 4 get the 3 fly frames:
127 SwDoc
* pDoc
= getSwDoc();
128 SwRootFrame
* pLayout
= pDoc
->getIDocumentLayoutAccess().GetCurrentLayout();
129 auto pPage1
= pLayout
->Lower()->DynCastPageFrame();
130 CPPUNIT_ASSERT(pPage1
);
131 CPPUNIT_ASSERT(!pPage1
->GetSortedObjs());
132 auto pPage2
= pPage1
->GetNext()->DynCastPageFrame();
133 CPPUNIT_ASSERT(pPage2
);
134 CPPUNIT_ASSERT(pPage2
->GetSortedObjs());
135 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage2
->GetSortedObjs()->size());
136 auto pPage3
= pPage2
->GetNext()->DynCastPageFrame();
137 CPPUNIT_ASSERT(pPage3
);
138 CPPUNIT_ASSERT(pPage3
->GetSortedObjs());
139 // Without the accompanying fix in place, this test would have failed with:
142 // i.e. the fly on page 4 was still on page 3.
143 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage3
->GetSortedObjs()->size());
144 auto pPage4
= pPage3
->GetNext()->DynCastPageFrame();
145 CPPUNIT_ASSERT(pPage4
);
146 CPPUNIT_ASSERT(pPage4
->GetSortedObjs());
147 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage4
->GetSortedObjs()->size());
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */