Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / svx / qa / unit / unodraw.cxx
blob6d3f23175b74088ca86d11c87b696d207bef50c0
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 <cppunit/TestAssert.h>
12 #include <com/sun/star/drawing/GraphicExportFilter.hpp>
13 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
14 #include <com/sun/star/frame/Desktop.hpp>
15 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
16 #include <com/sun/star/beans/XPropertySet.hpp>
17 #include <com/sun/star/awt/XControlModel.hpp>
18 #include <com/sun/star/graphic/XGraphic.hpp>
20 #include <comphelper/processfactory.hxx>
21 #include <comphelper/propertysequence.hxx>
22 #include <test/bootstrapfixture.hxx>
23 #include <unotest/macros_test.hxx>
24 #include <unotools/tempfile.hxx>
26 using namespace ::com::sun::star;
28 namespace
30 char const DATA_DIRECTORY[] = "/svx/qa/unit/data/";
32 /// Tests for svx/source/unodraw/ code.
33 class UnodrawTest : public test::BootstrapFixture, public unotest::MacrosTest
35 protected:
36 uno::Reference<uno::XComponentContext> mxComponentContext;
37 uno::Reference<lang::XComponent> mxComponent;
39 public:
40 void setUp() override;
41 void tearDown() override;
44 void UnodrawTest::setUp()
46 test::BootstrapFixture::setUp();
48 mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
49 mxDesktop.set(frame::Desktop::create(mxComponentContext));
52 void UnodrawTest::tearDown()
54 if (mxComponent.is())
55 mxComponent->dispose();
57 test::BootstrapFixture::tearDown();
60 CPPUNIT_TEST_FIXTURE(UnodrawTest, testWriterGraphicExport)
62 // Load a document with a Writer picture in it.
63 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "unodraw-writer-image.odt";
64 mxComponent = loadFromDesktop(aURL);
65 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
66 uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
67 uno::Reference<lang::XComponent> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
69 // Export it as JPEG.
70 uno::Reference<drawing::XGraphicExportFilter> xExportFilter
71 = drawing::GraphicExportFilter::create(mxComponentContext);
72 // This resulted in a css::lang::IllegalArgumentException for a Writer
73 // picture.
74 xExportFilter->setSourceDocument(xShape);
76 utl::TempFile aTempFile;
77 aTempFile.EnableKillingFile();
78 uno::Sequence<beans::PropertyValue> aProperties(
79 comphelper::InitPropertySequence({ { "URL", uno::Any(aTempFile.GetURL()) },
80 { "MediaType", uno::Any(OUString("image/jpeg")) } }));
81 CPPUNIT_ASSERT(xExportFilter->filter(aProperties));
84 CPPUNIT_TEST_FIXTURE(UnodrawTest, testTdf93998)
86 mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf93998.odp");
87 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
88 CPPUNIT_ASSERT(xDrawPagesSupplier.is());
90 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
91 uno::UNO_QUERY);
92 CPPUNIT_ASSERT(xDrawPage.is());
94 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
95 CPPUNIT_ASSERT(xShape.is());
97 uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory();
98 uno::Reference<awt::XControlModel> xModel(
99 xFactory->createInstance("com.sun.star.awt.UnoControlDialogModel"), uno::UNO_QUERY);
100 CPPUNIT_ASSERT(xModel.is());
102 uno::Reference<beans::XPropertySet> xModelProps(xModel, uno::UNO_QUERY);
103 CPPUNIT_ASSERT(xModelProps.is());
105 // This resulted in a uno::RuntimeException, assigning a shape to a dialog model's image was
106 // broken.
107 xModelProps->setPropertyValue("ImageURL", xShape->getPropertyValue("GraphicURL"));
108 uno::Reference<graphic::XGraphic> xGraphic;
109 xModelProps->getPropertyValue("Graphic") >>= xGraphic;
110 CPPUNIT_ASSERT(xGraphic.is());
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */