diff options
Diffstat (limited to 'vcl/source/uitest/uno')
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.cxx | 210 | ||||
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.hxx | 73 | ||||
-rw-r--r-- | vcl/source/uitest/uno/uitest_uno.cxx | 120 |
3 files changed, 403 insertions, 0 deletions
diff --git a/vcl/source/uitest/uno/uiobject_uno.cxx b/vcl/source/uitest/uno/uiobject_uno.cxx new file mode 100644 index 000000000..593f4a4c1 --- /dev/null +++ b/vcl/source/uitest/uno/uiobject_uno.cxx @@ -0,0 +1,210 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <memory> +#include "uiobject_uno.hxx" +#include <utility> +#include <cppuhelper/supportsservice.hxx> +#include <vcl/svapp.hxx> +#include <vcl/idle.hxx> + +#include <set> + +UIObjectUnoObj::UIObjectUnoObj(std::unique_ptr<UIObject> pObj): + UIObjectBase(m_aMutex), + mpObj(std::move(pObj)), + mReady(true) +{ +} + +UIObjectUnoObj::~UIObjectUnoObj() +{ + { + std::scoped_lock<std::mutex> lk3(mMutex); + } + SolarMutexGuard aGuard; + mpObj.reset(); +} + +css::uno::Reference<css::ui::test::XUIObject> SAL_CALL UIObjectUnoObj::getChild(const OUString& rID) +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + SolarMutexGuard aGuard; + std::unique_ptr<UIObject> pObj = mpObj->get_child(rID); + return new UIObjectUnoObj(std::move(pObj)); +} + +IMPL_LINK_NOARG(UIObjectUnoObj, NotifyHdl, Timer*, void) +{ + std::scoped_lock<std::mutex> lk(mMutex); + mReady = true; + cv.notify_all(); +} + +namespace { + +class ExecuteWrapper +{ + std::function<void()> mFunc; + Link<Timer*, void> mHandler; + volatile bool mbSignal; + +public: + + ExecuteWrapper(std::function<void()> func, Link<Timer*, void> handler): + mFunc(std::move(func)), + mHandler(handler), + mbSignal(false) + { + } + + void setSignal() + { + mbSignal = true; + } + + 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(); + } + + while (!mbSignal) { + Application::Reschedule(); + } + } + delete this; +} + +} + +void SAL_CALL UIObjectUnoObj::executeAction(const OUString& rAction, const css::uno::Sequence<css::beans::PropertyValue>& rPropValues) +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + std::unique_lock<std::mutex> lk(mMutex); + mAction = rAction; + mPropValues = rPropValues; + mReady = false; + auto aIdle = std::make_unique<Idle>(); + aIdle->SetDebugName("UI Test Idle Handler"); + aIdle->SetPriority(TaskPriority::HIGHEST); + + std::function<void()> func = [this](){ + + SolarMutexGuard aGuard; + StringMap aMap; + for (const auto& rPropVal : std::as_const(mPropValues)) + { + OUString aVal; + if (!(rPropVal.Value >>= aVal)) + continue; + + aMap[rPropVal.Name] = aVal; + } + mpObj->execute(mAction, aMap); + }; + + ExecuteWrapper* pWrapper = new ExecuteWrapper(func, LINK(this, UIObjectUnoObj, NotifyHdl)); + aIdle->SetInvokeHandler(LINK(pWrapper, ExecuteWrapper, ExecuteActionHdl)); + { + SolarMutexGuard aGuard; + aIdle->Start(); + } + + cv.wait(lk, [this]{return mReady;}); + pWrapper->setSignal(); + + SolarMutexGuard aGuard; + aIdle.reset(); +} + +css::uno::Sequence<css::beans::PropertyValue> UIObjectUnoObj::getState() +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + SolarMutexGuard aGuard; + StringMap aMap = mpObj->get_state(); + css::uno::Sequence<css::beans::PropertyValue> aProps(aMap.size()); + sal_Int32 i = 0; + for (auto const& elem : aMap) + { + aProps[i].Name = elem.first; + aProps[i].Value <<= elem.second; + ++i; + } + + return aProps; +} + +css::uno::Sequence<OUString> UIObjectUnoObj::getChildren() +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + std::set<OUString> aChildren = mpObj->get_children(); + + css::uno::Sequence<OUString> aRet(aChildren.size()); + sal_Int32 i = 0; + for (auto const& child : aChildren) + { + aRet[i] = child; + ++i; + } + + return aRet; +} + +OUString SAL_CALL UIObjectUnoObj::getType() +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + return mpObj->get_type(); +} + +OUString SAL_CALL UIObjectUnoObj::getImplementationName() +{ + return "org.libreoffice.uitest.UIObject"; +} + +sal_Bool UIObjectUnoObj::supportsService(OUString const & ServiceName) +{ + return cppu::supportsService(this, ServiceName); +} + +css::uno::Sequence<OUString> UIObjectUnoObj::getSupportedServiceNames() +{ + return { "com.sun.star.ui.test.UIObject" }; +} + +OUString SAL_CALL UIObjectUnoObj::getHierarchy() +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + SolarMutexGuard aGuard; + return mpObj->dumpHierarchy(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/uitest/uno/uiobject_uno.hxx b/vcl/source/uitest/uno/uiobject_uno.hxx new file mode 100644 index 000000000..2f98ab7c0 --- /dev/null +++ b/vcl/source/uitest/uno/uiobject_uno.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_VCL_SOURCE_UITEST_UNO_UIOBJECT_UNO_HXX +#define INCLUDED_VCL_SOURCE_UITEST_UNO_UIOBJECT_UNO_HXX + +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/ui/test/XUIObject.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; + +class UIObjectUnoObj : public cppu::BaseMutex, + public UIObjectBase +{ +private: + std::unique_ptr<UIObject> mpObj; + +public: + + explicit UIObjectUnoObj(std::unique_ptr<UIObject> pObj); + virtual ~UIObjectUnoObj() override; + + css::uno::Reference<css::ui::test::XUIObject> SAL_CALL getChild(const OUString& rID) override; + + void SAL_CALL executeAction(const OUString& rAction, const css::uno::Sequence<css::beans::PropertyValue>& xPropValues) override; + + css::uno::Sequence<css::beans::PropertyValue> SAL_CALL getState() override; + + css::uno::Sequence<OUString> SAL_CALL getChildren() override; + + OUString SAL_CALL getType() override; + + OUString SAL_CALL getImplementationName() override; + + sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; + + 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/uitest/uno/uitest_uno.cxx b/vcl/source/uitest/uno/uitest_uno.cxx new file mode 100644 index 000000000..d0d70a816 --- /dev/null +++ b/vcl/source/uitest/uno/uitest_uno.cxx @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/ui/test/XUITest.hpp> + +#include <memory> + +#include <vcl/uitest/uitest.hxx> +#include <vcl/svapp.hxx> + +#include "uiobject_uno.hxx" + +namespace +{ + typedef ::cppu::WeakComponentImplHelper < + css::ui::test::XUITest, css::lang::XServiceInfo + > UITestBase; + +class UITestUnoObj : public cppu::BaseMutex, + public UITestBase +{ +private: + std::unique_ptr<UITest> mpUITest; + +public: + + UITestUnoObj(); + + sal_Bool SAL_CALL executeCommand(const OUString& rCommand) override; + + sal_Bool SAL_CALL executeCommandWithParameters(const OUString& rCommand, + const css::uno::Sequence< css::beans::PropertyValue >& rArgs) override; + + sal_Bool SAL_CALL executeDialog(const OUString& rCommand) override; + + css::uno::Reference<css::ui::test::XUIObject> SAL_CALL getTopFocusWindow() override; + + css::uno::Reference<css::ui::test::XUIObject> SAL_CALL getFloatWindow() override; + + OUString SAL_CALL getImplementationName() override; + + sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; + + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; +}; + +} + +UITestUnoObj::UITestUnoObj(): + UITestBase(m_aMutex), + mpUITest(new UITest) +{ +} + +sal_Bool SAL_CALL UITestUnoObj::executeCommand(const OUString& rCommand) +{ + SolarMutexGuard aGuard; + return UITest::executeCommand(rCommand); +} + +sal_Bool SAL_CALL UITestUnoObj::executeCommandWithParameters(const OUString& rCommand, + const css::uno::Sequence< css::beans::PropertyValue >& rArgs) +{ + SolarMutexGuard aGuard; + return UITest::executeCommandWithParameters(rCommand,rArgs); +} + +sal_Bool SAL_CALL UITestUnoObj::executeDialog(const OUString& rCommand) +{ + SolarMutexGuard aGuard; + return UITest::executeDialog(rCommand); +} + +css::uno::Reference<css::ui::test::XUIObject> SAL_CALL UITestUnoObj::getTopFocusWindow() +{ + SolarMutexGuard aGuard; + std::unique_ptr<UIObject> pObj = UITest::getFocusTopWindow(); + return new UIObjectUnoObj(std::move(pObj)); +} + +css::uno::Reference<css::ui::test::XUIObject> SAL_CALL UITestUnoObj::getFloatWindow() +{ + SolarMutexGuard aGuard; + std::unique_ptr<UIObject> pObj = UITest::getFloatWindow(); + return new UIObjectUnoObj(std::move(pObj)); +} + +OUString SAL_CALL UITestUnoObj::getImplementationName() +{ + return "org.libreoffice.uitest.UITest"; +} + +sal_Bool UITestUnoObj::supportsService(OUString const & ServiceName) +{ + return cppu::supportsService(this, ServiceName); +} + +css::uno::Sequence<OUString> UITestUnoObj::getSupportedServiceNames() +{ + return { "com.sun.star.ui.test.UITest" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +UITest_get_implementation(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &) +{ + return cppu::acquire(new UITestUnoObj()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |