Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / core / text / itrform2.cxx
blob2d9166b123906e9b587dc21eaf6232057644aef2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <swmodeltestbase.hxx>
12 #include <memory>
14 #include <IDocumentLayoutAccess.hxx>
15 #include <rootfrm.hxx>
16 #include <sortedobjs.hxx>
17 #include <pagefrm.hxx>
18 #include <cntfrm.hxx>
20 namespace
22 /// Covers sw/source/core/text/itrform2.cxx fixes.
23 class Test : public SwModelTestBase
25 public:
26 Test()
27 : SwModelTestBase("/sw/qa/core/text/data/")
32 CPPUNIT_TEST_FIXTURE(Test, testFloattableWrapEmptyParagraph)
34 // Given a document with 2 pages, a floating table on both pages:
35 createSwDoc("floattable-wrap-empty-para.docx");
37 // When calculating the layout:
38 calcLayout();
40 // Then make sure that each page has exactly 1 floating table:
41 SwDoc* pDoc = getSwDoc();
42 SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
43 auto pPage = dynamic_cast<SwPageFrame*>(pLayout->Lower());
44 CPPUNIT_ASSERT(pPage);
45 CPPUNIT_ASSERT(pPage->GetSortedObjs());
46 const SwSortedObjs& rPageObjs = *pPage->GetSortedObjs();
47 // Without the accompanying fix in place, this test would have failed with:
48 // - Expected: 1
49 // - Actual : 2
50 // i.e. both tables were on page 1, leading to an overlap.
51 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs.size());
52 auto pPage2 = dynamic_cast<SwPageFrame*>(pPage->GetNext());
53 CPPUNIT_ASSERT(pPage2);
54 CPPUNIT_ASSERT(pPage2->GetSortedObjs());
55 const SwSortedObjs& rPageObjs2 = *pPage2->GetSortedObjs();
56 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs2.size());
59 CPPUNIT_TEST_FIXTURE(Test, testFloattableLegacyWrapEmptyParagraph)
61 // Given a document with 2 pages, a floating table on both pages (from DOC, so the table is
62 // shifted towards the left page edge slightly):
63 createSwDoc("floattable-wrap-empty-para-legacy.docx");
65 // When calculating the layout:
66 calcLayout();
68 // Then make sure that each page has exactly 1 floating table:
69 SwDoc* pDoc = getSwDoc();
70 SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
71 auto pPage = dynamic_cast<SwPageFrame*>(pLayout->Lower());
72 CPPUNIT_ASSERT(pPage);
73 CPPUNIT_ASSERT(pPage->GetSortedObjs());
74 const SwSortedObjs& rPageObjs = *pPage->GetSortedObjs();
75 // Without the accompanying fix in place, this test would have failed with:
76 // - Expected: 1
77 // - Actual : 2
78 // i.e. both tables were on page 1, leading to an overlap.
79 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs.size());
80 auto pPage2 = dynamic_cast<SwPageFrame*>(pPage->GetNext());
81 CPPUNIT_ASSERT(pPage2);
82 CPPUNIT_ASSERT(pPage2->GetSortedObjs());
83 const SwSortedObjs& rPageObjs2 = *pPage2->GetSortedObjs();
84 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs2.size());
87 CPPUNIT_TEST_FIXTURE(Test, testFlyMinimalWrap)
89 // Given a document with a first page that has a shape and a table in it (not floating table),
90 // some empty paragraphs wrapping around the shape:
91 createSwDoc("fly-minimal-wrap.docx");
93 // When calculating the layout:
94 calcLayout();
96 // Then make sure the wrap happens, so the 2nd page only has 2 paragraphs:
97 SwDoc* pDoc = getSwDoc();
98 SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
99 auto pPage = dynamic_cast<SwPageFrame*>(pLayout->Lower());
100 CPPUNIT_ASSERT(pPage);
101 CPPUNIT_ASSERT(pPage->GetSortedObjs());
102 const SwSortedObjs& rPageObjs = *pPage->GetSortedObjs();
103 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rPageObjs.size());
104 auto pPage2 = dynamic_cast<SwPageFrame*>(pPage->GetNext());
105 CPPUNIT_ASSERT(pPage2);
106 CPPUNIT_ASSERT(!pPage2->GetSortedObjs());
107 SwLayoutFrame* pBody2 = pPage2->FindBodyCont();
108 SwFrame* pPage2Para1 = pBody2->GetLower();
109 CPPUNIT_ASSERT(pPage2Para1);
110 SwFrame* pPage2Para2 = pPage2Para1->GetNext();
111 CPPUNIT_ASSERT(pPage2Para2);
112 // Without the accompanying fix in place, this test would have failed, the second page had 19
113 // text frames in the body frame, not 2.
114 CPPUNIT_ASSERT(!pPage2Para2->GetNext());
117 CPPUNIT_TEST_FIXTURE(Test, testContentControlHeaderPDFExport)
119 // Given a document with a content control in the header:
120 createSwDoc("content-control-header.docx");
122 // When exporting to PDF:
123 save("writer_pdf_Export");
125 // Then make sure all the expected text is there on page 2:
126 std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
127 std::unique_ptr<vcl::pdf::PDFiumPage> pPage2 = pPdfDocument->openPage(1);
128 int nTextCount = 0;
129 for (int i = 0; i < pPage2->getObjectCount(); ++i)
131 std::unique_ptr<vcl::pdf::PDFiumPageObject> pObject = pPage2->getObject(i);
132 if (pObject->getType() == vcl::pdf::PDFPageObjectType::Text)
134 ++nTextCount;
137 // Without the accompanying fix in place, this test would have failed with:
138 // - Expected: 3
139 // - Actual : 2
140 // i.e. not all of header, heading and body text was there on page 2, content was lost.
141 CPPUNIT_ASSERT_EQUAL(3, nTextCount);
144 CPPUNIT_TEST_FIXTURE(Test, testSplitFlyAnchorLeftMargin)
146 // Given a document with a floating table, anchor para is followed by an other para with a left
147 // margin:
148 createSwDoc("floattable-anchor-left-margin.docx");
150 // When laying out that document:
151 calcLayout();
153 // Then make sure that the left margin of this last paragraph is not lost:
154 SwDoc* pDoc = getSwDoc();
155 SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
156 auto pPage = dynamic_cast<SwPageFrame*>(pLayout->Lower());
157 CPPUNIT_ASSERT(pPage);
158 SwContentFrame* pLastPara = pPage->FindLastBodyContent();
159 // Without the accompanying fix in place, this test would have failed with:
160 // - Expected: 6480
161 // - Actual : 0
162 // i.e. the left margin was lost.
163 CPPUNIT_ASSERT_EQUAL(static_cast<SwTwips>(6480), pLastPara->getFramePrintArea().Left());
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */