[Libreoffice-commits] .: Branch 'libreoffice-3-6' - sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Dec 7 04:57:13 PST 2012


 sw/qa/core/macros-test.cxx         |   43 +++++++++++++++++++++++++++++++++++++
 sw/source/core/unocore/unodraw.cxx |    7 +++++-
 2 files changed, 49 insertions(+), 1 deletion(-)

New commits:
commit 4273e1411fbcbad9159925ccadb2e78b3fa9c0e4
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Dec 7 12:23:21 2012 +0100

    fdo#55289: fix crash in SwXShape::setPropertyValue:
    
    In the libreoffice-3-6 branch the docx import crashes here when setting
    the anchor position of a shape, because the previous setting of the
    AnchorType was not done properly: the position of the anchor in the
    SwFmt did not match the actual position of the text attribute, so we get
    these assertions: "Missing FlyInCnt-Hint." and crash.
    
    This cannot be reproduced with the docx import on master, because on
    master a different intermediate AnchorType is set, and transitioning
    from that happens not to cause the crash.  But it can be reproduced with
    a unit test.
    
    The regression was introduced in libreoffice-3-6 with
    backport commit bbbb10a0774b9da546557632cd09c4f6958f8939.
    
    Change-Id: I394643e11862543177ba57958a26cd8ce06dc09c
    (cherry picked from commit 01cd24df1ec7eaa53e9e2156d4d6890a7cc5996a)
    Reviewed-on: https://gerrit.libreoffice.org/1264
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/qa/core/macros-test.cxx b/sw/qa/core/macros-test.cxx
index 3f9262e..cbabeaf 100644
--- a/sw/qa/core/macros-test.cxx
+++ b/sw/qa/core/macros-test.cxx
@@ -37,8 +37,15 @@
 #include <com/sun/star/frame/XDesktop.hpp>
 
 #include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/frame/XComponentLoader.hpp>
 #include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
+#include <com/sun/star/drawing/XShapes.hpp>
+#include <com/sun/star/drawing/XShape.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/TextContentAnchorType.hpp>
 
 #include <sfx2/app.hxx>
 #include <sfx2/docfilt.hxx>
@@ -48,6 +55,7 @@
 
 #include <basic/sbxdef.hxx>
 
+#include <doc.hxx>
 #include "docsh.hxx"
 
 SO2_DECL_REF(SwDocShell)
@@ -73,6 +81,7 @@ public:
 
     //void testStarBasic();
     void testVba();
+    void testFdo55289();
     CPPUNIT_TEST_SUITE(SwMacrosTest);
 #if !defined(MACOSX) && !defined(WNT)
     //enable this test if you want to play with star basic macros in unit tests
@@ -80,6 +89,7 @@ public:
     //CPPUNIT_TEST(testStarBasic);
     CPPUNIT_TEST(testVba);
 #endif
+    CPPUNIT_TEST(testFdo55289);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -162,6 +172,39 @@ void SwMacrosTest::testVba()
     }
 }
 
+void SwMacrosTest::testFdo55289()
+{
+    SwDoc *const pDoc = new SwDoc;
+    SwDocShellRef pDocShell = new SwDocShell(pDoc, SFX_CREATE_MODE_EMBEDDED);
+    // this needs to run with no layout to tickle the bugs in the special
+    // cases in SwXShape re-anchoring
+    assert(!pDoc->GetCurrentLayout());
+
+    uno::Reference<frame::XModel> const xModel(pDocShell->GetModel());
+    uno::Reference<drawing::XDrawPageSupplier> const xDPS(xModel, UNO_QUERY);
+    uno::Reference<drawing::XShapes> const xShapes(xDPS->getDrawPage(),
+            UNO_QUERY);
+    uno::Reference<beans::XPropertySet> const xShape(
+        uno::Reference<lang::XMultiServiceFactory>(xModel, UNO_QUERY)->
+            createInstance("com.sun.star.drawing.GraphicObjectShape"),
+        UNO_QUERY);
+    xShape->setPropertyValue("AnchorType",
+            makeAny(text::TextContentAnchorType_AT_PAGE));
+    xShapes->add(uno::Reference<drawing::XShape>(xShape, UNO_QUERY));
+    xShape->setPropertyValue("AnchorType",
+            makeAny(text::TextContentAnchorType_AT_CHARACTER));
+    xShape->setPropertyValue("AnchorType",
+            makeAny(text::TextContentAnchorType_AS_CHARACTER));
+    xShape->setPropertyValue("AnchorType",
+            makeAny(text::TextContentAnchorType_AT_CHARACTER));
+    xShape->setPropertyValue("AnchorType",
+            makeAny(text::TextContentAnchorType_AS_CHARACTER));
+    uno::Reference<text::XTextRange> const xEnd =
+        uno::Reference<text::XTextDocument>(xModel, UNO_QUERY)->getText()->getEnd();
+    uno::Reference<text::XTextContent> const xShapeContent(xShape, UNO_QUERY);
+    xShapeContent->attach(xEnd);
+}
+
 SwMacrosTest::SwMacrosTest()
       : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data"))
 {
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index 267f6f2..769bf14 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -1366,7 +1366,12 @@ void SwXShape::setPropertyValue(const rtl::OUString& rPropertyName, const uno::A
                             SwFmtFlyCnt aFmt( pFlyFmt );
                             pNd->InsertItem(aFmt,
                                 aPam.GetPoint()->nContent.GetIndex(), 0 );
-                            //aPam.GetPoint()->nContent--;
+                            aPam.GetPoint()->nContent--; // InsertItem moved it
+                            SwFmtAnchor aNewAnchor(
+                                dynamic_cast<const SwFmtAnchor&>(
+                                    aSet.Get(RES_ANCHOR)));
+                            aNewAnchor.SetAnchor( aPam.GetPoint() );
+                            aSet.Put( aNewAnchor );
                         }
                         if( bSetAttr )
                             pFmt->SetFmtAttr(aSet);


More information about the Libreoffice-commits mailing list