[Libreoffice-commits] core.git: 2 commits - include/vcl vcl/source

Markus Mohrhard markus.mohrhard at googlemail.com
Mon Feb 27 23:31:07 UTC 2017


 include/vcl/scheduler.hxx              |    6 +
 vcl/source/app/svapp.cxx               |    8 ++
 vcl/source/uitest/uno/uiobject_uno.cxx |  110 ++++++++++++++++++++++++++++++---
 vcl/source/uitest/uno/uiobject_uno.hxx |   15 ++++
 4 files changed, 128 insertions(+), 11 deletions(-)

New commits:
commit 70f89e6b9f89177fc60f9cc9b55a87fdc5c6017f
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Feb 27 16:09:36 2017 +0100

    uitest: move the processing of actions into the idle handler
    
    Change-Id: Idead7314096f879f147dd87e6ce8f4b79b8f70c1
    Reviewed-on: https://gerrit.libreoffice.org/34691
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/vcl/source/uitest/uno/uiobject_uno.cxx b/vcl/source/uitest/uno/uiobject_uno.cxx
index c3db38a..ec2e3f7 100644
--- a/vcl/source/uitest/uno/uiobject_uno.cxx
+++ b/vcl/source/uitest/uno/uiobject_uno.cxx
@@ -9,17 +9,24 @@
 
 #include "uiobject_uno.hxx"
 #include <vcl/svapp.hxx>
+#include <vcl/idle.hxx>
 
 #include <set>
+#include <chrono>
+#include <thread>
 
 UIObjectUnoObj::UIObjectUnoObj(std::unique_ptr<UIObject> pObj):
     UIObjectBase(m_aMutex),
-    mpObj(std::move(pObj))
+    mpObj(std::move(pObj)),
+    mReady(true)
 {
 }
 
 UIObjectUnoObj::~UIObjectUnoObj()
 {
+    {
+        std::lock_guard<std::mutex> lk3(mMutex);
+    }
     SolarMutexGuard aGuard;
     mpObj.reset();
 }
@@ -34,22 +41,105 @@ css::uno::Reference<css::ui::test::XUIObject> SAL_CALL UIObjectUnoObj::getChild(
     return new UIObjectUnoObj(std::move(pObj));
 }
 
+IMPL_LINK_NOARG(UIObjectUnoObj, NotifyHdl, Timer*, void)
+{
+    std::lock_guard<std::mutex> lk(mMutex);
+    mReady = true;
+    cv.notify_all();
+}
+
+namespace {
+
+class ExecuteWrapper
+{
+    std::function<void()> mFunc;
+    Link<Timer*, void> mHandler;
+    bool mbSignal;
+    std::mutex mMutex;
+
+public:
+
+    ExecuteWrapper(std::function<void()> func, Link<Timer*, void> handler):
+        mFunc(func),
+        mHandler(handler),
+        mbSignal(false)
+    {
+    }
+
+    void setSignal()
+    {
+        mbSignal = true;
+    }
+
+    std::mutex& getMutex()
+    {
+        return mMutex;
+    }
+
+    DECL_LINK( ExecuteActionHdl, Timer*, void );
+};
+
+
+IMPL_LINK_NOARG(ExecuteWrapper, ExecuteActionHdl, Timer*, void)
+{
+    Idle aIdle;
+    {
+        mFunc();
+        aIdle.SetDebugName("UI Test Idle Handler2");
+        aIdle.SetPriority(TaskPriority::LOWEST);
+        aIdle.SetInvokeHandler(mHandler);
+        aIdle.Start();
+    }
+
+    Scheduler::ProcessEventsToSignal(mbSignal);
+    std::unique_lock<std::mutex> lock(mMutex);
+    while (!mbSignal)
+    {
+        std::this_thread::sleep_for(std::chrono::milliseconds(5));
+    }
+    delete this;
+}
+
+}
+
 void SAL_CALL UIObjectUnoObj::executeAction(const OUString& rAction, const css::uno::Sequence<css::beans::PropertyValue>& rPropValues)
 {
     if (!mpObj)
         throw css::uno::RuntimeException();
 
-    SolarMutexGuard aGuard;
-    StringMap aMap;
-    for (sal_Int32 i = 0, n = rPropValues.getLength(); i < n; ++i)
+    std::unique_lock<std::mutex> lk(mMutex);
+    mAction = rAction;
+    mPropValues = rPropValues;
+    mReady = false;
+    Idle aIdle;
+    aIdle.SetDebugName("UI Test Idle Handler");
+    aIdle.SetPriority(TaskPriority::HIGH);
+
+    std::function<void()> func = [this](){
+
+        SolarMutexGuard aGuard;
+        StringMap aMap;
+        for (sal_Int32 i = 0, n = mPropValues.getLength(); i < n; ++i)
+        {
+            OUString aVal;
+            if (!(mPropValues[i].Value >>= aVal))
+                continue;
+
+            aMap[mPropValues[i].Name] = aVal;
+        }
+        mpObj->execute(mAction, aMap);
+    };
+
+    ExecuteWrapper* pWrapper = new ExecuteWrapper(func, LINK(this, UIObjectUnoObj, NotifyHdl));
+    std::unique_lock<std::mutex>(pWrapper->getMutex());
+    aIdle.SetInvokeHandler(LINK(pWrapper, ExecuteWrapper, ExecuteActionHdl));
     {
-        OUString aVal;
-        if (!(rPropValues[i].Value >>= aVal))
-            continue;
-
-        aMap[rPropValues[i].Name] = aVal;
+        SolarMutexGuard aGuard;
+        aIdle.Start();
     }
-    mpObj->execute(rAction, aMap);
+
+    cv.wait(lk, [this]{return mReady;});
+    pWrapper->setSignal();
 }
 
 css::uno::Sequence<css::beans::PropertyValue> UIObjectUnoObj::getState()
diff --git a/vcl/source/uitest/uno/uiobject_uno.hxx b/vcl/source/uitest/uno/uiobject_uno.hxx
index b709cdc..9ce3f13 100644
--- a/vcl/source/uitest/uno/uiobject_uno.hxx
+++ b/vcl/source/uitest/uno/uiobject_uno.hxx
@@ -19,9 +19,13 @@
 #include <com/sun/star/beans/PropertyValues.hpp>
 
 #include <memory>
+#include <condition_variable>
+#include <mutex>
 
 #include <vcl/uitest/uiobject.hxx>
 
+class Timer;
+
 typedef ::cppu::WeakComponentImplHelper <
     css::ui::test::XUIObject, css::lang::XServiceInfo
     > UIObjectBase;
@@ -54,6 +58,17 @@ public:
     css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
 
     OUString SAL_CALL getHierarchy() override;
+
+private:
+
+    DECL_LINK( NotifyHdl, Timer*, void );
+
+    std::condition_variable cv;
+    std::mutex mMutex;
+    bool mReady;
+
+    OUString mAction;
+    css::uno::Sequence<css::beans::PropertyValue> mPropValues;
 };
 
 #endif
commit 2d48c9dce371f9121c00f07ab3b977c1157f623a
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Feb 27 13:51:27 2017 +0100

    uitest: add scheduler method that runs until a signal is received
    
    The other method only runs 1000 events.
    
    Change-Id: I43076988e9e25b35e3fdfd8dff19270d9e066d9a
    Reviewed-on: https://gerrit.libreoffice.org/34690
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/include/vcl/scheduler.hxx b/include/vcl/scheduler.hxx
index 19fbb4f..d504e28 100644
--- a/include/vcl/scheduler.hxx
+++ b/include/vcl/scheduler.hxx
@@ -44,8 +44,12 @@ public:
     static sal_uInt64 CalculateMinimumTimeout( bool &bHasActiveIdles );
     /// Process one pending task ahead of time with highest priority.
     static bool       ProcessTaskScheduling( bool bIdle );
-    /// Process all events until we are idle
+    /**
+     * Process events until the parameter turns true,
+     * allows processing until a specific event has been processed
+     */
     static void       ProcessEventsToIdle();
+    static void       ProcessEventsToSignal(bool& bSignal);
 
     /// Control the deterministic mode.  In this mode, two subsequent runs of
     /// LibreOffice fire about the same amount idles.
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index c2d0c8a..6184596 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -530,6 +530,14 @@ void Application::Reschedule( bool i_bAllEvents )
     ImplYield(false, i_bAllEvents, 0);
 }
 
+void Scheduler::ProcessEventsToSignal(bool& bSignal)
+{
+    while(!bSignal && (Scheduler::ProcessTaskScheduling( true ) ||
+          ImplYield(false, false, 0)))
+    {
+    }
+}
+
 void Scheduler::ProcessEventsToIdle()
 {
     int nSanity = 1000;


More information about the Libreoffice-commits mailing list