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

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Tue Mar 27 12:03:13 UTC 2018


 sc/qa/extras/anchor.cxx |   51 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

New commits:
commit 8766bb000afceb4a070ef310b939f7250e5c3a8a
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Mon Mar 26 11:24:07 2018 +0200

    tdf#116510 Unit test for copying columns with images anchored to cells
    
    Change-Id: I194252bb07842dbc0376da5a143e93b557bcc04d
    Reviewed-on: https://gerrit.libreoffice.org/51860
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sc/qa/extras/anchor.cxx b/sc/qa/extras/anchor.cxx
index dc0a8942b9dd..a457a2854391 100644
--- a/sc/qa/extras/anchor.cxx
+++ b/sc/qa/extras/anchor.cxx
@@ -39,11 +39,13 @@ public:
     void testUndoAnchor();
     void testTdf76183();
     void testODFAnchorTypes();
+    void testCopyColumnWithImages();
 
     CPPUNIT_TEST_SUITE(ScAnchorTest);
     CPPUNIT_TEST(testUndoAnchor);
     CPPUNIT_TEST(testTdf76183);
     CPPUNIT_TEST(testODFAnchorTypes);
+    CPPUNIT_TEST(testCopyColumnWithImages);
     CPPUNIT_TEST_SUITE_END();
 private:
 
@@ -233,6 +235,55 @@ void ScAnchorTest::testODFAnchorTypes()
     pDocSh->DoClose();
 }
 
+/// Test that copying a column with an image anchored to it also copies the image
+void ScAnchorTest::testCopyColumnWithImages()
+{
+    OUString aFileURL;
+    createFileURL("3AnchorTypes.ods", aFileURL);
+    // open the document with graphic included
+    uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
+    CPPUNIT_ASSERT(xComponent.is());
+
+    // Get the document model
+    SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
+    CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
+
+    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+    CPPUNIT_ASSERT(pDocSh);
+
+    ScDocument* pDoc = &(pDocSh->GetDocument());
+    ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
+    CPPUNIT_ASSERT(pDrawLayer);
+
+    // Get the document controller
+    ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false);
+    CPPUNIT_ASSERT(pViewShell != nullptr);
+
+    ScDocument aClipDoc(SCDOCMODE_CLIP);
+
+    // 1. Copy source range
+    ScRange aSrcRange;
+    aSrcRange.Parse("A1:A11", pDoc, pDoc->GetAddressConvention());
+    pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
+    pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, true, false);
+
+    // 2. Paste to target range
+    ScRange aDstRange;
+    aDstRange.Parse("D1:D11", pDoc, pDoc->GetAddressConvention());
+    pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange);
+    pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc);
+
+    // 3. Make sure the images have been copied too
+    std::map<SCROW, std::vector<SdrObject*>> aRowObjects
+        = pDrawLayer->GetObjectsAnchoredToRange(0, 3, 0, 11);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D:3", 1,
+                                 static_cast<int>(aRowObjects[2].size()));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D:11", 1,
+                                 static_cast<int>(aRowObjects[10].size()));
+
+    pDocSh->DoClose();
+}
+
 void ScAnchorTest::tearDown()
 {
     if (mxComponent.is())


More information about the Libreoffice-commits mailing list