From 8640e24b12c7df3170c9f3e7ff3edced81fd0838 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Tue, 24 Jan 2023 22:16:08 +0900 Subject: tdf#66580 added hybrid PDF test cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2a58e6cd5b40266b3c55729febb7006c7a7b4170 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146068 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sw/qa/extras/pdf/HybridPdfTest.cxx | 75 +++++++++++++++++++++ .../Hybrid_AdditionalStreamsAndPDFAttachedFile.pdf | Bin 0 -> 20671 bytes .../pdf/data/Hybrid_AdditionalStreamsOnly.pdf | Bin 0 -> 20314 bytes sw/qa/extras/pdf/data/PDFOnly.pdf | Bin 0 -> 9783 bytes 4 files changed, 75 insertions(+) create mode 100644 sw/qa/extras/pdf/HybridPdfTest.cxx create mode 100644 sw/qa/extras/pdf/data/Hybrid_AdditionalStreamsAndPDFAttachedFile.pdf create mode 100644 sw/qa/extras/pdf/data/Hybrid_AdditionalStreamsOnly.pdf create mode 100644 sw/qa/extras/pdf/data/PDFOnly.pdf (limited to 'sw/qa/extras/pdf') diff --git a/sw/qa/extras/pdf/HybridPdfTest.cxx b/sw/qa/extras/pdf/HybridPdfTest.cxx new file mode 100644 index 000000000000..fda2b409fbaa --- /dev/null +++ b/sw/qa/extras/pdf/HybridPdfTest.cxx @@ -0,0 +1,75 @@ +/* -*- 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 + +class HybridPdfTest : public SwModelTestBase +{ +public: + HybridPdfTest() + : SwModelTestBase("/sw/qa/extras/pdf/data/") + { + } + + void testNoHybridDataInPDF(); + void testHybridWithAdditionalStreams(); + void testHybridWithAdditionalStreamsAndAttachedFile(); + + CPPUNIT_TEST_SUITE(HybridPdfTest); + CPPUNIT_TEST(testNoHybridDataInPDF); + CPPUNIT_TEST(testHybridWithAdditionalStreams); + CPPUNIT_TEST(testHybridWithAdditionalStreamsAndAttachedFile); + CPPUNIT_TEST_SUITE_END(); +}; + +void HybridPdfTest::testNoHybridDataInPDF() +{ + // Load PDF document without attached ODT document + UnoApiXmlTest::load(createFileURL(u"PDFOnly.pdf"), nullptr); + CPPUNIT_ASSERT(mxComponent.is()); + uno::Reference xServiceInfo(mxComponent, uno::UNO_QUERY_THROW); + // Draw document is expected in this case - default when importing PDF + CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.drawing.DrawingDocument")); +} + +void HybridPdfTest::testHybridWithAdditionalStreams() +{ + // Load PDF document with an embedded ODT document + // The ODT document is embedded in "/AdditionalStreams" structure that is in the PDF trailer + createSwDoc("Hybrid_AdditionalStreamsOnly.pdf"); + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + + // We can access the document text in a single paragraph that spans multiple rows + // This wouldn't be possible with a PDF, so the opened document has to be ODT + CPPUNIT_ASSERT_EQUAL(OUString("He heard quiet steps behind him. \nThat didn't bode well."), + getParagraph(1)->getString()); +} + +void HybridPdfTest::testHybridWithAdditionalStreamsAndAttachedFile() +{ + // Load PDF document with an embedded ODT document + // The ODT document is embedded in "/AdditionalStreams" structure that is in the PDF trailer + // and is included as an attached file conforming to the PDF specs + createSwDoc("Hybrid_AdditionalStreamsAndPDFAttachedFile.pdf"); + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + + // We can access the document text in a single paragraph that spans multiple rows + // This wouldn't be possible with a PDF, so the opened document has to be ODT + CPPUNIT_ASSERT_EQUAL(OUString("He heard quiet steps behind him. \nThat didn't bode well."), + getParagraph(1)->getString()); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(HybridPdfTest); +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/pdf/data/Hybrid_AdditionalStreamsAndPDFAttachedFile.pdf b/sw/qa/extras/pdf/data/Hybrid_AdditionalStreamsAndPDFAttachedFile.pdf new file mode 100644 index 000000000000..fc05d01ba06a Binary files /dev/null and b/sw/qa/extras/pdf/data/Hybrid_AdditionalStreamsAndPDFAttachedFile.pdf differ diff --git a/sw/qa/extras/pdf/data/Hybrid_AdditionalStreamsOnly.pdf b/sw/qa/extras/pdf/data/Hybrid_AdditionalStreamsOnly.pdf new file mode 100644 index 000000000000..6e95a17d4770 Binary files /dev/null and b/sw/qa/extras/pdf/data/Hybrid_AdditionalStreamsOnly.pdf differ diff --git a/sw/qa/extras/pdf/data/PDFOnly.pdf b/sw/qa/extras/pdf/data/PDFOnly.pdf new file mode 100644 index 000000000000..53f24b33136e Binary files /dev/null and b/sw/qa/extras/pdf/data/PDFOnly.pdf differ -- cgit