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

Jan-Marek Glogowski glogow at fbihome.de
Tue Jan 5 06:51:29 PST 2016


 sw/qa/extras/mailmerge/data/tdf92623.odt                |binary
 sw/qa/extras/mailmerge/mailmerge.cxx                    |   51 ++++++++++++++++
 sw/source/core/doc/DocumentContentOperationsManager.cxx |   10 ++-
 3 files changed, 60 insertions(+), 1 deletion(-)

New commits:
commit bdcafdff89836518cb94f362ca7ea4c09a82fa03
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Thu Dec 3 23:18:16 2015 +0100

    tdf#92623 Handle StartOfContent node for copying bookmarks
    
    For SwDoc::AppendDoc we use the StartOfContent node as the
    starting copy node to prevent merging of the first node in
    CopyRange and to get a 2nd node needed for CopyRange in case
    of single content node documents.
    
    This correctly counts StartOfContent as a non-copy node when
    adapting the bookmark ranges for copying.
    
    Change-Id: Ia3ee0328a1be5548f8751aa2240812c4662fb73f
    Reviewed-on: https://gerrit.libreoffice.org/20383
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>
    (cherry picked from commit 689962feae2054f965a7378c3408b0ccfad2bbd5)
    
    tdf#92623 MM: add unit test
    
    Adds the missing unit test to the bugfix.
    
    Actually the original bug was a crash, so this just
    does some test on the resulting MM document.
    
    Change-Id: I4c9f031e57157fe5744aa8290b7503b7e1990fc7
    (cherry picked from commit 480e943f0100154fa82942db092ed1f66b76ef66)
    Reviewed-on: https://gerrit.libreoffice.org/21076
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/qa/extras/mailmerge/data/tdf92623.odt b/sw/qa/extras/mailmerge/data/tdf92623.odt
new file mode 100644
index 0000000..3dea831
Binary files /dev/null and b/sw/qa/extras/mailmerge/data/tdf92623.odt differ
diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx b/sw/qa/extras/mailmerge/mailmerge.cxx
index 992ddd5..f359809 100644
--- a/sw/qa/extras/mailmerge/mailmerge.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge.cxx
@@ -412,5 +412,56 @@ DECLARE_SHELL_MAILMERGE_TEST(testTdf90230, "empty.odt", "10-testing-addresses.od
     executeMailMerge();
 }
 
+DECLARE_SHELL_MAILMERGE_TEST(testTdf92623, "tdf92623.odt", "10-testing-addresses.ods", "testing-addresses")
+{
+    // Copying bookmarks for MM was broken because of the StartOfContent node copy
+    // copyied marks were off by one
+    executeMailMerge();
+
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    IDocumentMarkAccess const *pIDMA = pTextDoc->GetDocShell()->GetDoc()->getIDocumentMarkAccess();
+    // There is just one mark...
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pIDMA->getAllMarksCount());
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pIDMA->getBookmarksCount());
+    IDocumentMarkAccess::const_iterator_t mark = pIDMA->getAllMarksBegin();
+    // and it's a TEXT_FIELDMARK
+    CPPUNIT_ASSERT_EQUAL( sal_Int32(IDocumentMarkAccess::GetType( **mark )),
+                          sal_Int32(IDocumentMarkAccess::MarkType::TEXT_FIELDMARK ) );
+    sal_uLong src_pos = (*mark)->GetMarkPos().nNode.GetIndex();
+
+    // Get the size of the document in nodes
+    SwDoc *doc = pTextDoc->GetDocShell()->GetDoc();
+    sal_uLong size = doc->GetNodes().GetEndOfContent().GetIndex() - doc->GetNodes().GetEndOfExtras().GetIndex();
+    CPPUNIT_ASSERT_EQUAL( sal_uLong(13), size );
+    size -= 2; // For common start and end nodes
+
+    // Iterate over all field marks in the target document and check that they
+    // are positioned at a multitude of the document size
+    SwXTextDocument* pMMTextDoc = dynamic_cast<SwXTextDocument *>(mxMMComponent.get());
+    CPPUNIT_ASSERT(pMMTextDoc);
+    pIDMA = pMMTextDoc->GetDocShell()->GetDoc()->getIDocumentMarkAccess();
+    // The target document has the duplicated amount of bookmarks
+    // as the helping uno bookmark from the mail merge is left in the doc
+    // TODO should be fixed!
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(20), pIDMA->getAllMarksCount());
+    std::set<sal_uLong> pages;
+    sal_Int32 countFieldMarks = 0;
+    for( mark = pIDMA->getAllMarksBegin(); mark != pIDMA->getAllMarksEnd(); ++mark )
+    {
+        IDocumentMarkAccess::MarkType markType = IDocumentMarkAccess::GetType( **mark );
+        if( markType == IDocumentMarkAccess::MarkType::TEXT_FIELDMARK )
+        {
+            sal_uLong pos = (*mark)->GetMarkPos().nNode.GetIndex() - src_pos;
+            CPPUNIT_ASSERT_EQUAL(sal_uLong(0), pos % size);
+            CPPUNIT_ASSERT(pages.insert(pos).second);
+            countFieldMarks++;
+        }
+        else // see previous TODO
+            CPPUNIT_ASSERT_EQUAL( sal_Int32(markType), sal_Int32(IDocumentMarkAccess::MarkType::UNO_BOOKMARK) );
+    }
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(10), countFieldMarks);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index d1d0254..8fdc824 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -124,7 +124,8 @@ namespace
     /*
         The lcl_CopyBookmarks function has to copy bookmarks from the source to the destination nodes
         array. It is called after a call of the _CopyNodes(..) function. But this function does not copy
-        every node (at least at the moment: 2/08/2006 ), section start and end nodes will not be copied if the corresponding end/start node is outside the copied pam.
+        every node (at least at the moment: 2/08/2006 ), section start and end nodes will not be copied
+        if the corresponding end/start node is outside the copied pam.
         The lcl_NonCopyCount function counts the number of these nodes, given the copied pam and a node
         index inside the pam.
         rPam is the original source pam, rLastIdx is the last calculated position, rDelCount the number
@@ -138,6 +139,13 @@ namespace
         sal_uLong nEnd = rPam.End()->nNode.GetIndex();
         if( rLastIdx.GetIndex() < nNewIdx ) // Moving forward?
         {
+            // We never copy the StartOfContent node
+            // Special handling for SwDoc::AppendDoc
+            if( rPam.GetDoc()->GetNodes().GetEndOfExtras().GetIndex() + 1 == nStart )
+            {
+                ++rDelCount;
+                ++rLastIdx;
+            }
             do // count "non-copy" nodes
             {
                 SwNode& rNode = rLastIdx.GetNode();


More information about the Libreoffice-commits mailing list