From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- vcl/source/uitest/uno/uiobject_uno.cxx | 224 +++++++++++++++++++++++++++++++++ vcl/source/uitest/uno/uiobject_uno.hxx | 55 ++++++++ vcl/source/uitest/uno/uitest_uno.cxx | 121 ++++++++++++++++++ 3 files changed, 400 insertions(+) create mode 100644 vcl/source/uitest/uno/uiobject_uno.cxx create mode 100644 vcl/source/uitest/uno/uiobject_uno.hxx create mode 100644 vcl/source/uitest/uno/uitest_uno.cxx (limited to 'vcl/source/uitest/uno') diff --git a/vcl/source/uitest/uno/uiobject_uno.cxx b/vcl/source/uitest/uno/uiobject_uno.cxx new file mode 100644 index 000000000..042b2fcf5 --- /dev/null +++ b/vcl/source/uitest/uno/uiobject_uno.cxx @@ -0,0 +1,224 @@ +/* -*- 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 + +#include +#include +#include +#include +#include +#include "uiobject_uno.hxx" +#include +#include +#include +#include +#include +#include +#include + +#include + +class Timer; + +namespace { + +struct Notifier { + std::condition_variable cv; + std::mutex mMutex; + bool mReady = false; + + DECL_LINK( NotifyHdl, Timer*, void ); +}; + +} + +UIObjectUnoObj::UIObjectUnoObj(std::unique_ptr pObj): + UIObjectBase(m_aMutex), + mpObj(std::move(pObj)) +{ +} + +UIObjectUnoObj::~UIObjectUnoObj() +{ + SolarMutexGuard aGuard; + mpObj.reset(); +} + +css::uno::Reference SAL_CALL UIObjectUnoObj::getChild(const OUString& rID) +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + SolarMutexGuard aGuard; + std::unique_ptr pObj = mpObj->get_child(rID); + return new UIObjectUnoObj(std::move(pObj)); +} + +IMPL_LINK_NOARG(Notifier, NotifyHdl, Timer*, void) +{ + std::scoped_lock lk(mMutex); + mReady = true; + cv.notify_all(); +} + +namespace { + +class ExecuteWrapper +{ + std::function mFunc; + Link mHandler; + std::atomic mbSignal; + +public: + + ExecuteWrapper(std::function func, Link 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("UI Test Idle Handler2"); + { + mFunc(); + 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& rPropValues) +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + auto aIdle = std::make_unique("UI Test Idle Handler"); + aIdle->SetPriority(TaskPriority::HIGHEST); + + std::function func = [&rAction, &rPropValues, this](){ + + SolarMutexGuard aGuard; + StringMap aMap; + for (const auto& rPropVal : rPropValues) + { + OUString aVal; + if (!(rPropVal.Value >>= aVal)) + continue; + + aMap[rPropVal.Name] = aVal; + } + mpObj->execute(rAction, aMap); + }; + + Notifier notifier; + ExecuteWrapper* pWrapper = new ExecuteWrapper(std::move(func), LINK(¬ifier, Notifier, NotifyHdl)); + aIdle->SetInvokeHandler(LINK(pWrapper, ExecuteWrapper, ExecuteActionHdl)); + { + SolarMutexGuard aGuard; + aIdle->Start(); + } + + { + std::unique_lock lk(notifier.mMutex); + notifier.cv.wait(lk, [¬ifier]{return notifier.mReady;}); + } + pWrapper->setSignal(); + + SolarMutexGuard aGuard; + aIdle.reset(); +} + +css::uno::Sequence UIObjectUnoObj::getState() +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + SolarMutexGuard aGuard; + StringMap aMap = mpObj->get_state(); + css::uno::Sequence aProps(aMap.size()); + std::transform(aMap.begin(), aMap.end(), aProps.getArray(), + [](auto const& elem) + { return comphelper::makePropertyValue(elem.first, elem.second); }); + + return aProps; +} + +css::uno::Sequence UIObjectUnoObj::getChildren() +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + std::set aChildren; + + { + SolarMutexGuard aGuard; + aChildren = mpObj->get_children(); + } + + css::uno::Sequence aRet(aChildren.size()); + std::copy(aChildren.begin(), aChildren.end(), aRet.getArray()); + + return aRet; +} + +OUString SAL_CALL UIObjectUnoObj::getType() +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + SolarMutexGuard aGuard; + 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 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..47fc54696 --- /dev/null +++ b/vcl/source/uitest/uno/uiobject_uno.hxx @@ -0,0 +1,55 @@ +/* -*- 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/. + */ + +#pragma once + +#include +#include +#include +#include + +#include + +#include + +typedef ::cppu::WeakComponentImplHelper < + css::ui::test::XUIObject, css::lang::XServiceInfo + > UIObjectBase; + +class UIObjectUnoObj : public cppu::BaseMutex, + public UIObjectBase +{ +private: + std::unique_ptr mpObj; + +public: + + explicit UIObjectUnoObj(std::unique_ptr pObj); + virtual ~UIObjectUnoObj() override; + + css::uno::Reference SAL_CALL getChild(const OUString& rID) override; + + void SAL_CALL executeAction(const OUString& rAction, const css::uno::Sequence& xPropValues) override; + + css::uno::Sequence SAL_CALL getState() override; + + css::uno::Sequence 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 SAL_CALL getSupportedServiceNames() override; + + OUString SAL_CALL getHierarchy() override; +}; + +/* 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..4e5a6e0e0 --- /dev/null +++ b/vcl/source/uitest/uno/uitest_uno.cxx @@ -0,0 +1,121 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#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 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 SAL_CALL getTopFocusWindow() override; + + css::uno::Reference SAL_CALL getFloatWindow() override; + + OUString SAL_CALL getImplementationName() override; + + sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; + + css::uno::Sequence 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 SAL_CALL UITestUnoObj::getTopFocusWindow() +{ + SolarMutexGuard aGuard; + std::unique_ptr pObj = UITest::getFocusTopWindow(); + return new UIObjectUnoObj(std::move(pObj)); +} + +css::uno::Reference SAL_CALL UITestUnoObj::getFloatWindow() +{ + SolarMutexGuard aGuard; + std::unique_ptr 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 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 const &) +{ + return cppu::acquire(new UITestUnoObj()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3