[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - sw/qa sw/source

Jan-Marek Glogowski glogow at fbihome.de
Mon Jan 18 13:47:42 PST 2016


 sw/qa/extras/uiwriter/uiwriter.cxx |   97 +++++++++++++++++++++++++++++++++++++
 sw/source/core/txtnode/thints.cxx  |    7 +-
 2 files changed, 100 insertions(+), 4 deletions(-)

New commits:
commit 15d7875a814c4772d591bc26db9db6c1bffada09
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Wed Dec 30 01:20:23 2015 +0100

    tdf#96479 workaround bookmark end pos handling...
    
    ... when inserting text into a text node.
    
    Seems SwTextNode::InsertText doesn't handle bookmark end
    positions correctly. This is just handled correctly, if it
    also contains the bookmark start.
    
    This workaround simply concats the three strings to be
    inserted in advance, so we just have to call
    SwTextNode::InsertText once for the whole string.
    
    (cherry picked from commit c91024891ff10c2ae01e11a28a9aecca2f36b6c3)
    
    Conflicts:
    	sw/qa/extras/uiwriter/uiwriter.cxx
    
    loplugin:stringconstant
    
    (cherry picked from commit 67d440e6bd2c895833fa22d0f9bf5dc6901723e8)
    
    loplugin:stringconstant
    
    (cherry picked from commit 6aa4496c789fec271dcdc7995cf62ef2dabf1f96)
    Reviewed-on: https://gerrit.libreoffice.org/21077
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit e781a8273eb2938f905485c00fbaf432e517d1dc)
    
    Conflicts:
    	sw/qa/extras/uiwriter/uiwriter.cxx
    
    588a9c0205e03f701b617fd1775e7f9b9b88c6b0
    60ee2ccc6090c305ade4ba16d3d298866cf89c4e
    Reviewed-on: https://gerrit.libreoffice.org/21137
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    
    (cherry picked from commit 107664a977c4893a0bc02f10cd20411c330b6d94)
    
    Change-Id: Iab7708b4cc4df406bdbc3a685c7410e0e797fdc4

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index ce38f1e..f9d4a70b 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -109,6 +109,7 @@ public:
     void testTdf96943();
     void testTdf96536();
     void testTdf96961();
+    void testTdf96479();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -155,6 +156,7 @@ public:
     CPPUNIT_TEST(testTdf96943);
     CPPUNIT_TEST(testTdf96536);
     CPPUNIT_TEST(testTdf96961);
+    CPPUNIT_TEST(testTdf96479);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -1243,6 +1245,101 @@ void SwUiWriterTest::testTdf96961()
     CPPUNIT_ASSERT(nLast > nOther);
 }
 
+void SwUiWriterTest::testTdf96479()
+{
+    // We want to verify the empty input text field in the bookmark
+    static const OUString emptyInputTextField =
+        OUStringLiteral1<CH_TXT_ATR_INPUTFIELDSTART>() + OUStringLiteral1<CH_TXT_ATR_INPUTFIELDEND>();
+
+    SwDoc* pDoc = createDoc();
+    SwXTextDocument *xTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+    CPPUNIT_ASSERT(xTextDoc);
+
+    // So we can clean up all references for reload
+    {
+        // Append bookmark
+        SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
+        SwPaM aPaM(aIdx);
+        IDocumentMarkAccess &rIDMA = *pDoc->getIDocumentMarkAccess();
+        sw::mark::IMark *pMark =
+            rIDMA.makeMark(aPaM, "original", IDocumentMarkAccess::MarkType::BOOKMARK);
+        CPPUNIT_ASSERT(!pMark->IsExpanded());
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rIDMA.getBookmarksCount());
+
+        // Get helper objects
+        uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY);
+        uno::Reference<css::lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+
+        // Create cursor from bookmark
+        uno::Reference<text::XTextContent> xTextContent(xBookmarksSupplier->getBookmarks()->getByName("original"), uno::UNO_QUERY);
+        uno::Reference<text::XTextRange> xRange(xTextContent->getAnchor(), uno::UNO_QUERY);
+        uno::Reference<text::XTextCursor> xCursor(xRange->getText()->createTextCursorByRange(xRange), uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xCursor->isCollapsed());
+
+        // Remove bookmark
+        xRange->getText()->removeTextContent(xTextContent);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rIDMA.getBookmarksCount());
+
+        // Insert replacement bookmark
+        uno::Reference<text::XTextContent> xBookmarkNew(xFactory->createInstance("com.sun.star.text.Bookmark"), uno::UNO_QUERY);
+        uno::Reference<container::XNamed> xBookmarkName(xBookmarkNew, uno::UNO_QUERY);
+        xBookmarkName->setName("replacement");
+        CPPUNIT_ASSERT(xCursor->isCollapsed());
+        // Force bookmark expansion
+        xCursor->getText()->insertString(xCursor, ".", true);
+        xCursor->getText()->insertTextContent(xCursor, xBookmarkNew, true);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rIDMA.getBookmarksCount());
+        auto mark = *(rIDMA.getBookmarksBegin());
+        CPPUNIT_ASSERT(mark->IsExpanded());
+
+        // Create and insert input textfield with some content
+        uno::Reference<text::XTextField> xTextField(xFactory->createInstance("com.sun.star.text.TextField.Input"), uno::UNO_QUERY);
+        uno::Reference<text::XTextCursor> xCursorNew(xBookmarkNew->getAnchor()->getText()->createTextCursorByRange(xBookmarkNew->getAnchor()));
+        CPPUNIT_ASSERT(!xCursorNew->isCollapsed());
+        xCursorNew->getText()->insertTextContent(xCursorNew, xTextField, true);
+        xBookmarkNew = uno::Reference<text::XTextContent>(xBookmarksSupplier->getBookmarks()->getByName("replacement"), uno::UNO_QUERY);
+        xCursorNew = uno::Reference<text::XTextCursor>(xBookmarkNew->getAnchor()->getText()->createTextCursorByRange(xBookmarkNew->getAnchor()));
+        CPPUNIT_ASSERT(!xCursorNew->isCollapsed());
+
+        // Can't check the actual content of the text node via UNO
+        mark = *(rIDMA.getBookmarksBegin());
+        CPPUNIT_ASSERT(mark->IsExpanded());
+        SwPaM pam(mark->GetMarkStart(), mark->GetMarkEnd());
+        // Check for the actual bug, which didn't include CH_TXT_ATR_INPUTFIELDEND in the bookmark
+        CPPUNIT_ASSERT_EQUAL(emptyInputTextField, pam.GetText());
+    }
+
+    {
+        // Save and load cycle
+        // Actually not needed, but the bug symptom of a missing bookmark
+        // occured because a broken bookmar was saved and loading silently
+        // dropped the broken bookmark!
+        utl::TempFile aTempFile;
+        save("writer8", aTempFile);
+        loadURL(aTempFile.GetURL(), nullptr);
+        xTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+        CPPUNIT_ASSERT(xTextDoc);
+        pDoc = xTextDoc->GetDocShell()->GetDoc();
+
+        // Lookup "replacement" bookmark
+        IDocumentMarkAccess &rIDMA = *pDoc->getIDocumentMarkAccess();
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rIDMA.getBookmarksCount());
+        uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xBookmarksSupplier->getBookmarks()->hasByName("replacement"));
+
+        uno::Reference<text::XTextContent> xTextContent(xBookmarksSupplier->getBookmarks()->getByName("replacement"), uno::UNO_QUERY);
+        uno::Reference<text::XTextRange> xRange(xTextContent->getAnchor(), uno::UNO_QUERY);
+        uno::Reference<text::XTextCursor> xCursor(xRange->getText()->createTextCursorByRange(xRange), uno::UNO_QUERY);
+        CPPUNIT_ASSERT(!xCursor->isCollapsed());
+
+        // Verify bookmark content via text node / PaM
+        auto mark = *(rIDMA.getBookmarksBegin());
+        CPPUNIT_ASSERT(mark->IsExpanded());
+        SwPaM pam(mark->GetMarkStart(), mark->GetMarkEnd());
+        CPPUNIT_ASSERT_EQUAL(emptyInputTextField, pam.GetText());
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx
index a3a9047..2ba0b55 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1516,16 +1516,15 @@ bool SwTextNode::InsertHint( SwTextAttr * const pAttr, const SetAttrMode nMode )
                     if( !(SetAttrMode::NOTXTATRCHR & nMode) )
                     {
                         SwIndex aIdx( this, pAttr->GetStart() );
-                        InsertText( OUString(CH_TXT_ATR_INPUTFIELDSTART), aIdx, nInsertFlags );
-                        const OUString aContent = pTextInputField->GetFieldContent();
+                        const OUString aContent = OUStringLiteral1<CH_TXT_ATR_INPUTFIELDSTART>()
+                            + pTextInputField->GetFieldContent() + OUStringLiteral1<CH_TXT_ATR_INPUTFIELDEND>();
                         InsertText( aContent, aIdx, nInsertFlags );
-                        InsertText( OUString(CH_TXT_ATR_INPUTFIELDEND), aIdx, nInsertFlags );
 
                         sal_Int32* const pEnd(pAttr->GetEnd());
                         OSL_ENSURE( pEnd != NULL, "<SwTextNode::InsertHint(..)> - missing end of RES_TXTATR_INPUTFIELD!" );
                         if ( pEnd != NULL )
                         {
-                            *pEnd = *pEnd + 2 + aContent.getLength();
+                            *pEnd = *pEnd + aContent.getLength();
                             nEnd = *pEnd;
                         }
                     }


More information about the Libreoffice-commits mailing list