From 807f977b389f196d17701f01ddbb40b297face95 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 23 Dec 2024 12:02:12 +0900 Subject: pdfium: Log error when opening fails (useful for tests) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I597d82bb40c73b900c08c8b37fd303e8f5e98eed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179179 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- vcl/source/pdf/PDFiumLibrary.cxx | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'vcl/source') diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index f48d02595453..d2d91e88bb9a 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -495,6 +495,7 @@ private: PDFiumImpl& operator=(const PDFiumImpl&) = delete; OUString maLastError; + void setLastError(OUString const& rErrorString); public: PDFiumImpl(); @@ -522,10 +523,21 @@ PDFiumImpl::PDFiumImpl() PDFiumImpl::~PDFiumImpl() { FPDF_DestroyLibrary(); } +void PDFiumImpl::setLastError(OUString const& rErrorString) +{ + if (!rErrorString.isEmpty()) + { + // Report what error was set (useful in test failures) + SAL_WARN("vcl.filter", "PDFiumImpl Error: '" << rErrorString << "' Error numner: " + << sal_Int32(getLastErrorCode())); + } + maLastError = rErrorString; +} + std::unique_ptr PDFiumImpl::openDocument(const void* pData, int nSize, const OString& rPassword) { - maLastError = OUString(); + setLastError(u""_ustr); std::unique_ptr pPDFiumDocument; FPDF_BYTESTRING pPassword = nullptr; @@ -540,27 +552,28 @@ std::unique_ptr PDFiumImpl::openDocument(const void* pData, int switch (FPDF_GetLastError()) { case FPDF_ERR_SUCCESS: - maLastError = "Success"; + setLastError(u"Success"_ustr); break; case FPDF_ERR_UNKNOWN: - maLastError = "Unknown error"; + setLastError(u"Unknown error"_ustr); break; case FPDF_ERR_FILE: - maLastError = "File not found"; + setLastError(u"File not found"_ustr); break; case FPDF_ERR_FORMAT: - maLastError = "Input is not a PDF format"; + setLastError(u"Input is not a PDF format"_ustr); break; case FPDF_ERR_PASSWORD: - maLastError = "Incorrect password or password is required"; + setLastError(u"Incorrect password or password is required"_ustr); break; case FPDF_ERR_SECURITY: - maLastError = "Security error"; + setLastError(u"Security error"_ustr); break; case FPDF_ERR_PAGE: - maLastError = "Content error"; + setLastError(u"Content error"_ustr); break; default: + setLastError(u"Unknown error number"_ustr); break; } } @@ -605,8 +618,7 @@ std::unique_ptr PDFiumImpl::createBitmap(int& nWidth, int& nHeight if (!pPdfBitmap) { - maLastError = "Failed to create bitmap"; - SAL_WARN("vcl.filter", "PDFiumImpl: " << getLastError()); + setLastError(u"Failed to create bitmap"_ustr); } else { -- cgit