/* -*- 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 using namespace ::com::sun::star; namespace { /// Tests for svx/source/core/ code. class Test : public UnoApiTest { public: Test() : UnoApiTest("svx/qa/unit/data/") { } }; CPPUNIT_TEST_FIXTURE(Test, testChartExportToPdf) { // Given a Calc document with a chart in it: loadFromFile(u"chart.ods"); uno::Reference xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); // When exporting that chart to PDF: GraphicHelper::SaveShapeAsGraphicToPath(mxComponent, xShape, "application/pdf", maTempFile.GetURL()); // Then make sure we get a valid, non-empty PDF: // Without the accompanying fix in place, this test would have failed, because the output was // empty (0 bytes). std::unique_ptr pPdfDocument = parsePDFExport(); if (!pPdfDocument) { return; } int nPageCount = pPdfDocument->getPageCount(); CPPUNIT_ASSERT_GREATER(0, nPageCount); } CPPUNIT_TEST_FIXTURE(Test, testGraphicObjectResolver) { OUString aURL = createFileURL(u"GraphicObjectResolverTest.zip"); uno::Reference xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aURL, embed::ElementModes::READ); CPPUNIT_ASSERT(xStorage.is()); rtl::Reference xGraphicHelper = SvXMLGraphicHelper::Create(xStorage, SvXMLGraphicHelperMode::Read); CPPUNIT_ASSERT(xGraphicHelper.is()); // Test name in root folder { uno::Reference xGraphic = xGraphicHelper->loadGraphic("SomeImage.png"); CPPUNIT_ASSERT_EQUAL(true, xGraphic.is()); } // Test name in sub-folder { uno::Reference xGraphic = xGraphicHelper->loadGraphic("Pictures/SomeOtherImage.png"); CPPUNIT_ASSERT_EQUAL(true, xGraphic.is()); } // Test non-existent name { uno::Reference xGraphic; try { xGraphic = xGraphicHelper->loadGraphic("NoneExistent.png"); } catch (const uno::Exception&) { } CPPUNIT_ASSERT_EQUAL(false, xGraphic.is()); } } } CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */