diff options
author | Henry Castro <hcastro@collabora.com> | 2015-02-13 20:22:04 -0400 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-04-03 07:32:23 +0000 |
commit | bff29a3b30c8e57ab78937dca862fd738f26d89e (patch) | |
tree | 6188c3af93f0d18dc2f9c643906e4ae64ed2ab9d /sc/qa/extras | |
parent | 0c32c2133e3be1ddbc719772007ba3833d2bb848 (diff) |
tdf#51460 Calc fails to set undo step after changing image anchor mode
Fixed. Note that the undo button is still grayed out. Calc has not set an undo step.
Change-Id: I7ff713a906b365b460351e5202161c9152542395
Reviewed-on: https://gerrit.libreoffice.org/14489
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc/qa/extras')
-rw-r--r-- | sc/qa/extras/sccondformats.cxx | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/sc/qa/extras/sccondformats.cxx b/sc/qa/extras/sccondformats.cxx index 4a664c43cc87..8b6f66647f2c 100644 --- a/sc/qa/extras/sccondformats.cxx +++ b/sc/qa/extras/sccondformats.cxx @@ -8,6 +8,9 @@ */ #include <test/calc_unoapi_test.hxx> +#include <svx/svdograf.hxx> +#include <svx/svdpage.hxx> +#include <sfx2/dispatch.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/sheet/ConditionOperator.hpp> @@ -17,6 +20,11 @@ #include <com/sun/star/table/CellAddress.hpp> #include <unonames.hxx> +#include "tabvwsh.hxx" +#include "docsh.hxx" + +#include "sc.hrc" + using namespace css; namespace sc_apitest { @@ -33,9 +41,11 @@ public: uno::Reference< uno::XInterface > init(); void testCondFormat(); + void testUndoAnchor(); CPPUNIT_TEST_SUITE(ScConditionalFormatTest); CPPUNIT_TEST(testCondFormat); + CPPUNIT_TEST(testUndoAnchor); CPPUNIT_TEST_SUITE_END(); private: @@ -110,6 +120,106 @@ void ScConditionalFormatTest::testCondFormat() CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSheetConditionalEntries->getCount()); } +void ScConditionalFormatTest::testUndoAnchor() +{ + const OString sFailedMessage = OString("Failed on :"); + OUString aFileURL; + createFileURL(OUString("document_with_linked_graphic.ods"), aFileURL); + // open the document with graphic included + uno::Reference< com::sun::star::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* xDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(xDocSh != NULL); + + // Check whether graphic imported well + ScDocument& rDoc = xDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pDrawLayer != NULL ); + + const SdrPage *pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pPage != NULL ); + + SdrGrafObj* pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(0)); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pObject != NULL ); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pObject->IsLinkedGraphic() ); + + const GraphicObject& rGraphicObj = pObject->GetGraphicObject(true); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), !rGraphicObj.IsSwappedOut()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), GRAPHIC_BITMAP, rGraphicObj.GetGraphic().GetType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetSizeBytes()); + + // Get the document controller + ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pViewShell != NULL ); + + // Get the draw view of the document + ScDrawView* pDrawView = pViewShell->GetViewData().GetScDrawView(); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pDrawView != NULL ); + + // Select graphic object + pDrawView->MarkNextObj(false); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pDrawView->AreObjectsMarked() ); + + // Set Cell Anchor + ScDrawLayer::SetCellAnchoredFromPosition(*pObject, rDoc, 0); + // Check state + ScAnchorType oldType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), oldType == SCA_CELL ); + + // Change all selected objects to page anchor + pViewShell->GetViewData().GetDispatcher().Execute(SID_ANCHOR_PAGE); + // Check state + ScAnchorType newType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), newType == SCA_PAGE ); + + // Undo and check its result. + SfxUndoManager* pUndoMgr = rDoc.GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + pUndoMgr->Undo(); + + // Check anchor type + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), oldType == ScDrawLayer::GetAnchorType(*pObject) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), GRAPHIC_BITMAP, rGraphicObj.GetGraphic().GetType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetSizeBytes()); + + pUndoMgr->Redo(); + + // Check anchor type + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), newType == ScDrawLayer::GetAnchorType(*pObject) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), GRAPHIC_BITMAP, rGraphicObj.GetGraphic().GetType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetSizeBytes()); + + ScDrawLayer::SetPageAnchored(*pObject); + // Check state + oldType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), oldType == SCA_PAGE ); + + // Change all selected objects to cell anchor + pViewShell->GetViewData().GetDispatcher().Execute(SID_ANCHOR_CELL); + // Check state + newType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), newType == SCA_CELL ); + + pUndoMgr->Undo(); + + // Check anchor type + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), oldType == ScDrawLayer::GetAnchorType(*pObject) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), GRAPHIC_BITMAP, rGraphicObj.GetGraphic().GetType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetSizeBytes()); + + pUndoMgr->Redo(); + + // Check anchor type + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), newType == ScDrawLayer::GetAnchorType(*pObject) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), GRAPHIC_BITMAP, rGraphicObj.GetGraphic().GetType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetSizeBytes()); +} + void ScConditionalFormatTest::setUp() { nTest++; |