From ae2e7a2a7f9fc56f0388b823a6e35111c4005619 Mon Sep 17 00:00:00 2001 From: Regina Henschel Date: Mon, 15 Feb 2021 22:07:41 +0100 Subject: tdf#140252 unit test Controls in Calc are always on layer 'controls' This is the missing unit test for the case of drag-created controls in the fix in commit 1d53f3709de2956f14db31677b6c461f33843bd9. Change-Id: I3afce044588e6b5d850d948dd0cbc4df9185029d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110959 Tested-by: Jenkins Reviewed-by: Regina Henschel --- sc/qa/unit/scshapetest.cxx | 55 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'sc/qa') diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx index 8d50feb0f02e..a6d591c006fd 100644 --- a/sc/qa/unit/scshapetest.cxx +++ b/sc/qa/unit/scshapetest.cxx @@ -19,15 +19,16 @@ #include #include #include -#include #include #include +#include #include #include #include #include #include +#include #include #include @@ -45,6 +46,7 @@ public: ScShapeTest(); void saveAndReload(css::uno::Reference& xComponent, const OUString& rFilter); + void testTdf140252_DragCreateFormControl(); void testTdf134355_DragCreateCustomShape(); void testTdf140252_LayerOfControl(); void testTdf137082_LTR_to_RTL(); @@ -70,6 +72,7 @@ public: void testCustomShapeCellAnchoredRotatedShape(); CPPUNIT_TEST_SUITE(ScShapeTest); + CPPUNIT_TEST(testTdf140252_DragCreateFormControl); CPPUNIT_TEST(testTdf134355_DragCreateCustomShape); CPPUNIT_TEST(testTdf140252_LayerOfControl); CPPUNIT_TEST(testTdf137082_LTR_to_RTL); @@ -201,6 +204,56 @@ static SdrObject* lcl_getSdrObjectWithAssert(ScDocument& rDoc, sal_uInt16 nObjNu return pObj; } +void ScShapeTest::testTdf140252_DragCreateFormControl() +{ + // Error was, that drag-created form controls were initially not on layer 'controls' and thus + // other shapes could be placed in front of form controls. + // Load an empty document. + OUString aFileURL; + createFileURL(u"ManualColWidthRowHeight.ods", aFileURL); + uno::Reference xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Get ScTabViewShell + ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent); + ScTabViewShell* pTabViewShell = lcl_getScTabViewShellWithAssert(pDocSh); + + // drag-create a push button as example of form control + SfxUInt16Item aIdentifierItem(SID_FM_CONTROL_IDENTIFIER, OBJ_FM_BUTTON); + SfxUInt32Item aInventorItem(SID_FM_CONTROL_INVENTOR, sal_uInt32(SdrInventor::FmForm)); + const SfxPoolItem* pArgs[] = { &aIdentifierItem, &aInventorItem, nullptr }; + pTabViewShell->GetViewData().GetDispatcher().Execute(SID_FM_CREATE_CONTROL, + SfxCallMode::SYNCHRON, pArgs); + // above includes creation of FuConstUnoControl and call of its Activate() method + + // get FuConstUnoControl + ScTabView* pTabView = pTabViewShell->GetViewData().GetView(); + CPPUNIT_ASSERT(pTabView); + FuConstUnoControl* pFuConstUC = static_cast(pTabView->GetDrawFuncPtr()); + CPPUNIT_ASSERT(pFuConstUC); + + // drag-create shape, points are in pixel + MouseEvent aMouseEvent(Point(50, 100), 1, MouseEventModifiers::NONE, MOUSE_LEFT, 0); + pFuConstUC->MouseButtonDown(aMouseEvent); + aMouseEvent = MouseEvent(Point(200, 250), 1, MouseEventModifiers::DRAGMOVE, MOUSE_LEFT, 0); + pFuConstUC->MouseMove(aMouseEvent); + aMouseEvent = MouseEvent(Point(200, 250), 1, MouseEventModifiers::NONE, MOUSE_LEFT, 0); + pFuConstUC->MouseButtonUp(aMouseEvent); + pFuConstUC->Deactivate(); + pTabViewShell->SetDrawShell(false); + + // Get document and newly created push button. + ScDocument& rDoc = pDocSh->GetDocument(); + SdrUnoObj* pObj = static_cast(lcl_getSdrObjectWithAssert(rDoc, 0)); + + // Without the fix in place, the shape would be on layer SC_LAYER_FRONT (0) + sal_uInt8 nExpectedID = sal_uInt8(SC_LAYER_CONTROLS); + sal_uInt8 nActualID = pObj->GetLayer().get(); + CPPUNIT_ASSERT_EQUAL(nExpectedID, nActualID); + + pDocSh->DoClose(); +} + void ScShapeTest::testTdf134355_DragCreateCustomShape() { // Error was, that drag-created custom shapes were initially on layer "controls", although that -- cgit