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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Aug 31 01:00:42 UTC 2018


 sw/qa/extras/uiwriter/data/testInconsistentBookmark.ott |binary
 sw/qa/extras/uiwriter/uiwriter.cxx                      |   62 ++++++++++++++++
 2 files changed, 62 insertions(+)

New commits:
commit 6126de0363b070a914f06a1b853979317aa0a183
Author:     Serge Krot <Serge.Krot at cib.de>
AuthorDate: Thu Aug 30 18:01:42 2018 +0200
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Aug 31 03:00:12 2018 +0200

    sw: fix inconsistent bookmark behavior around at-char/as-char anchored frames
    
    Added unit test for Added fix for
       Change-Id: Ic1f173c85d3824afabb5b7ebf3a8594311eb9007
    
    Change-Id: I38444587d00b96d52ff725dc7c5852e057bc6bd9
    Reviewed-on: https://gerrit.libreoffice.org/59828
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/sw/qa/extras/uiwriter/data/testInconsistentBookmark.ott b/sw/qa/extras/uiwriter/data/testInconsistentBookmark.ott
new file mode 100644
index 000000000000..ff3970a27b27
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/testInconsistentBookmark.ott differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 6513d71bf006..8a2537a2292a 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -347,6 +347,7 @@ public:
     void testTdf117225();
     void testTdf91801();
     void testTdf51223();
+    void testInconsistentBookmark();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -545,6 +546,7 @@ public:
     CPPUNIT_TEST(testTdf117225);
     CPPUNIT_TEST(testTdf91801);
     CPPUNIT_TEST(testTdf51223);
+    CPPUNIT_TEST(testInconsistentBookmark);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6472,6 +6474,66 @@ void SwUiWriterTest::testFontEmbedding()
 #endif
 }
 
+// Unit test for fix inconsistent bookmark behavior around at-char/as-char anchored frames
+//
+// We have a placeholder character in the sw doc model for as-char anchored frames,
+// so it's possible to have a bookmark before/after the frame or a non-collapsed bookmark
+// which covers the frame. The same is not true for at-char anchored frames,
+// where the anchor points to a doc model position, but there is no placeholder character.
+// If a bookmark is created covering the start and end of the anchor of the frame,
+// internally we create a collapsed bookmark which has the same position as the anchor of the frame.
+// When this doc model is handled by SwXParagraph::createEnumeration(),
+// first the frame and then the bookmark is appended to the text portion enumeration,
+// so your bookmark around the frame is turned into a collapsed bookmark after the frame.
+// (The same happens when we roundtrip an ODT document representing this doc model.)
+//
+// Fix the problem by inserting collapsed bookmarks with affected anchor positions
+// (same position is the anchor for an at-char frame) into the enumeration in two stages:
+// first the start of them before frames and then the end of them + other bookmarks.
+// This way UNO API users get their non-collapsed bookmarks around at-char anchored frames,
+// similar to as-char ones.
+void SwUiWriterTest::testInconsistentBookmark()
+{
+    // create test document with text and bookmark
+    {
+        SwDoc* pDoc(createDoc("testInconsistentBookmark.ott"));
+        IDocumentMarkAccess& rIDMA(*pDoc->getIDocumentMarkAccess());
+        SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
+        SwCursor aPaM(SwPosition(aIdx), nullptr);
+        aPaM.SetMark();
+        aPaM.MovePara(GoCurrPara, fnParaStart);
+        aPaM.MovePara(GoCurrPara, fnParaEnd);
+        rIDMA.makeMark(aPaM, "Mark", IDocumentMarkAccess::MarkType::BOOKMARK,
+                       ::sw::mark::InsertMode::New);
+        aPaM.Exchange();
+        aPaM.DeleteMark();
+    }
+
+    // save document and verify the bookmark scoup
+    {
+        // save document
+        utl::TempFile aTempFile;
+        save("writer8", aTempFile);
+
+        // load only content.xml
+        if (xmlDocPtr pXmlDoc = parseExportInternal(aTempFile.GetURL(), "content.xml"))
+        {
+            const OString aPath("/office:document-content/office:body/office:text/text:p");
+
+            const OUString aTagBookmarkStart("bookmark-start");
+            const OUString aTagControl("control");
+            const OUString aTagBookmarkEnd("bookmark-end");
+
+            const int pos1 = getXPathPosition(pXmlDoc, aPath, aTagBookmarkStart);
+            const int pos2 = getXPathPosition(pXmlDoc, aPath, aTagControl);
+            const int pos3 = getXPathPosition(pXmlDoc, aPath, aTagBookmarkEnd);
+
+            CPPUNIT_ASSERT_GREATER(pos1, pos2);
+            CPPUNIT_ASSERT_GREATER(pos2, pos3);
+        }
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 


More information about the Libreoffice-commits mailing list