From 33ad3ee258587904afaa03550858beac25b883f7 Mon Sep 17 00:00:00 2001 From: Serge Krot Date: Tue, 16 Jun 2020 17:11:12 +0200 Subject: tdf#134043 DOCX import: DropDown text field instead of ComboBox form control Change-Id: Ide9cedefde3b00fa0eeb37a6540e8d4a420b70c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96471 Tested-by: Jenkins Reviewed-by: Thorsten Behrens --- sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 26 +++++++++++++++++----- sw/qa/extras/ooxmlexport/ooxmlexport13.cxx | 29 ++++++++++++++++++++----- sw/qa/extras/ooxmlexport/ooxmlexport4.cxx | 35 ++++++++++++++++++++++++------ sw/qa/extras/ooxmlexport/ooxmlexport8.cxx | 33 ++++++++++++++++++++++------ sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 4 ++-- 5 files changed, 99 insertions(+), 28 deletions(-) (limited to 'sw') diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 5ff581743ccd..133c2add7822 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -264,12 +264,26 @@ DECLARE_OOXMLEXPORT_TEST(testDropdownInCell, "dropdown-in-cell.docx") CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); // Second problem: dropdown shape wasn't anchored inside the B1 cell. - uno::Reference xShape(getShape(1), uno::UNO_QUERY); - uno::Reference xAnchor = xShape->getAnchor(); - uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); - uno::Reference xCell(xTable->getCellByName("B1"), uno::UNO_QUERY); - uno::Reference xTextRangeCompare(xCell, uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(sal_Int16(0), xTextRangeCompare->compareRegionStarts(xAnchor, xCell)); + if (getShapes() > 0) + { + uno::Reference xShape(getShape(1), uno::UNO_QUERY); + uno::Reference xAnchor = xShape->getAnchor(); + uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference xCell(xTable->getCellByName("B1"), uno::UNO_QUERY); + uno::Reference xTextRangeCompare(xCell, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), xTextRangeCompare->compareRegionStarts(xAnchor, xCell)); + } + else + { + // ComboBox was imported as DropDown text field + uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + CPPUNIT_ASSERT(xFields->hasMoreElements()); + uno::Any aField = xFields->nextElement(); + uno::Reference xServiceInfo(aField, uno::UNO_QUERY); + CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown")); + } } DECLARE_OOXMLEXPORT_TEST(testTableAlignment, "table-alignment.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index 272daae72c78..430749768862 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -560,7 +560,7 @@ DECLARE_OOXMLEXPORT_TEST(testParaAdjustDistribute, "para-adjust-distribute.docx" DECLARE_OOXMLEXPORT_TEST(testInputListExport, "tdf122186_input_list.odt") { CPPUNIT_ASSERT_EQUAL(1, getPages()); - if (!mbExported) // importing the ODT, an input field + if (!mbExported || getShapes() == 0) // importing the ODT, an input field { uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); @@ -1032,11 +1032,28 @@ DECLARE_OOXMLEXPORT_TEST(tdf127085, "tdf127085.docx") DECLARE_OOXMLEXPORT_TEST(tdf119809, "tdf119809.docx") { // Combobox without an item list lost during import - uno::Reference xControlShape(getShape(1), uno::UNO_QUERY); - uno::Reference xPropertySet(xControlShape->getControl(), uno::UNO_QUERY); - uno::Reference xServiceInfo(xPropertySet, uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo->supportsService("com.sun.star.form.component.ComboBox"))); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty< uno::Sequence >(xPropertySet, "StringItemList").getLength()); + if (getShapes() > 0) + { + uno::Reference xControlShape(getShape(1), uno::UNO_QUERY); + uno::Reference xPropertySet(xControlShape->getControl(), uno::UNO_QUERY); + uno::Reference xServiceInfo(xPropertySet, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo->supportsService("com.sun.star.form.component.ComboBox"))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty< uno::Sequence >(xPropertySet, "StringItemList").getLength()); + } + else + { + // ComboBox was imported as DropDown text field + uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + CPPUNIT_ASSERT(xFields->hasMoreElements()); + uno::Any aField = xFields->nextElement(); + uno::Reference xServiceInfo(aField, uno::UNO_QUERY); + CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown")); + + uno::Sequence aItems = getProperty< uno::Sequence >(aField, "Items"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aItems.getLength()); + } } DECLARE_OOXMLEXPORT_TEST(tdf118169, "tdf118169.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx index c1890a33c2cd..7356de7be9fe 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx @@ -714,17 +714,38 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testComboBoxControl, "combobox-control.docx" 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"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", "manolo"); // check imported control - uno::Reference xControl(getShape(1), uno::UNO_QUERY); + if (getShapes() > 0) + { + uno::Reference xControl(getShape(1), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("Manolo"), getProperty(xControl->getControl(), "Text")); + CPPUNIT_ASSERT_EQUAL(OUString("Manolo"), getProperty(xControl->getControl(), "Text")); - uno::Sequence aItems = getProperty< uno::Sequence >(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]); + uno::Sequence aItems = getProperty< uno::Sequence >(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 xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + CPPUNIT_ASSERT(xFields->hasMoreElements()); + uno::Any aField = xFields->nextElement(); + uno::Reference xServiceInfo(aField, uno::UNO_QUERY); + CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown")); + + CPPUNIT_ASSERT_EQUAL(OUString("manolo"), getProperty(aField, "SelectedItem")); + + uno::Sequence aItems = getProperty< uno::Sequence >(aField, "Items"); + 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(testCheckBoxControl, "checkbox-control.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx index 56e6e6b1079f..5f401b266bfc 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx @@ -926,13 +926,32 @@ DECLARE_OOXMLEXPORT_TEST(testN592908_Picture, "n592908-picture.docx") DECLARE_OOXMLEXPORT_TEST(testN779630, "n779630.docx") { // A combo box is imported - uno::Reference xControlShape(getShape(1), uno::UNO_QUERY); - uno::Reference xPropertySet(xControlShape->getControl(), uno::UNO_QUERY); - uno::Reference xServiceInfo(xPropertySet, uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo->supportsService("com.sun.star.form.component.ComboBox"))); - CPPUNIT_ASSERT_EQUAL(OUString("dropdown default text"), getProperty(xPropertySet, "DefaultText")); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty< uno::Sequence >(xPropertySet, "StringItemList").getLength()); - CPPUNIT_ASSERT_EQUAL(true, getProperty(xPropertySet, "Dropdown")); + if (getShapes() > 0) + { + uno::Reference xControlShape(getShape(1), uno::UNO_QUERY); + uno::Reference xPropertySet(xControlShape->getControl(), uno::UNO_QUERY); + uno::Reference xServiceInfo(xPropertySet, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo->supportsService("com.sun.star.form.component.ComboBox"))); + CPPUNIT_ASSERT_EQUAL(OUString("dropdown default text"), getProperty(xPropertySet, "DefaultText")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty< uno::Sequence >(xPropertySet, "StringItemList").getLength()); + CPPUNIT_ASSERT_EQUAL(true, getProperty(xPropertySet, "Dropdown")); + } + else + { + // ComboBox was imported as DropDown text field + uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + CPPUNIT_ASSERT(xFields->hasMoreElements()); + uno::Any aField = xFields->nextElement(); + uno::Reference xServiceInfo(aField, uno::UNO_QUERY); + CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.DropDown")); + + uno::Sequence aItems = getProperty< uno::Sequence >(aField, "Items"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aItems.getLength()); + CPPUNIT_ASSERT_EQUAL(OUString("Yes"), aItems[0]); + CPPUNIT_ASSERT_EQUAL(OUString("No"), aItems[1]); + } } DECLARE_OOXMLEXPORT_TEST(testIndentation, "indentation.docx") diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index ecd4c588fbbd..b2e67a1d3769 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -1367,8 +1367,8 @@ DECLARE_OOXMLIMPORT_TEST(testTdf133448, "tdf133448.docx") CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("SizePixel") >>= aSizePixel); //Without the fix in place, the graphic's size is 0x0 - CPPUNIT_ASSERT_EQUAL(sal_Int32(837), aSizePixel.Width); - CPPUNIT_ASSERT_EQUAL(sal_Int32(598), aSizePixel.Height); + CPPUNIT_ASSERT_GREATER(sal_Int32(0), aSizePixel.Width); + CPPUNIT_ASSERT_GREATER(sal_Int32(0), aSizePixel.Height); } DECLARE_OOXMLIMPORT_TEST(testTdf100072, "tdf100072.docx") -- cgit