diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-02-27 16:09:36 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-02-27 23:30:47 +0000 |
commit | 70f89e6b9f89177fc60f9cc9b55a87fdc5c6017f (patch) | |
tree | 23247e9f6b052bf6f9e6ce07bab7a180975862cd | |
parent | 2d48c9dce371f9121c00f07ab3b977c1157f623a (diff) |
uitest: move the processing of actions into the idle handler
Change-Id: Idead7314096f879f147dd87e6ce8f4b79b8f70c1
Reviewed-on: https://gerrit.libreoffice.org/34691
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.cxx | 110 | ||||
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.hxx | 15 |
2 files changed, 115 insertions, 10 deletions
diff --git a/vcl/source/uitest/uno/uiobject_uno.cxx b/vcl/source/uitest/uno/uiobject_uno.cxx index c3db38a3a57e..ec2e3f7b31d5 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 b709cdc6a992..9ce3f135aa14 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 |