diff --git a/sw/CppunitTest_sw_mailmerge2.mk b/sw/CppunitTest_sw_mailmerge2.mk index 0dcd55714c5b..f7a376b09eac 100644 --- a/sw/CppunitTest_sw_mailmerge2.mk +++ b/sw/CppunitTest_sw_mailmerge2.mk @@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_mailmerge2, \ tl \ unotest \ utl \ + vcl \ )) $(eval $(call gb_CppunitTest_use_externals,sw_mailmerge2, \ diff --git a/sw/qa/extras/mailmerge/mailmerge2.cxx b/sw/qa/extras/mailmerge/mailmerge2.cxx index 30c26402c1c3..20eb6b0f3896 100644 --- a/sw/qa/extras/mailmerge/mailmerge2.cxx +++ b/sw/qa/extras/mailmerge/mailmerge2.cxx @@ -14,7 +14,10 @@ #include +#include +#include #include +#include #include #include #include @@ -23,8 +26,12 @@ #include #include +#include #include #include +#include +#include +#include #include #include @@ -455,6 +462,69 @@ DECLARE_FILE_MAILMERGE_TEST(testTdf122156_file, "linked-with-condition.odt", "5- } } +DECLARE_SHELL_MAILMERGE_TEST(exportDirectToPDF_shell, "linked-with-condition.odt", "5-with-blanks.ods", + "names") +{ + executeMailMerge(); + + uno::Reference xModel(mxMMComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xModel.is()); + + uno::Reference xController(xModel->getCurrentController()); + CPPUNIT_ASSERT(xController.is()); + + uno::Reference xSupplier(xController, uno::UNO_QUERY); + CPPUNIT_ASSERT(xSupplier.is()); + + uno::Reference xPageCursor(xSupplier->getViewCursor(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xPageCursor.is()); + + xPageCursor->jumpToFirstPage(); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xPageCursor->getPage()); + + uno::Reference xFrame(xController->getFrame()); + CPPUNIT_ASSERT(xFrame.is()); + + uno::Reference xDispatchProvider(xFrame, uno::UNO_QUERY); + CPPUNIT_ASSERT(xDispatchProvider.is()); + + util::URL aURL; + aURL.Complete = ".uno:ExportDirectToPDF"; + { + uno::Reference xParser(css::util::URLTransformer::create( + comphelper::getProcessComponentContext())); + CPPUNIT_ASSERT(xParser.is()); + xParser->parseStrict(aURL); + } + + uno::Reference xDispatch = xDispatchProvider->queryDispatch(aURL, OUString(), 0); + CPPUNIT_ASSERT(xDispatch.is()); + + const OUString sExportTo(msMailMergeOutputURL + "/ExportDirectToPDF.pdf"); + uno::Sequence aArgs { + comphelper::makePropertyValue("SynchronMode", true), + comphelper::makePropertyValue("URL", sExportTo) + }; + + xDispatch->dispatch(aURL, aArgs); + CPPUNIT_ASSERT(comphelper::DirectoryHelper::fileExists(sExportTo)); + + SvFileStream aPDFFile(sExportTo, StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aPDFFile); + std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get(); + CPPUNIT_ASSERT(pPDFium); + + std::unique_ptr pPdfDocument + = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + CPPUNIT_ASSERT(pPdfDocument); + CPPUNIT_ASSERT_EQUAL(5, pPdfDocument->getPageCount()); + + std::unique_ptr pPdfPage = pPdfDocument->openPage(0); + CPPUNIT_ASSERT(pPdfPage); + CPPUNIT_ASSERT_EQUAL(4, pPdfPage->getObjectCount()); +} + DECLARE_SHELL_MAILMERGE_TEST(testTdf121168, "section_ps.odt", "4_v01.ods", "Tabelle1") { // A document starting with a section on a page with non-default page style with header