summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2021-11-12 09:19:40 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2021-11-12 11:59:44 +0100
commita0a4aa475e29bd030313c1a17e962386e6d063ca (patch)
treee7cbf54ce7a07fcf85898474c14363f04bf33b65 /sw
parentbb58293296f843654045d7b0eba6899d11533a4a (diff)
tdf#145584: sw_uiwriter3: Add unittest
Change-Id: I2713a6563542307e8103a88301bb623bd8da11d1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125079 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/uiwriter/uiwriter3.cxx54
1 files changed, 54 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index 72e91ba9f0cb..b90e5d18ee56 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -9,6 +9,7 @@
#include <swmodeltestbase.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <vcl/filter/PDFiumLibrary.hxx>
#include <vcl/scheduler.hxx>
#include <vcl/TypeSerializer.hxx>
#include <com/sun/star/awt/FontWeight.hpp>
@@ -29,6 +30,7 @@
#include <textboxhelper.hxx>
#include <o3tl/safeint.hxx>
#include <tools/json_writer.hxx>
+#include <unotools/mediadescriptor.hxx>
#include <unotools/streamwrap.hxx>
#include <sfx2/linkmgr.hxx>
@@ -1768,6 +1770,58 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf130629)
CPPUNIT_ASSERT_EQUAL(1, getShapes());
}
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf145584)
+{
+ std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
+ if (!pPDFium)
+ {
+ return;
+ }
+ SwDoc* const pDoc = createSwDoc();
+ SwWrtShell* const pWrtSh = pDoc->GetDocShell()->GetWrtShell();
+ CPPUNIT_ASSERT(pWrtSh);
+
+ pWrtSh->Insert("Hello World");
+
+ // Select 'World'
+ pWrtSh->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 5, /*bBasicCall=*/false);
+
+ // Save as PDF.
+ uno::Sequence<beans::PropertyValue> aFilterData(
+ comphelper::InitPropertySequence({ { "Selection", uno::Any(true) } }));
+
+ uno::Sequence<beans::PropertyValue> aDescriptor(comphelper::InitPropertySequence(
+ { { "FilterName", uno::Any(OUString("writer_pdf_Export")) },
+ { "FilterData", uno::Any(aFilterData) },
+ { "URL", uno::Any(maTempFile.GetURL()) } }));
+
+ // Without the fix in place, this test would have crashed here
+ dispatchCommand(mxComponent, ".uno:ExportToPDF", aDescriptor);
+
+ // Parse the export result.
+ SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+ SvMemoryStream aMemory;
+ aMemory.WriteStream(aFile);
+ std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument
+ = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize());
+ CPPUNIT_ASSERT(pPdfDocument);
+ CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
+ std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0);
+ CPPUNIT_ASSERT(pPdfPage);
+ CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getObjectCount());
+ std::unique_ptr<vcl::pdf::PDFiumTextPage> pPdfTextPage = pPdfPage->getTextPage();
+ CPPUNIT_ASSERT(pPdfTextPage);
+
+ int nChars = pPdfTextPage->countChars();
+ CPPUNIT_ASSERT_EQUAL(5, nChars);
+
+ std::vector<sal_uInt32> aChars(nChars);
+ for (int i = 0; i < nChars; i++)
+ aChars[i] = pPdfTextPage->getUnicode(i);
+ OUString aActualText(aChars.data(), aChars.size());
+ CPPUNIT_ASSERT_EQUAL(OUString("World"), aActualText);
+}
+
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf116315)
{
SwDoc* const pDoc = createSwDoc();