[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - sw/qa sw/source

Mike Kaganski mike.kaganski at collabora.com
Tue Jan 30 15:07:57 UTC 2018


 sw/qa/extras/uiwriter/data/datasource.ods |binary
 sw/qa/extras/uiwriter/uiwriter.cxx        |   47 ++++++++++++++++++++++++++++++
 sw/source/filter/ww8/ww8atr.cxx           |    3 +
 3 files changed, 49 insertions(+), 1 deletion(-)

New commits:
commit ec48a5a196b86678b01ba33e6589609dd4cecf39
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Tue Jan 16 09:40:11 2018 +0300

    tdf#115013: write merge field column into docx merge fields
    
    Change-Id: If1e0a8968407c72e42cb7ca487541d0b8227aabc
    Reviewed-on: https://gerrit.libreoffice.org/47895
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/47973
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/sw/qa/extras/uiwriter/data/datasource.ods b/sw/qa/extras/uiwriter/data/datasource.ods
new file mode 100644
index 000000000000..076659679575
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/datasource.ods differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 07f153dac973..80ba1a9a371b 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -60,6 +60,7 @@
 #include <i18nutil/transliteration.hxx>
 #include <i18nutil/searchopt.hxx>
 #include <reffld.hxx>
+#include <dbfld.hxx>
 #include <txatbase.hxx>
 #include <ftnidx.hxx>
 #include <txtftn.hxx>
@@ -291,6 +292,7 @@ public:
     void testTdf114306_2();
     void testTdf114536();
     void testTdf115065();
+    void testTdf115013();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -463,6 +465,7 @@ public:
     CPPUNIT_TEST(testTdf114306_2);
     CPPUNIT_TEST(testTdf114536);
     CPPUNIT_TEST(testTdf115065);
+    CPPUNIT_TEST(testTdf115013);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5646,6 +5649,50 @@ void SwUiWriterTest::testTdf115065()
     pWrtShell->Copy(pWrtShell, ptFrom, ptTo);
 }
 
+void SwUiWriterTest::testTdf115013()
+{
+    //create new writer document
+    SwDoc* pDoc = createDoc();
+
+    {
+        // Load and register data source
+        const OUString aDataSourceURI(m_directories.getURLFromSrc(DATA_DIRECTORY) + "datasource.ods");
+        OUString sDataSource = SwDBManager::LoadAndRegisterDataSource(aDataSourceURI, nullptr);
+        CPPUNIT_ASSERT(!sDataSource.isEmpty());
+
+        // Insert a new field type for the mailmerge field
+        SwDBData aDBData;
+        aDBData.sDataSource = sDataSource;
+        aDBData.sCommand = "Sheet1";
+        SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+        CPPUNIT_ASSERT(pWrtShell);
+        SwDBFieldType* pFieldType = static_cast<SwDBFieldType*>(pWrtShell->InsertFieldType(
+            SwDBFieldType(pDoc, "Name", aDBData)));
+        CPPUNIT_ASSERT(pFieldType);
+
+        // Insert the field into document
+        SwDBField aField(pFieldType);
+        pWrtShell->Insert(aField);
+    }
+    // Save it as DOCX & load it again
+    reload("Office Open XML Text", "mm-field.docx");
+
+    CPPUNIT_ASSERT(mxComponent.get());
+    pDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get())->GetDocShell()->GetDoc();
+    CPPUNIT_ASSERT(pDoc);
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    CPPUNIT_ASSERT(pWrtShell);
+    SwPaM* pCursor = pDoc->GetEditShell()->GetCursor();
+    CPPUNIT_ASSERT(pCursor);
+
+    // Get the field at the beginning of the document
+    SwDBField* pField = dynamic_cast<SwDBField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
+    CPPUNIT_ASSERT(pField);
+    OUString sColumn = static_cast<SwDBFieldType*>(pField->GetTyp())->GetColumnName();
+    // The column name must come correct after round trip
+    CPPUNIT_ASSERT_EQUAL(OUString("Name"), sColumn);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index c75ad43df571..80b620207195 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -122,6 +122,7 @@
 #include <chpfld.hxx>
 #include <fmthdft.hxx>
 #include <authfld.hxx>
+#include <dbfld.hxx>
 
 #include "sprmids.hxx"
 
@@ -2756,7 +2757,7 @@ void AttributeOutputBase::TextField( const SwFormatField& rField )
         break;
     case SwFieldIds::Database:
         {
-            OUString sStr = FieldString(ww::eMERGEFIELD) + pField->GetPar1() + " ";
+            OUString sStr = FieldString(ww::eMERGEFIELD) + static_cast<SwDBFieldType *>(pField->GetTyp())->GetColumnName() + " ";
             GetExport().OutputField(pField, ww::eMERGEFIELD, sStr);
         }
         break;


More information about the Libreoffice-commits mailing list