diff options
author | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-07-22 10:44:46 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-08-05 23:25:25 +0200 |
commit | 0c9a3fd2cf6e87e08d93f47f2d0987a57a8720c9 (patch) | |
tree | bd314fcb38970104a4aa3b82d27607af23f21215 | |
parent | 917c3d0520b4e4108ae1b26fdecbf6ec089497a7 (diff) |
tdf#134043 DOCX import: new unit tests: ComboBox to DropDown
Change-Id: I034b0cd9c6f66c531460d1bb69d9ede5ff46f7d7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97531
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99994
-rw-r--r-- | sw/CppunitTest_sw_ooxmlexport4.mk | 4 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport4.cxx | 86 |
2 files changed, 68 insertions, 22 deletions
diff --git a/sw/CppunitTest_sw_ooxmlexport4.mk b/sw/CppunitTest_sw_ooxmlexport4.mk index e3285932e004..0f026bc8384e 100644 --- a/sw/CppunitTest_sw_ooxmlexport4.mk +++ b/sw/CppunitTest_sw_ooxmlexport4.mk @@ -11,4 +11,8 @@ $(eval $(call sw_ooxmlexport_test,4)) +$(eval $(call gb_CppunitTest_use_custom_headers,sw_ooxmlexport4,\ + officecfg/registry \ +)) + # vim: set noet sw=4 ts=4: diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx index 9d3ce8cd9292..22d069a90864 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx @@ -23,6 +23,9 @@ #include <com/sun/star/util/Date.hpp> #include <unotools/tempfile.hxx> #include <config_features.h> +#include <comphelper/configuration.hxx> +#include <officecfg/Office/Writer.hxx> + class Test : public SwModelTestBase { @@ -43,6 +46,19 @@ protected: // If the testcase is stored in some other format, it's pointless to test. return (OString(filename).endsWith(".docx") && std::find(vBlacklist.begin(), vBlacklist.end(), filename) == vBlacklist.end()); } + + virtual std::unique_ptr<Resetter> preTest(const char* filename) override + { + if (OString(filename) == "combobox-control.docx" ) + { + std::shared_ptr< comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create()); + officecfg::Office::Writer::Filter::Import::DOCX::ImportComboBoxAsDropDown::set(true, batch); + batch->commit(); + } + return nullptr; + } + + void verifyComboBoxExport(bool aComboBoxAsDropDown); }; DECLARE_OOXMLEXPORT_TEST(testRelorientation, "relorientation.docx") @@ -711,27 +727,9 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFDO76312, "FDO76312.docx") assertXPath(pXmlDoc, "/w:document/w:body/w:tbl[1]/w:tr[1]/w:tc[1]"); } -DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testComboBoxControl, "combobox-control.docx") +void Test::verifyComboBoxExport(bool aComboBoxAsDropDown) { - // check XML - xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); - assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dropDownList/w:listItem[1]", "value", "manolo"); - assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dropDownList/w:listItem[2]", "value", "pepito"); - assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", "manolo"); - - // check imported control - if (getShapes() > 0) - { - uno::Reference<drawing::XControlShape> xControl(getShape(1), uno::UNO_QUERY); - - CPPUNIT_ASSERT_EQUAL(OUString("Manolo"), getProperty<OUString>(xControl->getControl(), "Text")); - - uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> >(xControl->getControl(), "StringItemList"); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aItems.getLength()); - CPPUNIT_ASSERT_EQUAL(OUString("manolo"), aItems[0]); - CPPUNIT_ASSERT_EQUAL(OUString("pepito"), aItems[1]); - } - else + if (aComboBoxAsDropDown) { // ComboBox was imported as DropDown text field uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); @@ -742,13 +740,57 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testComboBoxControl, "combobox-control.docx" uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY); CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown")); - CPPUNIT_ASSERT_EQUAL(OUString("manolo"), getProperty<OUString>(aField, "SelectedItem")); - uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> >(aField, "Items"); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aItems.getLength()); CPPUNIT_ASSERT_EQUAL(OUString("manolo"), aItems[0]); CPPUNIT_ASSERT_EQUAL(OUString("pepito"), aItems[1]); } + else + { + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference<drawing::XControlShape> xControl(xShape, uno::UNO_QUERY); + + CPPUNIT_ASSERT_EQUAL(OUString("Manolo"), getProperty<OUString>(xControl->getControl(), "Text")); + + uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> >(xControl->getControl(), "StringItemList"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aItems.getLength()); + CPPUNIT_ASSERT_EQUAL(OUString("manolo"), aItems[0]); + CPPUNIT_ASSERT_EQUAL(OUString("pepito"), aItems[1]); + } +} + +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testComboBoxControl, "combobox-control.docx") +{ + // check XML + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dropDownList/w:listItem[1]", "value", "manolo"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dropDownList/w:listItem[2]", "value", "pepito"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", "manolo"); + + // check imported control + verifyComboBoxExport(getShapes() == 0); +} + +CPPUNIT_TEST_FIXTURE(Test, tdf134043_ImportComboBoxAsDropDown_true) +{ + std::shared_ptr< comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create()); + officecfg::Office::Writer::Filter::Import::DOCX::ImportComboBoxAsDropDown::set(true, batch); + batch->commit(); + + load(mpTestDocumentPath, "combobox-control.docx"); + verifyComboBoxExport(true); +} + +CPPUNIT_TEST_FIXTURE(Test, tdf134043_ImportComboBoxAsDropDown_false) +{ + std::shared_ptr< comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create()); + officecfg::Office::Writer::Filter::Import::DOCX::ImportComboBoxAsDropDown::set(false, batch); + batch->commit(); + + load(mpTestDocumentPath, "combobox-control.docx"); + verifyComboBoxExport(false); } DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testCheckBoxControl, "checkbox-control.docx") |