[Libreoffice-commits] core.git: sw/qa sw/source

Tamás Zolnai (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 12 05:06:49 UTC 2019


 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx   |   57 +++++++++++++++++++--------
 sw/source/filter/ww8/docxattributeoutput.cxx |    2 
 2 files changed, 42 insertions(+), 17 deletions(-)

New commits:
commit 6fd9987ae650bb2f0dd40aec95662a75c9a85598
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Mon Jul 1 12:20:45 2019 +0200
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Jul 12 07:05:04 2019 +0200

    MSForms: DOCX filter: handle export of empty date from control
    
    * It's converted to date content control which is imported as text-based
    date control.
    * By now, we don't need to set a dummy text for empty date.
    
    Change-Id: I29b2a72e3ae2722c1d765c4fcb9bd13052619372
    Reviewed-on: https://gerrit.libreoffice.org/75458
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
    Tested-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index 4512bf04c4eb..3a0d1924c4c8 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -157,24 +157,51 @@ DECLARE_OOXMLEXPORT_TEST(tdf123912_protectedForm, "tdf123912_protectedForm.odt")
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Section1 is protected", false, getProperty<bool>(xSect, "IsProtected"));
 }
 
-/*DECLARE_OOXMLEXPORT_TEST(testDateControl, "empty-date-control.odt")
+DECLARE_OOXMLEXPORT_TEST(testDateControl, "empty-date-control.odt")
 {
-    // Check that we did not lost the date control
-    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
-    uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xDraws->getCount());
-    uno::Reference<drawing::XControlShape> xControl(getShape(1), uno::UNO_QUERY);
-    CPPUNIT_ASSERT(xControl->getControl().is());
+    // Check that we exported the empty date control correctly
+    // Date form field is converted to date content control.
+    if (!mbExported)
+        return ;
 
-    // check XML
-    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
-    if (!pXmlDoc)
-        return;
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+
+
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
+    ::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*pMarkAccess->getAllMarksBegin());
+
+    CPPUNIT_ASSERT(pFieldmark);
+    CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
 
-    // We need to export date format and a dummy character (" ") for empty date control
-    assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:dateFormat", "val", "dd/MM/yyyy");
-    assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", u" ");
-}*/
+    const sw::mark::IFieldmark::parameter_map_t* const pParameters = pFieldmark->GetParameters();
+    OUString sDateFormat;
+    auto pResult = pParameters->find(ODF_FORMDATE_DATEFORMAT);
+    if (pResult != pParameters->end())
+    {
+        pResult->second >>= sDateFormat;
+    }
+
+    OUString sLang;
+    pResult = pParameters->find(ODF_FORMDATE_DATEFORMAT_LANGUAGE);
+    if (pResult != pParameters->end())
+    {
+        pResult->second >>= sLang;
+    }
+
+    OUString sCurrentDate;
+    pResult = pParameters->find(ODF_FORMDATE_CURRENTDATE);
+    if (pResult != pParameters->end())
+    {
+        pResult->second >>= sCurrentDate;
+    }
+
+    CPPUNIT_ASSERT_EQUAL(OUString("dd/MM/yyyy"), sDateFormat);
+    CPPUNIT_ASSERT_EQUAL(OUString("en-US"), sLang);
+    CPPUNIT_ASSERT_EQUAL(OUString(""), sCurrentDate);
+}
 
 DECLARE_OOXMLEXPORT_TEST(testTdf121867, "tdf121867.odt")
 {
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 68d2e120bf5b..024e29182209 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5220,8 +5220,6 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
         else
         {
             aContentText = xPropertySet->getPropertyValue("HelpText").get<OUString>();
-            if(aContentText.isEmpty())
-                aContentText = " "; // Need to write out something to have it imported by MS Word
             if(sDateFormat.isEmpty())
                 sDateFormat = "dd/MM/yyyy"; // Need to set date format even if there is no date set
         }


More information about the Libreoffice-commits mailing list