Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / qa / unit / core.cxx
blob0625d7ad70fbe5909050fceaeb4ec46353a552b1
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/unoapi_test.hxx>
11 #include <com/sun/star/embed/XStorage.hpp>
12 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
14 #include <comphelper/storagehelper.hxx>
16 #include <svx/graphichelper.hxx>
17 #include <svx/xmlgrhlp.hxx>
18 #include <unotools/tempfile.hxx>
19 #include <vcl/filter/PDFiumLibrary.hxx>
21 using namespace ::com::sun::star;
23 namespace
25 /// Tests for svx/source/core/ code.
26 class Test : public UnoApiTest
28 public:
29 Test()
30 : UnoApiTest("svx/qa/unit/data/")
35 CPPUNIT_TEST_FIXTURE(Test, testChartExportToPdf)
37 // Given a Calc document with a chart in it:
38 loadFromURL(u"chart.ods");
39 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
40 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
41 uno::UNO_QUERY);
42 uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
44 // When exporting that chart to PDF:
45 GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "application/pdf",
46 maTempFile.GetURL());
48 // Then make sure we get a valid, non-empty PDF:
49 // Without the accompanying fix in place, this test would have failed, because the output was
50 // empty (0 bytes).
51 std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
52 if (!pPdfDocument)
54 return;
56 int nPageCount = pPdfDocument->getPageCount();
57 CPPUNIT_ASSERT_GREATER(0, nPageCount);
60 CPPUNIT_TEST_FIXTURE(Test, testGraphicObjectResolver)
62 OUString aURL = createFileURL(u"GraphicObjectResolverTest.zip");
63 uno::Reference<embed::XStorage> xStorage
64 = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aURL,
65 embed::ElementModes::READ);
66 CPPUNIT_ASSERT(xStorage.is());
68 rtl::Reference<SvXMLGraphicHelper> xGraphicHelper
69 = SvXMLGraphicHelper::Create(xStorage, SvXMLGraphicHelperMode::Read);
70 CPPUNIT_ASSERT(xGraphicHelper.is());
72 // Test name in root folder
74 uno::Reference<graphic::XGraphic> xGraphic = xGraphicHelper->loadGraphic("SomeImage.png");
75 CPPUNIT_ASSERT_EQUAL(true, xGraphic.is());
78 // Test name in sub-folder
80 uno::Reference<graphic::XGraphic> xGraphic
81 = xGraphicHelper->loadGraphic("Pictures/SomeOtherImage.png");
82 CPPUNIT_ASSERT_EQUAL(true, xGraphic.is());
85 // Test non-existent name
87 uno::Reference<graphic::XGraphic> xGraphic;
88 try
90 xGraphic = xGraphicHelper->loadGraphic("NoneExistent.png");
92 catch (const uno::Exception&)
95 CPPUNIT_ASSERT_EQUAL(false, xGraphic.is());
100 CPPUNIT_PLUGIN_IMPLEMENT();
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */