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 // FIXME: because breaking the lines at the right place, test document became obsolete
68 CPPUNIT_TEST_FIXTURE(Test
, testFloattableAvoidManipOfst
)
70 // Given a document with a 6-page floating table and some anchor text:
71 createSwDoc("floattable-avoid-manip-ofst.docx");
73 // When laying out that document:
76 // Then make sure all anchor text is on the last page:
77 SwDoc
* pDoc
= getSwDoc();
78 SwRootFrame
* pLayout
= pDoc
->getIDocumentLayoutAccess().GetCurrentLayout();
79 SwPageFrame
* pLastPage
= pLayout
->GetLastPage();
80 SwLayoutFrame
* pBodyFrame
= pLastPage
->FindBodyCont();
81 SwTextFrame
* pAnchor
= pBodyFrame
->GetLower()->DynCastTextFrame();
82 // If this is not 0, that means some of the anchor text is shifted to a previous page, while
83 // anchors of non-last split fly frames should contain no text.
84 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), pAnchor
->GetOffset().get());
88 CPPUNIT_TEST_FIXTURE(Test
, testFloattableAvoidLastManipOfst
)
90 // Given a document with a 5-page floating table and some anchor text:
91 createSwDoc("floattable-avoid-last-manip-ofst.docx");
92 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
93 pWrtShell
->SttEndDoc(/*bStt=*/false);
94 pWrtShell
->Insert2("dt");
96 // When expanding dummy text on the last page:
97 dispatchCommand(mxComponent
, ".uno:ExpandGlossary", {});
99 // Then make sure the expanded text starts on page 5:
100 SwDoc
* pDoc
= getSwDocShell()->GetDoc();
101 SwRootFrame
* pLayout
= pDoc
->getIDocumentLayoutAccess().GetCurrentLayout();
102 auto pPage1
= dynamic_cast<SwPageFrame
*>(pLayout
->Lower());
103 CPPUNIT_ASSERT(pPage1
);
104 auto pPage2
= dynamic_cast<SwPageFrame
*>(pPage1
->GetNext());
105 CPPUNIT_ASSERT(pPage2
);
106 auto pPage3
= dynamic_cast<SwPageFrame
*>(pPage2
->GetNext());
107 CPPUNIT_ASSERT(pPage3
);
108 auto pPage4
= dynamic_cast<SwPageFrame
*>(pPage3
->GetNext());
109 CPPUNIT_ASSERT(pPage4
);
110 auto pPage5
= dynamic_cast<SwPageFrame
*>(pPage4
->GetNext());
111 CPPUNIT_ASSERT(pPage5
);
112 SwContentFrame
* pAnchor
= pPage5
->FindFirstBodyContent();
113 SwTextFrame
* pAnchorText
= pAnchor
->DynCastTextFrame();
114 // Without the accompanying fix in place, this test would have failed with:
117 // i.e. the expand result went to page 4 and page 5 (page 5's content had no zero offset),
118 // instead of starting on page 5 (and creating a 6th page).
119 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0),
120 static_cast<sal_Int32
>(pAnchorText
->GetOffset()));
123 CPPUNIT_TEST_FIXTURE(Test
, testFloattableBadFlyPos
)
125 // Given a document with an inner floating table on page 2 -> 4:
126 // When laying out that document:
127 createSwDoc("floattable-bad-fly-pos.docx");
129 // Then make sure that pages 2 -> 4 get the 3 fly frames:
130 SwDoc
* pDoc
= getSwDoc();
131 SwRootFrame
* pLayout
= pDoc
->getIDocumentLayoutAccess().GetCurrentLayout();
132 auto pPage1
= pLayout
->Lower()->DynCastPageFrame();
133 CPPUNIT_ASSERT(pPage1
);
134 CPPUNIT_ASSERT(!pPage1
->GetSortedObjs());
135 auto pPage2
= pPage1
->GetNext()->DynCastPageFrame();
136 CPPUNIT_ASSERT(pPage2
);
137 CPPUNIT_ASSERT(pPage2
->GetSortedObjs());
138 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage2
->GetSortedObjs()->size());
139 auto pPage3
= pPage2
->GetNext()->DynCastPageFrame();
140 CPPUNIT_ASSERT(pPage3
);
141 CPPUNIT_ASSERT(pPage3
->GetSortedObjs());
142 // Without the accompanying fix in place, this test would have failed with:
145 // i.e. the fly on page 4 was still on page 3.
146 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage3
->GetSortedObjs()->size());
147 auto pPage4
= pPage3
->GetNext()->DynCastPageFrame();
148 CPPUNIT_ASSERT(pPage4
);
149 CPPUNIT_ASSERT(pPage4
->GetSortedObjs());
150 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage4
->GetSortedObjs()->size());
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */