Need help for unit test with rotated shape in Calc

Regina Henschel rb.henschel at t-online.de
Wed Dec 4 00:21:42 UTC 2019


Hi Miklos,

Miklos Vajna schrieb am 03-Dec-19 um 11:22:
> Hi Regina,
> 
> On Tue, Dec 03, 2019 at 01:38:59AM +0100, Regina Henschel <rb.henschel at t-online.de> wrote:
>> Any idea, how I can apply FitToCellSize() to a shape in a unit test?
> 
> Here is an sc/ test dispatching an UNO command:
> 
> sc/qa/unit/screenshots/screenshots.cxx:302
> 
> though this is commented out, but gives you an idea how to get an
> SfxViewShell in Calc.
> 
> Here is an sd/ test that does the same, and is an active test:
> 
> sd/qa/unit/uiimpress.cxx:99
> 
> Hopefully this is enough so that you can test your UNO command as well.

Thank you, for your code pointers. But I still have no solution.

See below, what I have tried so far. I'm not sure whether all of these 
is necessary. Nevertheless, it gives me a ScDrawView. The needed part was
SfxViewShell* pViewShell = SfxViewShell::Get(xController);

But the methods of ScDrawView are not available in the unit test, so I 
can not use FitToCellSize() directly. But more seriously, I can not even 
mark the object. The method MarkAll() is available, because it belongs 
to the parent SdrView. But it does not work, because the layer of the 
object is locked, and I have no idea why. And the object needs to be 
marked too, when I will try a solution with dispatcher.

Kind regards
Regina


Lines with // do not work.

void ScFiltersTest::testFitToCellSize()
{
     uno::Reference< frame::XDesktop2 > xDesktop = 
frame::Desktop::create(::comphelper::getProcessComponentContext());
     CPPUNIT_ASSERT(xDesktop.is());

     uno::Reference< frame::XFrame > xFrame = 
xDesktop->findFrame("_blank", 0);
     CPPUNIT_ASSERT(xTargetFrame.is());

     uno::Reference<awt::XWindow> xContainerWindow = 
xFrame->getContainerWindow();
     CPPUNIT_ASSERT(xContainerWindow.is());
     xContainerWindow->setPosSize(0, 0, 1024, 768, awt::PosSize::SIZE);
     VclPtr<vcl::Window> pContainerWindow = 
VCLUnoHelper::GetWindow(xContainerWindow);
     CPPUNIT_ASSERT(pContainerWindow);
     pContainerWindow->Show(true);

     ScDocShellRef xDocSh = loadDoc("tdf119191_FitToCellSize.", 
FORMAT_ODS, true);
     CPPUNIT_ASSERT(xDocSh.is());
     xDocSh = saveAndReload( &(*xDocSh), FORMAT_ODS);
     CPPUNIT_ASSERT( xDocSh.is() );

     uno::Reference< frame::XModel2 > xModel2(xDocSh->GetModel(), 
uno::UNO_QUERY);
     CPPUNIT_ASSERT(xModel2.is());

     uno::Reference< frame::XController2 > xController = 
xModel2->createDefaultViewController(xFrame);
     CPPUNIT_ASSERT(xController.is());

     xController->attachModel(xModel2.get());
     xModel2->connectController(xController.get());
     xFrame->setComponent(xController->getComponentWindow(), 
xController.get());
//  xController->attachFrame(xFrame);
     xModel2->setCurrentController(xController.get());

     SfxViewShell* pViewShell = SfxViewShell::Get(xController);
     ScTabViewShell* pTabViewShell = 
dynamic_cast<ScTabViewShell*>(pViewShell);
     CPPUNIT_ASSERT_MESSAGE("no ScTabViewShell", pTabViewShell);

     ScDrawView* pDrawView = pTabViewShell->GetViewData().GetScDrawView();
     CPPUNIT_ASSERT_MESSAGE("no ScDrawView*", pDrawView);

     ScDocument& rDoc = xDocSh->GetDocument();
     ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
     const SdrPage* pPage = pDrawLayer->GetPage(0);
     SdrObjCustomShape* pObj = 
dynamic_cast<SdrObjCustomShape*>(pPage->GetObj(0));
     CPPUNIT_ASSERT_MESSAGE("no SdrObjCustomShape*", pObj);

//    pDrawView->SelectObject("chevron");
     pDrawView->MarkAll();

//    CPPUNIT_ASSERT_MESSAGE("no object marked", 
pDrawView->AreObjectsMarked());
//    CPPUNIT_ASSERT_MESSAGE("wrong object marked", 
pDrawView->GetObjectIsMarked(pObj));

//    pDrawView->FitToCellSize();
     const tools::Rectangle& rObservedRect(pObj->GetSnapRect());
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2499), 
rObservedRect.Left());

     xDocSh->DoClose();
}



More information about the LibreOffice mailing list