[Libreoffice-commits] core.git: vcl/qa

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Sun Jan 17 00:08:57 UTC 2021


 vcl/qa/cppunit/pdfexport/data/BrownFoxLazyDog.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx            |   89 ++++++++++++++++++++++
 2 files changed, 89 insertions(+)

New commits:
commit 07d9819378192231322bb19a61f2cbd469f4611a
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Jan 17 00:10:00 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun Jan 17 01:07:54 2021 +0100

    tdf#139643: added a test, that checks the PDF/UA metadata is set
    
    If we enable support for PDF/UA, then the metadata object must be
    present and the metadata must have the PDF/UA flags set, or else
    the PDF document won't be recognied as having PDF/UA. The added
    test checks for this.
    
    Change-Id: I9baa31f17f5db73820d71d941979d6b9a90f4555
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109443
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/qa/cppunit/pdfexport/data/BrownFoxLazyDog.odt b/vcl/qa/cppunit/pdfexport/data/BrownFoxLazyDog.odt
new file mode 100644
index 000000000000..2e87c33c7194
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/BrownFoxLazyDog.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index b55d4856fbee..2b84591c3dca 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -36,6 +36,7 @@
 #include <unotools/tempfile.hxx>
 #include <vcl/filter/pdfdocument.hxx>
 #include <tools/zcodec.hxx>
+#include <tools/XmlWalker.hxx>
 #include <vcl/graphicfilter.hxx>
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <unotools/streamwrap.hxx>
@@ -2570,8 +2571,96 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testReexportDocumentWithComplexResources)
     }
 #endif
 }
+
+// Tests that at export the PDF has the PDF/UA metadata properly set
+// when we enable PDF/UA support.
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfUaMetadata)
+{
+    // Import a basic document (document doesn't really matter)
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "BrownFoxLazyDog.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");
+
+    // Enable PDF/UA
+    uno::Sequence<beans::PropertyValue> aFilterData(
+        comphelper::InitPropertySequence({ { "PDFUACompliance", uno::Any(true) } }));
+    aMediaDescriptor["FilterData"] <<= aFilterData;
+    xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+
+    // Parse the export result.
+    vcl::filter::PDFDocument aDocument;
+    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");
+    CPPUNIT_ASSERT(pMetadataObject);
+    auto* pMetadataDictionary = pMetadataObject->GetDictionary();
+    auto* pType
+        = dynamic_cast<vcl::filter::PDFNameElement*>(pMetadataDictionary->LookupElement("Type"));
+    CPPUNIT_ASSERT(pType);
+    CPPUNIT_ASSERT_EQUAL(OString("Metadata"), pType->GetValue());
+
+    auto* pStreamObject = pMetadataObject->GetStream();
+    CPPUNIT_ASSERT(pStreamObject);
+    auto& rStream = pStreamObject->GetMemory();
+    rStream.Seek(0);
+
+    // Search for the PDF/UA mrker in the metadata
+
+    tools::XmlWalker aWalker;
+    CPPUNIT_ASSERT(aWalker.open(&rStream));
+    CPPUNIT_ASSERT_EQUAL(OString("xmpmeta"), aWalker.name());
+
+    bool bPdfUaMarkerFound = false;
+    OString aPdfUaPart;
+
+    aWalker.children();
+    while (aWalker.isValid())
+    {
+        if (aWalker.name() == "RDF"
+            && aWalker.namespaceHref() == "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
+        {
+            aWalker.children();
+            while (aWalker.isValid())
+            {
+                if (aWalker.name() == "Description"
+                    && aWalker.namespaceHref() == "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
+                {
+                    aWalker.children();
+                    while (aWalker.isValid())
+                    {
+                        if (aWalker.name() == "part"
+                            && aWalker.namespaceHref() == "http://www.aiim.org/pdfua/ns/id/")
+                        {
+                            aPdfUaPart = aWalker.content();
+                            bPdfUaMarkerFound = true;
+                        }
+                        aWalker.next();
+                    }
+                    aWalker.parent();
+                }
+                aWalker.next();
+            }
+            aWalker.parent();
+        }
+        aWalker.next();
+    }
+    aWalker.parent();
+
+    CPPUNIT_ASSERT(bPdfUaMarkerFound);
+    CPPUNIT_ASSERT_EQUAL(OString("1"), aPdfUaPart);
 }
 
+} // end anonymous namespace
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list