vcl/qa/cppunit/pdfexport/pdfexport2.cxx | 194 ++++++++++++++++---------------- 1 file changed, 101 insertions(+), 93 deletions(-)
New commits: commit 651064b9dddf601055567ad73808bcaa88981872 Author: Xisco Fauli <[email protected]> AuthorDate: Thu Feb 26 10:32:30 2026 +0100 Commit: Xisco Fauli <[email protected]> CommitDate: Thu Feb 26 16:41:03 2026 +0100 tdf#157517: vcl_pdfexport2: improve test Change-Id: I5c5e1fd232fe5f52b837fe39a6db2b642affc923 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200418 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]> diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx index 0bf7c75f7db1..445f3cecb082 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx @@ -79,6 +79,12 @@ void PdfExportTest2::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) BAD_CAST("http://www.aiim.org/pdfua/ns/id/")); xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("pdfaid"), BAD_CAST("http://www.aiim.org/pdfa/ns/id/")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("pdfaExtension"), + BAD_CAST("http://www.aiim.org/pdfa/ns/extension/")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("pdfaSchema"), + BAD_CAST("http://www.aiim.org/pdfa/ns/schema#")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("pdfaProperty"), + BAD_CAST("http://www.aiim.org/pdfa/ns/property#")); } xmlDocUniquePtr PdfExportTest2::parseMetadata() @@ -1787,6 +1793,68 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf157517) loadFromFile(u"tdf157517.odt"); // Without the fix in place, the validation would have failed save(TestFilter::PDF_WRITER, aMediaDescriptor.getAsConstPropertyValueList()); + + xmlDocUniquePtr pXmlDoc = parseMetadata(); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:namespaceURI", + u"http://www.aiim.org/pdfua/ns/id/"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:prefix", + u"pdfuaid"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:schema", + u"PDF/UA identification schema"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[1]/pdfaProperty:category", + u"internal"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[1]/pdfaProperty:description", + u"PDF/UA version identifier"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[1]/pdfaProperty:name", + u"part"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[1]/pdfaProperty:valueType", + u"Integer"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[2]/pdfaProperty:category", + u"internal"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[2]/pdfaProperty:description", + u"PDF/UA amendment identifier"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[2]/pdfaProperty:name", + u"amd"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[2]/pdfaProperty:valueType", + u"Text"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[3]/pdfaProperty:category", + u"internal"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[3]/pdfaProperty:description", + u"PDF/UA corrigenda identifier"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[3]/pdfaProperty:name", + u"corr"); + assertXPathContent(pXmlDoc, + "/x:xmpmeta/rdf:RDF/rdf:Description[3]/pdfaExtension:schemas/rdf:Bag/rdf:li/" + "pdfaSchema:property/rdf:Seq/rdf:li[3]/pdfaProperty:valueType", + u"Text"); } CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf152218) commit 39e7972184237538ec97129fb5293a78dd213384 Author: Xisco Fauli <[email protected]> AuthorDate: Thu Feb 26 10:09:00 2026 +0100 Commit: Xisco Fauli <[email protected]> CommitDate: Thu Feb 26 16:40:50 2026 +0100 CppunitTest_vcl_pdfexport2: factor out common code Change-Id: Ifde48d17130e56186420a8388c79f76c801c99fe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200410 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]> diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx index a41bd2f5e5b3..0bf7c75f7db1 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx @@ -66,6 +66,7 @@ public: } void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; + xmlDocUniquePtr parseMetadata(); }; void PdfExportTest2::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) @@ -80,6 +81,34 @@ void PdfExportTest2::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) BAD_CAST("http://www.aiim.org/pdfa/ns/id/")); } +xmlDocUniquePtr PdfExportTest2::parseMetadata() +{ + vcl::filter::PDFDocument aDocument; + // Parse the export result. + SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); + CPPUNIT_ASSERT(aDocument.Read(aStream)); + + auto* pCatalog = aDocument.GetCatalog(); + CPPUNIT_ASSERT(pCatalog); + auto* pCatalogDictionary = pCatalog->GetDictionary(); + CPPUNIT_ASSERT(pCatalogDictionary); + auto* pMetadataObject = pCatalogDictionary->LookupObject("Metadata"_ostr); + CPPUNIT_ASSERT(pMetadataObject); + auto* pMetadataDictionary = pMetadataObject->GetDictionary(); + auto* pType = dynamic_cast<vcl::filter::PDFNameElement*>( + pMetadataDictionary->LookupElement("Type"_ostr)); + CPPUNIT_ASSERT(pType); + CPPUNIT_ASSERT_EQUAL("Metadata"_ostr, pType->GetValue()); + + auto* pStreamObject = pMetadataObject->GetStream(); + CPPUNIT_ASSERT(pStreamObject); + auto& rStream = pStreamObject->GetMemory(); + rStream.Seek(0); + xmlDocUniquePtr pXmlDoc = parseXmlStream(&rStream); + CPPUNIT_ASSERT(pXmlDoc); + return pXmlDoc; +} + CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf160705) { // Enable PDF/UA @@ -1422,33 +1451,10 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testReexportDocumentWithComplexResources) CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf170448) { - vcl::filter::PDFDocument aDocument; loadFromFile(u"tdf170448.odt"); save(TestFilter::PDF_WRITER); - // Parse the export result. - SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); - CPPUNIT_ASSERT(aDocument.Read(aStream)); - - auto* pCatalog = aDocument.GetCatalog(); - CPPUNIT_ASSERT(pCatalog); - auto* pCatalogDictionary = pCatalog->GetDictionary(); - CPPUNIT_ASSERT(pCatalogDictionary); - auto* pMetadataObject = pCatalogDictionary->LookupObject("Metadata"_ostr); - CPPUNIT_ASSERT(pMetadataObject); - auto* pMetadataDictionary = pMetadataObject->GetDictionary(); - auto* pType = dynamic_cast<vcl::filter::PDFNameElement*>( - pMetadataDictionary->LookupElement("Type"_ostr)); - CPPUNIT_ASSERT(pType); - CPPUNIT_ASSERT_EQUAL("Metadata"_ostr, pType->GetValue()); - - auto* pStreamObject = pMetadataObject->GetStream(); - CPPUNIT_ASSERT(pStreamObject); - auto& rStream = pStreamObject->GetMemory(); - rStream.Seek(0); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&rStream); - CPPUNIT_ASSERT(pXmlDoc); - + xmlDocUniquePtr pXmlDoc = parseMetadata(); // Without the fix in place, this test would have failed with // - Expected: ' " < > & - ‘ » - l’île (copié-collé du texte) // - Actual : ' " < > & - ‘ » - l’île (copié-collé du texte) @@ -1474,29 +1480,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testPdfUaMetadata) skipValidation(); save(TestFilter::PDF_WRITER, aMediaDescriptor.getAsConstPropertyValueList()); - // Parse the export result. - SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); - CPPUNIT_ASSERT(aDocument.Read(aStream)); - - auto* pCatalog = aDocument.GetCatalog(); - CPPUNIT_ASSERT(pCatalog); - auto* pCatalogDictionary = pCatalog->GetDictionary(); - CPPUNIT_ASSERT(pCatalogDictionary); - auto* pMetadataObject = pCatalogDictionary->LookupObject("Metadata"_ostr); - CPPUNIT_ASSERT(pMetadataObject); - auto* pMetadataDictionary = pMetadataObject->GetDictionary(); - auto* pType = dynamic_cast<vcl::filter::PDFNameElement*>( - pMetadataDictionary->LookupElement("Type"_ostr)); - CPPUNIT_ASSERT(pType); - CPPUNIT_ASSERT_EQUAL("Metadata"_ostr, pType->GetValue()); - - auto* pStreamObject = pMetadataObject->GetStream(); - CPPUNIT_ASSERT(pStreamObject); - auto& rStream = pStreamObject->GetMemory(); - rStream.Seek(0); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&rStream); - CPPUNIT_ASSERT(pXmlDoc); - + xmlDocUniquePtr pXmlDoc = parseMetadata(); assertXPathContent(pXmlDoc, "/x:xmpmeta/rdf:RDF/rdf:Description[1]/pdfuaid:part", u"1"); } @@ -1513,29 +1497,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf138792) skipValidation(); save(TestFilter::PDF_WRITER, aMediaDescriptor.getAsConstPropertyValueList()); - // Parse the export result. - SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); - CPPUNIT_ASSERT(aDocument.Read(aStream)); - - auto* pCatalog = aDocument.GetCatalog(); - CPPUNIT_ASSERT(pCatalog); - auto* pCatalogDictionary = pCatalog->GetDictionary(); - CPPUNIT_ASSERT(pCatalogDictionary); - auto* pMetadataObject = pCatalogDictionary->LookupObject("Metadata"_ostr); - CPPUNIT_ASSERT(pMetadataObject); - auto* pMetadataDictionary = pMetadataObject->GetDictionary(); - auto* pType = dynamic_cast<vcl::filter::PDFNameElement*>( - pMetadataDictionary->LookupElement("Type"_ostr)); - CPPUNIT_ASSERT(pType); - CPPUNIT_ASSERT_EQUAL("Metadata"_ostr, pType->GetValue()); - - auto* pStreamObject = pMetadataObject->GetStream(); - CPPUNIT_ASSERT(pStreamObject); - auto& rStream = pStreamObject->GetMemory(); - rStream.Seek(0); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&rStream); - CPPUNIT_ASSERT(pXmlDoc); - + xmlDocUniquePtr pXmlDoc = parseMetadata(); assertXPath(pXmlDoc, "/x:xmpmeta/rdf:RDF/rdf:Description[1]/dc:date/rdf:Seq/rdf:li"); assertXPathContent(pXmlDoc, "/x:xmpmeta/rdf:RDF/rdf:Description[1]/dc:format", u"application/pdf"); @@ -1561,29 +1523,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf153472) skipValidation(); save(TestFilter::PDF_WRITER, aMediaDescriptor.getAsConstPropertyValueList()); - // Parse the export result. - SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); - CPPUNIT_ASSERT(aDocument.Read(aStream)); - - auto* pCatalog = aDocument.GetCatalog(); - CPPUNIT_ASSERT(pCatalog); - auto* pCatalogDictionary = pCatalog->GetDictionary(); - CPPUNIT_ASSERT(pCatalogDictionary); - auto* pMetadataObject = pCatalogDictionary->LookupObject("Metadata"_ostr); - CPPUNIT_ASSERT(pMetadataObject); - auto* pMetadataDictionary = pMetadataObject->GetDictionary(); - auto* pType = dynamic_cast<vcl::filter::PDFNameElement*>( - pMetadataDictionary->LookupElement("Type"_ostr)); - CPPUNIT_ASSERT(pType); - CPPUNIT_ASSERT_EQUAL("Metadata"_ostr, pType->GetValue()); - - auto* pStreamObject = pMetadataObject->GetStream(); - CPPUNIT_ASSERT(pStreamObject); - auto& rStream = pStreamObject->GetMemory(); - rStream.Seek(0); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&rStream); - CPPUNIT_ASSERT(pXmlDoc); - + xmlDocUniquePtr pXmlDoc = parseMetadata(); assertXPathContent(pXmlDoc, "/x:xmpmeta/rdf:RDF/rdf:Description[1]/pdfaid:part", u"1"); assertXPathContent(pXmlDoc, "/x:xmpmeta/rdf:RDF/rdf:Description[1]/pdfaid:conformance", u"B"); }
