Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / core / text / porrst.cxx
blobf2e14e7f7f314e35824a921c7c834851451b9c6d
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 <doc.hxx>
16 #include <frame.hxx>
17 #include <layfrm.hxx>
18 #include <pagefrm.hxx>
19 #include <rootfrm.hxx>
20 #include <txtfrm.hxx>
21 #include <sortedobjs.hxx>
23 namespace
25 /// Covers sw/source/core/text/porrst.cxx fixes.
26 class Test : public SwModelTestBase
28 public:
29 Test()
30 : SwModelTestBase("/sw/qa/core/text/data/")
35 CPPUNIT_TEST_FIXTURE(Test, testFloattableLeftoverParaPortion)
37 // Given a document with a multi-page floating table, the anchor of the table has some text:
38 createSwDoc("floattable-leftover-para-portion.docx");
40 // When laying out that document:
41 calcLayout();
43 // Then make sure all anchor text goes to the second page:
44 SwDoc* pDoc = getSwDoc();
45 SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
46 auto pPage = dynamic_cast<SwPageFrame*>(pLayout->Lower());
47 CPPUNIT_ASSERT(pPage);
48 SwFrame* pBody = pPage->FindBodyCont();
49 SwFrame* pPara1 = pBody->GetLower();
50 auto pPara2 = pPara1->GetNext()->DynCastTextFrame();
51 CPPUNIT_ASSERT(pPara2);
52 // Without the accompanying fix in place, this test would have failed, the first page's anchor
53 // also had some (duplicated) anchor text.
54 CPPUNIT_ASSERT(!pPara2->GetPara());
57 CPPUNIT_TEST_FIXTURE(Test, testFloattableAnchorHeight)
59 #if !defined(MACOSX) // FIXME fails on macOS
60 // Given 3 tables, innermost table on pages 2-3-4:
61 createSwDoc("floattable-anchor-height.docx");
63 // When laying out the document:
64 calcLayout();
66 // Then make sure the flys are on the expected pages:
67 SwDoc* pDoc = getSwDoc();
68 SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
69 auto pPage1 = pLayout->Lower()->DynCastPageFrame();
70 CPPUNIT_ASSERT(pPage1);
71 CPPUNIT_ASSERT(!pPage1->GetSortedObjs());
72 auto pPage2 = pPage1->GetNext()->DynCastPageFrame();
73 CPPUNIT_ASSERT(pPage2);
74 SwSortedObjs* pPage2Objs = pPage2->GetSortedObjs();
75 CPPUNIT_ASSERT(pPage2Objs);
76 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage2Objs->size());
77 auto pPage3 = pPage2->GetNext()->DynCastPageFrame();
78 CPPUNIT_ASSERT(pPage3);
79 SwSortedObjs* pPage3Objs = pPage3->GetSortedObjs();
80 CPPUNIT_ASSERT(pPage3Objs);
81 // Without the accompanying fix in place, this test would have failed with:
82 // - Expected: 1
83 // - Actual : 2
84 // i.e. page 3 also had the fly frame of page 4 as well.
85 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage3Objs->size());
86 auto pPage4 = pPage3->GetNext()->DynCastPageFrame();
87 SwSortedObjs* pPage4Objs = pPage4->GetSortedObjs();
88 CPPUNIT_ASSERT(pPage4Objs);
89 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage4Objs->size());
90 #endif
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */