[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - sd/qa

Miklos Vajna vmiklos at collabora.co.uk
Fri Apr 3 08:09:10 PDT 2015


 sd/qa/unit/tiledrendering/tiledrendering.cxx |   42 +++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 6 deletions(-)

New commits:
commit dee3e28a87e10e413ea3ae5e1b830e9b4b2c8df9
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Apr 3 16:52:44 2015 +0200

    Add SdXImpressDocument::setTextSelection() testcase.
    
    Also, avoid early dispose in testRegisterCallback(), that was just a
    hack as I did not find SdrBeginTextEdit().
    
    Change-Id: Ic0576306297b4081979c2409c376867c7f530e2c

diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 7356a7c..0a4665c 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -38,11 +38,13 @@ public:
 
     void testRegisterCallback();
     void testPostMouseEvent();
+    void testSetTextSelection();
 
     CPPUNIT_TEST_SUITE(SdTiledRenderingTest);
 #if !defined(WNT) && !defined(MACOSX)
     CPPUNIT_TEST(testRegisterCallback);
     CPPUNIT_TEST(testPostMouseEvent);
+    CPPUNIT_TEST(testSetTextSelection);
 #endif
     CPPUNIT_TEST_SUITE_END();
 
@@ -109,16 +111,16 @@ void SdTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
 
 void SdTiledRenderingTest::testRegisterCallback()
 {
-    // Tests sd::Window::LogicInvalidate().
     SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp");
     pXImpressDocument->registerCallback(&SdTiledRenderingTest::callback, this);
     sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
 
-    // Append a character to the empty title shape.
-    vcl::KeyCode aKeyCode(0, 0);
-    KeyEvent aKeyEvent(static_cast<sal_Unicode>('x'), aKeyCode, 0);
-    pViewShell->KeyInput(aKeyEvent, 0);
-    mxComponent->dispose();
+    // Start text edit of the empty title shape.
+    SdPage* pActualPage = pViewShell->GetActualPage();
+    SdrObject* pObject = pActualPage->GetObj(0);
+    SdrView* pView = pViewShell->GetView();
+    pView->SdrBeginTextEdit(pObject);
+    CPPUNIT_ASSERT(pView->GetTextEditObject());
 
     // Check that the top left 256x256px tile would be invalidated.
     CPPUNIT_ASSERT(!m_aInvalidation.IsEmpty());
@@ -153,6 +155,34 @@ void SdTiledRenderingTest::testPostMouseEvent()
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), rEditView.GetSelection().nStartPos);
 }
 
+void SdTiledRenderingTest::testSetTextSelection()
+{
+    SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp");
+    uno::Reference<container::XIndexAccess> xDrawPage(pXImpressDocument->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+    xShape->setString("Aaa bbb.");
+    // Create a selection on the second word.
+    sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+    SdPage* pActualPage = pViewShell->GetActualPage();
+    SdrObject* pObject = pActualPage->GetObj(0);
+    SdrView* pView = pViewShell->GetView();
+    pView->SdrBeginTextEdit(pObject);
+    CPPUNIT_ASSERT(pView->GetTextEditObject());
+    EditView& rEditView = pView->GetTextEditOutlinerView()->GetEditView();
+    ESelection aWordSelection(0, 4, 0, 7);
+    rEditView.SetSelection(aWordSelection);
+    // Did we indeed manage to select the second word?
+    CPPUNIT_ASSERT_EQUAL(OUString("bbb"), rEditView.GetSelected());
+
+    // Now use setTextSelection() to move the end of the selection 1000 twips right.
+    vcl::Cursor* pCursor = rEditView.GetCursor();
+    Point aEnd = pCursor->GetPos();
+    aEnd.setX(aEnd.getX() + 1000);
+    pXImpressDocument->setTextSelection(LOK_SETTEXTSELECTION_END, aEnd.getX(), aEnd.getY());
+    // The new selection must include the ending dot, too -- but not the first word.
+    CPPUNIT_ASSERT_EQUAL(OUString("bbb."), rEditView.GetSelected());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list