calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / svx / qa / unit / sdr.cxx
blob4d6c4226d11b192ca377b5e7d27f23cc01f8cfed
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 <test/unoapixml_test.hxx>
12 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
13 #include <com/sun/star/drawing/XDrawPage.hpp>
15 #include <drawinglayer/tools/primitive2dxmldump.hxx>
16 #include <rtl/ustring.hxx>
17 #include <svx/sdr/contact/displayinfo.hxx>
18 #include <svx/sdr/contact/viewcontact.hxx>
19 #include <svx/sdr/contact/viewobjectcontact.hxx>
20 #include <svx/svdpage.hxx>
21 #include <svx/unopage.hxx>
22 #include <vcl/virdev.hxx>
23 #include <sdr/contact/objectcontactofobjlistpainter.hxx>
25 using namespace ::com::sun::star;
27 namespace
29 /// Tests for svx/source/sdr/ code.
30 class SdrTest : public UnoApiXmlTest
32 public:
33 SdrTest()
34 : UnoApiXmlTest("svx/qa/unit/data/")
38 drawinglayer::primitive2d::Primitive2DContainer
39 renderPageToPrimitives(const uno::Reference<drawing::XDrawPage>& xDrawPage);
42 drawinglayer::primitive2d::Primitive2DContainer
43 SdrTest::renderPageToPrimitives(const uno::Reference<drawing::XDrawPage>& xDrawPage)
45 auto pDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPage.get());
46 CPPUNIT_ASSERT(pDrawPage);
47 SdrPage* pSdrPage = pDrawPage->GetSdrPage();
48 ScopedVclPtrInstance<VirtualDevice> aVirtualDevice;
49 sdr::contact::ObjectContactOfObjListPainter aObjectContact(*aVirtualDevice,
50 { pSdrPage->GetObj(0) }, nullptr);
51 const sdr::contact::ViewObjectContact& rDrawPageVOContact
52 = pSdrPage->GetViewContact().GetViewObjectContact(aObjectContact);
53 sdr::contact::DisplayInfo aDisplayInfo;
54 drawinglayer::primitive2d::Primitive2DContainer aContainer;
55 rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo, aContainer);
56 return aContainer;
59 CPPUNIT_TEST_FIXTURE(SdrTest, testShadowScaleOrigin)
61 // Load a document containing a custom shape.
62 loadFromURL(u"shadow-scale-origin.pptx");
63 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
64 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
65 uno::UNO_QUERY);
66 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
67 = renderPageToPrimitives(xDrawPage);
69 // Examine the created primitives.
70 drawinglayer::Primitive2dXmlDump aDumper;
71 xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence);
72 sal_Int32 fShadowX = getXPath(pDocument, "//shadow/transform", "xy13").toInt32();
73 sal_Int32 fShadowY = getXPath(pDocument, "//shadow/transform", "xy23").toInt32();
74 // Without the accompanying fix in place, this test would have failed with:
75 // - Expected: -705
76 // - Actual : -158
77 // i.e. the shadow origin was not the top right corner for scaling (larger x position, so it was
78 // visible on the right of the shape as well).
79 CPPUNIT_ASSERT_EQUAL(sal_Int32(-705), fShadowX);
80 CPPUNIT_ASSERT_EQUAL(sal_Int32(-684), fShadowY);
83 CPPUNIT_TEST_FIXTURE(SdrTest, testShadowAlignment)
85 loadFromURL(u"tdf150020-shadow-alignment.pptx");
87 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
89 // Page 1 contains 9 shapes with each shadow alignment
90 uno::Reference<drawing::XDrawPage> xDrawPage(
91 xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
92 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
93 = renderPageToPrimitives(xDrawPage);
95 // Examine the created primitives.
96 drawinglayer::Primitive2dXmlDump aDumper;
97 xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence);
99 // Without the accompanying fix in place, this test would have failed with:
100 // - Expected: -567
101 // - Actual : 162
102 // - In <>, attribute 'xy13' of '(//shadow/transform)[1]' incorrect value.
103 // i.e. shadow alignment was ignored while scaling the shadow.
104 assertXPath(pDocument, "(//shadow/transform)[1]", "xy13", "-567");
105 assertXPath(pDocument, "(//shadow/transform)[1]", "xy23", "162");
107 assertXPath(pDocument, "(//shadow/transform)[2]", "xy13", "-1794");
108 assertXPath(pDocument, "(//shadow/transform)[2]", "xy23", "162");
110 assertXPath(pDocument, "(//shadow/transform)[3]", "xy13", "-3021");
111 assertXPath(pDocument, "(//shadow/transform)[3]", "xy23", "161");
113 assertXPath(pDocument, "(//shadow/transform)[4]", "xy13", "-567");
114 assertXPath(pDocument, "(//shadow/transform)[4]", "xy23", "-749");
116 assertXPath(pDocument, "(//shadow/transform)[5]", "xy13", "-3021");
117 assertXPath(pDocument, "(//shadow/transform)[5]", "xy23", "-750");
119 assertXPath(pDocument, "(//shadow/transform)[6]", "xy13", "-566");
120 assertXPath(pDocument, "(//shadow/transform)[6]", "xy23", "-1691");
122 assertXPath(pDocument, "(//shadow/transform)[7]", "xy13", "-1794");
123 assertXPath(pDocument, "(//shadow/transform)[7]", "xy23", "-1693");
125 assertXPath(pDocument, "(//shadow/transform)[8]", "xy13", "-3022");
126 assertXPath(pDocument, "(//shadow/transform)[8]", "xy23", "-1691");
128 assertXPath(pDocument, "(//shadow/transform)[9]", "xy13", "-1794");
129 assertXPath(pDocument, "(//shadow/transform)[9]", "xy23", "-750");
132 // Page 2 contains a table with shadow alignment center
133 uno::Reference<drawing::XDrawPage> xDrawPage(
134 xDrawPagesSupplier->getDrawPages()->getByIndex(1), uno::UNO_QUERY);
135 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
136 = renderPageToPrimitives(xDrawPage);
138 // Examine the created primitives.
139 drawinglayer::Primitive2dXmlDump aDumper;
140 xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence);
142 // Without the accompanying fix in place, this test would have failed with:
143 // - Expected: -5196
144 // - Actual : 0
145 // - In<>, attribute 'xy13' of '//shadow/transform' incorrect value.
146 assertXPath(pDocument, "//shadow/transform", "xy13", "-5196");
147 assertXPath(pDocument, "//shadow/transform", "xy23", "-2290");
151 CPPUNIT_TEST_FIXTURE(SdrTest, testZeroWidthTextWrap)
153 // Load a document containing a 0-width shape with text.
154 loadFromURL(u"0-width-text-wrap.pptx");
155 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
156 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
157 uno::UNO_QUERY);
158 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
159 = renderPageToPrimitives(xDrawPage);
161 // Examine the created primitives.
162 drawinglayer::Primitive2dXmlDump aDumper;
163 xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence);
164 // Without the accompanying fix in place, this test would have failed with:
165 // - Expected: 1
166 // - Actual : 12
167 // i.e. the text on the only shape on the slide had 12 lines, not a single one.
168 assertXPath(pDocument, "//textsimpleportion", 1);
171 CPPUNIT_TEST_FIXTURE(SdrTest, testSlideBackground)
173 // Given a document with a slide what has a linked background image:
174 loadFromURL(u"slide-background.odp");
175 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
176 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
177 uno::UNO_QUERY);
179 // When rendering that document:
180 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
181 = renderPageToPrimitives(xDrawPage);
183 // Then make sure that the background has a bitmap:
184 drawinglayer::Primitive2dXmlDump aDumper;
185 xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence);
186 // Without the accompanying fix in place, this test would have failed with:
187 // - Expected: 1
188 // - Actual : 0
189 // i.e. the rendering did not find the bitmap.
190 assertXPath(pDocument, "//bitmap", 1);
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */