diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2018-03-26 11:24:07 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2018-03-27 14:00:39 +0200 |
commit | 8766bb000afceb4a070ef310b939f7250e5c3a8a (patch) | |
tree | 81772e13a380fae71463b100e127b54c79c15059 | |
parent | edfa0562617c1330cc00923a5cf6e5916bacfed0 (diff) |
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@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r-- | sc/qa/extras/anchor.cxx | 51 |
1 files changed, 51 insertions, 0 deletions
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()) |