summaryrefslogtreecommitdiff
path: root/sw/qa/core/text/text.cxx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-09-14 08:35:28 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-09-14 10:08:04 +0200
commit6b2433f3b66c1f118dabcd40924122deb2d4f204 (patch)
tree330f56598f86dd31c6c450dfd1a7e281ead7621c /sw/qa/core/text/text.cxx
parente735ad1c57cddaf17d6ffc0cf15b5e14fa63c4ad (diff)
sw content controls, dropdown: add PDF export
Map this to vcl::PDFWriter::ListBoxWidget, which uses the /FT/Ch widget, i.e. a (dropdown) choice widget. Also extract a SwModelTestBase::StoreToTempFile() from the various test cases that export to a tempfile just by specifying the filter name. Change-Id: If9ad52ae2553d7199e28188cfdf455353e202ccd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139904 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/qa/core/text/text.cxx')
-rw-r--r--sw/qa/core/text/text.cxx49
1 files changed, 37 insertions, 12 deletions
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index e5d530af2531..26623e2d3f01 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -116,10 +116,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testBibliographyUrlPdfExport)
xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false);
// When exporting to PDF:
- uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
- utl::MediaDescriptor aMediaDescriptor;
- aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
- xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+ StoreToTempFile("writer_pdf_Export");
// Then make sure the field links the source.
SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
@@ -632,10 +629,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDF)
pWrtShell->InsertContentControl(SwContentControlType::RICH_TEXT);
// When exporting to PDF:
- uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
- utl::MediaDescriptor aMediaDescriptor;
- aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
- xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+ StoreToTempFile("writer_pdf_Export");
// Then make sure that a fillable form widget is emitted:
SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
@@ -664,10 +658,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testCheckboxContentControlPDF)
pWrtShell->InsertContentControl(SwContentControlType::CHECKBOX);
// When exporting to PDF:
- uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
- utl::MediaDescriptor aMediaDescriptor;
- aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
- xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+ StoreToTempFile("writer_pdf_Export");
// Then make sure that a checkbox form widget is emitted:
SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
@@ -693,6 +684,40 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testCheckboxContentControlPDF)
pAnnotation->getFormFieldType(pPdfDocument.get()));
}
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDropdownContentControlPDF)
+{
+ // Given a file with a dropdown content control:
+ SwDoc* pDoc = createSwDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST);
+
+ // When exporting to PDF:
+ StoreToTempFile("writer_pdf_Export");
+
+ // Then make sure that a dropdown form widget is emitted:
+ SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+ SvMemoryStream aMemory;
+ aMemory.WriteStream(aFile);
+ std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
+ if (!pPDFium)
+ {
+ return;
+ }
+ std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument
+ = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString());
+ std::unique_ptr<vcl::pdf::PDFiumPage> pPage = pPdfDocument->openPage(0);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 1
+ // - Actual : 0
+ // i.e. the dropdown content control was just exported as normal text.
+ CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount());
+ std::unique_ptr<vcl::pdf::PDFiumAnnotation> pAnnotation = pPage->getAnnotation(0);
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Widget, pAnnotation->getSubType());
+ // Also check the form widget type (our dropdown is called combo in PDF terms):
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFFormFieldType::ComboBox,
+ pAnnotation->getFormFieldType(pPdfDocument.get()));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */