Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / core / draw / draw.cxx
blob0cb50649a652d3d7637fe1ecdbc72071114d6bf4
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 <svx/svdpage.hxx>
14 #include <IDocumentDrawModelAccess.hxx>
15 #include <docsh.hxx>
16 #include <drawdoc.hxx>
17 #include <wrtsh.hxx>
18 #include <frameformats.hxx>
19 #include <textboxhelper.hxx>
21 #include <com/sun/star/table/BorderLine2.hpp>
22 #include <com/sun/star/text/XTextFramesSupplier.hpp>
24 /// Covers sw/source/core/draw/ fixes.
25 class SwCoreDrawTest : public SwModelTestBase
27 public:
28 SwCoreDrawTest()
29 : SwModelTestBase("/sw/qa/core/draw/data/")
34 CPPUNIT_TEST_FIXTURE(SwCoreDrawTest, testTextboxDeleteAsChar)
36 // Load a document with an as-char shape in it that has a textbox and an image in it.
37 createSwDoc("as-char-textbox.docx");
38 SwDoc* pDoc = getSwDoc();
39 SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
40 SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
41 sal_Int32 nActual = pPage->GetObjCount();
42 // 3 objects on the draw page: a shape + fly frame pair and a Writer image.
43 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), nActual);
45 // Select the shape of the textbox and delete it.
46 SdrObject* pObject = pPage->GetObj(0);
47 pWrtShell->SelectObj(Point(), 0, pObject);
48 pWrtShell->DelSelectedObj();
49 nActual = pPage->GetObjCount();
51 // Without the accompanying fix in place, this test would have failed with:
52 // - Expected: 0
53 // - Actual : 2
54 // i.e. the fly frame of the shape and the inner Writer image was not deleted.
55 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nActual);
58 CPPUNIT_TEST_FIXTURE(SwCoreDrawTest, testTextboxUndoOrdNum)
60 // Given a document with 5 frame formats:
61 // - picture
62 // - draw format + fly format and a picture in it
63 // - picture
64 createSwDoc("textbox-undo-ordnum.docx");
65 SwDoc* pDoc = getSwDoc();
66 SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
67 const auto& rFormats = *pDoc->GetSpzFrameFormats();
68 // Test the state before del + undo.
69 for (const auto& pFormat : rFormats)
71 const SwFrameFormat* pFlyFormat
72 = SwTextBoxHelper::getOtherTextBoxFormat(pFormat, RES_DRAWFRMFMT);
73 if (!pFlyFormat)
75 continue;
78 sal_Int32 nDrawOrdNum = pFormat->FindRealSdrObject()->GetOrdNum();
79 sal_Int32 nFlyOrdNum = pFlyFormat->FindRealSdrObject()->GetOrdNum();
80 CPPUNIT_ASSERT_EQUAL(nDrawOrdNum + 1, nFlyOrdNum);
83 // When selecting the first page, deleting the selection and undoing:
84 pWrtShell->Down(true, 3);
85 pWrtShell->DelLeft();
86 pWrtShell->Undo();
88 // Then the z-order of the fly format should be still the z-order of the draw format + 1, when
89 // the fly and draw formats form a textbox pair.
90 for (const auto& pFormat : rFormats)
92 const SwFrameFormat* pFlyFormat
93 = SwTextBoxHelper::getOtherTextBoxFormat(pFormat, RES_DRAWFRMFMT);
94 if (!pFlyFormat)
96 continue;
99 sal_Int32 nDrawOrdNum = pFormat->FindRealSdrObject()->GetOrdNum();
100 sal_Int32 nFlyOrdNum = pFlyFormat->FindRealSdrObject()->GetOrdNum();
101 // Without the accompanying fix in place, this test would have failed with:
102 // - Expected: 4
103 // - Actual : 2
104 // i.e. the fly format was behind the draw format, not visible.
105 CPPUNIT_ASSERT_EQUAL(nDrawOrdNum + 1, nFlyOrdNum);
109 CPPUNIT_TEST_FIXTURE(SwCoreDrawTest, testTdf107727FrameBorder)
111 // Load a document with a textframe without border, one with only left border
112 createSwDoc("tdf107727_FrameBorder.odt");
114 // Export to RTF and reload
115 saveAndReload("Rich Text Format");
117 // Get frame without border and inspect it.
118 uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
119 uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(),
120 uno::UNO_QUERY);
121 uno::Reference<beans::XPropertySet> xFrame0(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
122 auto aBorder = getProperty<table::BorderLine2>(xFrame0, "LeftBorder");
123 // fo:border="none" is not available via API, and aBorder.LineWidth has wrong value (why?).
124 sal_uInt32 nBorderWidth
125 = aBorder.OuterLineWidth + aBorder.InnerLineWidth + aBorder.LineDistance;
126 // Without patch it failed with Expected 0, Actual 26
127 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), nBorderWidth);
129 // Get frame with left border and inspect it.
130 uno::Reference<beans::XPropertySet> xFrame1(xIndexAccess->getByIndex(1), uno::UNO_QUERY);
131 aBorder = getProperty<table::BorderLine2>(xFrame1, "LeftBorder");
132 // Without patch it failed with Expected 127, Actual 26. Default border width was used.
133 nBorderWidth = aBorder.OuterLineWidth + aBorder.InnerLineWidth + aBorder.LineDistance;
134 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(127), nBorderWidth);
135 // Without patch it failed with Expected Color: R:0 G:0 B:255 A:0, Actual Color: R:0 G:0 B:0 A:0.
136 // Default border color was used.
137 CPPUNIT_ASSERT_EQUAL(Color(0x0000ff), Color(ColorTransparency, aBorder.Color));
140 CPPUNIT_TEST_FIXTURE(SwCoreDrawTest, testSdtTextboxHeader)
142 // Given a 2 page document, same header on both pages, content control in the header and
143 // shape+fly pair (textbox) anchored in the same header
144 // When loading that document, then make sure that layout doesn't fail with an assertion because
145 // the "master SdrObj should have the highest index" invariant doesn't hold:
146 createSwDoc("sdt-textbox-header.docx");
149 CPPUNIT_PLUGIN_IMPLEMENT();
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */