sw/CppunitTest_sw_ooxmlexport4.mk          |    4 +
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx |    2 
 sw/qa/extras/ooxmlexport/ooxmlexport4.cxx  |   96 +++++++++++++++++++++--------
 sw/qa/extras/ooxmlexport/ooxmlexport8.cxx  |    3 
 writerfilter/source/dmapper/SdtHelper.cxx  |    9 ++
 5 files changed, 86 insertions(+), 28 deletions(-)

New commits:
commit b6e41d97fa8ee9e265970325348a6be111978c2c
Author:     Thorsten Behrens <thorsten.behr...@cib.de>
AuthorDate: Wed Jul 22 10:44:46 2020 +0200
Commit:     Thorsten Behrens <thorsten.behr...@cib.de>
CommitDate: Wed Aug 12 09:19:43 2020 +0200

    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.behr...@cib.de>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99994
    
    tdf#134572 DOCX: Incorrect default value in dropdown text fields
    
    Change-Id: I3169e817c2f033d1525adc3b02ac3680ad220d70
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99074
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100306

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/ooxmlexport13.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index abb55384f68f..5ad0a4ece74c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -900,7 +900,7 @@ DECLARE_OOXMLEXPORT_TEST(tdf119809, "tdf119809.docx")
         
CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown"));
 
         uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> 
>(aField, "Items");
-        CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aItems.getLength());
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aItems.getLength());
     }
 }
 
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index c80c8f6655bb..c39c7d747b83 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")
@@ -765,12 +781,48 @@ DECLARE_OOXMLEXPORT_TEST(testFDO76312, "FDO76312.docx")
     assertXPath(pXmlDoc, "/w:document/w:body/w:tbl[1]/w:tr[1]/w:tc[1]");
 }
 
-DECLARE_OOXMLEXPORT_TEST(testComboBoxControl, "combobox-control.docx")
+void Test::verifyComboBoxExport(bool aComboBoxAsDropDown)
+{
+    if (aComboBoxAsDropDown)
+    {
+        // ComboBox was imported as DropDown text field
+        uno::Reference<text::XTextFieldsSupplier> 
xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+        uno::Reference<container::XEnumerationAccess> 
xFieldsAccess(xTextFieldsSupplier->getTextFields());
+        uno::Reference<container::XEnumeration> 
xFields(xFieldsAccess->createEnumeration());
+        CPPUNIT_ASSERT(xFields->hasMoreElements());
+        uno::Any aField = xFields->nextElement();
+        uno::Reference<lang::XServiceInfo> xServiceInfo(aField, 
uno::UNO_QUERY);
+        
CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown"));
+
+        uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> 
>(aField, "Items");
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aItems.getLength());
+        CPPUNIT_ASSERT_EQUAL(OUString("manolo"), aItems[0]);
+        CPPUNIT_ASSERT_EQUAL(OUString("pepito"), aItems[1]);
+        CPPUNIT_ASSERT_EQUAL(OUString("Manolo"), aItems[2]);
+    }
+    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
     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     if (!pXmlDoc)
         return;
+
     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");
@@ -779,35 +831,27 @@ DECLARE_OOXMLEXPORT_TEST(testComboBoxControl, 
"combobox-control.docx")
     uno::Reference<drawing::XDrawPage> xDrawPage = 
xDrawPageSupplier->getDrawPage();
 
     // check imported control
-    if (xDrawPage->getCount() > 0)
-    {
-        uno::Reference<drawing::XControlShape> xControl(getShape(1), 
uno::UNO_QUERY);
+    verifyComboBoxExport(xDrawPage->getCount() == 0);
+}
 
-        CPPUNIT_ASSERT_EQUAL(OUString("Manolo"), 
getProperty<OUString>(xControl->getControl(), "Text"));
+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();
 
-        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
-    {
-        // ComboBox was imported as DropDown text field
-        uno::Reference<text::XTextFieldsSupplier> 
xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
-        uno::Reference<container::XEnumerationAccess> 
xFieldsAccess(xTextFieldsSupplier->getTextFields());
-        uno::Reference<container::XEnumeration> 
xFields(xFieldsAccess->createEnumeration());
-        CPPUNIT_ASSERT(xFields->hasMoreElements());
-        uno::Any aField = xFields->nextElement();
-        uno::Reference<lang::XServiceInfo> xServiceInfo(aField, 
uno::UNO_QUERY);
-        
CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown"));
+    load(mpTestDocumentPath, "combobox-control.docx");
+    verifyComboBoxExport(true);
+}
 
-        CPPUNIT_ASSERT_EQUAL(OUString("manolo"), getProperty<OUString>(aField, 
"SelectedItem"));
+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();
 
-        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]);
-    }
+    load(mpTestDocumentPath, "combobox-control.docx");
+    verifyComboBoxExport(false);
 }
 
 DECLARE_OOXMLEXPORT_TEST(testCheckBoxControl, "checkbox-control.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
index 0e1416b7ee00..fbe8d9d01421 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
@@ -959,9 +959,10 @@ DECLARE_OOXMLEXPORT_TEST(testN779630, "n779630.docx")
         
CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown"));
 
         uno::Sequence<OUString> aItems = getProperty< uno::Sequence<OUString> 
>(aField, "Items");
-        CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aItems.getLength());
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aItems.getLength());
         CPPUNIT_ASSERT_EQUAL(OUString("Yes"), aItems[0]);
         CPPUNIT_ASSERT_EQUAL(OUString("No"), aItems[1]);
+        CPPUNIT_ASSERT_EQUAL(OUString("dropdown default text"), aItems[2]);
     }
 }
 
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx 
b/writerfilter/source/dmapper/SdtHelper.cxx
index 3685e92cf942..154e7660d842 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -93,6 +93,15 @@ void SdtHelper::createDropDownControl()
             
m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.text.TextField.DropDown"),
             uno::UNO_QUERY);
 
+        const auto it = std::find_if(
+            m_aDropDownItems.begin(), m_aDropDownItems.end(),
+            [aDefaultText](const OUString& item) -> bool { return 
!item.compareTo(aDefaultText); });
+
+        if (m_aDropDownItems.end() == it)
+        {
+            m_aDropDownItems.push_back(aDefaultText);
+        }
+
         // set properties
         uno::Reference<beans::XPropertySet> xPropertySet(xControlModel, 
uno::UNO_QUERY);
         xPropertySet->setPropertyValue("SelectedItem", 
uno::makeAny(aDefaultText));
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to