[Libreoffice-commits] core.git: sd/qa

Miklos Vajna vmiklos at collabora.co.uk
Fri Apr 24 02:57:47 PDT 2015


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

New commits:
commit 041de031e456d6122dc28aeac2edb7f913ddfdbe
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Apr 24 11:19:50 2015 +0200

    CppunitTest_sd_tiledrendering: add search testcase
    
    This fails without ef9722558a33a6e88ed5ab76198f2698ddd1e003
    (ImpEditView::SetEditSelection: fix missing tiled rendering selection
    callbacks, 2015-04-23).
    
    Change-Id: I5bf6bf6373e43e8551dd61d72d1f0012f92d2619

diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 7e3cf19..a55b026 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -10,7 +10,9 @@
 #define LOK_USE_UNSTABLE_API
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <com/sun/star/frame/Desktop.hpp>
+#include <comphelper/dispatchcommand.hxx>
 #include <comphelper/processfactory.hxx>
+#include <comphelper/propertysequence.hxx>
 #include <comphelper/string.hxx>
 #include <editeng/editids.hrc>
 #include <editeng/editview.hxx>
@@ -45,6 +47,7 @@ public:
     void testSetTextSelection();
     void testSetGraphicSelection();
     void testResetSelection();
+    void testSearch();
 #endif
 
     CPPUNIT_TEST_SUITE(SdTiledRenderingTest);
@@ -55,6 +58,7 @@ public:
     CPPUNIT_TEST(testSetTextSelection);
     CPPUNIT_TEST(testSetGraphicSelection);
     CPPUNIT_TEST(testResetSelection);
+    CPPUNIT_TEST(testSearch);
 #endif
     CPPUNIT_TEST_SUITE_END();
 
@@ -68,6 +72,7 @@ private:
     uno::Reference<lang::XComponent> mxComponent;
 #if !defined(WNT) && !defined(MACOSX)
     Rectangle m_aInvalidation;
+    std::vector<Rectangle> m_aSelection;
 #endif
 };
 
@@ -103,6 +108,33 @@ void SdTiledRenderingTest::callback(int nType, const char* pPayload, void* pData
     static_cast<SdTiledRenderingTest*>(pData)->callbackImpl(nType, pPayload);
 }
 
+static std::vector<OUString> lcl_convertSeparated(const OUString& rString, sal_Unicode nSeparator)
+{
+    std::vector<OUString> aRet;
+
+    sal_Int32 nIndex = 0;
+    do
+    {
+        OUString aToken = rString.getToken(0, nSeparator, nIndex);
+        aToken = aToken.trim();
+        if (!aToken.isEmpty())
+            aRet.push_back(aToken);
+    }
+    while (nIndex >= 0);
+
+    return aRet;
+}
+
+static void lcl_convertRectangle(const OUString& rString, Rectangle& rRectangle)
+{
+    uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(rString);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), aSeq.getLength());
+    rRectangle.setX(aSeq[0].toInt32());
+    rRectangle.setY(aSeq[1].toInt32());
+    rRectangle.setWidth(aSeq[2].toInt32());
+    rRectangle.setHeight(aSeq[3].toInt32());
+}
+
 void SdTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
 {
     switch (nType)
@@ -111,13 +143,18 @@ void SdTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
     {
         OUString aPayload = OUString::createFromAscii(pPayload);
         if (aPayload != "EMPTY" && m_aInvalidation.IsEmpty())
+            lcl_convertRectangle(aPayload, m_aInvalidation);
+    }
+    break;
+    case LOK_CALLBACK_TEXT_SELECTION:
+    {
+        OUString aPayload = OUString::createFromAscii(pPayload);
+        m_aSelection.clear();
+        for (const OUString& rString : lcl_convertSeparated(aPayload, static_cast<sal_Unicode>(';')))
         {
-            uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(aPayload);
-            CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), aSeq.getLength());
-            m_aInvalidation.setX(aSeq[0].toInt32());
-            m_aInvalidation.setY(aSeq[1].toInt32());
-            m_aInvalidation.setWidth(aSeq[2].toInt32());
-            m_aInvalidation.setHeight(aSeq[3].toInt32());
+            Rectangle aRectangle;
+            lcl_convertRectangle(rString, aRectangle);
+            m_aSelection.push_back(aRectangle);
         }
     }
     break;
@@ -269,6 +306,31 @@ void SdTiledRenderingTest::testResetSelection()
     CPPUNIT_ASSERT(!pView->GetTextEditObject());
 }
 
+void SdTiledRenderingTest::testSearch()
+{
+    SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp");
+    pXImpressDocument->registerCallback(&SdTiledRenderingTest::callback, this);
+    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.");
+
+    uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
+    {
+        {"SearchItem.SearchString", uno::makeAny(OUString("bbb"))},
+        {"SearchItem.Backward", uno::makeAny(false)}
+    }));
+    comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
+
+    sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+    SdrView* pView = pViewShell->GetView();
+    EditView& rEditView = pView->GetTextEditOutlinerView()->GetEditView();
+    // Did we indeed manage to select the second word?
+    CPPUNIT_ASSERT_EQUAL(OUString("bbb"), rEditView.GetSelected());
+
+    // Did the selection callback fire?
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), m_aSelection.size());
+}
+
 #endif
 
 CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest);


More information about the Libreoffice-commits mailing list