From 4eb05e0c0656516fce68475dc9be415874530094 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Tue, 3 Dec 2024 23:32:47 +0900 Subject: pdf: fix saving external PDF with form fields (CONTINUED) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This updates the test with comments and adds options at test start to make the test more robust (without those it can fail depending on the execution order of other tests) Change-Id: Ia7ea7e8810cc63b754d2d7f1ff1757839026ed3a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178760 Reviewed-by: Tomaž Vajngerl Tested-by: Jenkins --- vcl/qa/cppunit/pdfexport/pdfexport2.cxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'vcl') diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx index 548036654222..3445503f6377 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx @@ -5970,6 +5970,8 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf163913LeftRightMarginEm) CPPUNIT_TEST_FIXTURE(PdfExportTest2, testFormRoundtrip) { + // Loads and saves a PDF with filled forms. This checks the forms survive the round-trip. + // We need to enable PDFium import (and make sure to disable after the test) bool bResetEnvVar = false; if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr) @@ -5982,13 +5984,25 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testFormRoundtrip) osl_clearEnvironment(u"LO_IMPORT_USE_PDFIUM"_ustr.pData); }); + // Need to properly set the PDF export options + aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export"); + uno::Sequence aFilterData( + comphelper::InitPropertySequence({ { "UseTaggedPDF", uno::Any(true) } })); + aMediaDescriptor["FilterData"] <<= aFilterData; + saveAsPDF(u"FilledUpForm.pdf"); + + // Parse the round-tripped document with PDFium auto pPdfDocument = parsePDFExport(); + // Should be 1 page CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); std::unique_ptr pPage = pPdfDocument->openPage(0); std::unique_ptr pPageObject = pPage->getObject(1); + + // 5 annotations means 5 form fields CPPUNIT_ASSERT_EQUAL(5, pPage->getAnnotationCount()); + // Check each form { std::unique_ptr pAnnotation = pPage->getAnnotation(0); CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFFormFieldType::CheckBox, -- cgit