/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace ::com::sun::star; namespace { /// Tests for svx/source/sdr/ code. class SdrTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools { protected: uno::Reference mxComponent; public: virtual void setUp() override { test::BootstrapFixture::setUp(); mxDesktop.set(frame::Desktop::create(m_xContext)); } virtual void tearDown() override { if (mxComponent.is()) { mxComponent->dispose(); } test::BootstrapFixture::tearDown(); } uno::Reference& getComponent() { return mxComponent; } drawinglayer::primitive2d::Primitive2DContainer renderPageToPrimitives(const uno::Reference& xDrawPage); }; drawinglayer::primitive2d::Primitive2DContainer SdrTest::renderPageToPrimitives(const uno::Reference& xDrawPage) { auto pDrawPage = dynamic_cast(xDrawPage.get()); CPPUNIT_ASSERT(pDrawPage); SdrPage* pSdrPage = pDrawPage->GetSdrPage(); ScopedVclPtrInstance aVirtualDevice; sdr::contact::ObjectContactOfObjListPainter aObjectContact(*aVirtualDevice, { pSdrPage->GetObj(0) }, nullptr); const sdr::contact::ViewObjectContact& rDrawPageVOContact = pSdrPage->GetViewContact().GetViewObjectContact(aObjectContact); sdr::contact::DisplayInfo aDisplayInfo; drawinglayer::primitive2d::Primitive2DContainer aContainer; rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo, aContainer); return aContainer; } CPPUNIT_TEST_FIXTURE(SdrTest, testShadowScaleOrigin) { // Load a document containing a custom shape. test::Directories aDirectories; OUString aURL = aDirectories.getURLFromSrc(u"svx/qa/unit/data/shadow-scale-origin.pptx"); getComponent() = loadFromDesktop(aURL); uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence = renderPageToPrimitives(xDrawPage); // Examine the created primitives. drawinglayer::Primitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); sal_Int32 fShadowX = getXPath(pDocument, "//shadow/transform", "xy13").toInt32(); sal_Int32 fShadowY = getXPath(pDocument, "//shadow/transform", "xy23").toInt32(); // Without the accompanying fix in place, this test would have failed with: // - Expected: -705 // - Actual : -158 // i.e. the shadow origin was not the top right corner for scaling (larger x position, so it was // visible on the right of the shape as well). CPPUNIT_ASSERT_EQUAL(sal_Int32(-705), fShadowX); CPPUNIT_ASSERT_EQUAL(sal_Int32(-684), fShadowY); } CPPUNIT_TEST_FIXTURE(SdrTest, testZeroWidthTextWrap) { // Load a document containing a 0-width shape with text. test::Directories aDirectories; OUString aURL = aDirectories.getURLFromSrc(u"svx/qa/unit/data/0-width-text-wrap.pptx"); getComponent() = loadFromDesktop(aURL); uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence = renderPageToPrimitives(xDrawPage); // Examine the created primitives. drawinglayer::Primitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 // - Actual : 12 // i.e. the text on the only shape on the slide had 12 lines, not a single one. assertXPath(pDocument, "//textsimpleportion", 1); } CPPUNIT_TEST_FIXTURE(SdrTest, testSlideBackground) { // Given a document with a slide what has a linked background image: test::Directories aDirectories; OUString aURL = aDirectories.getURLFromSrc(u"svx/qa/unit/data/slide-background.odp"); getComponent() = loadFromDesktop(aURL); uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); // When rendering that document: drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence = renderPageToPrimitives(xDrawPage); // Then make sure that the background has a bitmap: drawinglayer::Primitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 // - Actual : 0 // i.e. the rendering did not find the bitmap. assertXPath(pDocument, "//bitmap", 1); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */