diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-03-11 13:21:49 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-03-12 15:33:03 +0100 |
commit | 2f1effff74c77eb13b53a7d4b5d31a7f2ac9ff8f (patch) | |
tree | 9e1ef2b168c9033542a2ba2728272674b0038703 /vcl/qa | |
parent | c0ec7d342bd715d9910cf28afe10a6bfa3ba28cb (diff) |
tdf#124272: vcl_pdfexport: Add unittest
Change-Id: I5d5aa7a2b9cc9c7cb522a84e00d48a348912ad95
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112341
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf124272.odt | bin | 0 -> 10292 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 44 |
2 files changed, 44 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf124272.odt b/vcl/qa/cppunit/pdfexport/data/tdf124272.odt Binary files differnew file mode 100644 index 000000000000..54d4dcb2a1a4 --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf124272.odt diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 365a9a0955c1..a15832aeabff 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -1688,6 +1688,50 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf115967) CPPUNIT_ASSERT_EQUAL(OUString("m=750abc"), sText); } +CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf124272) +{ + // Import the bugdoc and export as PDF. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf124272.odt"; + mxComponent = loadFromDesktop(aURL); + + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + + // Parse the export result. + vcl::filter::PDFDocument aDocument; + SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); + CPPUNIT_ASSERT(aDocument.Read(aStream)); + + // The document has one page. + std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size()); + + // The page has a stream. + vcl::filter::PDFObjectElement* pContents = aPages[0]->LookupObject("Contents"); + CPPUNIT_ASSERT(pContents); + vcl::filter::PDFStreamElement* pStream = pContents->GetStream(); + CPPUNIT_ASSERT(pStream); + SvMemoryStream& rObjectStream = pStream->GetMemory(); + // Uncompress it. + SvMemoryStream aUncompressed; + ZCodec aZCodec; + aZCodec.BeginCompression(); + rObjectStream.Seek(0); + aZCodec.Decompress(rObjectStream, aUncompressed); + CPPUNIT_ASSERT(aZCodec.EndCompression()); + + OString aBitmap("Q q 299.899 782.189 m\n" + "55.2 435.889 l 299.899 435.889 l 299.899 782.189 l\n" + "h"); + + auto pStart = static_cast<const char*>(aUncompressed.GetData()); + const char* pEnd = pStart + aUncompressed.GetSize(); + auto it = std::search(pStart, pEnd, aBitmap.getStr(), aBitmap.getStr() + aBitmap.getLength()); + CPPUNIT_ASSERT(it != pEnd); +} + CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf121615) { vcl::filter::PDFDocument aDocument; |