/* -*- 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 #include #include #include #include #include #include #include #include #include using namespace ::com::sun::star; namespace { constexpr OUStringLiteral DATA_DIRECTORY = u"/svx/qa/unit/data/"; /// Tests for svx/source/unodraw/ code. class UnodrawTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools { protected: uno::Reference mxComponent; public: void setUp() override; void tearDown() override; }; void UnodrawTest::setUp() { test::BootstrapFixture::setUp(); mxDesktop.set(frame::Desktop::create(mxComponentContext)); } void UnodrawTest::tearDown() { if (mxComponent.is()) mxComponent->dispose(); test::BootstrapFixture::tearDown(); } CPPUNIT_TEST_FIXTURE(UnodrawTest, testWriterGraphicExport) { // Load a document with a Writer picture in it. OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "unodraw-writer-image.odt"; mxComponent = loadFromDesktop(aURL); uno::Reference xDrawPageSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); // Export it as JPEG. uno::Reference xExportFilter = drawing::GraphicExportFilter::create(mxComponentContext); // This resulted in a css::lang::IllegalArgumentException for a Writer // picture. xExportFilter->setSourceDocument(xShape); utl::TempFile aTempFile; aTempFile.EnableKillingFile(); uno::Sequence aProperties( comphelper::InitPropertySequence({ { "URL", uno::Any(aTempFile.GetURL()) }, { "MediaType", uno::Any(OUString("image/jpeg")) } })); CPPUNIT_ASSERT(xExportFilter->filter(aProperties)); } CPPUNIT_TEST_FIXTURE(UnodrawTest, testTdf93998) { mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf93998.odp"); uno::Reference xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); CPPUNIT_ASSERT(xDrawPagesSupplier.is()); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); CPPUNIT_ASSERT(xDrawPage.is()); uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); CPPUNIT_ASSERT(xShape.is()); uno::Reference xFactory = comphelper::getProcessServiceFactory(); uno::Reference xModel( xFactory->createInstance("com.sun.star.awt.UnoControlDialogModel"), uno::UNO_QUERY); CPPUNIT_ASSERT(xModel.is()); uno::Reference xModelProps(xModel, uno::UNO_QUERY); CPPUNIT_ASSERT(xModelProps.is()); // This resulted in a uno::RuntimeException, assigning a shape to a dialog model's image was // broken. xModelProps->setPropertyValue("ImageURL", xShape->getPropertyValue("GraphicURL")); uno::Reference xGraphic; xModelProps->getPropertyValue("Graphic") >>= xGraphic; CPPUNIT_ASSERT(xGraphic.is()); } CPPUNIT_TEST_FIXTURE(UnodrawTest, testTableShadowDirect) { // Create an Impress document an insert a table shape. mxComponent = loadFromDesktop("private:factory/simpress", "com.sun.star.presentation.PresentationDocument"); uno::Reference xFactory(mxComponent, uno::UNO_QUERY); uno::Reference xShape( xFactory->createInstance("com.sun.star.drawing.TableShape"), uno::UNO_QUERY); xShape->setPosition(awt::Point(1000, 1000)); xShape->setSize(awt::Size(10000, 10000)); uno::Reference xSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xDrawPages = xSupplier->getDrawPages(); uno::Reference xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY); xDrawPage->add(xShape); // Create a red shadow on it without touching its style. uno::Reference xShapeProps(xShape, uno::UNO_QUERY); // Without the accompanying fix in place, this test would have failed with throwing a // beans.UnknownPropertyException, as shadow-as-direct-formatting on tables were not possible. xShapeProps->setPropertyValue("Shadow", uno::makeAny(true)); sal_Int32 nRed = 0xff0000; xShapeProps->setPropertyValue("ShadowColor", uno::makeAny(nRed)); CPPUNIT_ASSERT(xShapeProps->getPropertyValue("ShadowColor") >>= nRed); CPPUNIT_ASSERT_EQUAL(static_cast(0xff0000), nRed); // Add text. uno::Reference xTable(xShapeProps->getPropertyValue("Model"), uno::UNO_QUERY); uno::Reference xCell(xTable->getCellByPosition(0, 0), uno::UNO_QUERY); xCell->setString("A1"); // Generates drawinglayer primitives for the shape. 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 xPrimitiveSequence; rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo, xPrimitiveSequence); // Check the primitives. drawinglayer::Primitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); assertXPath(pDocument, "//shadow", /*nNumberOfNodes=*/1); // Without the accompanying fix in place, this test would have failed with: // - Expected: 0 // - Actual : 1 // i.e. there was shadow for the cell text, while here PowerPoint-compatible output is expected, // which has no shadow for cell text (only for cell borders and cell background). assertXPath(pDocument, "//shadow//sdrblocktext", /*nNumberOfNodes=*/0); } CPPUNIT_TEST_FIXTURE(UnodrawTest, testTitleShapeBullets) { // Create a title shape with 2 paragraphs in it. mxComponent = loadFromDesktop("private:factory/simpress", "com.sun.star.presentation.PresentationDocument"); uno::Reference xSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xDrawPages = xSupplier->getDrawPages(); uno::Reference xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY); // A default document contains a title shape and a text shape on the first slide. uno::Reference xTitleShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); uno::Reference xTitleShapeInfo(xTitleShape, uno::UNO_QUERY); CPPUNIT_ASSERT(xTitleShapeInfo->supportsService("com.sun.star.presentation.TitleTextShape")); uno::Reference xTitleShapeText(xTitleShape, uno::UNO_QUERY); uno::Reference xText = xTitleShapeText->getText(); uno::Reference xCursor = xText->createTextCursor(); xText->insertString(xCursor, "foo", /*bAbsorb=*/false); xText->insertControlCharacter(xCursor, text::ControlCharacter::APPEND_PARAGRAPH, /*bAbsorb=*/false); xText->insertString(xCursor, "bar", /*bAbsorb=*/false); // Check that the title shape has 2 paragraphs. uno::Reference xTextEA(xText, uno::UNO_QUERY); uno::Reference xTextE = xTextEA->createEnumeration(); // Has a first paragraph. CPPUNIT_ASSERT(xTextE->hasMoreElements()); xTextE->nextElement(); // Has a second paragraph. // Without the accompanying fix in place, this test would have failed, because the 2 paragraphs // were merged together (e.g. 1 bullet instead of 2 bullets for bulleted paragraphs). CPPUNIT_ASSERT(xTextE->hasMoreElements()); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */