Bump version to 6.4-15
[LibreOffice.git] / svx / qa / unit / sdr.cxx
blob093264549db7a67196e19c14dd02c57304076317
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/bootstrapfixture.hxx>
11 #include <unotest/macros_test.hxx>
12 #include <test/xmltesttools.hxx>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
16 #include <com/sun/star/drawing/XDrawPage.hpp>
17 #include <com/sun/star/frame/Desktop.hpp>
18 #include <com/sun/star/text/XTextRange.hpp>
20 #include <drawinglayer/tools/primitive2dxmldump.hxx>
21 #include <rtl/ustring.hxx>
22 #include <svx/sdr/contact/displayinfo.hxx>
23 #include <svx/sdr/contact/viewcontact.hxx>
24 #include <svx/sdr/contact/viewobjectcontact.hxx>
25 #include <svx/svdpage.hxx>
26 #include <svx/unopage.hxx>
27 #include <vcl/virdev.hxx>
28 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
30 using namespace ::com::sun::star;
32 namespace
34 /// Tests for svx/source/sdr/ code.
35 class SdrTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools
37 protected:
38 uno::Reference<lang::XComponent> mxComponent;
40 public:
41 virtual void setUp() override
43 test::BootstrapFixture::setUp();
44 mxDesktop.set(frame::Desktop::create(m_xContext));
47 virtual void tearDown() override
49 if (mxComponent.is())
51 mxComponent->dispose();
53 test::BootstrapFixture::tearDown();
55 uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
58 CPPUNIT_TEST_FIXTURE(SdrTest, testShadowScaleOrigin)
60 // Load a document containing a custom shape.
61 test::Directories aDirectories;
62 OUString aURL = aDirectories.getURLFromSrc("svx/qa/unit/data/shadow-scale-origin.pptx");
63 getComponent() = loadFromDesktop(aURL);
64 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
65 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
66 uno::UNO_QUERY);
68 // Render it.
69 auto pDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPage.get());
70 CPPUNIT_ASSERT(pDrawPage);
71 SdrPage* pSdrPage = pDrawPage->GetSdrPage();
72 ScopedVclPtrInstance<VirtualDevice> aVirtualDevice;
73 sdr::contact::ObjectContactOfObjListPainter aObjectContact(*aVirtualDevice,
74 { pSdrPage->GetObj(0) }, nullptr);
75 const sdr::contact::ViewObjectContact& rDrawPageVOContact
76 = pSdrPage->GetViewContact().GetViewObjectContact(aObjectContact);
77 sdr::contact::DisplayInfo aDisplayInfo;
78 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
79 = rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo);
81 // Examine the created primitives.
82 drawinglayer::tools::Primitive2dXmlDump aDumper;
83 xmlDocPtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence);
84 double fShadowX = getXPath(pDocument, "//shadow/transform", "xy13").toDouble();
85 double fShadowY = getXPath(pDocument, "//shadow/transform", "xy23").toDouble();
86 // Without the accompanying fix in place, this test would have failed with:
87 // - Expected: -705
88 // - Actual : -158
89 // i.e. the shadow origin was not the top right corner for scaling (larger x position, so it was
90 // visible on the right of the shape as well).
91 CPPUNIT_ASSERT_EQUAL(-705., std::round(fShadowX));
92 CPPUNIT_ASSERT_EQUAL(-685., std::round(fShadowY));
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */