RepositoryExternal.mk | 1 vcl/qa/cppunit/pdfexport/pdfexport.cxx | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)
New commits: commit 735d5f21b3cae332f8ea6d9736d2346566cc737f Author: Balazs Varga <balazs.varga.ext...@allotropia.de> AuthorDate: Mon Jun 27 15:50:32 2022 +0200 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Mon Jun 27 21:10:55 2022 +0200 Modify unit test for tdf#148706 Related to commit: 5b58b8a4c3d6473deb91ed8cb1a33f87ba4d5de9 (tdf#148706: map value prop in numericfield to text) Change-Id: I50db94a64dd762f5409197d2bab48021064e1418 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136502 Tested-by: Thorsten Behrens <thorsten.behr...@allotropia.de> Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> diff --git a/RepositoryExternal.mk b/RepositoryExternal.mk index 701fc5498a92..5eb997b3ff7f 100644 --- a/RepositoryExternal.mk +++ b/RepositoryExternal.mk @@ -4169,6 +4169,7 @@ endef ifneq ($(ENABLE_PDFIUM),) define gb_LinkTarget__use_pdfium $(call gb_LinkTarget_set_include,$(1),\ + -I$(call gb_UnpackedTarball_get_dir,pdfium) \ -I$(call gb_UnpackedTarball_get_dir,pdfium)/public \ -DCOMPONENT_BUILD \ $$(INCLUDE) \ diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 344a74f87521..b75d8eaa2c46 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -35,6 +35,7 @@ #include <fpdf_text.h> #include <fpdf_doc.h> #include <fpdfview.h> +#include <cpp/fpdf_scopers.h> #include <vcl/graphicfilter.hxx> #include <basegfx/matrix/b2dhommatrix.hxx> @@ -111,6 +112,7 @@ public: void testTdf107013(); void testTdf107018(); void testTdf107089(); + void testTdf148706(); void testTdf99680(); void testTdf99680_2(); void testTdf108963(); @@ -156,6 +158,7 @@ public: CPPUNIT_TEST(testTdf107013); CPPUNIT_TEST(testTdf107018); CPPUNIT_TEST(testTdf107089); + CPPUNIT_TEST(testTdf148706); CPPUNIT_TEST(testTdf99680); CPPUNIT_TEST(testTdf99680_2); CPPUNIT_TEST(testTdf108963); @@ -791,6 +794,58 @@ void PdfExportTest::testTdf107089() CPPUNIT_ASSERT(it != pEnd); } +void PdfExportTest::testTdf148706() +{ + // Import the bugdoc and export as PDF. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf148706.odt"; + mxComponent = loadFromDesktop(aURL); + CPPUNIT_ASSERT(mxComponent.is()); + + 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 with pdfium. + SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + ScopedFPDFDocument pPdfDocument( + FPDF_LoadMemDocument(aMemory.GetData(), aMemory.GetSize(), /*password=*/nullptr)); + // The document has one page. + CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument.get())); + ScopedFPDFPage pPdfPage(FPDF_LoadPage(pPdfDocument.get(), /*page_index=*/0)); + CPPUNIT_ASSERT(pPdfPage); + + // The page has one annotation. + CPPUNIT_ASSERT_EQUAL(1, FPDFPage_GetAnnotCount(pPdfPage.get())); + ScopedFPDFAnnotation pAnnot(FPDFPage_GetAnnot(pPdfPage.get(), 0)); + + //// Without the fix in place, this test would have failed with + //// - Expected: 1821.84 + //// - Actual : + CPPUNIT_ASSERT(FPDFAnnot_HasKey(pAnnot.get(), "V")); + CPPUNIT_ASSERT_EQUAL(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(pAnnot.get(), "V")); + + size_t nDALength = FPDFAnnot_GetStringValue(pAnnot.get(), "V", nullptr, 0); + CPPUNIT_ASSERT_EQUAL(std::size_t(0), nDALength % 2); + std::vector<sal_Unicode> aDABuf(nDALength / 2); + FPDFAnnot_GetStringValue( + pAnnot.get(), "V", reinterpret_cast<FPDF_WCHAR*>(aDABuf.data()), nDALength); + + OUString aDA(reinterpret_cast<sal_Unicode*>(aDABuf.data())); + CPPUNIT_ASSERT_EQUAL(OUString("1821.84"), aDA); + + CPPUNIT_ASSERT(FPDFAnnot_HasKey(pAnnot.get(), "DV")); + CPPUNIT_ASSERT_EQUAL(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(pAnnot.get(), "DV")); + + FPDFAnnot_GetStringValue( + pAnnot.get(), "DV", reinterpret_cast<FPDF_WCHAR*>(aDABuf.data()), nDALength); + + aDA = reinterpret_cast<sal_Unicode*>(aDABuf.data()); + CPPUNIT_ASSERT_EQUAL(OUString("1821.84"), aDA); +} + void PdfExportTest::testTdf99680() { vcl::filter::PDFDocument aDocument;