sw/CppunitTest_sw_globalfilter.mk | 1 sw/qa/extras/globalfilter/data/SimpleTOC.odt |binary sw/qa/extras/globalfilter/globalfilter.cxx | 50 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+)
New commits: commit 9955ff410b1b8949a9c9c222f1f08cb8b55f48cd Author: Tomaž Vajngerl <[email protected]> AuthorDate: Fri Jul 11 17:08:00 2025 +0200 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri Jul 11 22:23:00 2025 +0200 sw: test for tdf#167409 - check PDF Annotation /Contents Change-Id: I7f24868387672f4237a9333f91acada1d33b81d8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187738 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/sw/CppunitTest_sw_globalfilter.mk b/sw/CppunitTest_sw_globalfilter.mk index e6d136efbe3a..819f233fcb00 100644 --- a/sw/CppunitTest_sw_globalfilter.mk +++ b/sw/CppunitTest_sw_globalfilter.mk @@ -42,6 +42,7 @@ $(eval $(call gb_CppunitTest_use_externals,sw_globalfilter,\ $(eval $(call gb_CppunitTest_set_include,sw_globalfilter,\ -I$(SRCDIR)/sw/inc \ -I$(SRCDIR)/sw/source/core/inc \ + -I$(SRCDIR)/sw/source/uibase/inc \ -I$(SRCDIR)/sw/qa/inc \ $$(INCLUDE) \ )) diff --git a/sw/qa/extras/globalfilter/data/SimpleTOC.odt b/sw/qa/extras/globalfilter/data/SimpleTOC.odt new file mode 100644 index 000000000000..fbcf101dbb24 Binary files /dev/null and b/sw/qa/extras/globalfilter/data/SimpleTOC.odt differ diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx index 19ffaaee929c..ed4a4b7ae761 100644 --- a/sw/qa/extras/globalfilter/globalfilter.cxx +++ b/sw/qa/extras/globalfilter/globalfilter.cxx @@ -32,6 +32,7 @@ #include <ndtxt.hxx> #include <ndindex.hxx> #include <pam.hxx> +#include <wrtsh.hxx> #include <xmloff/odffields.hxx> #include <IDocumentMarkAccess.hxx> #include <IMark.hxx> @@ -1649,6 +1650,55 @@ CPPUNIT_TEST_FIXTURE(Test, testListLabelPDFExport) CPPUNIT_ASSERT_EQUAL(static_cast<decltype(nL)>(1), nL); } +CPPUNIT_TEST_FIXTURE(Test, testTableOfContentLinksHaveContentSet) +{ + // Test for tdf#167409 + + // TOC is expected to have alt. text set (written to /Contents key), PDF/UA conformance tests + // will fail. TOC links can't be set by the user. + + createSwDoc("SimpleTOC.odt"); + + // Let's update TOC first + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pWrtShell->GetTOXCount()); + const SwTOXBase* pTOX = pWrtShell->GetTOX(0); + CPPUNIT_ASSERT(pTOX); + pWrtShell->UpdateTableOf(*pTOX); + + // Export as PDF + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor[u"FilterName"_ustr] <<= u"writer_pdf_Export"_ustr; + // Enable PDF/UA + uno::Sequence<beans::PropertyValue> aFilterData( + comphelper::InitPropertySequence({ { "PDFUACompliance", uno::Any(true) } })); + aMediaDescriptor[u"FilterData"_ustr] <<= aFilterData; + css::uno::Reference<frame::XStorable> xStorable(mxComponent, css::uno::UNO_QUERY_THROW); + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + + // Parse the export result with pdfium. + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport(); + + // Non-NULL pPdfDocument means pdfium is available. + if (!pPdfDocument) + return; + + // The document has one page. + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); + CPPUNIT_ASSERT(pPdfPage); + + // The page has one annotation. + CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getAnnotationCount()); + std::unique_ptr<vcl::pdf::PDFiumAnnotation> pAnnotation = pPdfPage->getAnnotation(0); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Link, pAnnotation->getSubType()); + CPPUNIT_ASSERT(pAnnotation->hasKey("Contents"_ostr)); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFObjectType::String, + pAnnotation->getValueType("Contents"_ostr)); + OUString aContent = pAnnotation->getString("Contents"_ostr); + CPPUNIT_ASSERT_EQUAL(u"Heading 1"_ustr, aContent); +} + CPPUNIT_TEST_FIXTURE(Test, testTdf143311) { createSwDoc("tdf143311-1.docx");
