bump product version to 6.3.0.0.beta1
[LibreOffice.git] / svx / qa / unit / unodraw.cxx
blobf3d28bda4bacc7066f1d8da4d1c1bccdd61fd378
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>
11 #include <cppunit/extensions/HelperMacros.h>
13 #include <com/sun/star/drawing/GraphicExportFilter.hpp>
14 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
15 #include <com/sun/star/frame/Desktop.hpp>
17 #include <comphelper/processfactory.hxx>
18 #include <comphelper/propertysequence.hxx>
19 #include <test/bootstrapfixture.hxx>
20 #include <unotest/macros_test.hxx>
21 #include <unotools/tempfile.hxx>
23 using namespace ::com::sun::star;
25 namespace
27 char const DATA_DIRECTORY[] = "/svx/qa/unit/data/";
29 /// Tests for svx/source/unodraw/ code.
30 class UnodrawTest : public test::BootstrapFixture, public unotest::MacrosTest
32 protected:
33 uno::Reference<uno::XComponentContext> mxComponentContext;
34 uno::Reference<lang::XComponent> mxComponent;
36 public:
37 void setUp() override;
38 void tearDown() override;
41 void UnodrawTest::setUp()
43 test::BootstrapFixture::setUp();
45 mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
46 mxDesktop.set(frame::Desktop::create(mxComponentContext));
49 void UnodrawTest::tearDown()
51 if (mxComponent.is())
52 mxComponent->dispose();
54 test::BootstrapFixture::tearDown();
57 CPPUNIT_TEST_FIXTURE(UnodrawTest, testWriterGraphicExport)
59 // Load a document with a Writer picture in it.
60 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "unodraw-writer-image.odt";
61 mxComponent = loadFromDesktop(aURL);
62 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
63 uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
64 uno::Reference<lang::XComponent> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
66 // Export it as JPEG.
67 uno::Reference<drawing::XGraphicExportFilter> xExportFilter
68 = drawing::GraphicExportFilter::create(mxComponentContext);
69 // This resulted in a css::lang::IllegalArgumentException for a Writer
70 // picture.
71 xExportFilter->setSourceDocument(xShape);
73 utl::TempFile aTempFile;
74 aTempFile.EnableKillingFile();
75 uno::Sequence<beans::PropertyValue> aProperties(
76 comphelper::InitPropertySequence({ { "URL", uno::Any(aTempFile.GetURL()) },
77 { "MediaType", uno::Any(OUString("image/jpeg")) } }));
78 CPPUNIT_ASSERT(xExportFilter->filter(aProperties));
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */