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

Tamás Zolnai (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 12 04:11:14 UTC 2019


 sw/qa/extras/ooxmlexport/data/invalid_date_form_field.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx                 |   78 +++++++++++++
 sw/qa/extras/ooxmlimport/ooxmlimport2.cxx                  |   16 +-
 writerfilter/source/dmapper/DomainMapper.cxx               |   17 +-
 4 files changed, 100 insertions(+), 11 deletions(-)

New commits:
commit 52205f85582aaaee04fcfffd1c1729454f512400
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Mon Jul 1 15:49:01 2019 +0200
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Jul 12 06:10:11 2019 +0200

    MSForms: DOCX filter: import manually set date field as plain text
    
    In MSO the user can add any text in the date field without having it
    in the specified date format. We import this kind of date as plain text.
    
    Change-Id: Ied4bf03a3ac4c9b6f1cfc78d91e6a52ad3d6e179
    Reviewed-on: https://gerrit.libreoffice.org/75452
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index 0e49295227f0..5e917d09a0b4 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -35,13 +35,19 @@ DECLARE_OOXMLIMPORT_TEST(testTdf108545_embeddedDocxIcon, "tdf108545_embeddedDocx
     CPPUNIT_ASSERT_EQUAL(embed::Aspects::MSOLE_ICON, xSupplier->getAspect());
 }
 
-/*DECLARE_OOXMLIMPORT_TEST(testTdf121203, "tdf121203.docx")
+DECLARE_OOXMLIMPORT_TEST(testTdf121203, "tdf121203.docx")
 {
-    // Make sure that the date SDT's content is imported as plain text, as it
-    // has no ISO date, so we have no idea how to represent that with our date
-    // control.
+    // Make sure that the date SDT's content is imported as plain text, as
+    // the field has no fullDate attribute which we can use to find out the actual date.
     CPPUNIT_ASSERT_EQUAL(OUString("17-Oct-2018 09:00"), getRun(getParagraph(1), 1)->getString());
-}*/
+
+    // Make sure we did not import a date field.
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
+}
 
 DECLARE_OOXMLIMPORT_TEST(testTdf109053, "tdf109053.docx")
 {
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 72b647cb24b8..e1493a31fcb3 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1029,10 +1029,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
             m_pImpl->m_pSdtHelper->getDropDownItems().push_back(sStringValue);
         break;
         case NS_ooxml::LN_CT_SdtDate_fullDate:
-            if (!IsInHeaderFooter())
-                m_pImpl->m_pSdtHelper->getDate().append(sStringValue);
-            else
-                m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_SdtDate_fullDate", sStringValue);
+            m_pImpl->m_pSdtHelper->getDate().append(sStringValue);
         break;
         case NS_ooxml::LN_CT_Background_color:
             if (m_pImpl->GetSettingsTable()->GetDisplayBackgroundShape())
@@ -3233,8 +3230,16 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
     // Form controls are not allowed in headers / footers; see sw::DocumentContentOperationsManager::InsertDrawObj()
     else if (m_pImpl->m_pSdtHelper->validateDateFormat() && !IsInHeaderFooter())
     {
-        // date field is imported, we don't need the corresponding date text
-        return;
+        // Date field will be imported, so we don't need the corresponding date text in most of the cases
+        // however when fullDate is not specified, but we have a date string we need to import it as
+        // simple text (this is the case when user sets date field manually in MSO).
+        if(!m_pImpl->m_pSdtHelper->getDate().toString().isEmpty() || sText.isEmpty())
+        {
+            return;
+        }
+        // Remove date field attributes to avoid to import an actual date field
+        m_pImpl->m_pSdtHelper->getDateFormat().truncate();
+        m_pImpl->m_pSdtHelper->getLocale().truncate();
     }
     else if (!m_pImpl->m_pSdtHelper->isInteropGrabBagEmpty())
     {
commit 2f4ccb1d5ea4258da42f2f6a0b62161399e13bcc
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Mon Jul 1 14:51:38 2019 +0200
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Jul 12 06:10:00 2019 +0200

    MSForms: DOCX filter: add a test case about invalid date form fields
    
    Change-Id: I2048198d81ea4abf58b2b499b89495cd51b5c7ff
    Reviewed-on: https://gerrit.libreoffice.org/75451
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/invalid_date_form_field.docx b/sw/qa/extras/ooxmlexport/data/invalid_date_form_field.docx
new file mode 100644
index 000000000000..9dc24e768b0f
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/invalid_date_form_field.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index 06103147ff1c..4512bf04c4eb 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -15,6 +15,7 @@
 #include <com/sun/star/style/ParagraphAdjust.hpp>
 #include <editeng/frmdiritem.hxx>
 #include <IDocumentSettingAccess.hxx>
+#include <xmloff/odffields.hxx>
 
 #include <editsh.hxx>
 #include <frmatr.hxx>
@@ -456,6 +457,83 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf121663, "tdf121663.docx")
     assertXPath(pXmlDoc, "//w:lnNumType", "distance", "283");
 }
 
+DECLARE_OOXMLIMPORT_TEST(testInvalidDateFormField, "invalid_date_form_field.docx")
+{
+
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(6), pMarkAccess->getAllMarksCount());
+
+    int nIndex = 0;
+    for(auto aIter = pMarkAccess->getAllMarksBegin(); aIter != pMarkAccess->getAllMarksEnd(); ++aIter)
+    {
+        ::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*aIter);
+
+        if(!pFieldmark)
+            continue;
+
+        CPPUNIT_ASSERT(pFieldmark);
+        CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
+
+        // Check date field's parameters.
+        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;
+        }
+
+        // The first one has invalid date format (invalid = LO can't parse it)
+        if(nIndex == 0)
+        {
+
+            CPPUNIT_ASSERT_EQUAL(OUString("YYYY.MM.DDT00:00:00Z"), sDateFormat);
+            CPPUNIT_ASSERT_EQUAL(OUString("en-US"), sLang);
+            CPPUNIT_ASSERT_EQUAL(OUString(""), sCurrentDate);
+
+            CPPUNIT_ASSERT_EQUAL(sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex());
+            CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pFieldmark->GetMarkStart().nContent.GetIndex());
+        }
+        else if (nIndex == 1) // The second has wrong date
+        {
+            CPPUNIT_ASSERT_EQUAL(OUString("MM/DD/YY"), sDateFormat);
+            CPPUNIT_ASSERT_EQUAL(OUString("en-US"), sLang);
+            CPPUNIT_ASSERT_EQUAL(OUString("2019.06.34"), sCurrentDate);
+
+            CPPUNIT_ASSERT_EQUAL(sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex());
+            CPPUNIT_ASSERT_EQUAL(sal_Int32(13), pFieldmark->GetMarkStart().nContent.GetIndex());
+        }
+        else // The third one has wrong local
+        {
+            CPPUNIT_ASSERT_EQUAL(OUString("[NatNum12 MMMM=abbreviation]YYYY\". \"MMMM D."), sDateFormat);
+            CPPUNIT_ASSERT_EQUAL(OUString("xxxx"), sLang);
+            CPPUNIT_ASSERT_EQUAL(OUString("2019.06.11"), sCurrentDate);
+
+            CPPUNIT_ASSERT_EQUAL(sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex());
+            CPPUNIT_ASSERT_EQUAL(sal_Int32(23), pFieldmark->GetMarkStart().nContent.GetIndex());
+        }
+        ++nIndex;
+    }
+    CPPUNIT_ASSERT_EQUAL(int(3), nIndex);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list