diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-05-04 09:04:04 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-05-04 10:49:31 +0200 |
commit | e9c01db5268a16d657d20f07a083583c2d2b011c (patch) | |
tree | e8d36d8f63a49919ae1505555b344c271de797c0 /vcl | |
parent | 9eae606ebc1ebd20dbc0aeb44e1f760e62afcdbe (diff) |
CppunitTest_vcl_pdfexport: replace std::search() with pdfium calls
The old code would also pass if the page has e.g. a literal "re f*"
string (since the tokenizer doesn't parse streams), the new one uses a
proper parser.
Change-Id: Iabb242b420c14f619f716f5ba47a1165a942f88a
Reviewed-on: https://gerrit.libreoffice.org/37223
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 | 5 | ||||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 78 |
2 files changed, 58 insertions, 25 deletions
diff --git a/vcl/CppunitTest_vcl_pdfexport.mk b/vcl/CppunitTest_vcl_pdfexport.mk index fbc95d868d57..7f87335fc049 100644 --- a/vcl/CppunitTest_vcl_pdfexport.mk +++ b/vcl/CppunitTest_vcl_pdfexport.mk @@ -28,7 +28,10 @@ $(eval $(call gb_CppunitTest_use_libraries,vcl_pdfexport, \ xmlsecurity \ )) -$(eval $(call gb_CppunitTest_use_external,vcl_pdfexport,boost_headers)) +$(eval $(call gb_CppunitTest_use_externals,vcl_pdfexport, \ + boost_headers \ + $(if $(filter PDFIUM,$(BUILD_TYPE)),pdfium) \ +)) $(eval $(call gb_CppunitTest_use_sdk_api,vcl_pdfexport)) diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 36b5134bdaf3..2e2d0f5b4972 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -21,6 +21,10 @@ #include <unotools/tempfile.hxx> #include <vcl/filter/pdfdocument.hxx> #include <tools/zcodec.hxx> +#if HAVE_FEATURE_PDFIUM +#include <fpdf_edit.h> +#include <fpdfview.h> +#endif using namespace ::com::sun::star; @@ -193,34 +197,60 @@ void PdfExportTest::testTdf106693() void PdfExportTest::testTdf105461() { - vcl::filter::PDFDocument aDocument; - load("tdf105461.odp", aDocument); + // Setup. + FPDF_LIBRARY_CONFIG config; + config.version = 2; + config.m_pUserFontPaths = nullptr; + config.m_pIsolate = nullptr; + config.m_v8EmbedderSlot = 0; + FPDF_InitLibraryWithConfig(&config); - // The document has one page. - std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size()); + // Import the bugdoc and export as PDF. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf105461.odp"; + mxComponent = loadFromDesktop(aURL); + CPPUNIT_ASSERT(mxComponent.is()); - // 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()); + 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 with pdfium. + SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + FPDF_DOCUMENT pPdfDocument = FPDF_LoadMemDocument(aMemory.GetData(), aMemory.GetSize(), /*password=*/nullptr); + CPPUNIT_ASSERT(pPdfDocument); + + // The document has one page. + CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument)); + FPDF_PAGE pPdfPage = FPDF_LoadPage(pPdfDocument, /*page_index=*/0); + CPPUNIT_ASSERT(pPdfPage); // Make sure there is a filled rectangle inside. - OString aFilledRectangle("re f*"); - auto pStart = static_cast<const char*>(aUncompressed.GetData()); - const char* pEnd = pStart + aUncompressed.GetSize(); - auto it = std::search(pStart, pEnd, aFilledRectangle.getStr(), aFilledRectangle.getStr() + aFilledRectangle.getLength()); - // This failed, stream contained no filled rectangle. - CPPUNIT_ASSERT(it != pEnd); + int nPageObjectCount = FPDFPage_CountObject(pPdfPage); + int nYellowPathCount = 0; + for (int i = 0; i < nPageObjectCount; ++i) + { + FPDF_PAGEOBJECT pPdfPageObject = FPDFPage_GetObject(pPdfPage, i); + if (FPDFPageObj_GetType(pPdfPageObject) != FPDF_PAGEOBJ_PATH) + continue; + + unsigned int nRed = 0, nGreen = 0, nBlue = 0, nAlpha = 0; + FPDFPath_GetFillColor(pPdfPageObject, &nRed, &nGreen, &nBlue, &nAlpha); + if (RGB_COLORDATA(nRed, nGreen, nBlue) == COL_YELLOW) + ++nYellowPathCount; + } + + // This was 0, the page contained no yellow paths. + CPPUNIT_ASSERT_EQUAL(1, nYellowPathCount); + + // Cleanup. + FPDF_ClosePage(pPdfPage); + FPDF_CloseDocument(pPdfDocument); + FPDF_DestroyLibrary(); } void PdfExportTest::testTdf105093() |