From 2bcf4407ebcd9b24feee5dd3dbd03df14389a539 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Wed, 11 May 2016 01:42:39 +0200 Subject: uitest: add method to get all children of a ui object This makes writing ui tests so much easier. Change-Id: Ice7d98c354fc9b68ee4532bc854561b5b9446e3f --- include/vcl/uitest/uiobject.hxx | 9 ++++++++ offapi/com/sun/star/ui/test/XUIObject.idl | 2 ++ vcl/source/uitest/uiobject.cxx | 37 +++++++++++++++++++++++++++++++ vcl/source/uitest/uno/uiobject_uno.cxx | 20 +++++++++++++++++ vcl/source/uitest/uno/uiobject_uno.hxx | 3 +++ 5 files changed, 71 insertions(+) diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx index f4c6ddba54bd..4ea2897908b9 100644 --- a/include/vcl/uitest/uiobject.hxx +++ b/include/vcl/uitest/uiobject.hxx @@ -14,6 +14,8 @@ #include #include +#include + typedef std::map StringMap; /** @@ -54,6 +56,11 @@ public: */ virtual std::unique_ptr get_child(const OUString& rID); + /** + * Returns a set containing all decendants of the object. + */ + virtual std::set get_children() const; + /** * Currently an internal method to dump the state of the current UIObject as represented by get_state(). * @@ -98,6 +105,8 @@ public: virtual std::unique_ptr get_child(const OUString& rID) override; + virtual std::set get_children() const override; + virtual void dumpState() const override; virtual void dumpHierarchy() const override; diff --git a/offapi/com/sun/star/ui/test/XUIObject.idl b/offapi/com/sun/star/ui/test/XUIObject.idl index 9a0ca6b36fd0..9409490226ff 100644 --- a/offapi/com/sun/star/ui/test/XUIObject.idl +++ b/offapi/com/sun/star/ui/test/XUIObject.idl @@ -23,6 +23,8 @@ interface XUIObject com::sun::star::beans::PropertyValues getState(); string getType(); + + sequence getChildren(); }; }; }; }; }; }; diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx index e7378c61805e..bc6c26b87a52 100644 --- a/vcl/source/uitest/uiobject.cxx +++ b/vcl/source/uitest/uiobject.cxx @@ -56,6 +56,11 @@ std::unique_ptr UIObject::get_child(const OUString&) return std::unique_ptr(); } +std::set UIObject::get_children() const +{ + return std::set(); +} + void UIObject::dumpState() const { } @@ -311,6 +316,29 @@ vcl::Window* findChild(vcl::Window* pParent, const OUString& rID) return nullptr; } +void addChildren(vcl::Window* pParent, std::set& rChildren) +{ + if (!pParent) + return; + + size_t nCount = pParent->GetChildCount(); + for (size_t i = 0; i < nCount; ++i) + { + vcl::Window* pChild = pParent->GetChild(i); + if (pChild) + { + OUString aId = pChild->get_id(); + if (!aId.isEmpty()) + { + auto ret = rChildren.insert(aId); + SAL_WARN_IF(!ret.second, "vcl.uitest", "duplicate ids for ui elements. violates locally unique requirement"); + } + + addChildren(pChild, rChildren); + } + } +} + } std::unique_ptr WindowUIObject::get_child(const OUString& rID) @@ -322,6 +350,15 @@ std::unique_ptr WindowUIObject::get_child(const OUString& rID) return aFunction(pWindow); } +std::set WindowUIObject::get_children() const +{ + vcl::Window* pDialogParent = get_dialog_parent(mxWindow.get()); + std::set aChildren; + aChildren.insert(pDialogParent->get_id()); + addChildren(pDialogParent, aChildren); + return aChildren; +} + OUString WindowUIObject::get_name() const { return OUString("WindowUIObject"); diff --git a/vcl/source/uitest/uno/uiobject_uno.cxx b/vcl/source/uitest/uno/uiobject_uno.cxx index 998a0d9a78b8..7c6ca8398b90 100644 --- a/vcl/source/uitest/uno/uiobject_uno.cxx +++ b/vcl/source/uitest/uno/uiobject_uno.cxx @@ -10,6 +10,8 @@ #include "uiobject_uno.hxx" #include +#include + UIObjectUnoObj::UIObjectUnoObj(std::unique_ptr pObj): UIObjectBase(m_aMutex), mpObj(std::move(pObj)) @@ -69,6 +71,24 @@ css::uno::Sequence UIObjectUnoObj::getState() return aProps; } +css::uno::Sequence UIObjectUnoObj::getChildren() + throw (css::uno::RuntimeException, std::exception) +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + std::set aChildren = mpObj->get_children(); + + css::uno::Sequence aRet(aChildren.size()); + sal_Int32 i = 0; + for (auto itr = aChildren.begin(), itrEnd = aChildren.end(); itr != itrEnd; ++itr, ++i) + { + aRet[i] = *itr; + } + + return aRet; +} + OUString SAL_CALL UIObjectUnoObj::getType() throw (css::uno::RuntimeException, std::exception) { diff --git a/vcl/source/uitest/uno/uiobject_uno.hxx b/vcl/source/uitest/uno/uiobject_uno.hxx index d3519bfbaadc..fe0669a0c977 100644 --- a/vcl/source/uitest/uno/uiobject_uno.hxx +++ b/vcl/source/uitest/uno/uiobject_uno.hxx @@ -46,6 +46,9 @@ public: css::uno::Sequence SAL_CALL getState() throw (css::uno::RuntimeException, std::exception) override; + css::uno::Sequence SAL_CALL getChildren() + throw (css::uno::RuntimeException, std::exception) override; + OUString SAL_CALL getType() throw (css::uno::RuntimeException, std::exception) override; -- cgit