diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-02-24 13:46:52 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-02-24 15:49:15 +0000 |
commit | 58eac1105f8504bd5320911fc6fe967ccaa3d469 (patch) | |
tree | a71f1ba78135b13bedf7a20924db1bd2df18a94e /vcl | |
parent | 3cc3dc176e00062d8395d9f3d83b49ab24542a61 (diff) |
vcl: add initial CppunitTest_vcl_pdfexport
Invoke the PDF export filter and then use the PDF tokenizer from
xmlsecurity to assert the contents of created PDF file. The testcase
fails with commit 6db0f1feb1d9931d2726dd11a889c58815710ce0 (tdf#106059
PDF export: create a reference XObject for PDF images, 2017-02-22)
reverted.
Change-Id: I90526fef41d9560ae447f586df766bc50a491c43
Reviewed-on: https://gerrit.libreoffice.org/34609
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/CppunitTest_vcl_pdfexport.mk | 42 | ||||
-rw-r--r-- | vcl/Module_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf106059.odt | bin | 0 -> 13585 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 103 |
4 files changed, 146 insertions, 0 deletions
diff --git a/vcl/CppunitTest_vcl_pdfexport.mk b/vcl/CppunitTest_vcl_pdfexport.mk new file mode 100644 index 000000000000..8f0cbcdf47f9 --- /dev/null +++ b/vcl/CppunitTest_vcl_pdfexport.mk @@ -0,0 +1,42 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# 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/. +# + +$(eval $(call gb_CppunitTest_CppunitTest,vcl_pdfexport)) + +$(eval $(call gb_CppunitTest_add_exception_objects,vcl_pdfexport, \ + vcl/qa/cppunit/pdfexport/pdfexport \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,vcl_pdfexport)) + +$(eval $(call gb_CppunitTest_use_libraries,vcl_pdfexport, \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + test \ + unotest \ + utl \ + tl \ + xmlsecurity \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_CppunitTest_use_external,vcl_pdfexport,boost_headers)) + +$(eval $(call gb_CppunitTest_use_sdk_api,vcl_pdfexport)) + +$(eval $(call gb_CppunitTest_use_ure,vcl_pdfexport)) +$(eval $(call gb_CppunitTest_use_vcl,vcl_pdfexport)) + +$(eval $(call gb_CppunitTest_use_rdb,vcl_pdfexport,services)) + +$(eval $(call gb_CppunitTest_use_configuration,vcl_pdfexport)) + +# vim: set noet sw=4 ts=4: diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk index 2180084aaa25..730a3b007df6 100644 --- a/vcl/Module_vcl.mk +++ b/vcl/Module_vcl.mk @@ -143,6 +143,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\ $(if $(MERGELIBS),,CppunitTest_vcl_wmf_test) \ CppunitTest_vcl_jpeg_read_write_test \ CppunitTest_vcl_svm_test \ + CppunitTest_vcl_pdfexport \ )) diff --git a/vcl/qa/cppunit/pdfexport/data/tdf106059.odt b/vcl/qa/cppunit/pdfexport/data/tdf106059.odt Binary files differnew file mode 100644 index 000000000000..a2c18037833e --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf106059.odt diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx new file mode 100644 index 000000000000..bcc3345ae2b5 --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -0,0 +1,103 @@ +/* -*- 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 <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XStorable.hpp> + +#include <comphelper/processfactory.hxx> +#include <cppuhelper/implbase.hxx> +#include <test/bootstrapfixture.hxx> +#include <unotest/macros_test.hxx> +#include <unotools/mediadescriptor.hxx> +#include <unotools/tempfile.hxx> +#include <xmlsecurity/pdfio/pdfdocument.hxx> + +using namespace ::com::sun::star; + +namespace +{ + +const char* const DATA_DIRECTORY = "/vcl/qa/cppunit/pdfexport/data/"; + +/// Tests the PDF export filter. +class PdfExportTest : public test::BootstrapFixture, public unotest::MacrosTest +{ + uno::Reference<uno::XComponentContext> mxComponentContext; + uno::Reference<lang::XComponent> mxComponent; + +public: + virtual void setUp() override; + virtual void tearDown() override; + /// Tests that a pdf image is roundtripped back to PDF as a vector format. + void testTdf106059(); + + CPPUNIT_TEST_SUITE(PdfExportTest); + CPPUNIT_TEST(testTdf106059); + CPPUNIT_TEST_SUITE_END(); +}; + +void PdfExportTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory())); + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void PdfExportTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +void PdfExportTest::testTdf106059() +{ + // Import the bugdoc and export as PDF. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf106059.odt"; + mxComponent = loadFromDesktop(aURL); + CPPUNIT_ASSERT(mxComponent.is()); + + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); + xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + + // Parse the export result. + xmlsecurity::pdfio::PDFDocument aDocument; + SvFileStream aStream(aTempFile.GetURL(), StreamMode::READ); + CPPUNIT_ASSERT(aDocument.Read(aStream)); + + // Assert that the XObject in the page resources dictionary is a reference XObject. + std::vector<xmlsecurity::pdfio::PDFObjectElement*> aPages = aDocument.GetPages(); + // The document has one page. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size()); + xmlsecurity::pdfio::PDFObjectElement* pResources = aPages[0]->LookupObject("Resources"); + CPPUNIT_ASSERT(pResources); + auto pXObjects = dynamic_cast<xmlsecurity::pdfio::PDFDictionaryElement*>(pResources->Lookup("XObject")); + CPPUNIT_ASSERT(pXObjects); + // The page has one image. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pXObjects->GetItems().size()); + xmlsecurity::pdfio::PDFObjectElement* pReferenceXObject = pXObjects->LookupObject(pXObjects->GetItems().begin()->first); + CPPUNIT_ASSERT(pReferenceXObject); + // The image is a reference XObject. + // This dictionary key was missing, so the XObject wasn't a reference one. + CPPUNIT_ASSERT(pReferenceXObject->Lookup("Ref")); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |