diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sd/qa/unit/SdrPdfImportTest.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sd/qa/unit/SdrPdfImportTest.cxx')
-rw-r--r-- | sd/qa/unit/SdrPdfImportTest.cxx | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/sd/qa/unit/SdrPdfImportTest.cxx b/sd/qa/unit/SdrPdfImportTest.cxx new file mode 100644 index 000000000..9f30ff500 --- /dev/null +++ b/sd/qa/unit/SdrPdfImportTest.cxx @@ -0,0 +1,128 @@ +/* -*- 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 <test/bootstrapfixture.hxx> +#include <unotest/macros_test.hxx> + +#include <svdpdf.hxx> + +#include <config_features.h> + +#include <comphelper/scopeguard.hxx> +#include <comphelper/processfactory.hxx> + +#include <svx/svdograf.hxx> +#include <editeng/outlobj.hxx> +#include <editeng/editobj.hxx> + +#include <DrawDocShell.hxx> +#include <DrawController.hxx> +#include <ViewShell.hxx> +#include <drawdoc.hxx> +#include <sdpage.hxx> +#include <unomodel.hxx> + +#include <com/sun/star/frame/Desktop.hpp> + +using namespace css; + +class SdrPdfImportTest : public test::BootstrapFixture, public unotest::MacrosTest +{ +protected: + uno::Reference<lang::XComponent> mxComponent; + +public: + virtual void setUp() override; + virtual void tearDown() override; +}; + +void SdrPdfImportTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void SdrPdfImportTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +// Load the PDF in Draw, which will load the PDF as an Graphic, then +// mark the graphic object and trigger "break" function. This should +// convert the PDF content into objects/shapes. +CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testImportSimpleText) +{ +#if HAVE_FEATURE_PDFIUM && !defined(_WIN32) + // We need to enable PDFium import (and make sure to disable after the test) + bool bResetEnvVar = false; + if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr) + { + bResetEnvVar = true; + setenv("LO_IMPORT_USE_PDFIUM", "1", false); + } + comphelper::ScopeGuard aPDFiumEnvVarGuard([&]() { + if (bResetEnvVar) + unsetenv("LO_IMPORT_USE_PDFIUM"); + }); + + mxComponent = loadFromDesktop(m_directories.getURLFromSrc("sd/qa/unit/data/SimplePDF.pdf")); + auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get()); + sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell(); + CPPUNIT_ASSERT(pViewShell); + + // Get the first page - there should be only one. + SdPage* pPage = pViewShell->GetActualPage(); + CPPUNIT_ASSERT(pPage); + + // Get the first object - there should be only one. + SdrObject* pObject = pPage->GetObj(0); + CPPUNIT_ASSERT(pObject); + + // Check the object is a graphic object + SdrGrafObj* pGraphicObject = dynamic_cast<SdrGrafObj*>(pObject); + CPPUNIT_ASSERT(pGraphicObject); + // Check the graphic is a vector graphic and that it is PDF + Graphic aGraphic = pGraphicObject->GetGraphic(); + auto const& pVectorGraphicData = aGraphic.getVectorGraphicData(); + CPPUNIT_ASSERT(pVectorGraphicData); + CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, + pVectorGraphicData->getVectorGraphicDataType()); + + // Mark the object + SdrView* pView = pViewShell->GetView(); + pView->MarkObj(pObject, pView->GetSdrPageView()); + + // Execute the break operation - to turn the PDF into shapes/objects + pViewShell->GetDrawView()->DoImportMarkedMtf(); + + // Check Objects after import + + SdrObject* pImportedObject = pPage->GetObj(0); + CPPUNIT_ASSERT(pImportedObject); + + // Object should be a text object containing one paragraph with + // content "This is PDF!" + + SdrTextObj* pTextObject = dynamic_cast<SdrTextObj*>(pImportedObject); + CPPUNIT_ASSERT(pTextObject); + OutlinerParaObject* pOutlinerParagraphObject = pTextObject->GetOutlinerParaObject(); + const EditTextObject& aEdit = pOutlinerParagraphObject->GetTextObject(); + OUString sText = aEdit.GetText(0); + CPPUNIT_ASSERT_EQUAL(OUString("This is PDF!"), sText); + +#endif // HAVE_FEATURE_PDFIUM +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |