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 93c9a14134eb4afbfd7819ac3b4482d109c0c2f3
Author: Mike Kaganski <mike.kagan...@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 <c...@libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/47975
    Reviewed-by: Aron Budea <aron.bu...@collabora.com>
    Tested-by: Aron Budea <aron.bu...@collabora.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 d022e2fb26c6..6a065e712bea 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -55,6 +55,7 @@
 #include <editeng/fontitem.hxx>
 #include <editeng/wghtitem.hxx>
 #include <reffld.hxx>
+#include <dbfld.hxx>
 #include <txatbase.hxx>
 #include <ftnidx.hxx>
 #include <txtftn.hxx>
@@ -240,6 +241,7 @@ public:
     void testTdf107976();
     void testCreateDocxAnnotation();
     void testTdf113790();
+    void testTdf115013();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -368,6 +370,7 @@ public:
     CPPUNIT_TEST(testTdf107976);
     CPPUNIT_TEST(testCreateDocxAnnotation);
     CPPUNIT_TEST(testTdf113790);
+    CPPUNIT_TEST(testTdf115013);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -4642,6 +4645,50 @@ void SwUiWriterTest::testTdf104492()
     assertXPath(pXmlDoc, "//page", 3);
 }
 
+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, nullptr, 
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 f8d35a0edae1..abb637f923a4 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>
 
@@ -2534,7 +2535,7 @@ void AttributeOutputBase::TextField( const SwFormatField& 
rField )
         break;
     case RES_DBFLD:
         {
-            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;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to