tdf#160117: vcl_pdfexport2: Add unittest
Change-Id: I5b10d92d1ba4d62a8a0b4e2d8b0f023b58225fb0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165098
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf160117.ods b/vcl/qa/cppunit/pdfexport/data/tdf160117.ods
new file mode 100644
index 0000000..ed18444
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/tdf160117.ods
Binary files differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
index 061b79e..525f1d9 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
@@ -1047,6 +1047,48 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testReexportPDF)
#endif
}
CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf160117)
{
vcl::filter::PDFDocument aDocument;
load(u"tdf160117.ods", aDocument);
// The document has one page.
std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
int nCount = 0;
bool bFound1 = false;
bool bFound2 = false;
bool bFound3 = false;
for (const auto& rDocElement : aDocument.GetElements())
{
auto pObject = dynamic_cast<vcl::filter::PDFObjectElement*>(rDocElement.get());
if (!pObject)
continue;
auto pType = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("Type"_ostr));
if (pType && pType->GetValue() == "FontDescriptor")
{
auto pFontName
= dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("FontName"_ostr));
CPPUNIT_ASSERT(pFontName);
if ("CAAAAA+LiberationSans-Bold"_ostr == pFontName->GetValue())
bFound1 = true;
else if ("DAAAAA+LiberationSans-Italic"_ostr == pFontName->GetValue())
bFound2 = true;
else if ("BAAAAA+LiberationSans"_ostr == pFontName->GetValue())
bFound3 = true;
++nCount;
}
}
// Without the fix in place, this test would have failed with
// - Expected: 3
// - Actual : 2
CPPUNIT_ASSERT_EQUAL(3, nCount);
CPPUNIT_ASSERT(bFound1);
CPPUNIT_ASSERT(bFound2);
CPPUNIT_ASSERT(bFound3);
}
// Check we correctly copy more complex resources (Fonts describing
// glyphs in recursive arrays) to the target PDF
CPPUNIT_TEST_FIXTURE(PdfExportTest2, testReexportDocumentWithComplexResources)